Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
e1cda4b7
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,发现更多精彩内容 >>
提交
e1cda4b7
编写于
11月 12, 2016
作者:
A
artpaul
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
move impl of common parsers to cpp
上级
c617565f
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
198 addition
and
113 deletion
+198
-113
dbms/CMakeLists.txt
dbms/CMakeLists.txt
+1
-0
dbms/include/DB/Interpreters/InterpreterSelectQuery.h
dbms/include/DB/Interpreters/InterpreterSelectQuery.h
+3
-17
dbms/include/DB/Parsers/CommonParsers.h
dbms/include/DB/Parsers/CommonParsers.h
+18
-94
dbms/include/DB/Parsers/ParserSelectQuery.h
dbms/include/DB/Parsers/ParserSelectQuery.h
+2
-2
dbms/src/Interpreters/InterpreterSelectQuery.cpp
dbms/src/Interpreters/InterpreterSelectQuery.cpp
+22
-0
dbms/src/Parsers/CommonParsers.cpp
dbms/src/Parsers/CommonParsers.cpp
+152
-0
未找到文件。
dbms/CMakeLists.txt
浏览文件 @
e1cda4b7
...
...
@@ -829,6 +829,7 @@ add_library (dbms
src/Parsers/ASTIdentifier.cpp
src/Parsers/ASTSampleRatio.cpp
src/Parsers/ASTTablesInSelectQuery.cpp
src/Parsers/CommonParsers.cpp
src/Parsers/IAST.cpp
src/Parsers/IParserBase.cpp
src/Parsers/ExpressionElementParsers.cpp
...
...
dbms/include/DB/Interpreters/InterpreterSelectQuery.h
浏览文件 @
e1cda4b7
...
...
@@ -144,25 +144,11 @@ private:
void
executeSubqueriesInSetsAndJoins
(
std
::
unordered_map
<
String
,
SubqueryForSet
>
&
subqueries_for_sets
);
template
<
typename
Transform
>
void
transformStreams
(
Transform
&&
transform
)
{
for
(
auto
&
stream
:
streams
)
transform
(
stream
);
void
transformStreams
(
Transform
&&
transform
);
if
(
stream_with_non_joined_data
)
transform
(
stream_with_non_joined_data
);
}
bool
hasNoData
()
const
{
return
streams
.
empty
()
&&
!
stream_with_non_joined_data
;
}
bool
hasMoreThanOneStream
()
const
{
return
streams
.
size
()
+
(
stream_with_non_joined_data
?
1
:
0
)
>
1
;
}
bool
hasNoData
()
const
;
bool
hasMoreThanOneStream
()
const
;
void
ignoreWithTotals
();
...
...
dbms/include/DB/Parsers/CommonParsers.h
浏览文件 @
e1cda4b7
#pragma once
#include <string.h> /// strncmp, strncasecmp
#include <DB/Parsers/IParserBase.h>
namespace
DB
{
/** Если прямо сейчас не s, то ошибка.
* Если word_boundary установлен в true, и последний символ строки - словарный (\w),
* то проверяется, что последующий символ строки не словарный.
...
...
@@ -22,26 +18,12 @@ private:
bool
case_insensitive
;
public:
ParserString
(
const
char
*
s_
,
bool
word_boundary_
=
false
,
bool
case_insensitive_
=
false
)
:
s
(
s_
),
s_size
(
strlen
(
s
)),
word_boundary
(
word_boundary_
),
case_insensitive
(
case_insensitive_
)
{}
ParserString
(
const
char
*
s_
,
bool
word_boundary_
=
false
,
bool
case_insensitive_
=
false
);
protected:
const
char
*
getName
()
const
{
return
s
;
}
bool
parseImpl
(
Pos
&
pos
,
Pos
end
,
ASTPtr
&
node
,
Pos
&
max_parsed_pos
,
Expected
&
expected
)
{
if
(
static_cast
<
ssize_t
>
(
s_size
)
>
end
-
pos
||
(
case_insensitive
?
strncasecmp
:
strncmp
)(
pos
,
s
,
s_size
))
return
false
;
else
{
if
(
word_boundary
&&
s_size
&&
isWordCharASCII
(
s
[
s_size
-
1
])
&&
pos
+
s_size
!=
end
&&
isWordCharASCII
(
pos
[
s_size
]))
return
false
;
pos
+=
s_size
;
return
true
;
}
}
const
char
*
getName
()
const
override
;
bool
parseImpl
(
Pos
&
pos
,
Pos
end
,
ASTPtr
&
node
,
Pos
&
max_parsed_pos
,
Expected
&
expected
)
override
;
};
...
...
@@ -50,74 +32,32 @@ protected:
class
ParserWhiteSpace
:
public
IParserBase
{
public:
ParserWhiteSpace
(
bool
allow_newlines_
=
true
)
:
allow_newlines
(
allow_newlines_
)
{}
ParserWhiteSpace
(
bool
allow_newlines_
=
true
)
;
protected:
bool
allow_newlines
;
const
char
*
getName
()
const
{
return
"white space"
;
}
bool
parseImpl
(
Pos
&
pos
,
Pos
end
,
ASTPtr
&
node
,
Pos
&
max_parsed_pos
,
Expected
&
expected
)
{
Pos
begin
=
pos
;
while
(
pos
<
end
&&
(
*
pos
==
' '
||
*
pos
==
'\t'
||
(
allow_newlines
&&
*
pos
==
'\n'
)
||
*
pos
==
'\r'
||
*
pos
==
'\f'
))
++
pos
;
const
char
*
getName
()
const
override
;
return
pos
!=
begin
;
}
bool
parseImpl
(
Pos
&
pos
,
Pos
end
,
ASTPtr
&
node
,
Pos
&
max_parsed_pos
,
Expected
&
expected
)
override
;
};
class
ParserCStyleComment
:
public
IParserBase
{
protected:
const
char
*
getName
()
const
{
return
"C-style comment"
;
}
bool
parseImpl
(
Pos
&
pos
,
Pos
end
,
ASTPtr
&
node
,
Pos
&
max_parsed_pos
,
Expected
&
expected
)
{
if
(
end
-
pos
>=
4
&&
pos
[
0
]
==
'/'
&&
pos
[
1
]
==
'*'
)
{
pos
+=
2
;
while
(
end
-
pos
>=
2
&&
(
pos
[
0
]
!=
'*'
||
pos
[
1
]
!=
'/'
))
++
pos
;
if
(
end
-
pos
<
2
)
{
expected
=
"closing of C-style comment '*/'"
;
return
false
;
}
else
{
pos
+=
2
;
return
true
;
}
}
else
return
false
;
}
const
char
*
getName
()
const
override
;
bool
parseImpl
(
Pos
&
pos
,
Pos
end
,
ASTPtr
&
node
,
Pos
&
max_parsed_pos
,
Expected
&
expected
)
override
;
};
class
ParserSQLStyleComment
:
public
IParserBase
{
protected:
const
char
*
getName
()
const
{
return
"SQL-style comment"
;
}
bool
parseImpl
(
Pos
&
pos
,
Pos
end
,
ASTPtr
&
node
,
Pos
&
max_parsed_pos
,
Expected
&
expected
)
{
if
(
end
-
pos
>=
2
&&
pos
[
0
]
==
'-'
&&
pos
[
1
]
==
'-'
)
{
pos
+=
2
;
while
(
pos
!=
end
&&
*
pos
!=
'\n'
)
++
pos
;
if
(
pos
!=
end
)
++
pos
;
return
true
;
}
else
return
false
;
}
const
char
*
getName
()
const
override
;
bool
parseImpl
(
Pos
&
pos
,
Pos
end
,
ASTPtr
&
node
,
Pos
&
max_parsed_pos
,
Expected
&
expected
)
override
;
};
...
...
@@ -126,39 +66,23 @@ protected:
class
ParserComment
:
public
IParserBase
{
protected:
const
char
*
getName
()
const
{
return
"comment"
;
}
const
char
*
getName
()
const
override
;
bool
parseImpl
(
Pos
&
pos
,
Pos
end
,
ASTPtr
&
node
,
Pos
&
max_parsed_pos
,
Expected
&
expected
)
{
ParserCStyleComment
p1
;
ParserSQLStyleComment
p2
;
return
p1
.
ignore
(
pos
,
end
,
max_parsed_pos
,
expected
)
||
p2
.
ignore
(
pos
,
end
,
max_parsed_pos
,
expected
);
}
bool
parseImpl
(
Pos
&
pos
,
Pos
end
,
ASTPtr
&
node
,
Pos
&
max_parsed_pos
,
Expected
&
expected
)
override
;
};
class
ParserWhiteSpaceOrComments
:
public
IParserBase
{
public:
ParserWhiteSpaceOrComments
(
bool
allow_newlines_outside_comments_
=
true
)
:
allow_newlines_outside_comments
(
allow_newlines_outside_comments_
)
{}
ParserWhiteSpaceOrComments
(
bool
allow_newlines_outside_comments_
=
true
)
;
protected:
bool
allow_newlines_outside_comments
;
const
char
*
getName
()
const
{
return
"white space or comments"
;
}
bool
parseImpl
(
Pos
&
pos
,
Pos
end
,
ASTPtr
&
node
,
Pos
&
max_parsed_pos
,
Expected
&
expected
)
{
ParserWhiteSpace
p1
(
allow_newlines_outside_comments
);
ParserComment
p2
;
const
char
*
getName
()
const
override
;
bool
res
=
false
;
while
(
p1
.
ignore
(
pos
,
end
,
max_parsed_pos
,
expected
)
||
p2
.
ignore
(
pos
,
end
,
max_parsed_pos
,
expected
))
res
=
true
;
return
res
;
}
bool
parseImpl
(
Pos
&
pos
,
Pos
end
,
ASTPtr
&
node
,
Pos
&
max_parsed_pos
,
Expected
&
expected
)
override
;
};
}
dbms/include/DB/Parsers/ParserSelectQuery.h
浏览文件 @
e1cda4b7
...
...
@@ -10,8 +10,8 @@ namespace DB
class
ParserSelectQuery
:
public
ParserQueryWithOutput
{
protected:
const
char
*
getName
()
const
{
return
"SELECT query"
;
}
bool
parseImpl
(
Pos
&
pos
,
Pos
end
,
ASTPtr
&
node
,
Pos
&
max_parsed_pos
,
Expected
&
expected
);
const
char
*
getName
()
const
override
{
return
"SELECT query"
;
}
bool
parseImpl
(
Pos
&
pos
,
Pos
end
,
ASTPtr
&
node
,
Pos
&
max_parsed_pos
,
Expected
&
expected
)
override
;
};
}
dbms/src/Interpreters/InterpreterSelectQuery.cpp
浏览文件 @
e1cda4b7
...
...
@@ -1229,6 +1229,28 @@ void InterpreterSelectQuery::executeSubqueriesInSetsAndJoins(SubqueriesForSets &
streams
[
0
]
=
std
::
make_shared
<
CreatingSetsBlockInputStream
>
(
streams
[
0
],
subqueries_for_sets
,
settings
.
limits
);
}
template
<
typename
Transform
>
void
InterpreterSelectQuery
::
transformStreams
(
Transform
&&
transform
)
{
for
(
auto
&
stream
:
streams
)
transform
(
stream
);
if
(
stream_with_non_joined_data
)
transform
(
stream_with_non_joined_data
);
}
bool
InterpreterSelectQuery
::
hasNoData
()
const
{
return
streams
.
empty
()
&&
!
stream_with_non_joined_data
;
}
bool
InterpreterSelectQuery
::
hasMoreThanOneStream
()
const
{
return
streams
.
size
()
+
(
stream_with_non_joined_data
?
1
:
0
)
>
1
;
}
void
InterpreterSelectQuery
::
ignoreWithTotals
()
{
...
...
dbms/src/Parsers/CommonParsers.cpp
0 → 100644
浏览文件 @
e1cda4b7
#include <DB/Parsers/CommonParsers.h>
#include <string.h> /// strncmp, strncasecmp
namespace
DB
{
ParserString
::
ParserString
(
const
char
*
s_
,
bool
word_boundary_
,
bool
case_insensitive_
)
:
s
(
s_
)
,
s_size
(
strlen
(
s
))
,
word_boundary
(
word_boundary_
)
,
case_insensitive
(
case_insensitive_
)
{
}
const
char
*
ParserString
::
getName
()
const
{
return
s
;
}
bool
ParserString
::
parseImpl
(
Pos
&
pos
,
Pos
end
,
ASTPtr
&
node
,
Pos
&
max_parsed_pos
,
Expected
&
expected
)
{
if
(
static_cast
<
ssize_t
>
(
s_size
)
>
end
-
pos
||
(
case_insensitive
?
strncasecmp
:
strncmp
)(
pos
,
s
,
s_size
))
return
false
;
else
{
if
(
word_boundary
&&
s_size
&&
isWordCharASCII
(
s
[
s_size
-
1
])
&&
pos
+
s_size
!=
end
&&
isWordCharASCII
(
pos
[
s_size
]))
return
false
;
pos
+=
s_size
;
return
true
;
}
}
ParserWhiteSpace
::
ParserWhiteSpace
(
bool
allow_newlines_
)
:
allow_newlines
(
allow_newlines_
)
{
}
const
char
*
ParserWhiteSpace
::
getName
()
const
{
return
"white space"
;
}
bool
ParserWhiteSpace
::
parseImpl
(
Pos
&
pos
,
Pos
end
,
ASTPtr
&
node
,
Pos
&
max_parsed_pos
,
Expected
&
expected
)
{
Pos
begin
=
pos
;
while
(
pos
<
end
&&
(
*
pos
==
' '
||
*
pos
==
'\t'
||
(
allow_newlines
&&
*
pos
==
'\n'
)
||
*
pos
==
'\r'
||
*
pos
==
'\f'
))
++
pos
;
return
pos
!=
begin
;
}
const
char
*
ParserCStyleComment
::
getName
()
const
{
return
"C-style comment"
;
}
bool
ParserCStyleComment
::
parseImpl
(
Pos
&
pos
,
Pos
end
,
ASTPtr
&
node
,
Pos
&
max_parsed_pos
,
Expected
&
expected
)
{
if
(
end
-
pos
>=
4
&&
pos
[
0
]
==
'/'
&&
pos
[
1
]
==
'*'
)
{
pos
+=
2
;
while
(
end
-
pos
>=
2
&&
(
pos
[
0
]
!=
'*'
||
pos
[
1
]
!=
'/'
))
++
pos
;
if
(
end
-
pos
<
2
)
{
expected
=
"closing of C-style comment '*/'"
;
return
false
;
}
else
{
pos
+=
2
;
return
true
;
}
}
else
return
false
;
}
const
char
*
ParserSQLStyleComment
::
getName
()
const
{
return
"SQL-style comment"
;
}
bool
ParserSQLStyleComment
::
parseImpl
(
Pos
&
pos
,
Pos
end
,
ASTPtr
&
node
,
Pos
&
max_parsed_pos
,
Expected
&
expected
)
{
if
(
end
-
pos
>=
2
&&
pos
[
0
]
==
'-'
&&
pos
[
1
]
==
'-'
)
{
pos
+=
2
;
while
(
pos
!=
end
&&
*
pos
!=
'\n'
)
++
pos
;
if
(
pos
!=
end
)
++
pos
;
return
true
;
}
else
return
false
;
}
const
char
*
ParserComment
::
getName
()
const
{
return
"comment"
;
}
bool
ParserComment
::
parseImpl
(
Pos
&
pos
,
Pos
end
,
ASTPtr
&
node
,
Pos
&
max_parsed_pos
,
Expected
&
expected
)
{
ParserCStyleComment
p1
;
ParserSQLStyleComment
p2
;
return
p1
.
ignore
(
pos
,
end
,
max_parsed_pos
,
expected
)
||
p2
.
ignore
(
pos
,
end
,
max_parsed_pos
,
expected
);
}
ParserWhiteSpaceOrComments
::
ParserWhiteSpaceOrComments
(
bool
allow_newlines_outside_comments_
)
:
allow_newlines_outside_comments
(
allow_newlines_outside_comments_
)
{
}
const
char
*
ParserWhiteSpaceOrComments
::
getName
()
const
{
return
"white space or comments"
;
}
bool
ParserWhiteSpaceOrComments
::
parseImpl
(
Pos
&
pos
,
Pos
end
,
ASTPtr
&
node
,
Pos
&
max_parsed_pos
,
Expected
&
expected
)
{
ParserWhiteSpace
p1
(
allow_newlines_outside_comments
);
ParserComment
p2
;
bool
res
=
false
;
while
(
p1
.
ignore
(
pos
,
end
,
max_parsed_pos
,
expected
)
||
p2
.
ignore
(
pos
,
end
,
max_parsed_pos
,
expected
))
res
=
true
;
return
res
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录