MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / rewriteFunc

Function rewriteFunc

src/function/struct/keys_function.cpp:14–36  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12namespace function {
13
14static std::shared_ptr<Expression> rewriteFunc(const RewriteFunctionBindInput& input) {
15 DASSERT(input.arguments.size() == 1);
16 auto argument = input.arguments[0].get();
17 auto expressionBinder = input.expressionBinder;
18 if (ExpressionUtil::isNullLiteral(*argument)) {
19 return expressionBinder->createNullLiteralExpression();
20 }
21 auto uniqueExpressionName =
22 ScalarFunctionExpression::getUniqueName(KeysFunctions::name, input.arguments);
23 const auto& resultType = LogicalType::LIST(LogicalType::STRING());
24 auto fields = common::StructType::getFieldNames(input.arguments[0]->dataType);
25 std::vector<std::unique_ptr<Value>> children;
26 for (auto field : fields) {
27 if (field == InternalKeyword::ID || field == InternalKeyword::LABEL ||
28 field == InternalKeyword::SRC || field == InternalKeyword::DST) {
29 continue;
30 }
31 children.push_back(std::make_unique<Value>(field));
32 }
33 auto resultExpr = std::make_shared<binder::LiteralExpression>(
34 Value{resultType.copy(), std::move(children)}, std::move(uniqueExpressionName));
35 return resultExpr;
36}
37
38static std::unique_ptr<Function> getKeysFunction(LogicalTypeID logicalTypeID) {
39 return std::make_unique<function::RewriteFunction>(KeysFunctions::name,

Callers

nothing calls this directly

Calls 6

getUniqueNameFunction · 0.85
sizeMethod · 0.45
getMethod · 0.45
push_backMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected