Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
eb057981
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,发现更多精彩内容 >>
提交
eb057981
编写于
8月 04, 2017
作者:
V
Vitaliy Lyudvichenko
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add SYSTEM queries parser. [#CLICKHOUSE-2931]
上级
fd63277b
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
297 addition
and
21 deletion
+297
-21
dbms/src/Interpreters/InterpreterFactory.cpp
dbms/src/Interpreters/InterpreterFactory.cpp
+8
-0
dbms/src/Interpreters/InterpreterSystemQuery.cpp
dbms/src/Interpreters/InterpreterSystemQuery.cpp
+14
-0
dbms/src/Interpreters/InterpreterSystemQuery.h
dbms/src/Interpreters/InterpreterSystemQuery.h
+27
-0
dbms/src/Interpreters/evaluateConstantExpression.cpp
dbms/src/Interpreters/evaluateConstantExpression.cpp
+22
-1
dbms/src/Interpreters/evaluateConstantExpression.h
dbms/src/Interpreters/evaluateConstantExpression.h
+6
-0
dbms/src/Parsers/ASTQueryWithOnCluster.cpp
dbms/src/Parsers/ASTQueryWithOnCluster.cpp
+2
-15
dbms/src/Parsers/ASTSetQuery.h
dbms/src/Parsers/ASTSetQuery.h
+1
-1
dbms/src/Parsers/ASTSystemQuery.cpp
dbms/src/Parsers/ASTSystemQuery.cpp
+55
-0
dbms/src/Parsers/ASTSystemQuery.h
dbms/src/Parsers/ASTSystemQuery.h
+59
-0
dbms/src/Parsers/ParserQuery.cpp
dbms/src/Parsers/ParserQuery.cpp
+4
-1
dbms/src/Parsers/ParserSetQuery.h
dbms/src/Parsers/ParserSetQuery.h
+3
-3
dbms/src/Parsers/ParserSystemQuery.cpp
dbms/src/Parsers/ParserSystemQuery.cpp
+57
-0
dbms/src/Parsers/ParserSystemQuery.h
dbms/src/Parsers/ParserSystemQuery.h
+19
-0
dbms/tests/queries/0_stateless/00486_system_query_simple.reference
...s/queries/0_stateless/00486_system_query_simple.reference
+0
-0
dbms/tests/queries/0_stateless/00486_system_query_simple.sh
dbms/tests/queries/0_stateless/00486_system_query_simple.sh
+20
-0
未找到文件。
dbms/src/Interpreters/InterpreterFactory.cpp
浏览文件 @
eb057981
...
...
@@ -32,6 +32,9 @@
#include <Interpreters/InterpreterFactory.h>
#include <Common/typeid_cast.h>
#include <Parsers/ASTSystemQuery.h>
#include "InterpreterSystemQuery.h"
namespace
DB
{
...
...
@@ -123,6 +126,11 @@ std::unique_ptr<IInterpreter> InterpreterFactory::get(ASTPtr & query, Context &
{
return
std
::
make_unique
<
InterpreterKillQueryQuery
>
(
query
,
context
);
}
else
if
(
typeid_cast
<
ASTSystemQuery
*>
(
query
.
get
()))
{
throwIfReadOnly
(
context
);
return
std
::
make_unique
<
InterpreterSystemQuery
>
(
query
,
context
);
}
else
throw
Exception
(
"Unknown type of query: "
+
query
->
getID
(),
ErrorCodes
::
UNKNOWN_TYPE_OF_QUERY
);
}
...
...
dbms/src/Interpreters/InterpreterSystemQuery.cpp
0 → 100644
浏览文件 @
eb057981
#include "InterpreterSystemQuery.h"
namespace
DB
{
InterpreterSystemQuery
::
InterpreterSystemQuery
(
const
ASTPtr
&
query_ptr_
,
Context
&
context_
)
:
query_ptr
(
query_ptr_
),
context
(
context_
)
{}
BlockIO
InterpreterSystemQuery
::
execute
()
{
return
BlockIO
();
}
}
\ No newline at end of file
dbms/src/Interpreters/InterpreterSystemQuery.h
0 → 100644
浏览文件 @
eb057981
#pragma once
#include <Interpreters/IInterpreter.h>
namespace
DB
{
class
Context
;
class
IAST
;
using
ASTPtr
=
std
::
shared_ptr
<
IAST
>
;
/** Return list of currently executing queries.
*/
class
InterpreterSystemQuery
:
public
IInterpreter
{
public:
InterpreterSystemQuery
(
const
ASTPtr
&
query_ptr_
,
Context
&
context_
);
BlockIO
execute
()
override
;
private:
ASTPtr
query_ptr
;
Context
&
context
;
};
}
dbms/src/Interpreters/evaluateConstantExpression.cpp
浏览文件 @
eb057981
...
...
@@ -4,6 +4,7 @@
#include <Parsers/IAST.h>
#include <Parsers/ASTIdentifier.h>
#include <Parsers/ASTLiteral.h>
#include <Parsers/ExpressionElementParsers.h>
#include <DataTypes/DataTypesNumber.h>
#include <Interpreters/Context.h>
#include <Interpreters/ExpressionAnalyzer.h>
...
...
@@ -62,10 +63,30 @@ ASTPtr evaluateConstantExpressionAsLiteral(ASTPtr & node, const Context & contex
ASTPtr
evaluateConstantExpressionOrIdentifierAsLiteral
(
ASTPtr
&
node
,
const
Context
&
context
)
{
if
(
const
ASTIdentifier
*
id
=
typeid_cast
<
const
ASTIdentifier
*>
(
node
.
get
()))
if
(
auto
id
=
typeid_cast
<
const
ASTIdentifier
*>
(
node
.
get
()))
return
std
::
make_shared
<
ASTLiteral
>
(
node
->
range
,
Field
(
id
->
name
));
return
evaluateConstantExpressionAsLiteral
(
node
,
context
);
}
bool
parseIdentifierOrStringLiteral
(
IParser
::
Pos
&
pos
,
Expected
&
expected
,
String
&
result
)
{
IParser
::
Pos
begin
=
pos
;
ASTPtr
res
;
if
(
!
ParserIdentifier
().
parse
(
pos
,
res
,
expected
))
{
pos
=
begin
;
if
(
!
ParserStringLiteral
().
parse
(
pos
,
res
,
expected
))
return
false
;
result
=
typeid_cast
<
const
ASTLiteral
&>
(
*
res
).
value
.
safeGet
<
String
>
();
}
else
result
=
typeid_cast
<
const
ASTIdentifier
&>
(
*
res
).
name
;
return
true
;
}
}
dbms/src/Interpreters/evaluateConstantExpression.h
浏览文件 @
eb057981
...
...
@@ -2,6 +2,7 @@
#include <memory>
#include <Core/Field.h>
#include <Parsers/IParser.h>
namespace
DB
...
...
@@ -11,6 +12,7 @@ class IAST;
class
Context
;
class
IDataType
;
/** Evaluate constant expression and its type.
* Used in rare cases - for elements of set for IN, for data to INSERT.
* Quite suboptimal.
...
...
@@ -31,4 +33,8 @@ std::shared_ptr<IAST> evaluateConstantExpressionAsLiteral(std::shared_ptr<IAST>
*/
std
::
shared_ptr
<
IAST
>
evaluateConstantExpressionOrIdentifierAsLiteral
(
std
::
shared_ptr
<
IAST
>
&
node
,
const
Context
&
context
);
/** Parses a name of an object which could be written in 3 forms:
* name, `name` or 'name' */
bool
parseIdentifierOrStringLiteral
(
IParser
::
Pos
&
pos
,
Expected
&
expected
,
String
&
result
);
}
dbms/src/Parsers/ASTQueryWithOnCluster.cpp
浏览文件 @
eb057981
...
...
@@ -5,6 +5,7 @@
#include <Parsers/ASTIdentifier.h>
#include <Parsers/ASTLiteral.h>
#include <Common/typeid_cast.h>
#include <Interpreters/evaluateConstantExpression.h>
namespace
DB
...
...
@@ -21,21 +22,7 @@ bool ASTQueryWithOnCluster::parse(Pos & pos, std::string & cluster_str, Expected
if
(
!
ParserKeyword
{
"CLUSTER"
}.
ignore
(
pos
,
expected
))
return
false
;
Pos
begin
=
pos
;
ASTPtr
res
;
if
(
!
ParserIdentifier
().
parse
(
pos
,
res
,
expected
))
{
pos
=
begin
;
if
(
!
ParserStringLiteral
().
parse
(
pos
,
res
,
expected
))
return
false
;
else
cluster_str
=
typeid_cast
<
const
ASTLiteral
&>
(
*
res
).
value
.
safeGet
<
String
>
();
}
else
cluster_str
=
typeid_cast
<
const
ASTIdentifier
&>
(
*
res
).
name
;
return
true
;
return
parseIdentifierOrStringLiteral
(
pos
,
expected
,
cluster_str
);
}
...
...
dbms/src/Parsers/ASTSetQuery.h
浏览文件 @
eb057981
...
...
@@ -24,7 +24,7 @@ public:
Changes
changes
;
ASTSetQuery
()
=
default
;
ASTSetQuery
(
const
StringRange
range_
)
:
IAST
(
range_
)
{}
explicit
ASTSetQuery
(
const
StringRange
range_
)
:
IAST
(
range_
)
{}
/** Get the text that identifies this element. */
String
getID
()
const
override
{
return
"Set"
;
};
...
...
dbms/src/Parsers/ASTSystemQuery.cpp
0 → 100644
浏览文件 @
eb057981
#include <Parsers/IAST.h>
#include <Parsers/ASTSystemQuery.h>
namespace
ErrorCodes
{
extern
const
int
BAD_TYPE_OF_FIELD
;
}
namespace
DB
{
const
char
*
ASTSystemQuery
::
typeToString
(
Type
type
)
{
switch
(
type
)
{
case
Type
::
SHUTDOWN
:
return
"SHUTDOWN"
;
case
Type
::
KILL
:
return
"KILL"
;
case
Type
::
DROP_DNS_CACHE
:
return
"DROP DNS CACHE"
;
case
Type
::
DROP_MARK_CACHE
:
return
"DROP MARK CACHE"
;
case
Type
::
DROP_UNCOMPRESSED_CACHE
:
return
"DROP UNCOMPRESSED CACHE"
;
case
Type
::
STOP_LISTEN_QUERIES
:
return
"STOP LISTEN QUERIES"
;
case
Type
::
START_LISTEN_QUERIES
:
return
"START LISTEN QUERIES"
;
case
Type
::
RESTART_REPLICAS
:
return
"RESTART REPLICAS"
;
case
Type
::
SYNC_REPLICA
:
return
"SYNC REPLICA"
;
case
Type
::
RELOAD_DICTIONARY
:
return
"RELOAD DICTIONARY"
;
case
Type
::
RELOAD_DICTIONARIES
:
return
"RELOAD DICTIONARIES"
;
case
Type
::
STOP_MERGES
:
return
"STOP MERGES"
;
case
Type
::
START_MERGES
:
return
"START MERGES"
;
case
Type
::
STOP_REPLICATION_QUEUES
:
return
"STOP REPLICATION QUEUES"
;
case
Type
::
START_REPLICATION_QUEUES
:
return
"START REPLICATION QUEUES"
;
default:
throw
Exception
(
"Unknown SYSTEM query command"
,
ErrorCodes
::
BAD_TYPE_OF_FIELD
);
}
}
}
\ No newline at end of file
dbms/src/Parsers/ASTSystemQuery.h
0 → 100644
浏览文件 @
eb057981
#pragma once
#include <Parsers/IAST.h>
#include <AggregateFunctions/AggregateFunctionCount.h>
namespace
DB
{
class
ASTSystemQuery
:
public
IAST
{
public:
enum
class
Type
{
_UNKNOWN
,
SHUTDOWN
,
KILL
,
DROP_DNS_CACHE
,
DROP_MARK_CACHE
,
DROP_UNCOMPRESSED_CACHE
,
STOP_LISTEN_QUERIES
,
START_LISTEN_QUERIES
,
RESTART_REPLICAS
,
SYNC_REPLICA
,
RELOAD_DICTIONARY
,
RELOAD_DICTIONARIES
,
STOP_MERGES
,
START_MERGES
,
STOP_REPLICATION_QUEUES
,
START_REPLICATION_QUEUES
,
_END
};
static
const
char
*
typeToString
(
Type
type
);
Type
type
=
Type
::
_UNKNOWN
;
String
target_dictionary
;
//String target_replica;
ASTSystemQuery
()
=
default
;
explicit
ASTSystemQuery
(
const
StringRange
range
)
:
IAST
(
range
)
{}
String
getID
()
const
override
{
return
"SYSTEM"
;
};
ASTPtr
clone
()
const
override
{
return
std
::
make_shared
<
ASTSystemQuery
>
(
*
this
);
}
~
ASTSystemQuery
()
override
=
default
;
protected:
void
formatImpl
(
const
FormatSettings
&
settings
,
FormatState
&
state
,
FormatStateStacked
frame
)
const
override
{
settings
.
ostr
<<
(
settings
.
hilite
?
hilite_keyword
:
""
)
<<
"SYSTEM "
<<
(
settings
.
hilite
?
hilite_none
:
""
);
}
};
}
\ No newline at end of file
dbms/src/Parsers/ParserQuery.cpp
浏览文件 @
eb057981
...
...
@@ -8,6 +8,7 @@
#include <Parsers/ParserUseQuery.h>
#include <Parsers/ParserSetQuery.h>
#include <Parsers/ParserAlterQuery.h>
#include "ParserSystemQuery.h"
namespace
DB
...
...
@@ -22,12 +23,14 @@ bool ParserQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
ParserUseQuery
use_p
;
ParserSetQuery
set_p
;
ParserOptimizeQuery
optimize_p
;
ParserSystemQuery
system_p
;
bool
res
=
query_with_output_p
.
parse
(
pos
,
node
,
expected
)
||
insert_p
.
parse
(
pos
,
node
,
expected
)
||
use_p
.
parse
(
pos
,
node
,
expected
)
||
set_p
.
parse
(
pos
,
node
,
expected
)
||
optimize_p
.
parse
(
pos
,
node
,
expected
);
||
optimize_p
.
parse
(
pos
,
node
,
expected
)
||
system_p
.
parse
(
pos
,
node
,
expected
);
return
res
;
}
...
...
dbms/src/Parsers/ParserSetQuery.h
浏览文件 @
eb057981
...
...
@@ -13,11 +13,11 @@ namespace DB
class
ParserSetQuery
:
public
IParserBase
{
public:
ParserSetQuery
(
bool
parse_only_internals_
=
false
)
:
parse_only_internals
(
parse_only_internals_
)
{}
explicit
ParserSetQuery
(
bool
parse_only_internals_
=
false
)
:
parse_only_internals
(
parse_only_internals_
)
{}
protected:
const
char
*
getName
()
const
{
return
"SET query"
;
}
bool
parseImpl
(
Pos
&
pos
,
ASTPtr
&
node
,
Expected
&
expected
);
const
char
*
getName
()
const
override
{
return
"SET query"
;
}
bool
parseImpl
(
Pos
&
pos
,
ASTPtr
&
node
,
Expected
&
expected
)
override
;
/// Parse the list `name = value` pairs, without SET [GLOBAL].
bool
parse_only_internals
;
...
...
dbms/src/Parsers/ParserSystemQuery.cpp
0 → 100644
浏览文件 @
eb057981
#include <Parsers/ParserSystemQuery.h>
#include <Parsers/ASTSystemQuery.h>
#include <Parsers/CommonParsers.h>
#include <Parsers/ASTIdentifier.h>
#include <Parsers/ASTLiteral.h>
#include <Interpreters/evaluateConstantExpression.h>
#include "ASTSystemQuery.h"
namespace
ErrorCodes
{
extern
const
int
NOT_IMPLEMENTED
;
}
namespace
DB
{
bool
ParserSystemQuery
::
parseImpl
(
IParser
::
Pos
&
pos
,
ASTPtr
&
node
,
Expected
&
expected
)
{
if
(
!
ParserKeyword
{
"SYSTEM"
}.
ignore
(
pos
))
return
false
;
using
Type
=
ASTSystemQuery
::
Type
;
auto
res
=
std
::
make_shared
<
ASTSystemQuery
>
();
bool
found
=
false
;
for
(
int
i
=
static_cast
<
int
>
(
Type
::
SHUTDOWN
);
i
<
static_cast
<
int
>
(
Type
::
_END
);
++
i
)
{
Type
t
=
static_cast
<
Type
>
(
i
);
if
(
ParserKeyword
{
ASTSystemQuery
::
typeToString
(
t
)}.
ignore
(
pos
))
{
res
->
type
=
t
;
found
=
true
;
}
}
if
(
!
found
)
return
false
;
if
(
res
->
type
==
Type
::
RELOAD_DICTIONARY
)
{
if
(
!
parseIdentifierOrStringLiteral
(
pos
,
expected
,
res
->
target_dictionary
))
return
false
;
}
else
if
(
res
->
type
==
Type
::
SYNC_REPLICA
)
{
throw
Exception
(
"SYNC REPLICA is not supported yet"
,
ErrorCodes
::
NOT_IMPLEMENTED
);
}
node
=
std
::
move
(
res
);
return
true
;
}
}
dbms/src/Parsers/ParserSystemQuery.h
0 → 100644
浏览文件 @
eb057981
#pragma once
#include <Parsers/IParserBase.h>
namespace
DB
{
class
ParserSystemQuery
:
public
IParserBase
{
public:
ParserSystemQuery
()
=
default
;
protected:
const
char
*
getName
()
const
override
{
return
"SYSTEM query"
;
}
bool
parseImpl
(
Pos
&
pos
,
ASTPtr
&
node
,
Expected
&
expected
)
override
;
};
}
\ No newline at end of file
dbms/tests/queries/0_stateless/00486_system_query_simple.reference
0 → 100644
浏览文件 @
eb057981
dbms/tests/queries/0_stateless/00486_system_query_simple.sh
0 → 100755
浏览文件 @
eb057981
#!/bin/bash
set
-e
cli
=
"clickhouse-client -q "
$cli
"SYSTEM SHUTDOWN"
$cli
"SYSTEM KILL"
$cli
"SYSTEM DROP DNS CACHE"
$cli
"SYSTEM DROP MARK CACHE"
$cli
"SYSTEM DROP UNCOMPRESSED CACHE"
$cli
"SYSTEM STOP LISTEN QUERIES"
$cli
"SYSTEM START LISTEN QUERIES"
$cli
"SYSTEM RESTART REPLICAS"
#$cli "SYSTEM SYNC REPLICA test"
$cli
"SYSTEM RELOAD DICTIONARY dict"
$cli
"SYSTEM RELOAD DICTIONARIES"
$cli
"SYSTEM STOP MERGES"
$cli
"SYSTEM START MERGES"
$cli
"SYSTEM STOP REPLICATION QUEUES"
$cli
"SYSTEM START REPLICATION QUEUES"
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录