Skip to content

Commit 1908c38

Browse files
committed
wip: transformQueryForExternalDatabase for analyzer
1 parent 56d4f42 commit 1908c38

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+553
-186
lines changed

src/Analyzer/ArrayJoinNode.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ QueryTreeNodePtr ArrayJoinNode::cloneImpl() const
4949
return std::make_shared<ArrayJoinNode>(getTableExpression(), getJoinExpressionsNode(), is_left);
5050
}
5151

52-
ASTPtr ArrayJoinNode::toASTImpl() const
52+
ASTPtr ArrayJoinNode::toASTImpl(ConvertToASTOptions options) const
5353
{
5454
auto array_join_ast = std::make_shared<ASTArrayJoin>();
5555
array_join_ast->kind = is_left ? ASTArrayJoin::Kind::Left : ASTArrayJoin::Kind::Inner;
@@ -63,9 +63,9 @@ ASTPtr ArrayJoinNode::toASTImpl() const
6363

6464
auto * column_node = array_join_expression->as<ColumnNode>();
6565
if (column_node && column_node->getExpression())
66-
array_join_expression_ast = column_node->getExpression()->toAST();
66+
array_join_expression_ast = column_node->getExpression()->toAST(options);
6767
else
68-
array_join_expression_ast = array_join_expression->toAST();
68+
array_join_expression_ast = array_join_expression->toAST(options);
6969

7070
array_join_expression_ast->setAlias(array_join_expression->getAlias());
7171
array_join_expressions_ast->children.push_back(std::move(array_join_expression_ast));

src/Analyzer/ArrayJoinNode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class ArrayJoinNode final : public IQueryTreeNode
9999

100100
QueryTreeNodePtr cloneImpl() const override;
101101

102-
ASTPtr toASTImpl() const override;
102+
ASTPtr toASTImpl(ConvertToASTOptions options) const override;
103103

104104
private:
105105
bool is_left = false;

src/Analyzer/ColumnNode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ QueryTreeNodePtr ColumnNode::cloneImpl() const
9191
return std::make_shared<ColumnNode>(column, getSourceWeakPointer());
9292
}
9393

