Create the join operator based on conditions and join type.
374112 {
374113 auto is_asof = (ref_type == JoinRefType::ASOF);
374114
374115
374116 if (is_asof) {
374118 case JoinType::RIGHT:
374119 case JoinType::OUTER:
374120
374121 if (!arbitrary_expressions.empty()) {
374122 throw NotImplementedException("Unsupported ASOF JOIN type (%s) with arbitrary predicate",
374123 EnumUtil::ToChars(
type));
374124 }
374125 break;
374126 case JoinType::SEMI:
374127 case JoinType::ANTI:
374128
374129
374130 is_asof = false;
374131 ref_type = JoinRefType::REGULAR;
374132 break;
374133 default:
374134 break;
374135 }
374136
374138 for (
size_t c = 0; c <
conditions.size(); ++c) {
374140 switch (cond.comparison) {
374141 case ExpressionType::COMPARE_EQUAL:
374142 case ExpressionType::COMPARE_NOT_DISTINCT_FROM:
374143 break;
374144 case ExpressionType::COMPARE_GREATERTHANOREQUALTO:
374145 case ExpressionType::COMPARE_GREATERTHAN:
374146 case ExpressionType::COMPARE_LESSTHANOREQUALTO:
374147 case ExpressionType::COMPARE_LESSTHAN:
374149 throw BinderException("Multiple ASOF JOIN inequalities");
374150 }
374151 asof_idx = c;
374152 break;
374153 default:
374154 throw BinderException("Invalid ASOF JOIN comparison");
374155 }
374156 }
374158 throw BinderException("Missing ASOF JOIN inequality");
374159 }
374160 }
374161
374162
374163
374164 if (is_asof) {
374165 auto asof_join = make_uniq<LogicalComparisonJoin>(
type, LogicalOperatorType::LOGICAL_ASOF_JOIN);
374166 asof_join->conditions = std::move(
conditions);
374167 asof_join->children.push_back(std::move(left_child));
374168 asof_join->children.push_back(std::move(right_child));
374169
374170 if (!arbitrary_expressions.empty()) {
374171 asof_join->predicate = std::move(arbitrary_expressions[0]);
374172 for (
idx_t i = 1; i < arbitrary_expressions.size(); i++) {
374173 asof_join->predicate = make_uniq<BoundConjunctionExpression>(ExpressionType::CONJUNCTION_AND,
374174 std::move(asof_join->predicate),
374175 std::move(arbitrary_expressions[i]));
374176 }
374177 }
374178
374179 return std::move(asof_join);
374180 }
374181
374182
374184 if (arbitrary_expressions.empty()) {
374185 arbitrary_expressions.push_back(make_uniq<BoundConstantExpression>(
Value::BOOLEAN(
true)));
374186 }
374187
374188 auto any_join = make_uniq<LogicalAnyJoin>(
type);
374189 any_join->children.push_back(std::move(left_child));
374190 any_join->children.push_back(std::move(right_child));
374191
374192 any_join->condition = std::move(arbitrary_expressions[0]);
374193 for (
idx_t i = 1; i < arbitrary_expressions.size(); i++) {
374194 any_join->condition = make_uniq<BoundConjunctionExpression>(
374195 ExpressionType::CONJUNCTION_AND, std::move(any_join->condition), std::move(arbitrary_expressions[i]));
374196 }
374197
374198 return std::move(any_join);
374199 }
374200
374201
374202 if (!arbitrary_expressions.empty()) {
374203
374204 if (
type == JoinType::INNER) {
374205 auto comp_join = make_uniq<LogicalComparisonJoin>(
type, LogicalOperatorType::LOGICAL_COMPARISON_JOIN);
374206 comp_join->conditions = std::move(
conditions);
374207 comp_join->children.push_back(std::move(left_child));
374208 comp_join->children.push_back(std::move(right_child));
374209
374210 auto filter = make_uniq<LogicalFilter>();
374211 for (auto &expr : arbitrary_expressions) {
374212 filter->expressions.push_back(std::move(expr));
374213 }
374214 filter->children.push_back(std::move(comp_join));
374215
374216 return std::move(filter);
374217 } else {
374218 auto any_join = make_uniq<LogicalAnyJoin>(
type);
374219 any_join->children.push_back(std::move(left_child));
374220 any_join->children.push_back(std::move(right_child));
374221
374224 any_join->condition = make_uniq<BoundConjunctionExpression>(
374225 ExpressionType::CONJUNCTION_AND, std::move(any_join->condition),
374227 }
374228
374229 for (auto &expr : arbitrary_expressions) {
374230 any_join->condition = make_uniq<BoundConjunctionExpression>(
374231 ExpressionType::CONJUNCTION_AND, std::move(any_join->condition), std::move(expr));
374232 }
374233
374234 return std::move(any_join);
374235 }
374236 }
374237
374238
374239 auto comp_join = make_uniq<LogicalComparisonJoin>(
type, LogicalOperatorType::LOGICAL_COMPARISON_JOIN);
374240 comp_join->conditions = std::move(
conditions);
374241 comp_join->children.push_back(std::move(left_child));
374242 comp_join->children.push_back(std::move(right_child));
374243
374244 return std::move(comp_join);
374245}
static DUCKDB_API Value BOOLEAN(bool value)
Create a boolean Value from a specified value.
Definition duckdb.cpp:132118
void filter(InputArray image, InputArray kernel, OutputArray output)
static unique_ptr< Expression > CreateExpression(JoinCondition cond)
Turns the JoinCondition into an expression; note that this destroys the JoinCondition as the expressi...
Definition duckdb.cpp:380359