This is an automated email from the ASF dual-hosted git repository.
jackietien pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new e5e4980331e Support OFFSET XXX LIMIT XXXX in relational model
e5e4980331e is described below
commit e5e4980331ee0724f8d1f84fbba1437c61cb8eb8
Author: Jackie Tien <[email protected]>
AuthorDate: Thu Sep 19 20:21:38 2024 +0800
Support OFFSET XXX LIMIT XXXX in relational model
---
.../it/query/recent/IoTDBNullIdQueryIT.java | 51 ++++++++++++++++++++++
.../plan/relational/sql/parser/AstBuilder.java | 14 +++---
.../db/relational/grammar/sql/RelationalSql.g4 | 15 ++++---
3 files changed, 67 insertions(+), 13 deletions(-)
diff --git
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/recent/IoTDBNullIdQueryIT.java
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/recent/IoTDBNullIdQueryIT.java
index 7c76e2fac66..d3565d40302 100644
---
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/recent/IoTDBNullIdQueryIT.java
+++
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/recent/IoTDBNullIdQueryIT.java
@@ -309,4 +309,55 @@ public class IoTDBNullIdQueryIT {
retArray,
DATABASE_NAME);
}
+
+ @Test
+ public void limitOffsetTest() {
+ String[] expectedHeader = new String[] {"time", "device_id", "s2", "s3"};
+ String[] retArray =
+ new String[] {
+ "1970-01-01T00:00:00.003Z,d1,null,null,",
+ };
+ tableResultSetEqualTest(
+ "select time, device_id, s2, s3 from table1 OFFSET 2 limit 1",
+ expectedHeader,
+ retArray,
+ DATABASE_NAME);
+
+ expectedHeader = new String[] {"time", "device_id", "s2", "s3"};
+ retArray =
+ new String[] {
+ "1970-01-01T00:00:00.003Z,d1,null,null,",
+ };
+ tableResultSetEqualTest(
+ "select time, device_id, s2, s3 from table1 limit 1 OFFSET 2",
+ expectedHeader,
+ retArray,
+ DATABASE_NAME);
+
+ expectedHeader = new String[] {"time", "device_id", "s2", "s3"};
+ retArray =
+ new String[] {
+ "1970-01-01T00:00:00.003Z,d1,null,null,",
+ "1970-01-01T00:00:00.004Z,d1,true,44,",
+ "1970-01-01T00:00:00.005Z,d1,null,null,",
+ "1970-01-01T00:00:00.006Z,d1,null,null,",
+ "1970-01-01T00:00:00.007Z,d1,false,77,"
+ };
+ tableResultSetEqualTest(
+ "select time, device_id, s2, s3 from table1 OFFSET 2",
+ expectedHeader,
+ retArray,
+ DATABASE_NAME);
+
+ expectedHeader = new String[] {"time", "device_id", "s2", "s3"};
+ retArray =
+ new String[] {
+ "1970-01-01T00:00:00.001Z,d1,false,11,",
"1970-01-01T00:00:00.002Z,d1,null,null,",
+ };
+ tableResultSetEqualTest(
+ "select time, device_id, s2, s3 from table1 limit 2",
+ expectedHeader,
+ retArray,
+ DATABASE_NAME);
+ }
}
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java
index 52792876c31..7df892dbeda 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java
@@ -553,8 +553,8 @@ public class AstBuilder extends
RelationalSqlBaseVisitor<Node> {
getLocation(ctx),
new Table(getLocation(ctx), getQualifiedName(ctx.qualifiedName())),
visitIfPresent(ctx.where, Expression.class).orElse(null),
- visitIfPresent(ctx.offset, Offset.class).orElse(null),
- visitIfPresent(ctx.limit, Node.class).orElse(null));
+ visitIfPresent(ctx.limitOffsetClause().offset,
Offset.class).orElse(null),
+ visitIfPresent(ctx.limitOffsetClause().limit,
Node.class).orElse(null));
}
@Override
@@ -797,16 +797,16 @@ public class AstBuilder extends
RelationalSqlBaseVisitor<Node> {
}
Optional<Offset> offset = Optional.empty();
- if (ctx.OFFSET() != null) {
- offset = visitIfPresent(ctx.offset, Offset.class);
+ if (ctx.limitOffsetClause().OFFSET() != null) {
+ offset = visitIfPresent(ctx.limitOffsetClause().offset, Offset.class);
}
Optional<Node> limit = Optional.empty();
- if (ctx.LIMIT() != null) {
- if (ctx.limit == null) {
+ if (ctx.limitOffsetClause().LIMIT() != null) {
+ if (ctx.limitOffsetClause().limit == null) {
throw new IllegalStateException("Missing LIMIT value");
}
- limit = visitIfPresent(ctx.limit, Node.class);
+ limit = visitIfPresent(ctx.limitOffsetClause().limit, Node.class);
}
if (term instanceof QuerySpecification) {
diff --git
a/iotdb-core/relational-grammar/src/main/antlr4/org/apache/iotdb/db/relational/grammar/sql/RelationalSql.g4
b/iotdb-core/relational-grammar/src/main/antlr4/org/apache/iotdb/db/relational/grammar/sql/RelationalSql.g4
index 8866fd6c65c..bfcdaf96fb1 100644
---
a/iotdb-core/relational-grammar/src/main/antlr4/org/apache/iotdb/db/relational/grammar/sql/RelationalSql.g4
+++
b/iotdb-core/relational-grammar/src/main/antlr4/org/apache/iotdb/db/relational/grammar/sql/RelationalSql.g4
@@ -237,8 +237,7 @@ loadTsFileStatement
showDevicesStatement
: SHOW DEVICES FROM tableName=qualifiedName
(WHERE where=booleanExpression)?
- (OFFSET offset=rowCount (ROW | ROWS)?)?
- (LIMIT limit=limitRowCount)?
+ limitOffsetClause
;
countDevicesStatement
@@ -322,8 +321,7 @@ showQueriesStatement
: SHOW (QUERIES | QUERY PROCESSLIST)
(WHERE where=booleanExpression)?
(ORDER BY sortItem (',' sortItem)*)?
- (OFFSET offset=rowCount (ROW | ROWS)?)?
- (LIMIT limit=limitRowCount)?
+ limitOffsetClause
;
@@ -383,10 +381,15 @@ queryNoWith
: queryTerm
(ORDER BY sortItem (',' sortItem)*)?
(FILL '(' (LINEAR | PREVIOUS | literalExpression) (','
duration=timeDuration)? ')')?
- (OFFSET offset=rowCount)?
- (LIMIT limit=limitRowCount)?
+ limitOffsetClause
;
+limitOffsetClause
+ : (OFFSET offset=rowCount)? (LIMIT limit=limitRowCount)?
+ | (LIMIT limit=limitRowCount)? (OFFSET offset=rowCount)?
+ ;
+
+
limitRowCount
: ALL
| rowCount