Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
7470ac98
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,发现更多精彩内容 >>
未验证
提交
7470ac98
编写于
10月 14, 2020
作者:
A
Anton Popov
提交者:
GitHub
10月 14, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #15855 from hexiaoting/dev_fetch
Add Support for OFFSET_FETCH_CLAUSE
上级
b1cdcf2d
2c72cdef
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
81 addition
and
0 deletion
+81
-0
src/Common/ErrorCodes.cpp
src/Common/ErrorCodes.cpp
+2
-0
src/Parsers/ParserSelectQuery.cpp
src/Parsers/ParserSelectQuery.cpp
+61
-0
tests/queries/0_stateless/01525_select_with_offset_fetch_clause.reference
...stateless/01525_select_with_offset_fetch_clause.reference
+10
-0
tests/queries/0_stateless/01525_select_with_offset_fetch_clause.sql
...ies/0_stateless/01525_select_with_offset_fetch_clause.sql
+8
-0
未找到文件。
src/Common/ErrorCodes.cpp
浏览文件 @
7470ac98
...
...
@@ -507,6 +507,8 @@ namespace ErrorCodes
extern
const
int
CANNOT_CREATE_RABBITMQ_QUEUE_BINDING
=
541
;
extern
const
int
CANNOT_REMOVE_RABBITMQ_EXCHANGE
=
542
;
extern
const
int
UNKNOWN_MYSQL_DATATYPES_SUPPORT_LEVEL
=
543
;
extern
const
int
ROW_AND_ROWS_TOGETHER
=
544
;
extern
const
int
FIRST_AND_NEXT_TOGETHER
=
545
;
extern
const
int
KEEPER_EXCEPTION
=
999
;
extern
const
int
POCO_EXCEPTION
=
1000
;
...
...
src/Parsers/ParserSelectQuery.cpp
浏览文件 @
7470ac98
...
...
@@ -19,6 +19,8 @@ namespace ErrorCodes
extern
const
int
TOP_AND_LIMIT_TOGETHER
;
extern
const
int
WITH_TIES_WITHOUT_ORDER_BY
;
extern
const
int
LIMIT_BY_WITH_TIES_IS_NOT_SUPPORTED
;
extern
const
int
ROW_AND_ROWS_TOGETHER
;
extern
const
int
FIRST_AND_NEXT_TOGETHER
;
}
...
...
@@ -45,6 +47,12 @@ bool ParserSelectQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
ParserKeyword
s_top
(
"TOP"
);
ParserKeyword
s_with_ties
(
"WITH TIES"
);
ParserKeyword
s_offset
(
"OFFSET"
);
ParserKeyword
s_fetch
(
"FETCH"
);
ParserKeyword
s_only
(
"ONLY"
);
ParserKeyword
s_row
(
"ROW"
);
ParserKeyword
s_rows
(
"ROWS"
);
ParserKeyword
s_first
(
"FIRST"
);
ParserKeyword
s_next
(
"NEXT"
);
ParserNotEmptyExpressionList
exp_list
(
false
);
ParserNotEmptyExpressionList
exp_list_for_with_clause
(
false
);
...
...
@@ -247,8 +255,61 @@ bool ParserSelectQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
}
else
if
(
s_offset
.
ignore
(
pos
,
expected
))
{
/// OFFSET offset_row_count {ROW | ROWS} FETCH {FIRST | NEXT} fetch_row_count {ROW | ROWS} {ONLY | WITH TIES}
bool
offset_with_fetch_maybe
=
false
;
if
(
!
exp_elem
.
parse
(
pos
,
limit_offset
,
expected
))
return
false
;
if
(
s_row
.
ignore
(
pos
,
expected
))
{
if
(
s_rows
.
ignore
(
pos
,
expected
))
throw
Exception
(
"Can not use ROW and ROWS together"
,
ErrorCodes
::
ROW_AND_ROWS_TOGETHER
);
offset_with_fetch_maybe
=
true
;
}
else
if
(
s_rows
.
ignore
(
pos
,
expected
))
{
offset_with_fetch_maybe
=
true
;
}
if
(
offset_with_fetch_maybe
&&
s_fetch
.
ignore
(
pos
,
expected
))
{
/// OFFSET FETCH clause must exists with "ORDER BY"
if
(
!
order_expression_list
)
return
false
;
if
(
s_first
.
ignore
(
pos
,
expected
))
{
if
(
s_next
.
ignore
(
pos
,
expected
))
throw
Exception
(
"Can not use FIRST and NEXT together"
,
ErrorCodes
::
FIRST_AND_NEXT_TOGETHER
);
}
else
if
(
!
s_next
.
ignore
(
pos
,
expected
))
return
false
;
if
(
!
exp_elem
.
parse
(
pos
,
limit_length
,
expected
))
return
false
;
if
(
s_row
.
ignore
(
pos
,
expected
))
{
if
(
s_rows
.
ignore
(
pos
,
expected
))
throw
Exception
(
"Can not use ROW and ROWS together"
,
ErrorCodes
::
ROW_AND_ROWS_TOGETHER
);
}
else
if
(
!
s_rows
.
ignore
(
pos
,
expected
))
return
false
;
if
(
s_with_ties
.
ignore
(
pos
,
expected
))
{
select_query
->
limit_with_ties
=
true
;
}
else
if
(
s_only
.
ignore
(
pos
,
expected
))
{
select_query
->
limit_with_ties
=
false
;
}
else
{
return
false
;
}
}
}
/// Because TOP n in totally equals LIMIT n
...
...
tests/queries/0_stateless/01525_select_with_offset_fetch_clause.reference
0 → 100644
浏览文件 @
7470ac98
7
6
5
1 1
2 1
3 4
1 1
2 1
3 4
3 3
tests/queries/0_stateless/01525_select_with_offset_fetch_clause.sql
0 → 100644
浏览文件 @
7470ac98
SELECT
number
FROM
numbers
(
10
)
ORDER
BY
number
DESC
OFFSET
2
ROWS
FETCH
NEXT
3
ROWS
WITH
TIES
;
DROP
TABLE
IF
EXISTS
test_fetch
;
CREATE
TABLE
test_fetch
(
a
Int32
,
b
Int32
)
Engine
=
Memory
;
INSERT
INTO
test_fetch
VALUES
(
1
,
1
),
(
2
,
1
),
(
3
,
4
),
(
3
,
3
),
(
5
,
4
),
(
0
,
6
),
(
5
,
7
);
SELECT
*
FROM
test_fetch
ORDER
BY
a
OFFSET
1
ROW
FETCH
FIRST
3
ROWS
ONLY
;
SELECT
*
FROM
test_fetch
ORDER
BY
a
OFFSET
1
ROW
FETCH
FIRST
3
ROWS
WITH
TIES
;
DROP
TABLE
test_fetch
;
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录