Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
bc071d70
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,发现更多精彩内容 >>
提交
bc071d70
编写于
10月 18, 2013
作者:
M
Michael Kolupaev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ClickHouse: fixed ARRAY JOIN when its result is unused. [#CONV-8821]
上级
59b80197
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
50 addition
and
20 deletion
+50
-20
dbms/src/Interpreters/ExpressionAnalyzer.cpp
dbms/src/Interpreters/ExpressionAnalyzer.cpp
+50
-20
未找到文件。
dbms/src/Interpreters/ExpressionAnalyzer.cpp
浏览文件 @
bc071d70
...
...
@@ -662,6 +662,35 @@ void ExpressionAnalyzer::getArrayJoinedColumns()
getArrayJoinedColumnsImpl
(
select_query
->
where_expression
);
getArrayJoinedColumnsImpl
(
select_query
->
having_expression
);
getArrayJoinedColumnsImpl
(
select_query
->
order_expression_list
);
/// Если результат ARRAY JOIN не используется, придется все равно по-ARRAY-JOIN-ить какой-нибудь столбец,
/// чтобы получить правильное количество строк.
if
(
columns_for_array_join
.
empty
())
{
ASTPtr
expr
=
select_query
->
array_join_expression_list
->
children
[
0
];
String
source_name
=
expr
->
getColumnName
();
String
result_name
=
expr
->
getAlias
();
/// Это массив.
if
(
!
dynamic_cast
<
ASTIdentifier
*>
(
&*
expr
)
||
findColumn
(
source_name
,
columns
)
!=
columns
.
end
())
{
columns_for_array_join
.
insert
(
result_name
);
}
else
/// Это вложенная таблица.
{
bool
found
=
false
;
for
(
NamesAndTypesList
::
iterator
it
=
columns
.
begin
();
it
!=
columns
.
end
();
++
it
)
{
String
table_name
=
DataTypeNested
::
extractNestedTableName
(
it
->
first
);
String
column_name
=
DataTypeNested
::
extractNestedColumnName
(
it
->
first
);
if
(
table_name
==
source_name
)
{
columns_for_array_join
.
insert
(
DataTypeNested
::
concatenateNestedName
(
result_name
,
column_name
));
found
=
true
;
break
;
}
}
}
}
}
}
...
...
@@ -990,9 +1019,8 @@ void ExpressionAnalyzer::initChain(ExpressionActionsChain & chain, NamesAndTypes
void
ExpressionAnalyzer
::
addMultipleArrayJoinAction
(
ExpressionActions
&
actions
)
{
ASTs
&
asts
=
select_query
->
array_join_expression_list
->
children
;
typedef
std
::
map
<
String
,
String
>
NameToAlias
;
NameToAlias
name_to_alias
;
NameSet
known_aliases
;
typedef
std
::
map
<
String
,
String
>
AliasToName
;
AliasToName
alias_to_name
;
for
(
size_t
i
=
0
;
i
<
asts
.
size
();
++
i
)
{
ASTPtr
ast
=
asts
[
i
];
...
...
@@ -1002,31 +1030,33 @@ void ExpressionAnalyzer::addMultipleArrayJoinAction(ExpressionActions & actions)
if
(
nested_table_alias
==
nested_table_name
&&
!
dynamic_cast
<
ASTIdentifier
*>
(
&*
ast
))
throw
Exception
(
"No alias for non-trivial value in ARRAY JOIN: "
+
nested_table_name
,
ErrorCodes
::
ALIAS_REQUIRED
);
if
(
known_aliases
.
count
(
nested_table_alias
)
||
aliases
.
count
(
nested_table_alias
))
if
(
alias_to_name
.
count
(
nested_table_alias
)
||
aliases
.
count
(
nested_table_alias
))
throw
Exception
(
"Duplicate alias "
+
nested_table_alias
,
ErrorCodes
::
MULTIPLE_EXPRESSIONS_FOR_ALIAS
);
if
(
name_to_alias
.
count
(
nested_table_name
))
throw
Exception
(
"Duplicate ARRAY JOIN on column "
+
nested_table_name
,
ErrorCodes
::
MULTIPLE_EXPRESSIONS_FOR_ALIAS
);
known_aliases
.
insert
(
nested_table_alias
);
name_to_alias
[
nested_table_name
]
=
nested_table_alias
;
alias_to_name
[
nested_table_alias
]
=
nested_table_name
;
}
NamesAndTypesList
input_columns
=
actions
.
getSampleBlock
().
getColumnsList
();
for
(
NamesAndTypesList
::
const_iterator
it
=
input_columns
.
begin
();
it
!=
input_columns
.
end
();
++
it
)
for
(
NamesSet
::
iterator
it
=
columns_for_array_join
.
begin
();
it
!=
columns_for_array_join
.
end
();
++
it
)
{
const
String
&
name
=
it
->
firs
t
;
const
String
&
result_name
=
*
i
t
;
String
nested_table
=
DataTypeNested
::
extractNestedTableName
(
name
);
String
nested_column
=
DataTypeNested
::
extractNestedColumnName
(
name
);
String
result_table
=
DataTypeNested
::
extractNestedTableName
(
result_
name
);
String
result_column
=
DataTypeNested
::
extractNestedColumnName
(
result_
name
);
String
array_joined_name
;
if
(
name_to_alias
.
count
(
name
))
array_joined_name
=
name_to_alias
[
name
];
else
if
(
name_to_alias
.
count
(
nested_table
))
array_joined_name
=
DataTypeNested
::
concatenateNestedName
(
name_to_alias
[
nested_table
],
nested_column
);
String
source_name
;
if
(
alias_to_name
.
count
(
result_name
))
{
source_name
=
alias_to_name
[
result_name
];
}
else
if
(
alias_to_name
.
count
(
result_table
))
{
source_name
=
DataTypeNested
::
concatenateNestedName
(
alias_to_name
[
result_table
],
result_column
);
}
else
continue
;
{
throw
Exception
(
"Unexpected result of ARRAY JOIN"
,
ErrorCodes
::
LOGICAL_ERROR
);
}
actions
.
add
(
ExpressionActions
::
Action
::
copyColumn
(
name
,
array_joined
_name
));
actions
.
add
(
ExpressionActions
::
Action
::
copyColumn
(
source_name
,
result
_name
));
}
actions
.
add
(
ExpressionActions
::
Action
::
arrayJoin
(
columns_for_array_join
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录