@@ -241,31 +241,45 @@ class PlanCCVisitor : public PlanVisitor {
241
241
TRY_WITH_EXCEPTION (info.data_type () == proto::schema::DataType::Array ||
242
242
info.data_type () == proto::schema::DataType::JSON);
243
243
auto elem = std::any_cast<ExprWithDtype>(expr_ret[1 ]->accept (this ));
244
+ TRY_WITH_EXCEPTION (elem.expr ->value_expr ().has_value () &&
245
+ elem.expr ->value_expr ().value ().has_array_val ());
244
246
if (info.data_type () == proto::schema::DataType::Array) {
245
- proto::plan::GenericValue expr =
246
- proto::plan::GenericValue (elem.expr ->value_expr ().value ());
247
- TRY_WITH_EXCEPTION (
248
- canBeCompared (field, toValueExpr (&expr, this ->arena .get ())));
247
+ auto arr = elem.expr ->value_expr ().value ().array_val ();
248
+ for (int idx = 0 ; idx < arr.array_size (); idx++) {
249
+ proto::plan::GenericValue expr = arr.array (idx);
250
+ TRY_WITH_EXCEPTION (canBeCompared (
251
+ field, toValueExpr (&expr, this ->arena .get ())));
252
+ }
249
253
}
250
254
251
255
auto expr = google::protobuf::Arena::CreateMessage<proto::plan::Expr>(
252
256
this ->arena .get ());
253
257
auto json_contain_expr = google::protobuf::Arena::CreateMessage<
254
258
proto::plan::JSONContainsExpr>(this ->arena .get ());
255
- auto value = json_contain_expr->add_elements (); // MayBe BUG
256
- value->unsafe_arena_set_allocated_array_val (
257
- CreateMessageWithCopy<proto::plan::Array>(
258
- this ->arena .get (),
259
- elem.expr ->value_expr ().value ().array_val ()));
259
+
260
+ auto arr = elem.expr ->value_expr ().value ().array_val ();
261
+ for (int idx = 0 ; idx < arr.array_size (); idx++) {
262
+ proto::plan::GenericValue expr = arr.array (idx);
263
+ auto val = json_contain_expr->add_elements ();
264
+ if (expr.has_bool_val ())
265
+ val->set_bool_val (expr.bool_val ());
266
+ if (expr.has_string_val ())
267
+ val->set_string_val (expr.string_val ());
268
+ if (expr.has_float_val ())
269
+ val->set_float_val (expr.float_val ());
270
+ if (expr.has_int64_val ())
271
+ val->set_int64_val (expr.int64_val ());
272
+ }
273
+
260
274
json_contain_expr->set_elements_same_type (
261
275
elem.expr ->value_expr ().value ().array_val ().same_type ());
262
276
json_contain_expr->unsafe_arena_set_allocated_column_info (
263
277
CreateMessageWithCopy<proto::plan::ColumnInfo>(this ->arena .get (),
264
278
info));
265
-
266
279
json_contain_expr->set_op (
267
280
proto::plan::JSONContainsExpr_JSONOp_ContainsAll);
268
281
expr->unsafe_arena_set_allocated_json_contains_expr (json_contain_expr);
282
+
269
283
return ExprWithDtype (expr, proto::schema::Bool, false );
270
284
}
271
285
@@ -1398,6 +1412,18 @@ class PlanCCVisitor : public PlanVisitor {
1398
1412
}
1399
1413
continue ;
1400
1414
}
1415
+
1416
+ if (value.type () == typeid (std::string)) {
1417
+ v->set_string_val (std::any_cast<std::string>(value));
1418
+ if (dtype != proto::schema::DataType::None &&
1419
+ dtype != proto::schema::DataType::VarChar) {
1420
+ is_same = false ;
1421
+ }
1422
+ if (dtype == proto::schema::DataType::None) {
1423
+ dtype = proto::schema::DataType::VarChar;
1424
+ }
1425
+ continue ;
1426
+ }
1401
1427
}
1402
1428
}
1403
1429
@@ -1423,23 +1449,35 @@ class PlanCCVisitor : public PlanVisitor {
1423
1449
TRY_WITH_EXCEPTION (info.data_type () == proto::schema::DataType::Array ||
1424
1450
info.data_type () == proto::schema::DataType::JSON);
1425
1451
auto elem = std::any_cast<ExprWithDtype>(expr_ret[1 ]->accept (this ));
1452
+ TRY_WITH_EXCEPTION (elem.expr ->value_expr ().has_value () &&
1453
+ elem.expr ->value_expr ().value ().has_array_val ());
1426
1454
if (info.data_type () == proto::schema::DataType::Array) {
1427
- proto::plan::GenericValue expr =
1428
- proto::plan::GenericValue (elem.expr ->value_expr ().value ());
1429
- TRY_WITH_EXCEPTION (
1430
- canBeCompared (field, toValueExpr (&expr, this ->arena .get ())));
1455
+ auto arr = elem.expr ->value_expr ().value ().array_val ();
1456
+ for (int idx = 0 ; idx < arr.array_size (); idx++) {
1457
+ proto::plan::GenericValue expr = arr.array (idx);
1458
+ TRY_WITH_EXCEPTION (canBeCompared (
1459
+ field, toValueExpr (&expr, this ->arena .get ())));
1460
+ }
1431
1461
}
1432
1462
1433
1463
auto expr = google::protobuf::Arena::CreateMessage<proto::plan::Expr>(
1434
1464
this ->arena .get ());
1435
1465
auto json_contain_expr = google::protobuf::Arena::CreateMessage<
1436
1466
proto::plan::JSONContainsExpr>(this ->arena .get ());
1437
1467
1438
- auto value = json_contain_expr->add_elements ();
1439
- value->unsafe_arena_set_allocated_array_val (
1440
- CreateMessageWithCopy<proto::plan::Array>(
1441
- this ->arena .get (),
1442
- elem.expr ->value_expr ().value ().array_val ()));
1468
+ auto arr = elem.expr ->value_expr ().value ().array_val ();
1469
+ for (int idx = 0 ; idx < arr.array_size (); idx++) {
1470
+ proto::plan::GenericValue expr = arr.array (idx);
1471
+ auto val = json_contain_expr->add_elements ();
1472
+ if (expr.has_bool_val ())
1473
+ val->set_bool_val (expr.bool_val ());
1474
+ if (expr.has_string_val ())
1475
+ val->set_string_val (expr.string_val ());
1476
+ if (expr.has_float_val ())
1477
+ val->set_float_val (expr.float_val ());
1478
+ if (expr.has_int64_val ())
1479
+ val->set_int64_val (expr.int64_val ());
1480
+ }
1443
1481
1444
1482
json_contain_expr->set_elements_same_type (
1445
1483
elem.expr ->value_expr ().value ().array_val ().same_type ());
@@ -1449,6 +1487,7 @@ class PlanCCVisitor : public PlanVisitor {
1449
1487
json_contain_expr->set_op (
1450
1488
proto::plan::JSONContainsExpr_JSONOp_ContainsAny);
1451
1489
expr->unsafe_arena_set_allocated_json_contains_expr (json_contain_expr);
1490
+
1452
1491
return ExprWithDtype (expr, proto::schema::Bool, false );
1453
1492
}
1454
1493
0 commit comments