Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
4d65dd3b
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,发现更多精彩内容 >>
提交
4d65dd3b
编写于
9月 04, 2016
作者:
A
Alexey Milovidov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Get rid of buggy code (that coincidently was useless too) [#METR-2944].
上级
322e5031
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
5 addition
and
141 deletion
+5
-141
dbms/include/DB/Parsers/ASTFunction.h
dbms/include/DB/Parsers/ASTFunction.h
+3
-18
dbms/src/Interpreters/ExpressionAnalyzer.cpp
dbms/src/Interpreters/ExpressionAnalyzer.cpp
+1
-32
dbms/src/Parsers/ASTFunction.cpp
dbms/src/Parsers/ASTFunction.cpp
+1
-87
dbms/src/Parsers/ParserCase.cpp
dbms/src/Parsers/ParserCase.cpp
+0
-4
未找到文件。
dbms/include/DB/Parsers/ASTFunction.h
浏览文件 @
4d65dd3b
...
...
@@ -10,7 +10,7 @@
namespace
DB
{
/**
Применение функции или оператора
/**
AST for function application or operator.
*/
class
ASTFunction
:
public
ASTWithAlias
{
...
...
@@ -25,41 +25,26 @@ public:
ARRAY_JOIN
,
};
/// имя функции
String
name
;
/// аргументы
ASTPtr
arguments
;
///
параметры - для параметрических агрегатных функций. Пример: quantile(0.9)(x) - то, что в первых скобках - параметры
.
///
parameters - for parametric aggregate function. Example: quantile(0.9)(x) - what in first parens are 'parameters'
.
ASTPtr
parameters
;
FunctionKind
kind
{
UNKNOWN
};
enum
class
Genus
{
ORDINARY
=
0
,
CASE_WITH_EXPR
,
CASE_WITHOUT_EXPR
,
CASE_ARRAY
};
Genus
genus
{
Genus
::
ORDINARY
};
public:
ASTFunction
()
=
default
;
ASTFunction
(
const
StringRange
range_
)
:
ASTWithAlias
(
range_
)
{}
String
getColumnName
()
const
override
;
/**
Получить текст, который идентифицирует этот элемент
. */
/**
Get text identifying the AST node
. */
String
getID
()
const
override
;
ASTPtr
clone
()
const
override
;
protected:
void
formatImplWithoutAlias
(
const
FormatSettings
&
settings
,
FormatState
&
state
,
FormatStateStacked
frame
)
const
override
;
private:
void
formatCase
(
const
FormatSettings
&
settings
,
FormatState
&
state
,
FormatStateStacked
frame
)
const
;
};
...
...
dbms/src/Interpreters/ExpressionAnalyzer.cpp
浏览文件 @
4d65dd3b
...
...
@@ -129,37 +129,6 @@ bool functionIsInOrGlobalInOperator(const String & name)
return
name
==
"in"
||
name
==
"notIn"
||
name
==
"globalIn"
||
name
==
"globalNotIn"
;
}
/// Create a function uniquely identified by the first two parameters. If this
/// function actually is a CASE expression, record this information.
FunctionPtr
getFunctionFromFactory
(
const
String
&
name
,
const
ASTFunction
::
Genus
genus
,
const
Context
&
context
)
{
FunctionPtr
function
=
FunctionFactory
::
instance
().
get
(
name
,
context
);
if
(
genus
==
ASTFunction
::
Genus
::
CASE_WITH_EXPR
)
{
FunctionTransform
*
fun_transform
=
typeid_cast
<
FunctionTransform
*>
(
&*
function
);
if
(
fun_transform
==
nullptr
)
throw
Exception
{
"Internal error"
,
ErrorCodes
::
LOGICAL_ERROR
};
fun_transform
->
setCaseMode
();
}
else
if
(
genus
==
ASTFunction
::
Genus
::
CASE_WITHOUT_EXPR
)
{
FunctionMultiIf
*
fun_multi_if
=
typeid_cast
<
FunctionMultiIf
*>
(
&*
function
);
if
(
fun_multi_if
==
nullptr
)
throw
Exception
{
"Internal error"
,
ErrorCodes
::
LOGICAL_ERROR
};
fun_multi_if
->
setCaseMode
();
}
else
if
(
genus
==
ASTFunction
::
Genus
::
CASE_ARRAY
)
{
FunctionArray
*
fun_array
=
typeid_cast
<
FunctionArray
*>
(
&*
function
);
if
(
fun_array
==
nullptr
)
throw
Exception
{
"Internal error"
,
ErrorCodes
::
LOGICAL_ERROR
};
fun_array
->
setCaseMode
();
}
return
function
;
}
void
removeDuplicateColumns
(
NamesAndTypesList
&
columns
)
{
std
::
set
<
String
>
names
;
...
...
@@ -1753,7 +1722,7 @@ void ExpressionAnalyzer::getActionsImpl(ASTPtr ast, bool no_subqueries, bool onl
return
;
}
const
FunctionPtr
&
function
=
getFunctionFromFactory
(
node
->
name
,
node
->
genus
,
context
);
const
FunctionPtr
&
function
=
FunctionFactory
::
instance
().
get
(
node
->
name
,
context
);
Names
argument_names
;
DataTypes
argument_types
;
...
...
dbms/src/Parsers/ASTFunction.cpp
浏览文件 @
4d65dd3b
...
...
@@ -66,13 +66,7 @@ void ASTFunction::formatImplWithoutAlias(const FormatSettings & settings, Format
nested_need_parens
.
need_parens
=
true
;
nested_dont_need_parens
.
need_parens
=
false
;
if
((
genus
==
Genus
::
CASE_WITH_EXPR
)
||
(
genus
==
Genus
::
CASE_WITHOUT_EXPR
))
{
formatCase
(
settings
,
state
,
frame
);
return
;
}
/// Стоит ли записать эту функцию в виде оператора?
/// Should this function to be written as operator?
bool
written
=
false
;
if
(
arguments
&&
!
parameters
)
{
...
...
@@ -264,84 +258,4 @@ void ASTFunction::formatImplWithoutAlias(const FormatSettings & settings, Format
}
}
void
ASTFunction
::
formatCase
(
const
FormatSettings
&
settings
,
FormatState
&
state
,
FormatStateStacked
frame
)
const
{
static
constexpr
auto
s_case
=
"CASE"
;
static
constexpr
auto
s_when
=
"WHEN"
;
static
constexpr
auto
s_then
=
"THEN"
;
static
constexpr
auto
s_else
=
"ELSE"
;
static
constexpr
auto
s_end
=
"END"
;
static
constexpr
auto
s_ws
=
" "
;
const
ASTExpressionList
*
expr_list
=
static_cast
<
const
ASTExpressionList
*>
(
&*
arguments
);
const
ASTs
&
args
=
expr_list
->
children
;
frame
.
need_parens
=
false
;
std
::
string
indent_str
=
settings
.
one_line
?
""
:
std
::
string
(
4
*
frame
.
indent
,
' '
);
std
::
string
indent_str2
=
settings
.
one_line
?
""
:
std
::
string
(
4
*
(
frame
.
indent
+
1
),
' '
);
settings
.
ostr
<<
(
settings
.
hilite
?
hilite_keyword
:
""
)
<<
s_case
<<
s_ws
<<
(
settings
.
hilite
?
hilite_none
:
""
);
if
(
genus
==
Genus
::
CASE_WITH_EXPR
)
{
args
[
0
]
->
formatImpl
(
settings
,
state
,
frame
);
settings
.
ostr
<<
settings
.
nl_or_ws
;
const
ASTFunction
*
src_array_function
=
static_cast
<
const
ASTFunction
*>
(
&*
args
[
1
]);
const
ASTExpressionList
*
src_expr_list
=
static_cast
<
const
ASTExpressionList
*>
(
&*
src_array_function
->
arguments
);
const
ASTFunction
*
dst_array_function
=
static_cast
<
const
ASTFunction
*>
(
&*
args
[
2
]);
const
ASTExpressionList
*
dst_expr_list
=
static_cast
<
const
ASTExpressionList
*>
(
&*
dst_array_function
->
arguments
);
size_t
size
=
src_expr_list
->
children
.
size
();
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
settings
.
ostr
<<
(
settings
.
hilite
?
hilite_keyword
:
""
)
<<
indent_str2
<<
s_when
<<
s_ws
;
src_expr_list
->
children
[
i
]
->
formatImpl
(
settings
,
state
,
frame
);
settings
.
ostr
<<
s_ws
;
settings
.
ostr
<<
(
settings
.
hilite
?
hilite_keyword
:
""
)
<<
s_then
<<
s_ws
;
settings
.
ostr
<<
hilite_none
;
dst_expr_list
->
children
[
i
]
->
formatImpl
(
settings
,
state
,
frame
);
settings
.
ostr
<<
settings
.
nl_or_ws
;
}
}
else
if
(
genus
==
Genus
::
CASE_WITHOUT_EXPR
)
{
settings
.
ostr
<<
settings
.
nl_or_ws
;
for
(
size_t
i
=
0
;
i
<
(
args
.
size
()
-
1
);
++
i
)
{
if
((
i
%
2
)
==
0
)
{
settings
.
ostr
<<
(
settings
.
hilite
?
hilite_keyword
:
""
)
<<
indent_str2
<<
s_when
<<
s_ws
;
args
[
i
]
->
formatImpl
(
settings
,
state
,
frame
);
settings
.
ostr
<<
" "
;
}
else
{
settings
.
ostr
<<
(
settings
.
hilite
?
hilite_keyword
:
""
)
<<
s_then
<<
s_ws
;
settings
.
ostr
<<
hilite_none
;
args
[
i
]
->
formatImpl
(
settings
,
state
,
frame
);
settings
.
ostr
<<
settings
.
nl_or_ws
;
}
}
}
else
throw
Exception
{
"Invalid function genus"
,
ErrorCodes
::
INVALID_FUNCTION_GENUS
};
settings
.
ostr
<<
(
settings
.
hilite
?
hilite_keyword
:
""
)
<<
indent_str2
<<
s_else
<<
s_ws
;
settings
.
ostr
<<
hilite_none
;
args
.
back
()
->
formatImpl
(
settings
,
state
,
frame
);
settings
.
ostr
<<
settings
.
nl_or_ws
;
settings
.
ostr
<<
(
settings
.
hilite
?
hilite_keyword
:
""
)
<<
indent_str
<<
s_end
;
}
}
dbms/src/Parsers/ParserCase.cpp
浏览文件 @
4d65dd3b
...
...
@@ -113,13 +113,11 @@ bool ParserCase::parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_p
auto
src_array_function
=
std
::
make_shared
<
ASTFunction
>
(
StringRange
{
begin
,
pos
});
src_array_function
->
name
=
"array"
;
src_array_function
->
genus
=
ASTFunction
::
Genus
::
CASE_ARRAY
;
src_array_function
->
arguments
=
src_expr_list
;
src_array_function
->
children
.
push_back
(
src_array_function
->
arguments
);
auto
dst_array_function
=
std
::
make_shared
<
ASTFunction
>
(
StringRange
{
begin
,
pos
});
dst_array_function
->
name
=
"array"
;
dst_array_function
->
genus
=
ASTFunction
::
Genus
::
CASE_ARRAY
;
dst_array_function
->
arguments
=
dst_expr_list
;
dst_array_function
->
children
.
push_back
(
dst_array_function
->
arguments
);
...
...
@@ -131,7 +129,6 @@ bool ParserCase::parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_p
auto
function
=
std
::
make_shared
<
ASTFunction
>
(
StringRange
{
begin
,
pos
});
function
->
name
=
"transform"
;
function
->
genus
=
ASTFunction
::
Genus
::
CASE_WITH_EXPR
;
function
->
arguments
=
function_args
;
function
->
children
.
push_back
(
function
->
arguments
);
...
...
@@ -148,7 +145,6 @@ bool ParserCase::parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_p
auto
function
=
std
::
make_shared
<
ASTFunction
>
(
StringRange
{
begin
,
pos
});
function
->
name
=
"multiIf"
;
function
->
genus
=
ASTFunction
::
Genus
::
CASE_WITHOUT_EXPR
;
function
->
arguments
=
function_args
;
function
->
children
.
push_back
(
function
->
arguments
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录