Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
d4b2a373
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,发现更多精彩内容 >>
未验证
提交
d4b2a373
编写于
2月 16, 2021
作者:
T
tavplubix
提交者:
GitHub
2月 16, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #20350 from amosbird/tviewf
Disable table function view in expression
上级
cb2beb47
a551edd8
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
98 addition
and
41 deletion
+98
-41
src/Parsers/ExpressionElementParsers.cpp
src/Parsers/ExpressionElementParsers.cpp
+50
-31
src/Parsers/ExpressionElementParsers.h
src/Parsers/ExpressionElementParsers.h
+15
-1
src/Parsers/ExpressionListParsers.cpp
src/Parsers/ExpressionListParsers.cpp
+13
-4
src/Parsers/ExpressionListParsers.h
src/Parsers/ExpressionListParsers.h
+18
-4
src/Parsers/ParserTablesInSelectQuery.cpp
src/Parsers/ParserTablesInSelectQuery.cpp
+1
-1
tests/queries/0_stateless/01715_table_function_view_fix.reference
...eries/0_stateless/01715_table_function_view_fix.reference
+0
-0
tests/queries/0_stateless/01715_table_function_view_fix.sql
tests/queries/0_stateless/01715_table_function_view_fix.sql
+1
-0
未找到文件。
src/Parsers/ExpressionElementParsers.cpp
浏览文件 @
d4b2a373
...
...
@@ -266,7 +266,7 @@ bool ParserFunction::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
ParserIdentifier
id_parser
;
ParserKeyword
distinct
(
"DISTINCT"
);
ParserKeyword
all
(
"ALL"
);
ParserExpressionList
contents
(
false
);
ParserExpressionList
contents
(
false
,
is_table_function
);
ParserSelectWithUnionQuery
select
;
ParserKeyword
over
(
"OVER"
);
...
...
@@ -278,6 +278,12 @@ bool ParserFunction::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
ASTPtr
expr_list_args
;
ASTPtr
expr_list_params
;
if
(
is_table_function
)
{
if
(
ParserTableFunctionView
().
parse
(
pos
,
node
,
expected
))
return
true
;
}
if
(
!
id_parser
.
parse
(
pos
,
identifier
,
expected
))
return
false
;
...
...
@@ -312,36 +318,6 @@ bool ParserFunction::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
}
}
if
(
!
has_distinct
&&
!
has_all
)
{
auto
old_pos
=
pos
;
auto
maybe_an_subquery
=
pos
->
type
==
TokenType
::
OpeningRoundBracket
;
if
(
select
.
parse
(
pos
,
query
,
expected
))
{
auto
&
select_ast
=
query
->
as
<
ASTSelectWithUnionQuery
&>
();
if
(
select_ast
.
list_of_selects
->
children
.
size
()
==
1
&&
maybe_an_subquery
)
{
// It's an subquery. Bail out.
pos
=
old_pos
;
}
else
{
if
(
pos
->
type
!=
TokenType
::
ClosingRoundBracket
)
return
false
;
++
pos
;
auto
function_node
=
std
::
make_shared
<
ASTFunction
>
();
tryGetIdentifierNameInto
(
identifier
,
function_node
->
name
);
auto
expr_list_with_single_query
=
std
::
make_shared
<
ASTExpressionList
>
();
expr_list_with_single_query
->
children
.
push_back
(
query
);
function_node
->
arguments
=
expr_list_with_single_query
;
function_node
->
children
.
push_back
(
function_node
->
arguments
);
node
=
function_node
;
return
true
;
}
}
}
const
char
*
contents_begin
=
pos
->
begin
;
if
(
!
contents
.
parse
(
pos
,
expr_list_args
,
expected
))
return
false
;
...
...
@@ -477,6 +453,49 @@ bool ParserFunction::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
return
true
;
}
bool
ParserTableFunctionView
::
parseImpl
(
Pos
&
pos
,
ASTPtr
&
node
,
Expected
&
expected
)
{
ParserIdentifier
id_parser
;
ParserKeyword
view
(
"VIEW"
);
ParserSelectWithUnionQuery
select
;
ASTPtr
identifier
;
ASTPtr
query
;
if
(
!
view
.
ignore
(
pos
,
expected
))
return
false
;
if
(
pos
->
type
!=
TokenType
::
OpeningRoundBracket
)
return
false
;
++
pos
;
bool
maybe_an_subquery
=
pos
->
type
==
TokenType
::
OpeningRoundBracket
;
if
(
!
select
.
parse
(
pos
,
query
,
expected
))
return
false
;
auto
&
select_ast
=
query
->
as
<
ASTSelectWithUnionQuery
&>
();
if
(
select_ast
.
list_of_selects
->
children
.
size
()
==
1
&&
maybe_an_subquery
)
{
// It's an subquery. Bail out.
return
false
;
}
if
(
pos
->
type
!=
TokenType
::
ClosingRoundBracket
)
return
false
;
++
pos
;
auto
function_node
=
std
::
make_shared
<
ASTFunction
>
();
tryGetIdentifierNameInto
(
identifier
,
function_node
->
name
);
auto
expr_list_with_single_query
=
std
::
make_shared
<
ASTExpressionList
>
();
expr_list_with_single_query
->
children
.
push_back
(
query
);
function_node
->
name
=
"view"
;
function_node
->
arguments
=
expr_list_with_single_query
;
function_node
->
children
.
push_back
(
function_node
->
arguments
);
node
=
function_node
;
return
true
;
}
bool
ParserWindowReference
::
parseImpl
(
Pos
&
pos
,
ASTPtr
&
node
,
Expected
&
expected
)
{
ASTFunction
*
function
=
dynamic_cast
<
ASTFunction
*>
(
node
.
get
());
...
...
src/Parsers/ExpressionElementParsers.h
浏览文件 @
d4b2a373
...
...
@@ -149,11 +149,25 @@ protected:
class
ParserFunction
:
public
IParserBase
{
public:
ParserFunction
(
bool
allow_function_parameters_
=
true
)
:
allow_function_parameters
(
allow_function_parameters_
)
{}
ParserFunction
(
bool
allow_function_parameters_
=
true
,
bool
is_table_function_
=
false
)
:
allow_function_parameters
(
allow_function_parameters_
),
is_table_function
(
is_table_function_
)
{
}
protected:
const
char
*
getName
()
const
override
{
return
"function"
;
}
bool
parseImpl
(
Pos
&
pos
,
ASTPtr
&
node
,
Expected
&
expected
)
override
;
bool
allow_function_parameters
;
bool
is_table_function
;
};
// A special function parser for view table function.
// It parses an SELECT query as its argument and doesn't support getColumnName().
class
ParserTableFunctionView
:
public
IParserBase
{
protected:
const
char
*
getName
()
const
override
{
return
"function"
;
}
bool
parseImpl
(
Pos
&
pos
,
ASTPtr
&
node
,
Expected
&
expected
)
override
;
};
// Window reference (the thing that goes after OVER) for window function.
...
...
src/Parsers/ExpressionListParsers.cpp
浏览文件 @
d4b2a373
...
...
@@ -468,6 +468,14 @@ bool ParserLambdaExpression::parseImpl(Pos & pos, ASTPtr & node, Expected & expe
}
bool
ParserTableFunctionExpression
::
parseImpl
(
Pos
&
pos
,
ASTPtr
&
node
,
Expected
&
expected
)
{
if
(
ParserTableFunctionView
().
parse
(
pos
,
node
,
expected
))
return
true
;
return
elem_parser
.
parse
(
pos
,
node
,
expected
);
}
bool
ParserPrefixUnaryOperatorExpression
::
parseImpl
(
Pos
&
pos
,
ASTPtr
&
node
,
Expected
&
expected
)
{
/// try to find any of the valid operators
...
...
@@ -570,9 +578,10 @@ bool ParserTupleElementExpression::parseImpl(Pos & pos, ASTPtr & node, Expected
}
ParserExpressionWithOptionalAlias
::
ParserExpressionWithOptionalAlias
(
bool
allow_alias_without_as_keyword
)
:
impl
(
std
::
make_unique
<
ParserWithOptionalAlias
>
(
std
::
make_unique
<
ParserExpression
>
(),
allow_alias_without_as_keyword
))
ParserExpressionWithOptionalAlias
::
ParserExpressionWithOptionalAlias
(
bool
allow_alias_without_as_keyword
,
bool
is_table_function
)
:
impl
(
std
::
make_unique
<
ParserWithOptionalAlias
>
(
is_table_function
?
ParserPtr
(
std
::
make_unique
<
ParserTableFunctionExpression
>
())
:
ParserPtr
(
std
::
make_unique
<
ParserExpression
>
()),
allow_alias_without_as_keyword
))
{
}
...
...
@@ -580,7 +589,7 @@ ParserExpressionWithOptionalAlias::ParserExpressionWithOptionalAlias(bool allow_
bool
ParserExpressionList
::
parseImpl
(
Pos
&
pos
,
ASTPtr
&
node
,
Expected
&
expected
)
{
return
ParserList
(
std
::
make_unique
<
ParserExpressionWithOptionalAlias
>
(
allow_alias_without_as_keyword
),
std
::
make_unique
<
ParserExpressionWithOptionalAlias
>
(
allow_alias_without_as_keyword
,
is_table_function
),
std
::
make_unique
<
ParserToken
>
(
TokenType
::
Comma
))
.
parse
(
pos
,
node
,
expected
);
}
...
...
src/Parsers/ExpressionListParsers.h
浏览文件 @
d4b2a373
...
...
@@ -436,13 +436,26 @@ protected:
};
// It's used to parse expressions in table function.
class
ParserTableFunctionExpression
:
public
IParserBase
{
private:
ParserLambdaExpression
elem_parser
;
protected:
const
char
*
getName
()
const
override
{
return
"table function expression"
;
}
bool
parseImpl
(
Pos
&
pos
,
ASTPtr
&
node
,
Expected
&
expected
)
override
;
};
using
ParserExpression
=
ParserLambdaExpression
;
class
ParserExpressionWithOptionalAlias
:
public
IParserBase
{
public:
ParserExpressionWithOptionalAlias
(
bool
allow_alias_without_as_keyword
);
explicit
ParserExpressionWithOptionalAlias
(
bool
allow_alias_without_as_keyword
,
bool
is_table_function
=
false
);
protected:
ParserPtr
impl
;
...
...
@@ -459,11 +472,12 @@ protected:
class
ParserExpressionList
:
public
IParserBase
{
public:
ParserExpressionList
(
bool
allow_alias_without_as_keyword_
)
:
allow_alias_without_as_keyword
(
allow_alias_without_as_keyword_
)
{}
explicit
ParserExpressionList
(
bool
allow_alias_without_as_keyword_
,
bool
is_table_function_
=
false
)
:
allow_alias_without_as_keyword
(
allow_alias_without_as_keyword_
)
,
is_table_function
(
is_table_function_
)
{}
protected:
bool
allow_alias_without_as_keyword
;
bool
is_table_function
;
// This expression list is used by a table function
const
char
*
getName
()
const
override
{
return
"list of expressions"
;
}
bool
parseImpl
(
Pos
&
pos
,
ASTPtr
&
node
,
Expected
&
expected
)
override
;
...
...
@@ -473,7 +487,7 @@ protected:
class
ParserNotEmptyExpressionList
:
public
IParserBase
{
public:
ParserNotEmptyExpressionList
(
bool
allow_alias_without_as_keyword
)
explicit
ParserNotEmptyExpressionList
(
bool
allow_alias_without_as_keyword
)
:
nested_parser
(
allow_alias_without_as_keyword
)
{}
private:
ParserExpressionList
nested_parser
;
...
...
src/Parsers/ParserTablesInSelectQuery.cpp
浏览文件 @
d4b2a373
...
...
@@ -22,7 +22,7 @@ bool ParserTableExpression::parseImpl(Pos & pos, ASTPtr & node, Expected & expec
auto
res
=
std
::
make_shared
<
ASTTableExpression
>
();
if
(
!
ParserWithOptionalAlias
(
std
::
make_unique
<
ParserSubquery
>
(),
true
).
parse
(
pos
,
res
->
subquery
,
expected
)
&&
!
ParserWithOptionalAlias
(
std
::
make_unique
<
ParserFunction
>
(),
true
).
parse
(
pos
,
res
->
table_function
,
expected
)
&&
!
ParserWithOptionalAlias
(
std
::
make_unique
<
ParserFunction
>
(
true
,
true
),
true
).
parse
(
pos
,
res
->
table_function
,
expected
)
&&
!
ParserWithOptionalAlias
(
std
::
make_unique
<
ParserCompoundIdentifier
>
(
false
,
true
),
true
).
parse
(
pos
,
res
->
database_and_table_name
,
expected
))
return
false
;
...
...
tests/queries/0_stateless/01715_table_function_view_fix.reference
0 → 100644
浏览文件 @
d4b2a373
tests/queries/0_stateless/01715_table_function_view_fix.sql
0 → 100644
浏览文件 @
d4b2a373
SELECT
view
(
SELECT
1
);
-- { clientError 62 }
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录