149262 {
149263
149264
149265 auto expression_type = expr.GetExpressionType();
149266 if (expression_type == ExpressionType::COMPARE_IN || expression_type == ExpressionType::COMPARE_NOT_IN) {
149267 if (expr.children.size() < 2) {
149268 throw InvalidInputException("IN needs at least two children");
149269 }
149270
149271 Vector left(expr.children[0]->return_type);
149272
149273 Execute(*expr.children[0], state->child_states[0].get(), sel, count, left);
149274
149275
149276 Vector intermediate(LogicalType::BOOLEAN);
149278 intermediate.Reference(false_val);
149279
149280
149281
149282
149283 for (
idx_t child = 1; child < expr.children.size(); child++) {
149284 Vector vector_to_check(expr.children[child]->return_type);
149285 Vector comp_res(LogicalType::BOOLEAN);
149286
149287 Execute(*expr.children[child], state->child_states[child].get(), sel, count, vector_to_check);
149288 VectorOperations::Equals(left, vector_to_check, comp_res, count);
149289
149290 if (child == 1) {
149291
149292 intermediate.Reference(comp_res);
149293 } else {
149294
149295 Vector new_result(LogicalType::BOOLEAN, true, false);
149296 VectorOperations::Or(intermediate, comp_res, new_result, count);
149297 intermediate.Reference(new_result);
149298 }
149299 }
149300 if (expression_type == ExpressionType::COMPARE_NOT_IN) {
149301
149302 VectorOperations::Not(intermediate, result, count);
149303 } else {
149304
149305 result.Reference(intermediate);
149306 }
149307 } else if (expression_type == ExpressionType::OPERATOR_COALESCE) {
149308 SelectionVector sel_a(count);
149309 SelectionVector sel_b(count);
149310 SelectionVector slice_sel(count);
149311 SelectionVector result_sel(count);
149312 SelectionVector *next_sel = &sel_a;
149313 const SelectionVector *current_sel = sel;
149314 idx_t remaining_count = count;
149316 for (
idx_t child = 0; child < expr.children.size(); child++) {
149317 Vector vector_to_check(expr.children[child]->return_type);
149318 Execute(*expr.children[child], state->child_states[child].get(), current_sel, remaining_count,
149319 vector_to_check);
149320
149321 UnifiedVectorFormat vdata;
149322 vector_to_check.ToUnifiedFormat(remaining_count, vdata);
149323
149324 idx_t result_count = 0;
149325 next_count = 0;
149326 for (
idx_t i = 0; i < remaining_count; i++) {
149327 auto base_idx = current_sel ? current_sel->get_index(i) : i;
149328 auto idx = vdata.sel->get_index(i);
149329 if (vdata.validity.RowIsValid(idx)) {
149330 slice_sel.set_index(result_count, i);
149331 result_sel.set_index(result_count++, base_idx);
149332 } else {
149333 next_sel->set_index(next_count++, base_idx);
149334 }
149335 }
149336 if (result_count > 0) {
149337 vector_to_check.Slice(slice_sel, result_count);
149338 FillSwitch(vector_to_check, result, result_sel, NumericCast<sel_t>(result_count));
149339 }
149340 current_sel = next_sel;
149341 next_sel = next_sel == &sel_a ? &sel_b : &sel_a;
149342 remaining_count = next_count;
149343 if (next_count == 0) {
149344 break;
149345 }
149346 }
149347 if (remaining_count > 0) {
149348 for (
idx_t i = 0; i < remaining_count; i++) {
149349 FlatVector::SetNull(result, current_sel->get_index(i), true);
149350 }
149351 }
149352 if (sel) {
149353 result.Slice(*sel, count);
149354 } else if (count == 1) {
149355 result.SetVectorType(VectorType::CONSTANT_VECTOR);
149356 }
149357 } else if (expression_type == ExpressionType::OPERATOR_TRY) {
149358 auto &child_state = *state->child_states[0];
149359 Vector try_result(result.GetType());
149360 try {
149361 Execute(*expr.children[0], &child_state, sel, count, try_result);
149362 if (try_result.GetVectorType() == VectorType::CONSTANT_VECTOR) {
149363 result.Reference(try_result);
149364 return;
149365 }
149366 VectorOperations::Copy(try_result, result, count, 0, 0);
149367 return;
149368 } catch (std::exception &ex) {
149369 ErrorData error(ex);
149370 auto error_type = error.Type();
149372 throw;
149373 }
149374 }
149375
149376
149377 SelectionVector selvec(1);
149378 DataChunk intermediate;
149379 intermediate.
Initialize(GetAllocator(), {result.GetType()}, 1);
149380 for (
idx_t i = 0; i < count; i++) {
149381 intermediate.
Reset();
149382 intermediate.SetCardinality(1);
149383
149384
149385
149386 child_state.ResetDictionaryStates();
149387
149388 selvec.set_index(0, sel ? sel->get_index(i) : i);
149389 Value val(result.GetType());
149390 try {
149391 Execute(*expr.children[0], &child_state, &selvec, 1, intermediate.
data[0]);
149392 val = intermediate.GetValue(0, 0);
149393 } catch (std::exception &ex) {
149394 ErrorData error(ex);
149395 auto error_type = error.Type();
149397 throw;
149398 }
149399 }
149400 result.SetValue(i, val);
149401 }
149402 if (count == 1) {
149403 result.SetVectorType(VectorType::CONSTANT_VECTOR);
149404 }
149405 } else if (expr.children.size() == 1) {
149406 state->intermediate_chunk.Reset();
149407 auto &child = state->intermediate_chunk.data[0];
149408
149409 Execute(*expr.children[0], state->child_states[0].get(), sel, count, child);
149410 switch (expr.GetExpressionType()) {
149411 case ExpressionType::OPERATOR_NOT: {
149412 VectorOperations::Not(child, result, count);
149413 break;
149414 }
149415 case ExpressionType::OPERATOR_IS_NULL: {
149417 break;
149418 }
149419 case ExpressionType::OPERATOR_IS_NOT_NULL: {
149421 break;
149422 }
149423 default:
149424 throw NotImplementedException("Unsupported operator type with 1 child!");
149425 }
149426 } else {
149427 throw NotImplementedException("operator");
149428 }
149429}
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
vector< Vector > data
The vectors owned by the DataChunk.
Definition duckdb.hpp:11445
static DUCKDB_API bool IsExecutionError(ExceptionType type)
Whether this exception type can occur during execution of a query.
Definition duckdb.cpp:70769
static DUCKDB_API Value BOOLEAN(bool value)
Create a boolean Value from a specified value.
Definition duckdb.cpp:132118
static void IsNull(Vector &input, Vector &result, idx_t count)
result = IS NULL (input)
Definition duckdb.cpp:143320
static void IsNotNull(Vector &arg, Vector &result, idx_t count)
result = IS NOT NULL(input)
Definition duckdb.cpp:143316