310187 {
310188 if (expr.GetExpressionType() != ExpressionType::COMPARE_IN &&
310189 expr.GetExpressionType() != ExpressionType::COMPARE_NOT_IN) {
310190 return nullptr;
310191 }
310192 D_ASSERT(root);
310193 auto in_type = expr.children[0]->return_type;
310194 bool is_regular_in = expr.GetExpressionType() == ExpressionType::COMPARE_IN;
310195 bool all_scalar = true;
310196
310197
310198 for (
idx_t i = 1; i < expr.children.size(); i++) {
310199 if (!expr.children[i]->IsFoldable()) {
310200
310201 all_scalar = false;
310202 }
310203 }
310204 if (expr.children.size() == 2) {
310205
310206
310207
310208 return make_uniq<BoundComparisonExpression>(is_regular_in ? ExpressionType::COMPARE_EQUAL
310209 : ExpressionType::COMPARE_NOTEQUAL,
310210 std::move(expr.children[0]), std::move(expr.children[1]));
310211 }
310212 if (expr.children.size() < 6 || !all_scalar) {
310213
310214
310215
310216 auto conjunction = make_uniq<BoundConjunctionExpression>(is_regular_in ? ExpressionType::CONJUNCTION_OR
310217 : ExpressionType::CONJUNCTION_AND);
310218 for (
idx_t i = 1; i < expr.children.size(); i++) {
310219 conjunction->children.push_back(make_uniq<BoundComparisonExpression>(
310220 is_regular_in ? ExpressionType::COMPARE_EQUAL : ExpressionType::COMPARE_NOTEQUAL,
310221 expr.children[0]->Copy(), std::move(expr.children[i])));
310222 }
310223 return std::move(conjunction);
310224 }
310225
310226
310227
310228 vector<LogicalType> types = {in_type};
310229 auto collection = make_uniq<ColumnDataCollection>(context, types);
310230 ColumnDataAppendState append_state;
310231 collection->InitializeAppend(append_state);
310232
310233 DataChunk chunk;
310235 for (
idx_t i = 1; i < expr.children.size(); i++) {
310236
310237 Value value;
310239
310240 return nullptr;
310241 }
310243 chunk.SetCardinality(chunk.size() + 1);
310244 chunk.SetValue(0, index, value);
310245 if (chunk.size() == STANDARD_VECTOR_SIZE || i + 1 == expr.children.size()) {
310246
310247 collection->Append(append_state, chunk);
310249 }
310250 }
310251
310252 auto chunk_index = optimizer.binder.GenerateTableIndex();
310253 auto chunk_scan = make_uniq<LogicalColumnDataGet>(chunk_index, types, std::move(collection));
310254
310255
310256 auto mark_index = optimizer.binder.GenerateTableIndex();
310257 auto join = make_uniq<LogicalComparisonJoin>(JoinType::MARK);
310258 join->mark_index = mark_index;
310259 join->AddChild(std::move(root));
310260 join->AddChild(std::move(chunk_scan));
310261
310262 JoinCondition cond;
310263 cond.left = std::move(expr.children[0]);
310264
310265 cond.right = make_uniq<BoundColumnRefExpression>(in_type, ColumnBinding(chunk_index, 0));
310266 cond.comparison = ExpressionType::COMPARE_EQUAL;
310267 join->conditions.push_back(std::move(cond));
310268 root = std::move(join);
310269
310270 if (current_op->type == LogicalOperatorType::LOGICAL_FILTER) {
310271
310272 auto &
filter = current_op->Cast<LogicalFilter>();
310273 if (
filter.projection_map.empty()) {
310274 auto child_bindings = root->GetColumnBindings();
310275 for (
idx_t i = 0; i < child_bindings.size(); i++) {
310276 if (child_bindings[i].table_index != mark_index) {
310277 filter.projection_map.push_back(i);
310278 }
310279 }
310280 }
310281 }
310282
310283
310284 unique_ptr<Expression> result =
310285 make_uniq<BoundColumnRefExpression>("IN (...)", LogicalType::BOOLEAN, ColumnBinding(mark_index, 0));
310286 if (!is_regular_in) {
310287
310288 auto invert = make_uniq<BoundOperatorExpression>(ExpressionType::OPERATOR_NOT, LogicalType::BOOLEAN);
310289 invert->children.push_back(std::move(result));
310290 result = std::move(invert);
310291 }
310292 return result;
310293}
DUCKDB_API void Reset()
Definition duckdb.cpp:116840
DUCKDB_API void Initialize(ClientContext &context, const vector< LogicalType > &types, idx_t capacity=STANDARD_VECTOR_SIZE)
Definition duckdb.cpp:116791
static DUCKDB_API bool TryEvaluateScalar(ClientContext &context, const Expression &expr, Value &result)
Try to evaluate a scalar expression and fold it into a single value, returns false if an exception is...
Definition duckdb.cpp:150008
double invert(InputArray src, OutputArray dst, int flags=DECOMP_LU)
void filter(InputArray image, InputArray kernel, OutputArray output)
cv::String join(const cv::String &base, const cv::String &path)
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237