MCPcopy Create free account
hub / github.com/ByConity/ByConity / executeImpl

Method executeImpl

src/Functions/FunctionSQLJSON.h:1669–1830  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1667 }
1668
1669 ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, size_t input_rows_count) const override
1670 {
1671 //Only support Object JSON
1672 bool has_nothing_argument = false;
1673 for (const auto & arg : arguments)
1674 has_nothing_argument |= isNothing(arg.type);
1675
1676 if (arguments.empty())
1677 throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, "Function {} requires at least one argument", Name::name);
1678
1679 // TODO: add logic to handle single argument
1680 if (arguments.size() < 3)
1681 {
1682 throw Exception{"Function JSON_CONTAINS_PATH require at least 3 arguments", ErrorCodes::TOO_FEW_ARGUMENTS_FOR_FUNCTION};
1683 }
1684
1685 const auto & json_column = arguments[0];
1686 auto first_type_base = removeNullable(removeLowCardinality(json_column.type));
1687
1688 bool is_string = isString(first_type_base);
1689 bool is_object = isObject(first_type_base);
1690 bool is_tuple = isTuple(first_type_base);
1691
1692 if (!is_string && !is_object && !is_tuple)
1693 throw Exception(
1694 ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
1695 "The first argument of function {} should be a string containing Object or Tuple or JSON, illegal type: {}",
1696 Name::name,
1697 json_column.type->getName());
1698
1699 const auto & any_or_all_column = arguments[1];
1700 if (!isString(any_or_all_column.type) || !isColumnConst(*any_or_all_column.column))
1701 throw Exception("Second argument (any or all) must be constant string", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
1702
1703 const ColumnPtr & arg_any_or_all = any_or_all_column.column;
1704 const auto * arg_any_or_all_const = typeid_cast<const ColumnConst *>(arg_any_or_all.get());
1705 const auto * arg_any_or_all_string = typeid_cast<const ColumnString *>(arg_any_or_all_const->getDataColumnPtr().get());
1706
1707 bool contains_all = false;
1708 if (Poco::toLower(arg_any_or_all_string->getDataAt(0).toString()) == "all")
1709 contains_all = true;
1710 else if (Poco::toLower(arg_any_or_all_string->getDataAt(0).toString()) == "one")
1711 contains_all = false;
1712 else
1713 throw Exception("Second argument (any or all) only can be any or all", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
1714
1715 ASTs json_path_ast_ptrs;
1716 for (size_t i = 2; i < arguments.size(); i++)
1717 {
1718 const auto & json_path_column = arguments[i];
1719
1720 if (!isString(json_path_column.type))
1721 {
1722 throw Exception(
1723 "JSONPath functions require third argument to be JSONPath of type string, illegal type: "
1724 + json_path_column.type->getName(),
1725 ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
1726 }

Callers

nothing calls this directly

Calls 15

insertResultToColumnMethod · 0.95
isNothingFunction · 0.85
removeNullableFunction · 0.85
removeLowCardinalityFunction · 0.85
isStringFunction · 0.85
isObjectFunction · 0.85
isTupleFunction · 0.85
isColumnConstFunction · 0.85
unflattenObjectToTupleFunction · 0.85
rangeFunction · 0.85
ExceptionClass · 0.50
emptyMethod · 0.45

Tested by

no test coverage detected