Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
864dacd1
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,发现更多精彩内容 >>
提交
864dacd1
编写于
6月 16, 2019
作者:
A
Alexey Milovidov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Merging
上级
f98d0a10
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
39 addition
and
35 deletion
+39
-35
dbms/src/Common/ErrorCodes.cpp
dbms/src/Common/ErrorCodes.cpp
+1
-0
dbms/src/Interpreters/InterpreterCreateQuery.cpp
dbms/src/Interpreters/InterpreterCreateQuery.cpp
+16
-10
dbms/src/Interpreters/QueryNormalizer.cpp
dbms/src/Interpreters/QueryNormalizer.cpp
+12
-8
dbms/src/Interpreters/addTypeConversionToAST.cpp
dbms/src/Interpreters/addTypeConversionToAST.cpp
+3
-10
dbms/src/Parsers/ASTColumnDeclaration.cpp
dbms/src/Parsers/ASTColumnDeclaration.cpp
+6
-6
dbms/src/Parsers/ASTColumnDeclaration.h
dbms/src/Parsers/ASTColumnDeclaration.h
+1
-1
未找到文件。
dbms/src/Common/ErrorCodes.cpp
浏览文件 @
864dacd1
...
...
@@ -430,6 +430,7 @@ namespace ErrorCodes
extern
const
int
MYSQL_CLIENT_INSUFFICIENT_CAPABILITIES
=
453
;
extern
const
int
OPENSSL_ERROR
=
454
;
extern
const
int
SUSPICIOUS_TYPE_FOR_LOW_CARDINALITY
=
455
;
extern
const
int
UNKNOWN_QUERY_PARAMETER
=
456
;
extern
const
int
KEEPER_EXCEPTION
=
999
;
extern
const
int
POCO_EXCEPTION
=
1000
;
...
...
dbms/src/Interpreters/InterpreterCreateQuery.cpp
浏览文件 @
864dacd1
...
...
@@ -41,10 +41,10 @@
#include <Databases/DatabaseFactory.h>
#include <Databases/IDatabase.h>
#include <Common/ZooKeeper/ZooKeeper.h>
#include <Compression/CompressionFactory.h>
#include <Interpreters/InterpreterDropQuery.h>
#include <Interpreters/addTypeConversionToAST.h>
namespace
DB
...
...
@@ -278,19 +278,25 @@ ColumnsDescription InterpreterCreateQuery::getColumnsDescription(const ASTExpres
/// add column to postprocessing if there is a default_expression specified
if
(
col_decl
.
default_expression
)
{
/** for columns with explicitly-specified type create two expressions:
* 1. default_expression aliased as column name with _tmp suffix
* 2. conversion of expression (1) to explicitly-specified type alias as column name */
/** For columns with explicitly-specified type create two expressions:
* 1. default_expression aliased as column name with _tmp suffix
* 2. conversion of expression (1) to explicitly-specified type alias as column name
*/
if
(
col_decl
.
type
)
{
const
auto
&
final_column_name
=
col_decl
.
name
;
const
auto
tmp_column_name
=
final_column_name
+
"_tmp"
;
const
auto
data_type_ptr
=
column_names_and_types
.
back
().
type
.
get
();
default_expr_list
->
children
.
emplace_back
(
setAlias
(
makeASTFunction
(
"CAST"
,
std
::
make_shared
<
ASTIdentifier
>
(
tmp_column_name
),
std
::
make_shared
<
ASTLiteral
>
(
data_type_ptr
->
getName
())),
final_column_name
));
default_expr_list
->
children
.
emplace_back
(
setAlias
(
col_decl
.
default_expression
->
clone
(),
tmp_column_name
));
default_expr_list
->
children
.
emplace_back
(
setAlias
(
addTypeConversionToAST
(
std
::
make_shared
<
ASTIdentifier
>
(
tmp_column_name
),
data_type_ptr
->
getName
()),
final_column_name
));
default_expr_list
->
children
.
emplace_back
(
setAlias
(
col_decl
.
default_expression
->
clone
(),
tmp_column_name
));
}
else
default_expr_list
->
children
.
emplace_back
(
setAlias
(
col_decl
.
default_expression
->
clone
(),
col_decl
.
name
));
...
...
@@ -329,7 +335,7 @@ ColumnsDescription InterpreterCreateQuery::getColumnsDescription(const ASTExpres
column
.
type
=
name_type_it
->
type
;
if
(
!
column
.
type
->
equals
(
*
deduced_type
))
default_expr
=
makeASTFunction
(
"CAST"
,
default_expr
,
std
::
make_shared
<
ASTLiteral
>
(
column
.
type
->
getName
()
));
default_expr
=
addTypeConversionToAST
(
std
::
move
(
default_expr
),
column
.
type
->
getName
(
));
}
else
column
.
type
=
defaults_sample_block
.
getByName
(
column
.
name
).
type
;
...
...
dbms/src/Interpreters/QueryNormalizer.cpp
浏览文件 @
864dacd1
...
...
@@ -8,6 +8,7 @@
#include <Parsers/ASTFunction.h>
#include <Parsers/ASTIdentifier.h>
#include <Parsers/ASTSelectQuery.h>
#include <Parsers/ASTQueryParameter.h>
#include <Parsers/ASTTablesInSelectQuery.h>
#include <Common/StringUtils/StringUtils.h>
#include <Common/typeid_cast.h>
...
...
@@ -20,6 +21,7 @@ namespace ErrorCodes
{
extern
const
int
TOO_DEEP_AST
;
extern
const
int
CYCLIC_ALIASES
;
extern
const
int
UNKNOWN_QUERY_PARAMETER
;
}
...
...
@@ -227,14 +229,16 @@ void QueryNormalizer::visit(ASTPtr & ast, Data & data)
data
.
current_alias
=
my_alias
;
}
if
(
auto
*
node
=
ast
->
as
<
ASTFunction
>
())
visit
(
*
node
,
ast
,
data
);
if
(
auto
*
node
=
ast
->
as
<
ASTIdentifier
>
())
visit
(
*
node
,
ast
,
data
);
if
(
auto
*
node
=
ast
->
as
<
ASTTablesInSelectQueryElement
>
())
visit
(
*
node
,
ast
,
data
);
if
(
auto
*
node
=
ast
->
as
<
ASTSelectQuery
>
())
visit
(
*
node
,
ast
,
data
);
if
(
auto
*
node_func
=
ast
->
as
<
ASTFunction
>
())
visit
(
*
node_func
,
ast
,
data
);
else
if
(
auto
*
node_id
=
ast
->
as
<
ASTIdentifier
>
())
visit
(
*
node_id
,
ast
,
data
);
else
if
(
auto
*
node_tables
=
ast
->
as
<
ASTTablesInSelectQueryElement
>
())
visit
(
*
node_tables
,
ast
,
data
);
else
if
(
auto
*
node_select
=
ast
->
as
<
ASTSelectQuery
>
())
visit
(
*
node_select
,
ast
,
data
);
else
if
(
auto
*
node_param
=
ast
->
as
<
ASTQueryParameter
>
())
throw
Exception
(
"Query parameter "
+
backQuote
(
node_param
->
name
)
+
" was not set"
,
ErrorCodes
::
UNKNOWN_QUERY_PARAMETER
);
/// If we replace the root of the subtree, we will be called again for the new root, in case the alias is replaced by an alias.
if
(
ast
.
get
()
!=
initial_ast
.
get
())
...
...
dbms/src/Interpreters/addTypeConversionToAST.cpp
浏览文件 @
864dacd1
...
...
@@ -11,23 +11,16 @@ namespace DB
ASTPtr
addTypeConversionToAST
(
ASTPtr
&&
ast
,
const
String
&
type_name
)
{
auto
func
=
std
::
make_shared
<
ASTFunction
>
();
ASTPtr
res
=
func
;
auto
func
=
makeASTFunction
(
"CAST"
,
ast
,
std
::
make_shared
<
ASTLiteral
>
(
type_name
));
if
(
ASTWithAlias
*
ast_with_alias
=
ast
->
as
<
ASTWithAlias
>
(
))
if
(
ASTWithAlias
*
ast_with_alias
=
dynamic_cast
<
ASTWithAlias
*>
(
ast
.
get
()
))
{
func
->
alias
=
ast_with_alias
->
alias
;
func
->
prefer_alias_to_column_name
=
ast_with_alias
->
prefer_alias_to_column_name
;
ast_with_alias
->
alias
.
clear
();
}
func
->
name
=
"CAST"
;
auto
exp_list
=
std
::
make_shared
<
ASTExpressionList
>
();
func
->
arguments
=
exp_list
;
func
->
children
.
push_back
(
func
->
arguments
);
exp_list
->
children
.
emplace_back
(
std
::
move
(
ast
));
exp_list
->
children
.
emplace_back
(
std
::
make_shared
<
ASTLiteral
>
(
type_name
));
return
res
;
return
func
;
}
}
dbms/src/Parsers/ASTColumnDeclaration.cpp
浏览文件 @
864dacd1
...
...
@@ -21,18 +21,18 @@ ASTPtr ASTColumnDeclaration::clone() const
res
->
children
.
push_back
(
res
->
default_expression
);
}
if
(
codec
)
{
res
->
codec
=
codec
->
clone
();
res
->
children
.
push_back
(
res
->
codec
);
}
if
(
comment
)
{
res
->
comment
=
comment
->
clone
();
res
->
children
.
push_back
(
res
->
comment
);
}
if
(
codec
)
{
res
->
codec
=
codec
->
clone
();
res
->
children
.
push_back
(
res
->
codec
);
}
if
(
ttl
)
{
res
->
ttl
=
ttl
->
clone
();
...
...
dbms/src/Parsers/ASTColumnDeclaration.h
浏览文件 @
864dacd1
...
...
@@ -15,8 +15,8 @@ public:
ASTPtr
type
;
String
default_specifier
;
ASTPtr
default_expression
;
ASTPtr
codec
;
ASTPtr
comment
;
ASTPtr
codec
;
ASTPtr
ttl
;
String
getID
(
char
delim
)
const
override
{
return
"ColumnDeclaration"
+
(
delim
+
name
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录