Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
95c618b1
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,发现更多精彩内容 >>
提交
95c618b1
编写于
10月 26, 2018
作者:
C
chertus
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ExpressionAnalyzer: remove duplicated code
上级
713c44c3
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
44 addition
and
73 deletion
+44
-73
dbms/src/Interpreters/ExpressionAnalyzer.cpp
dbms/src/Interpreters/ExpressionAnalyzer.cpp
+5
-46
dbms/src/Interpreters/PredicateExpressionsOptimizer.cpp
dbms/src/Interpreters/PredicateExpressionsOptimizer.cpp
+3
-25
dbms/src/Interpreters/PredicateExpressionsOptimizer.h
dbms/src/Interpreters/PredicateExpressionsOptimizer.h
+0
-2
dbms/src/Interpreters/evaluateQualified.cpp
dbms/src/Interpreters/evaluateQualified.cpp
+32
-0
dbms/src/Interpreters/evaluateQualified.h
dbms/src/Interpreters/evaluateQualified.h
+4
-0
未找到文件。
dbms/src/Interpreters/ExpressionAnalyzer.cpp
浏览文件 @
95c618b1
...
...
@@ -275,55 +275,14 @@ bool ExpressionAnalyzer::isRemoteStorage() const
}
static
std
::
vector
<
ASTTableExpression
>
getTableExpressions
(
const
ASTPtr
&
query
)
{
ASTSelectQuery
*
select_query
=
typeid_cast
<
ASTSelectQuery
*>
(
query
.
get
());
std
::
vector
<
ASTTableExpression
>
table_expressions
;
if
(
select_query
&&
select_query
->
tables
)
{
for
(
const
auto
&
element
:
select_query
->
tables
->
children
)
{
ASTTablesInSelectQueryElement
&
select_element
=
static_cast
<
ASTTablesInSelectQueryElement
&>
(
*
element
);
if
(
select_element
.
table_expression
)
table_expressions
.
emplace_back
(
static_cast
<
ASTTableExpression
&>
(
*
select_element
.
table_expression
));
}
}
return
table_expressions
;
}
void
ExpressionAnalyzer
::
translateQualifiedNames
()
{
if
(
!
select_query
||
!
select_query
->
tables
||
select_query
->
tables
->
children
.
empty
())
return
;
std
::
vector
<
DatabaseAndTableWithAlias
>
tables
;
std
::
vector
<
ASTTableExpression
>
tables_expression
=
getTableExpressions
(
query
);
std
::
vector
<
DatabaseAndTableWithAlias
>
tables
=
getDatabaseAndTableWithAliases
(
select_query
,
context
.
getCurrentDatabase
());
LogAST
log
;
for
(
const
auto
&
table_expression
:
tables_expression
)
{
auto
table
=
getTableNameWithAliasFromTableExpression
(
table_expression
,
context
.
getCurrentDatabase
());
{
/// debug print
size_t
depth
=
0
;
DumpASTNode
dump
(
table_expression
,
log
.
stream
(),
depth
,
"getTableNames"
);
if
(
table_expression
.
database_and_table_name
)
DumpASTNode
(
*
table_expression
.
database_and_table_name
,
log
.
stream
(),
depth
);
if
(
table_expression
.
table_function
)
DumpASTNode
(
*
table_expression
.
table_function
,
log
.
stream
(),
depth
);
if
(
table_expression
.
subquery
)
DumpASTNode
(
*
table_expression
.
subquery
,
log
.
stream
(),
depth
);
dump
.
print
(
"getTableNameWithAlias"
,
table
.
database
+
'.'
+
table
.
table
+
' '
+
table
.
alias
);
}
tables
.
emplace_back
(
table
);
}
TranslateQualifiedNamesVisitor
visitor
(
source_columns
,
tables
,
log
.
stream
());
visitor
.
visit
(
query
);
}
...
...
@@ -602,13 +561,13 @@ void ExpressionAnalyzer::normalizeTree()
TableNamesAndColumnNames
table_names_and_column_names
;
if
(
select_query
&&
select_query
->
tables
&&
!
select_query
->
tables
->
children
.
empty
())
{
std
::
vector
<
ASTTableExpression
>
tables_expression
=
getTableExpressions
(
query
);
std
::
vector
<
const
ASTTableExpression
*>
tables_expression
=
getSelectTablesExpression
(
select_
query
);
bool
first
=
true
;
for
(
const
auto
&
table_expression
:
tables_expression
)
for
(
const
auto
*
table_expression
:
tables_expression
)
{
const
auto
table_name
=
getTableNameWithAliasFromTableExpression
(
table_expression
,
context
.
getCurrentDatabase
());
NamesAndTypesList
names_and_types
=
getNamesAndTypeListFromTableExpression
(
table_expression
,
context
);
const
auto
table_name
=
getTableNameWithAliasFromTableExpression
(
*
table_expression
,
context
.
getCurrentDatabase
());
NamesAndTypesList
names_and_types
=
getNamesAndTypeListFromTableExpression
(
*
table_expression
,
context
);
if
(
!
first
)
{
...
...
dbms/src/Interpreters/PredicateExpressionsOptimizer.cpp
浏览文件 @
95c618b1
...
...
@@ -44,11 +44,8 @@ bool PredicateExpressionsOptimizer::optimizeImpl(
/// split predicate with `and`
PredicateExpressions
outer_predicate_expressions
=
splitConjunctionPredicate
(
outer_expression
);
std
::
vector
<
ASTTableExpression
*>
tables_expression
=
getSelectTablesExpression
(
ast_select
);
std
::
vector
<
DatabaseAndTableWithAlias
>
database_and_table_with_aliases
;
for
(
const
auto
&
table_expression
:
tables_expression
)
database_and_table_with_aliases
.
emplace_back
(
getTableNameWithAliasFromTableExpression
(
*
table_expression
,
context
.
getCurrentDatabase
()));
std
::
vector
<
DatabaseAndTableWithAlias
>
database_and_table_with_aliases
=
getDatabaseAndTableWithAliases
(
ast_select
,
context
.
getCurrentDatabase
());
bool
is_rewrite_subquery
=
false
;
for
(
const
auto
&
outer_predicate
:
outer_predicate_expressions
)
...
...
@@ -336,7 +333,7 @@ ASTs PredicateExpressionsOptimizer::evaluateAsterisk(ASTSelectQuery * select_que
if
(
!
select_query
->
tables
||
select_query
->
tables
->
children
.
empty
())
return
{};
std
::
vector
<
ASTTableExpression
*>
tables_expression
=
getSelectTablesExpression
(
select_query
);
std
::
vector
<
const
ASTTableExpression
*>
tables_expression
=
getSelectTablesExpression
(
select_query
);
if
(
const
auto
qualified_asterisk
=
typeid_cast
<
ASTQualifiedAsterisk
*>
(
asterisk
.
get
()))
{
...
...
@@ -406,25 +403,6 @@ ASTs PredicateExpressionsOptimizer::evaluateAsterisk(ASTSelectQuery * select_que
return
projection_columns
;
}
std
::
vector
<
ASTTableExpression
*>
PredicateExpressionsOptimizer
::
getSelectTablesExpression
(
ASTSelectQuery
*
select_query
)
{
if
(
!
select_query
->
tables
)
return
{};
std
::
vector
<
ASTTableExpression
*>
tables_expression
;
const
ASTTablesInSelectQuery
&
tables_in_select_query
=
static_cast
<
const
ASTTablesInSelectQuery
&>
(
*
select_query
->
tables
);
for
(
const
auto
&
child
:
tables_in_select_query
.
children
)
{
ASTTablesInSelectQueryElement
*
tables_element
=
static_cast
<
ASTTablesInSelectQueryElement
*>
(
child
.
get
());
if
(
tables_element
->
table_expression
)
tables_expression
.
emplace_back
(
static_cast
<
ASTTableExpression
*>
(
tables_element
->
table_expression
.
get
()));
}
return
tables_expression
;
}
void
PredicateExpressionsOptimizer
::
cleanExpressionAlias
(
ASTPtr
&
expression
)
{
const
auto
my_alias
=
expression
->
tryGetAlias
();
...
...
dbms/src/Interpreters/PredicateExpressionsOptimizer.h
浏览文件 @
95c618b1
...
...
@@ -105,8 +105,6 @@ private:
ASTs
getSelectQueryProjectionColumns
(
ASTPtr
&
ast
);
std
::
vector
<
ASTTableExpression
*>
getSelectTablesExpression
(
ASTSelectQuery
*
select_query
);
ASTs
evaluateAsterisk
(
ASTSelectQuery
*
select_query
,
const
ASTPtr
&
asterisk
);
void
cleanExpressionAlias
(
ASTPtr
&
expression
);
...
...
dbms/src/Interpreters/evaluateQualified.cpp
浏览文件 @
95c618b1
...
...
@@ -5,6 +5,7 @@
#include <Parsers/IAST.h>
#include <Parsers/ASTIdentifier.h>
#include <Parsers/ASTTablesInSelectQuery.h>
#include <Parsers/ASTSelectQuery.h>
namespace
DB
{
...
...
@@ -164,4 +165,35 @@ void DatabaseAndTableWithAlias::makeQualifiedName(const ASTPtr & ast) const
}
}
std
::
vector
<
const
ASTTableExpression
*>
getSelectTablesExpression
(
const
ASTSelectQuery
*
select_query
)
{
if
(
!
select_query
->
tables
)
return
{};
std
::
vector
<
const
ASTTableExpression
*>
tables_expression
;
for
(
const
auto
&
child
:
select_query
->
tables
->
children
)
{
ASTTablesInSelectQueryElement
*
tables_element
=
static_cast
<
ASTTablesInSelectQueryElement
*>
(
child
.
get
());
if
(
tables_element
->
table_expression
)
tables_expression
.
emplace_back
(
static_cast
<
const
ASTTableExpression
*>
(
tables_element
->
table_expression
.
get
()));
}
return
tables_expression
;
}
std
::
vector
<
DatabaseAndTableWithAlias
>
getDatabaseAndTableWithAliases
(
const
ASTSelectQuery
*
select_query
,
const
String
&
current_database
)
{
std
::
vector
<
const
ASTTableExpression
*>
tables_expression
=
getSelectTablesExpression
(
select_query
);
std
::
vector
<
DatabaseAndTableWithAlias
>
database_and_table_with_aliases
;
database_and_table_with_aliases
.
reserve
(
tables_expression
.
size
());
for
(
const
auto
&
table_expression
:
tables_expression
)
database_and_table_with_aliases
.
emplace_back
(
getTableNameWithAliasFromTableExpression
(
*
table_expression
,
current_database
));
return
database_and_table_with_aliases
;
}
}
dbms/src/Interpreters/evaluateQualified.h
浏览文件 @
95c618b1
...
...
@@ -9,6 +9,7 @@ namespace DB
class
IAST
;
using
ASTPtr
=
std
::
shared_ptr
<
IAST
>
;
class
ASTSelectQuery
;
class
ASTIdentifier
;
struct
ASTTableExpression
;
...
...
@@ -36,4 +37,7 @@ size_t getNumComponentsToStripInOrderToTranslateQualifiedName(const ASTIdentifie
std
::
pair
<
String
,
String
>
getDatabaseAndTableNameFromIdentifier
(
const
ASTIdentifier
&
identifier
);
std
::
vector
<
const
ASTTableExpression
*>
getSelectTablesExpression
(
const
ASTSelectQuery
*
select_query
);
std
::
vector
<
DatabaseAndTableWithAlias
>
getDatabaseAndTableWithAliases
(
const
ASTSelectQuery
*
select_query
,
const
String
&
current_database
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录