Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
9f9bf0cb
C
ClickHouse
项目概览
2dot5
/
ClickHouse
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
ClickHouse
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9f9bf0cb
编写于
12月 10, 2018
作者:
C
chertus
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ArrayJoinedColumnsVisitor via InDepthNodeVisitor
上级
49d80bf8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
45 addition
and
55 deletion
+45
-55
dbms/src/Interpreters/ArrayJoinedColumnsVisitor.h
dbms/src/Interpreters/ArrayJoinedColumnsVisitor.h
+40
-50
dbms/src/Interpreters/InDepthNodeVisitor.h
dbms/src/Interpreters/InDepthNodeVisitor.h
+1
-1
dbms/src/Interpreters/SyntaxAnalyzer.cpp
dbms/src/Interpreters/SyntaxAnalyzer.cpp
+4
-4
未找到文件。
dbms/src/Interpreters/ArrayJoinedColumnsVisitor.h
浏览文件 @
9f9bf0cb
...
...
@@ -9,42 +9,55 @@
#include <Parsers/ASTIdentifier.h>
#include <DataTypes/NestedUtils.h>
#include <Interpreters/InDepthNodeVisitor.h>
namespace
DB
{
/// Visitors consist of functions with unified interface 'void visit(Casted & x, ASTPtr & y)', there x is y, successfully casted to Casted.
/// Both types and fuction could have const specifiers. The second argument is used by visitor to replaces AST node (y) if needed.
/// Fills the array_join_result_to_source: on which columns-arrays to replicate, and how to call them after that.
class
ArrayJoinedColumns
Visito
r
class
ArrayJoinedColumns
Matche
r
{
public:
ArrayJoinedColumnsVisitor
(
NameToNameMap
&
array_join_name_to_alias_
,
NameToNameMap
&
array_join_alias_to_name_
,
NameToNameMap
&
array_join_result_to_source_
)
:
array_join_name_to_alias
(
array_join_name_to_alias_
),
array_join_alias_to_name
(
array_join_alias_to_name_
),
array_join_result_to_source
(
array_join_result_to_source_
)
{}
void
visit
(
ASTPtr
&
ast
)
const
struct
Data
{
if
(
!
tryVisit
<
ASTTablesInSelectQuery
>
(
ast
)
&&
!
tryVisit
<
ASTIdentifier
>
(
ast
))
visitChildren
(
ast
)
;
}
NameToNameMap
&
array_join_name_to_alias
;
NameToNameMap
&
array_join_alias_to_name
;
NameToNameMap
&
array_join_result_to_source
;
}
;
private:
NameToNameMap
&
array_join_name_to_alias
;
NameToNameMap
&
array_join_alias_to_name
;
NameToNameMap
&
array_join_result_to_source
;
static
constexpr
const
char
*
label
=
"ArrayJoinedColumns"
;
static
bool
needChildVisit
(
ASTPtr
&
node
,
const
ASTPtr
&
child
)
{
/// Processed
if
(
typeid_cast
<
ASTIdentifier
*>
(
node
.
get
()))
return
false
;
if
(
typeid_cast
<
ASTTablesInSelectQuery
*>
(
node
.
get
()))
return
false
;
void
visit
(
const
ASTTablesInSelectQuery
&
,
ASTPtr
&
)
const
{}
if
(
typeid_cast
<
ASTSubquery
*>
(
child
.
get
())
||
typeid_cast
<
ASTSelectQuery
*>
(
child
.
get
()))
return
false
;
void
visit
(
const
ASTIdentifier
&
node
,
ASTPtr
&
)
const
return
true
;
}
static
std
::
vector
<
ASTPtr
*>
visit
(
ASTPtr
&
ast
,
Data
&
data
)
{
if
(
auto
*
t
=
typeid_cast
<
ASTIdentifier
*>
(
ast
.
get
()))
visit
(
*
t
,
ast
,
data
);
return
{};
}
private:
static
void
visit
(
const
ASTIdentifier
&
node
,
ASTPtr
&
,
Data
&
data
)
{
NameToNameMap
&
array_join_name_to_alias
=
data
.
array_join_name_to_alias
;
NameToNameMap
&
array_join_alias_to_name
=
data
.
array_join_alias_to_name
;
NameToNameMap
&
array_join_result_to_source
=
data
.
array_join_result_to_source
;
if
(
!
node
.
general
())
return
;
...
...
@@ -74,34 +87,11 @@ private:
/** Example: SELECT ParsedParams.Key1 FROM ... ARRAY JOIN ParsedParams AS PP.
*/
array_join_result_to_source
[
/// PP.Key1 -> ParsedParams.Key1
Nested
::
concatenateName
(
array_join_name_to_alias
[
splitted
.
first
],
splitted
.
second
)]
=
node
.
name
;
}
}
void
visit
(
const
ASTSubquery
&
,
ASTPtr
&
)
const
{}
void
visit
(
const
ASTSelectQuery
&
,
ASTPtr
&
)
const
{}
void
visitChildren
(
ASTPtr
&
ast
)
const
{
for
(
auto
&
child
:
ast
->
children
)
if
(
!
tryVisit
<
ASTSubquery
>
(
child
)
&&
!
tryVisit
<
ASTSelectQuery
>
(
child
))
visit
(
child
);
}
template
<
typename
T
>
bool
tryVisit
(
ASTPtr
&
ast
)
const
{
if
(
const
T
*
t
=
typeid_cast
<
const
T
*>
(
ast
.
get
()))
{
visit
(
*
t
,
ast
);
return
true
;
Nested
::
concatenateName
(
array_join_name_to_alias
[
splitted
.
first
],
splitted
.
second
)]
=
node
.
name
;
}
return
false
;
}
};
using
ArrayJoinedColumnsVisitor
=
InDepthNodeVisitor
<
ArrayJoinedColumnsMatcher
,
true
>
;
}
dbms/src/Interpreters/InDepthNodeVisitor.h
浏览文件 @
9f9bf0cb
...
...
@@ -6,7 +6,7 @@
namespace
DB
{
/// Visits AST tree in depth, call fu
cn
tions for nodes according to Matcher type data.
/// Visits AST tree in depth, call fu
nc
tions for nodes according to Matcher type data.
/// You need to define Data, label, visit() and needChildVisit() in Matcher class.
template
<
typename
Matcher
,
bool
_topToBottom
>
class
InDepthNodeVisitor
...
...
dbms/src/Interpreters/SyntaxAnalyzer.cpp
浏览文件 @
9f9bf0cb
...
...
@@ -697,10 +697,10 @@ void getArrayJoinedColumns(ASTPtr & query, SyntaxAnalyzerResult & result, const
}
{
ArrayJoinedColumnsVisitor
visitor
(
result
.
array_join_name_to_alias
,
result
.
array_join_alias_to_name
,
result
.
array_join_result_to_source
)
;
visitor
.
visit
(
query
);
ArrayJoinedColumnsVisitor
::
Data
visitor_data
{
result
.
array_join_name_to_alias
,
result
.
array_join_alias_to_name
,
result
.
array_join_result_to_source
}
;
ArrayJoinedColumnsVisitor
(
visitor_data
)
.
visit
(
query
);
}
/// If the result of ARRAY JOIN is not used, it is necessary to ARRAY-JOIN any column,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录