| 1426 | } |
| 1427 | |
| 1428 | ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, size_t input_rows_count) const override |
| 1429 | { |
| 1430 | //Only support Object JSON |
| 1431 | bool has_nothing_argument = false; |
| 1432 | for (const auto & arg : arguments) |
| 1433 | has_nothing_argument |= isNothing(arg.type); |
| 1434 | |
| 1435 | if (arguments.empty()) |
| 1436 | throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, "Function {} requires at least one argument", Name::name); |
| 1437 | |
| 1438 | // TODO: add logic to handle single argument |
| 1439 | if (arguments.size() < 2) |
| 1440 | { |
| 1441 | throw Exception{"JSONPath functions require at least 2 arguments", ErrorCodes::TOO_FEW_ARGUMENTS_FOR_FUNCTION}; |
| 1442 | } |
| 1443 | |
| 1444 | const auto & json_column = arguments[0]; |
| 1445 | auto first_type_base = removeNullable(removeLowCardinality(json_column.type)); |
| 1446 | |
| 1447 | bool is_string = isString(first_type_base); |
| 1448 | bool is_object = isObject(first_type_base); |
| 1449 | bool is_tuple = isTuple(first_type_base); |
| 1450 | |
| 1451 | if (!is_string && !is_object && !is_tuple) |
| 1452 | throw Exception( |
| 1453 | ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, |
| 1454 | "The first argument of function {} should be a string containing Object or Tuple or JSON, illegal type: {}", |
| 1455 | Name::name, |
| 1456 | json_column.type->getName()); |
| 1457 | |
| 1458 | const auto & candidate = arguments[1]; |
| 1459 | if (!isColumnConst(*candidate.column)) |
| 1460 | throw Exception("Second argument (Candidate) must be constant", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); |
| 1461 | |
| 1462 | MutableColumnPtr to{result_type->createColumn()}; |
| 1463 | to->reserve(input_rows_count); |
| 1464 | |
| 1465 | ASTPtr res; |
| 1466 | if (arguments.size() == 3) |
| 1467 | { |
| 1468 | const auto & json_path_column = arguments[2]; |
| 1469 | |
| 1470 | if (!isString(json_path_column.type)) |
| 1471 | { |
| 1472 | throw Exception( |
| 1473 | "JSONPath functions require third argument to be JSONPath of type string, illegal type: " |
| 1474 | + json_path_column.type->getName(), |
| 1475 | ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); |
| 1476 | } |
| 1477 | |
| 1478 | if (!isColumnConst(*json_path_column.column)) |
| 1479 | { |
| 1480 | throw Exception("Third argument (JSONPath) must be constant string", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); |
| 1481 | } |
| 1482 | |
| 1483 | const ColumnPtr & arg_jsonpath = json_path_column.column; |
| 1484 | const auto * arg_jsonpath_const = typeid_cast<const ColumnConst *>(arg_jsonpath.get()); |
| 1485 | const auto * arg_jsonpath_string = typeid_cast<const ColumnString *>(arg_jsonpath_const->getDataColumnPtr().get()); |
nothing calls this directly
no test coverage detected