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

Function extractPartitionKey

programs/copier/Internals.cpp:99–139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

97}
98
99ASTPtr extractPartitionKey(const ASTPtr & storage_ast)
100{
101 String storage_str = queryToString(storage_ast);
102
103 const auto & storage = storage_ast->as<ASTStorage &>();
104 const auto & engine = storage.engine->as<ASTFunction &>();
105
106 if (!endsWith(engine.name, "MergeTree"))
107 {
108 throw Exception(
109 "Unsupported engine was specified in " + storage_str + ", only *MergeTree engines are supported",
110 ErrorCodes::BAD_ARGUMENTS);
111 }
112
113 if (isExtendedDefinitionStorage(storage_ast))
114 {
115 if (storage.partition_by)
116 return storage.partition_by->clone();
117
118 static const char * all = "all";
119 return std::make_shared<ASTLiteral>(Field(all, strlen(all)));
120 }
121 else
122 {
123 bool is_replicated = startsWith(engine.name, "Replicated");
124 size_t min_args = is_replicated ? 3 : 1;
125
126 if (!engine.arguments)
127 throw Exception("Expected arguments in " + storage_str, ErrorCodes::BAD_ARGUMENTS);
128
129 ASTPtr arguments_ast = engine.arguments->clone();
130 ASTs & arguments = arguments_ast->children;
131
132 if (arguments.size() < min_args)
133 throw Exception("Expected at least " + toString(min_args) + " arguments in " + storage_str,
134 ErrorCodes::BAD_ARGUMENTS);
135
136 ASTPtr & month_arg = is_replicated ? arguments[2] : arguments[1];
137 return makeASTFunction("toYYYYMM", month_arg->clone());
138 }
139}
140
141ASTPtr extractPrimaryKey(const ASTPtr & storage_ast)
142{

Callers 1

TaskTableMethod · 0.85

Calls 10

queryToStringFunction · 0.85
makeASTFunctionFunction · 0.85
endsWithFunction · 0.50
ExceptionClass · 0.50
FieldClass · 0.50
startsWithFunction · 0.50
toStringFunction · 0.50
cloneMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected