You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ja...@apache.org on 2022/04/14 08:24:08 UTC

[iotdb] branch master updated: Generate header of result set: show timeseries/devices/sg (#5531)

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 a8c8acbc94 Generate header of result set: show timeseries/devices/sg (#5531)
a8c8acbc94 is described below

commit a8c8acbc945d3f6ce1f008d15ac5097c1e0edb56
Author: liuminghui233 <36...@users.noreply.github.com>
AuthorDate: Thu Apr 14 16:24:03 2022 +0800

    Generate header of result set: show timeseries/devices/sg (#5531)
---
 .../iotdb/db/mpp/common/header/HeaderConstant.java | 90 ++++++++++++++++++++++
 .../apache/iotdb/db/mpp/sql/analyze/Analyzer.java  | 21 +++--
 .../apache/iotdb/db/mpp/sql/parser/ASTVisitor.java | 12 +++
 .../db/mpp/sql/statement/StatementVisitor.java     |  5 ++
 .../db/mpp/sql/statement/crud/QueryStatement.java  |  4 +-
 .../metadata/ShowStorageGroupStatement.java        | 42 ++++++++++
 6 files changed, 167 insertions(+), 7 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/common/header/HeaderConstant.java b/server/src/main/java/org/apache/iotdb/db/mpp/common/header/HeaderConstant.java
new file mode 100644
index 0000000000..1751cf6a8c
--- /dev/null
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/common/header/HeaderConstant.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.mpp.common.header;
+
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+
+import java.util.Arrays;
+import java.util.Collections;
+
+public class HeaderConstant {
+
+  // column names for query statement
+  public static final String COLUMN_DEVICE = "Device";
+
+  // column names for schema statement
+  public static final String COLUMN_STORAGE_GROUP = "storage group";
+  public static final String COLUMN_TIMESERIES = "timeseries";
+  public static final String COLUMN_TIMESERIES_ALIAS = "alias";
+  public static final String COLUMN_TIMESERIES_DATATYPE = "dataType";
+  public static final String COLUMN_TIMESERIES_ENCODING = "encoding";
+  public static final String COLUMN_TIMESERIES_COMPRESSION = "compression";
+  public static final String COLUMN_DEVICES = "devices";
+  public static final String COLUMN_TAGS = "tags";
+  public static final String COLUMN_ATTRIBUTES = "attributes";
+  public static final String COLUMN_IS_ALIGNED = "isAligned";
+
+  // dataset header for schema statement
+  public static final DatasetHeader showTimeSeriesHeader;
+  public static final DatasetHeader showDevicesHeader;
+  public static final DatasetHeader showDevicesWithSgHeader;
+  public static final DatasetHeader showStorageGroupHeader;
+
+  static {
+    showTimeSeriesHeader =
+        new DatasetHeader(
+            Arrays.asList(
+                new ColumnHeader(COLUMN_TIMESERIES, TSDataType.TEXT),
+                new ColumnHeader(COLUMN_TIMESERIES_ALIAS, TSDataType.TEXT),
+                new ColumnHeader(COLUMN_STORAGE_GROUP, TSDataType.TEXT),
+                new ColumnHeader(COLUMN_TIMESERIES_DATATYPE, TSDataType.TEXT),
+                new ColumnHeader(COLUMN_TIMESERIES_ENCODING, TSDataType.TEXT),
+                new ColumnHeader(COLUMN_TIMESERIES_COMPRESSION, TSDataType.TEXT),
+                new ColumnHeader(COLUMN_TAGS, TSDataType.TEXT),
+                new ColumnHeader(COLUMN_ATTRIBUTES, TSDataType.TEXT)),
+            true);
+  }
+
+  static {
+    showDevicesHeader =
+        new DatasetHeader(
+            Arrays.asList(
+                new ColumnHeader(COLUMN_DEVICES, TSDataType.TEXT),
+                new ColumnHeader(COLUMN_IS_ALIGNED, TSDataType.TEXT)),
+            true);
+  }
+
+  static {
+    showDevicesWithSgHeader =
+        new DatasetHeader(
+            Arrays.asList(
+                new ColumnHeader(COLUMN_DEVICES, TSDataType.TEXT),
+                new ColumnHeader(COLUMN_STORAGE_GROUP, TSDataType.TEXT),
+                new ColumnHeader(COLUMN_IS_ALIGNED, TSDataType.TEXT)),
+            true);
+  }
+
+  static {
+    showStorageGroupHeader =
+        new DatasetHeader(
+            Collections.singletonList(new ColumnHeader(COLUMN_STORAGE_GROUP, TSDataType.TEXT)),
+            true);
+  }
+}
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/sql/analyze/Analyzer.java b/server/src/main/java/org/apache/iotdb/db/mpp/sql/analyze/Analyzer.java
index 53d03fcaed..3e205637c0 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/sql/analyze/Analyzer.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/sql/analyze/Analyzer.java
@@ -29,6 +29,7 @@ import org.apache.iotdb.db.exception.sql.StatementAnalyzeException;
 import org.apache.iotdb.db.metadata.path.PartialPath;
 import org.apache.iotdb.db.mpp.common.MPPQueryContext;
 import org.apache.iotdb.db.mpp.common.filter.QueryFilter;
+import org.apache.iotdb.db.mpp.common.header.HeaderConstant;
 import org.apache.iotdb.db.mpp.common.schematree.PathPatternTree;
 import org.apache.iotdb.db.mpp.common.schematree.SchemaTree;
 import org.apache.iotdb.db.mpp.sql.rewriter.ConcatPathRewriter;
@@ -41,11 +42,7 @@ import org.apache.iotdb.db.mpp.sql.statement.StatementVisitor;
 import org.apache.iotdb.db.mpp.sql.statement.component.ResultColumn;
 import org.apache.iotdb.db.mpp.sql.statement.component.WhereCondition;
 import org.apache.iotdb.db.mpp.sql.statement.crud.*;
-import org.apache.iotdb.db.mpp.sql.statement.metadata.AlterTimeSeriesStatement;
-import org.apache.iotdb.db.mpp.sql.statement.metadata.CreateAlignedTimeSeriesStatement;
-import org.apache.iotdb.db.mpp.sql.statement.metadata.CreateTimeSeriesStatement;
-import org.apache.iotdb.db.mpp.sql.statement.metadata.ShowDevicesStatement;
-import org.apache.iotdb.db.mpp.sql.statement.metadata.ShowTimeSeriesStatement;
+import org.apache.iotdb.db.mpp.sql.statement.metadata.*;
 import org.apache.iotdb.db.mpp.sql.statement.sys.AuthorStatement;
 import org.apache.iotdb.db.qp.constant.SQLConstant;
 import org.apache.iotdb.tsfile.exception.filter.QueryFilterOptimizationException;
@@ -306,6 +303,16 @@ public class Analyzer {
         throw new SemanticException("An error occurred when fetching schema partition infos");
       }
       analysis.setSchemaPartitionInfo(schemaPartitionInfo);
+      analysis.setRespDatasetHeader(HeaderConstant.showTimeSeriesHeader);
+      return analysis;
+    }
+
+    @Override
+    public Analysis visitShowStorageGroup(
+        ShowStorageGroupStatement showStorageGroupStatement, MPPQueryContext context) {
+      Analysis analysis = new Analysis();
+      analysis.setStatement(showStorageGroupStatement);
+      analysis.setRespDatasetHeader(HeaderConstant.showStorageGroupHeader);
       return analysis;
     }
 
@@ -324,6 +331,10 @@ public class Analyzer {
         throw new SemanticException("An error occurred when fetching schema partition infos");
       }
       analysis.setSchemaPartitionInfo(schemaPartitionInfo);
+      analysis.setRespDatasetHeader(
+          showDevicesStatement.hasSgCol()
+              ? HeaderConstant.showDevicesWithSgHeader
+              : HeaderConstant.showDevicesHeader);
       return analysis;
     }
 
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/sql/parser/ASTVisitor.java b/server/src/main/java/org/apache/iotdb/db/mpp/sql/parser/ASTVisitor.java
index 6bb7be3283..e445961919 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/sql/parser/ASTVisitor.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/sql/parser/ASTVisitor.java
@@ -59,6 +59,7 @@ import org.apache.iotdb.db.mpp.sql.statement.metadata.CreateTimeSeriesStatement;
 import org.apache.iotdb.db.mpp.sql.statement.metadata.SetStorageGroupStatement;
 import org.apache.iotdb.db.mpp.sql.statement.metadata.ShowDevicesStatement;
 import org.apache.iotdb.db.mpp.sql.statement.metadata.ShowStatement;
+import org.apache.iotdb.db.mpp.sql.statement.metadata.ShowStorageGroupStatement;
 import org.apache.iotdb.db.mpp.sql.statement.metadata.ShowTimeSeriesStatement;
 import org.apache.iotdb.db.mpp.sql.statement.sys.AuthorStatement;
 import org.apache.iotdb.db.qp.constant.SQLConstant;
@@ -389,6 +390,17 @@ public class ASTVisitor extends IoTDBSqlParserBaseVisitor<Statement> {
     statement.setValue(parseStringLiteral(propertyValueContext.getText()));
   }
 
+  // Show Storage Group
+
+  @Override
+  public Statement visitShowStorageGroup(IoTDBSqlParser.ShowStorageGroupContext ctx) {
+    if (ctx.prefixPath() != null) {
+      return new ShowStorageGroupStatement(parsePrefixPath(ctx.prefixPath()));
+    } else {
+      return new ShowStorageGroupStatement(new PartialPath(SQLConstant.getSingleRootArray()));
+    }
+  }
+
   // Show Devices ========================================================================
 
   @Override
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/sql/statement/StatementVisitor.java b/server/src/main/java/org/apache/iotdb/db/mpp/sql/statement/StatementVisitor.java
index ce6030b704..5224ae4bde 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/sql/statement/StatementVisitor.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/sql/statement/StatementVisitor.java
@@ -37,6 +37,7 @@ import org.apache.iotdb.db.mpp.sql.statement.metadata.AlterTimeSeriesStatement;
 import org.apache.iotdb.db.mpp.sql.statement.metadata.CreateAlignedTimeSeriesStatement;
 import org.apache.iotdb.db.mpp.sql.statement.metadata.CreateTimeSeriesStatement;
 import org.apache.iotdb.db.mpp.sql.statement.metadata.ShowDevicesStatement;
+import org.apache.iotdb.db.mpp.sql.statement.metadata.ShowStorageGroupStatement;
 import org.apache.iotdb.db.mpp.sql.statement.metadata.ShowTimeSeriesStatement;
 import org.apache.iotdb.db.mpp.sql.statement.sys.AuthorStatement;
 
@@ -222,6 +223,10 @@ public abstract class StatementVisitor<R, C> {
     return visitStatement(authorStatement, context);
   }
 
+  public R visitShowStorageGroup(ShowStorageGroupStatement showStorageGroupStatement, C context) {
+    return visitStatement(showStorageGroupStatement, context);
+  }
+
   public R visitShowTimeSeries(ShowTimeSeriesStatement showTimeSeriesStatement, C context) {
     return visitStatement(showTimeSeriesStatement, context);
   }
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/sql/statement/crud/QueryStatement.java b/server/src/main/java/org/apache/iotdb/db/mpp/sql/statement/crud/QueryStatement.java
index 850bdd21c6..2d11e62df5 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/sql/statement/crud/QueryStatement.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/sql/statement/crud/QueryStatement.java
@@ -24,6 +24,7 @@ import org.apache.iotdb.db.index.common.IndexType;
 import org.apache.iotdb.db.metadata.path.PartialPath;
 import org.apache.iotdb.db.mpp.common.header.ColumnHeader;
 import org.apache.iotdb.db.mpp.common.header.DatasetHeader;
+import org.apache.iotdb.db.mpp.common.header.HeaderConstant;
 import org.apache.iotdb.db.mpp.sql.constant.StatementType;
 import org.apache.iotdb.db.mpp.sql.statement.Statement;
 import org.apache.iotdb.db.mpp.sql.statement.StatementVisitor;
@@ -267,8 +268,7 @@ public class QueryStatement extends Statement {
     List<ColumnHeader> columnHeaders = new ArrayList<>();
     if (this.isAlignByDevice()) {
       // add DEVICE column
-      columnHeaders.add(
-          new ColumnHeader(SQLConstant.ALIGNBY_DEVICE_COLUMN_NAME, TSDataType.TEXT, null));
+      columnHeaders.add(new ColumnHeader(HeaderConstant.COLUMN_DEVICE, TSDataType.TEXT, null));
 
       // TODO: consider ALIGN BY DEVICE
     } else {
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/sql/statement/metadata/ShowStorageGroupStatement.java b/server/src/main/java/org/apache/iotdb/db/mpp/sql/statement/metadata/ShowStorageGroupStatement.java
new file mode 100644
index 0000000000..50742ce767
--- /dev/null
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/sql/statement/metadata/ShowStorageGroupStatement.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.mpp.sql.statement.metadata;
+
+import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.mpp.sql.statement.StatementVisitor;
+
+public class ShowStorageGroupStatement extends ShowStatement {
+
+  private final PartialPath pathPattern;
+
+  public ShowStorageGroupStatement(PartialPath pathPattern) {
+    super();
+    this.pathPattern = pathPattern;
+  }
+
+  public PartialPath getPathPattern() {
+    return pathPattern;
+  }
+
+  @Override
+  public <R, C> R accept(StatementVisitor<R, C> visitor, C context) {
+    return visitor.visitShowStorageGroup(this, context);
+  }
+}