94-
ASTPtr ColumnNode::toASTImpl() const
94+
ASTPtr ColumnNode::toASTImpl(ConvertToASTOptions options) const
9595
{
9696
std::vector<std::string> column_identifier_parts;
9797

9898
auto column_source = getColumnSourceOrNull();
99-
if (column_source)
99+
if (column_source && options.fully_qualified_identifiers)
100100
{
101101
auto node_type = column_source->getNodeType();
102102
if (node_type == QueryTreeNodeType::TABLE ||

src/Analyzer/ColumnNode.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ class ColumnNode final : public IQueryTreeNode
103103
*/
104104
QueryTreeNodePtr getColumnSource() const;
105105

106+
void dropColumnSource()
107+
{
108+
getSourceWeakPointer().reset();
109+
}
110+
106111
/** Get column source.
107112
* If column source is not valid null is returned.
108113
*/
@@ -132,7 +137,7 @@ class ColumnNode final : public IQueryTreeNode
132137

133138
QueryTreeNodePtr cloneImpl() const override;
134139

135-
ASTPtr toASTImpl() const override;
140+
ASTPtr toASTImpl(ConvertToASTOptions options) const override;
136141

137142
private:
138143
const QueryTreeNodeWeakPtr & getSourceWeakPointer() const

src/Analyzer/ColumnTransformers.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ QueryTreeNodePtr ApplyColumnTransformerNode::cloneImpl() const
9191
return std::make_shared<ApplyColumnTransformerNode>(getExpressionNode());
9292
}
9393

94-
ASTPtr ApplyColumnTransformerNode::toASTImpl() const
94+
ASTPtr ApplyColumnTransformerNode::toASTImpl(ConvertToASTOptions options) const
9595
{
9696
auto ast_apply_transformer = std::make_shared<ASTColumnsApplyTransformer>();
9797
const auto & expression_node = getExpressionNode();
@@ -100,14 +100,14 @@ ASTPtr ApplyColumnTransformerNode::toASTImpl() const
100100
{
101101
auto & function_expression = expression_node->as<FunctionNode &>();
102102
ast_apply_transformer->func_name = function_expression.getFunctionName();
103-
ast_apply_transformer->parameters = function_expression.getParametersNode()->toAST();
103+
ast_apply_transformer->parameters = function_expression.getParametersNode()->toAST(options);
104104
}
105105
else
106106
{
107107
auto & lambda_expression = expression_node->as<LambdaNode &>();
108108
if (!lambda_expression.getArgumentNames().empty())
109109
ast_apply_transformer->lambda_arg = lambda_expression.getArgumentNames()[0];
110-
ast_apply_transformer->lambda = lambda_expression.toAST();
110+
ast_apply_transformer->lambda = lambda_expression.toAST(options);
111111
}
112112

113113
return ast_apply_transformer;
@@ -227,7 +227,7 @@ QueryTreeNodePtr ExceptColumnTransformerNode::cloneImpl() const
227227
return std::make_shared<ExceptColumnTransformerNode>(except_column_names, is_strict);
228228
}
229229

230-
ASTPtr ExceptColumnTransformerNode::toASTImpl() const
230+
ASTPtr ExceptColumnTransformerNode::toASTImpl(ConvertToASTOptions /* options */) const
231231
{
232232
auto ast_except_transformer = std::make_shared<ASTColumnsExceptTransformer>();
233233

@@ -334,7 +334,7 @@ QueryTreeNodePtr ReplaceColumnTransformerNode::cloneImpl() const
334334
return result_replace_transformer;
335335
}
336336

337-
ASTPtr ReplaceColumnTransformerNode::toASTImpl() const
337+
ASTPtr ReplaceColumnTransformerNode::toASTImpl(ConvertToASTOptions options) const
338338
{
339339
auto ast_replace_transformer = std::make_shared<ASTColumnsReplaceTransformer>();
340340

@@ -347,7 +347,7 @@ ASTPtr ReplaceColumnTransformerNode::toASTImpl() const
347347
{
348348
auto replacement_ast = std::make_shared<ASTColumnsReplaceTransformer::Replacement>();
349349
replacement_ast->name = replacements_names[i];
350-
replacement_ast->children.push_back(replacement_expressions_nodes[i]->toAST());
350+
replacement_ast->children.push_back(replacement_expressions_nodes[i]->toAST(options));
351351
ast_replace_transformer->children.push_back(std::move(replacement_ast));
352352
}
353353

src/Analyzer/ColumnTransformers.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class ApplyColumnTransformerNode final : public IColumnTransformerNode
141141

142142
QueryTreeNodePtr cloneImpl() const override;
143143

144-
ASTPtr toASTImpl() const override;
144+
ASTPtr toASTImpl(ConvertToASTOptions options) const override;
145145

146146
private:
147147
ApplyColumnTransformerType apply_transformer_type = ApplyColumnTransformerType::LAMBDA;
@@ -220,7 +220,7 @@ class ExceptColumnTransformerNode final : public IColumnTransformerNode
220220

221221
QueryTreeNodePtr cloneImpl() const override;
222222

223-
ASTPtr toASTImpl() const override;
223+
ASTPtr toASTImpl(ConvertToASTOptions options) const override;
224224

225225
private:
226226
ExceptColumnTransformerType except_transformer_type;
@@ -298,7 +298,7 @@ class ReplaceColumnTransformerNode final : public IColumnTransformerNode
298298

299299
QueryTreeNodePtr cloneImpl() const override;
300300

301-
ASTPtr toASTImpl() const override;
301+
ASTPtr toASTImpl(ConvertToASTOptions options) const override;
302302

303303
private:
304304
ListNode & getReplacements()

src/Analyzer/ConstantNode.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,14 @@ QueryTreeNodePtr ConstantNode::cloneImpl() const
7575
return std::make_shared<ConstantNode>(constant_value, source_expression);
7676
}
7777

78-
ASTPtr ConstantNode::toASTImpl() const
78+
ASTPtr ConstantNode::toASTImpl(ConvertToASTOptions options) const
7979
{
8080
const auto & constant_value_literal = constant_value->getValue();
8181
auto constant_value_ast = std::make_shared<ASTLiteral>(constant_value_literal);
8282

83+
if (!options.add_cast_for_constants)
84+
return constant_value_ast;
85+
8386
bool need_to_add_cast_function = false;
8487
auto constant_value_literal_type = constant_value_literal.getType();
8588
WhichDataType constant_value_type(constant_value->getType());

src/Analyzer/ConstantNode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class ConstantNode final : public IQueryTreeNode
8383

8484
QueryTreeNodePtr cloneImpl() const override;
8585

86-
ASTPtr toASTImpl() const override;
86+
ASTPtr toASTImpl(ConvertToASTOptions options) const override;
8787

8888
private:
8989
ConstantValuePtr constant_value;

src/Analyzer/FunctionNode.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ QueryTreeNodePtr FunctionNode::cloneImpl() const
197197
return result_function;
198198
}
199199

200-
ASTPtr FunctionNode::toASTImpl() const
200+
ASTPtr FunctionNode::toASTImpl(ConvertToASTOptions options) const
201201
{
202202
auto function_ast = std::make_shared<ASTFunction>();
203203

@@ -212,12 +212,12 @@ ASTPtr FunctionNode::toASTImpl() const
212212
const auto & parameters = getParameters();
213213
if (!parameters.getNodes().empty())
214214
{
215-
function_ast->children.push_back(parameters.toAST());
215+
function_ast->children.push_back(parameters.toAST(options));
216216
function_ast->parameters = function_ast->children.back();
217217
}
218218

219219
const auto & arguments = getArguments();
220-
function_ast->children.push_back(arguments.toAST());
220+
function_ast->children.push_back(arguments.toAST(options));
221221
function_ast->arguments = function_ast->children.back();
222222

223223
auto window_node = getWindowNode();
@@ -226,7 +226,7 @@ ASTPtr FunctionNode::toASTImpl() const
226226
if (auto * identifier_node = window_node->as<IdentifierNode>())
227227
function_ast->window_name = identifier_node->getIdentifier().getFullName();
228228
else
229-
function_ast->window_definition = window_node->toAST();
229+
function_ast->window_definition = window_node->toAST(options);
230230
}
231231

232232
return function_ast;

src/Analyzer/FunctionNode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class FunctionNode final : public IQueryTreeNode
209209

210210
QueryTreeNodePtr cloneImpl() const override;
211211

212-
ASTPtr toASTImpl() const override;
212+
ASTPtr toASTImpl(ConvertToASTOptions options) const override;
213213

214214
private:
215215
String function_name;

0 commit comments

Comments
 (0)