Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
1cae264e
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,发现更多精彩内容 >>
提交
1cae264e
编写于
9月 10, 2020
作者:
N
Nikolai Kochetov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add ExpressionDAG [Part 3].
上级
c1469aff
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
42 addition
and
21 deletion
+42
-21
src/Interpreters/ArrayJoinAction.cpp
src/Interpreters/ArrayJoinAction.cpp
+5
-3
src/Interpreters/ArrayJoinAction.h
src/Interpreters/ArrayJoinAction.h
+1
-1
src/Interpreters/ExpressionActions.cpp
src/Interpreters/ExpressionActions.cpp
+16
-0
src/Interpreters/ExpressionActions.h
src/Interpreters/ExpressionActions.h
+2
-0
src/Interpreters/ExpressionAnalyzer.cpp
src/Interpreters/ExpressionAnalyzer.cpp
+17
-16
src/Interpreters/ExpressionAnalyzer.h
src/Interpreters/ExpressionAnalyzer.h
+1
-1
未找到文件。
src/Interpreters/ArrayJoinAction.cpp
浏览文件 @
1cae264e
...
...
@@ -35,11 +35,13 @@ ArrayJoinAction::ArrayJoinAction(const NameSet & array_joined_columns_, bool arr
}
void
ArrayJoinAction
::
prepare
(
Block
&
sample_block
)
void
ArrayJoinAction
::
prepare
(
ColumnsWithTypeAndName
&
sample
)
const
{
for
(
const
auto
&
name
:
columns
)
for
(
auto
&
current
:
sample
)
{
ColumnWithTypeAndName
&
current
=
sample_block
.
getByName
(
name
);
if
(
columns
.
count
(
current
.
name
)
==
0
)
continue
;
const
DataTypeArray
*
array_type
=
typeid_cast
<
const
DataTypeArray
*>
(
&*
current
.
type
);
if
(
!
array_type
)
throw
Exception
(
"ARRAY JOIN requires array argument"
,
ErrorCodes
::
TYPE_MISMATCH
);
...
...
src/Interpreters/ArrayJoinAction.h
浏览文件 @
1cae264e
...
...
@@ -28,7 +28,7 @@ public:
FunctionOverloadResolverPtr
function_builder
;
ArrayJoinAction
(
const
NameSet
&
array_joined_columns_
,
bool
array_join_is_left
,
const
Context
&
context
);
void
prepare
(
Block
&
sample_block
)
;
void
prepare
(
ColumnsWithTypeAndName
&
sample
)
const
;
void
execute
(
Block
&
block
);
};
...
...
src/Interpreters/ExpressionActions.cpp
浏览文件 @
1cae264e
...
...
@@ -1414,6 +1414,12 @@ ActionsDAG::ActionsDAG(const NamesAndTypesList & inputs)
addInput
(
input
.
name
,
input
.
type
);
}
ActionsDAG
::
ActionsDAG
(
const
ColumnsWithTypeAndName
&
inputs
)
{
for
(
const
auto
&
input
:
inputs
)
addInput
(
input
.
name
,
input
.
type
);
}
ActionsDAG
::
Node
&
ActionsDAG
::
addNode
(
Node
node
)
{
if
(
index
.
count
(
node
.
result_name
)
!=
0
)
...
...
@@ -1582,6 +1588,16 @@ const ActionsDAG::Node & ActionsDAG::addFunction(
return
addNode
(
std
::
move
(
node
));
}
ColumnsWithTypeAndName
ActionsDAG
::
getResultColumns
()
const
{
ColumnsWithTypeAndName
result
;
result
.
reserve
(
nodes
.
size
());
for
(
const
auto
&
node
:
nodes
)
result
.
emplace_back
(
node
.
column
,
node
.
result_type
,
node
.
result_name
);
return
result
;
}
NamesAndTypesList
ActionsDAG
::
getNamesAndTypesList
()
const
{
NamesAndTypesList
result
;
...
...
src/Interpreters/ExpressionActions.h
浏览文件 @
1cae264e
...
...
@@ -190,10 +190,12 @@ public:
ActionsDAG
(
const
ActionsDAG
&
)
=
delete
;
ActionsDAG
&
operator
=
(
const
ActionsDAG
&
)
=
delete
;
ActionsDAG
(
const
NamesAndTypesList
&
inputs
);
ActionsDAG
(
const
ColumnsWithTypeAndName
&
inputs
);
const
std
::
list
<
Node
>
&
getNodes
()
const
;
const
Index
&
getIndex
()
const
{
return
index
;
}
ColumnsWithTypeAndName
getResultColumns
()
const
;
NamesAndTypesList
getNamesAndTypesList
()
const
;
std
::
string
dumpNames
()
const
;
...
...
src/Interpreters/ExpressionAnalyzer.cpp
浏览文件 @
1cae264e
...
...
@@ -165,14 +165,14 @@ void ExpressionAnalyzer::analyzeAggregation()
getRootActionsNoMakeSet
(
array_join_expression_list
,
true
,
temp_actions
,
false
);
if
(
auto
array_join
=
addMultipleArrayJoinAction
(
temp_actions
,
is_array_join_left
))
{
auto
sample_
block
=
temp_actions
->
getSampleBlock
();
array_join
->
prepare
(
sample_
block
);
temp_actions
=
std
::
make_shared
<
ExpressionActions
>
(
sample_block
.
getColumnsWithTypeAndName
(),
context
);
auto
sample_
columns
=
temp_actions
->
getResultColumns
();
array_join
->
prepare
(
sample_
columns
);
temp_actions
=
std
::
make_shared
<
ActionsDAG
>
(
sample_columns
);
}
for
(
auto
&
column
:
temp_actions
->
get
SampleBlock
().
getNamesAndTypesList
())
for
(
auto
&
column
:
temp_actions
->
get
ResultColumns
())
if
(
syntax
->
array_join_result_to_source
.
count
(
column
.
name
))
array_join_columns
.
emplace_back
(
column
);
array_join_columns
.
emplace_back
(
column
.
name
,
column
.
type
);
}
columns_after_array_join
=
sourceColumns
();
...
...
@@ -182,9 +182,9 @@ void ExpressionAnalyzer::analyzeAggregation()
if
(
join
)
{
getRootActionsNoMakeSet
(
analyzedJoin
().
leftKeysList
(),
true
,
temp_actions
,
false
);
auto
sample_columns
=
temp_actions
->
get
SampleBlock
().
getColumnsWithTypeAndName
();
auto
sample_columns
=
temp_actions
->
get
ResultColumns
();
analyzedJoin
().
addJoinedColumnsAndCorrectNullability
(
sample_columns
);
temp_actions
=
std
::
make_shared
<
ExpressionActions
>
(
sample_columns
,
context
);
temp_actions
=
std
::
make_shared
<
ActionsDAG
>
(
sample_columns
);
}
columns_after_join
=
columns_after_array_join
;
...
...
@@ -212,15 +212,16 @@ void ExpressionAnalyzer::analyzeAggregation()
getRootActionsNoMakeSet
(
group_asts
[
i
],
true
,
temp_actions
,
false
);
const
auto
&
column_name
=
group_asts
[
i
]
->
getColumnName
();
const
auto
&
block
=
temp_actions
->
getSampleBlock
();
const
auto
&
index
=
temp_actions
->
getIndex
();
if
(
!
block
.
has
(
column_name
))
auto
it
=
index
.
find
(
column_name
);
if
(
it
==
index
.
end
())
throw
Exception
(
"Unknown identifier (in GROUP BY): "
+
column_name
,
ErrorCodes
::
UNKNOWN_IDENTIFIER
);
const
auto
&
col
=
block
.
getByName
(
column_name
)
;
const
auto
&
node
=
it
->
second
;
/// Constant expressions have non-null column pointer at this stage.
if
(
col
.
column
&&
isColumnConst
(
*
col
.
column
))
if
(
node
->
column
&&
isColumnConst
(
*
node
->
column
))
{
/// But don't remove last key column if no aggregate functions, otherwise aggregation will not work.
if
(
!
aggregate_descriptions
.
empty
()
||
size
>
1
)
...
...
@@ -235,7 +236,7 @@ void ExpressionAnalyzer::analyzeAggregation()
}
}
NameAndTypePair
key
{
column_name
,
col
.
type
};
NameAndTypePair
key
{
column_name
,
node
->
result_
type
};
/// Aggregation keys are uniqued.
if
(
!
unique_keys
.
count
(
key
.
name
))
...
...
@@ -256,14 +257,14 @@ void ExpressionAnalyzer::analyzeAggregation()
}
}
else
aggregated_columns
=
temp_actions
->
get
SampleBlock
().
get
NamesAndTypesList
();
aggregated_columns
=
temp_actions
->
getNamesAndTypesList
();
for
(
const
auto
&
desc
:
aggregate_descriptions
)
aggregated_columns
.
emplace_back
(
desc
.
column_name
,
desc
.
function
->
getReturnType
());
}
else
{
aggregated_columns
=
temp_actions
->
get
SampleBlock
().
get
NamesAndTypesList
();
aggregated_columns
=
temp_actions
->
getNamesAndTypesList
();
}
}
...
...
@@ -396,7 +397,7 @@ void ExpressionAnalyzer::getRootActionsNoMakeSet(const ASTPtr & ast, bool no_sub
}
bool
ExpressionAnalyzer
::
makeAggregateDescriptions
(
ExpressionActions
Ptr
&
actions
)
bool
ExpressionAnalyzer
::
makeAggregateDescriptions
(
ActionsDAG
Ptr
&
actions
)
{
for
(
const
ASTFunction
*
node
:
aggregates
())
{
...
...
@@ -411,7 +412,7 @@ bool ExpressionAnalyzer::makeAggregateDescriptions(ExpressionActionsPtr & action
{
getRootActionsNoMakeSet
(
arguments
[
i
],
true
,
actions
);
const
std
::
string
&
name
=
arguments
[
i
]
->
getColumnName
();
types
[
i
]
=
actions
->
get
SampleBlock
().
getByName
(
name
).
type
;
types
[
i
]
=
actions
->
get
Index
().
find
(
name
)
->
second
->
result_
type
;
aggregate
.
argument_names
[
i
]
=
name
;
}
...
...
src/Interpreters/ExpressionAnalyzer.h
浏览文件 @
1cae264e
...
...
@@ -156,7 +156,7 @@ protected:
* Set has_aggregation = true if there is GROUP BY or at least one aggregate function.
*/
void
analyzeAggregation
();
bool
makeAggregateDescriptions
(
ExpressionActions
Ptr
&
actions
);
bool
makeAggregateDescriptions
(
ActionsDAG
Ptr
&
actions
);
const
ASTSelectQuery
*
getSelectQuery
()
const
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录