You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by hu...@apache.org on 2022/10/13 10:57:36 UTC
[iotdb] 04/04: fix bugs
This is an automated email from the ASF dual-hosted git repository.
hui pushed a commit to branch lmh/mppSelectInto
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 66a200c55b30c35513ef87975a593f661acfac0b
Author: Minghui Liu <li...@foxmail.com>
AuthorDate: Thu Oct 13 18:56:55 2022 +0800
fix bugs
---
.../iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java | 11 +++---
.../iotdb/db/mpp/plan/parser/ASTVisitor.java | 2 +-
.../parameter/IntoDeviceMeasurementDescriptor.java | 39 ++++++++++++----------
.../plan/statement/component/IntoComponent.java | 5 +--
.../tsfile/common/constant/TsFileConstant.java | 2 +-
5 files changed, 34 insertions(+), 25 deletions(-)
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java
index 8837208abc..30d945044a 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java
@@ -201,6 +201,10 @@ public class AnalyzeVisitor extends StatementVisitor<Analysis, MPPQueryContext>
logger.info("[EndFetchSchema]");
// If there is no leaf node in the schema tree, the query should be completed immediately
if (schemaTree.isEmpty()) {
+ if (queryStatement.isSelectInto()) {
+ analysis.setRespDatasetHeader(
+ DatasetHeaderFactory.getSelectIntoHeader(queryStatement.isAlignByDevice()));
+ }
if (queryStatement.isLastQuery()) {
analysis.setRespDatasetHeader(DatasetHeaderFactory.getLastQueryHeader());
}
@@ -1026,7 +1030,6 @@ public class AnalyzeVisitor extends StatementVisitor<Analysis, MPPQueryContext>
PartialPath deviceTemplate = intoDeviceMeasurementIterator.getDeviceTemplate();
boolean isAlignedDevice = intoDeviceMeasurementIterator.isAlignedDevice();
PartialPath targetDevice = constructTargetDevice(sourceDevice, deviceTemplate);
- intoDeviceMeasurementDescriptor.specifyTargetDevice(sourceDevice, targetDevice);
intoDeviceMeasurementDescriptor.specifyDeviceAlignment(targetDevice, isAlignedDevice);
for (Expression sourceColumn : sourceColumns) {
@@ -1037,10 +1040,10 @@ public class AnalyzeVisitor extends StatementVisitor<Analysis, MPPQueryContext>
constructTargetMeasurement(
sourceDevice.concatNode(sourceColumn.toString()), measurementTemplate);
} else {
- targetMeasurement = sourceColumn.toString();
+ targetMeasurement = measurementTemplate;
}
- intoDeviceMeasurementDescriptor.specifyTargetMeasurement(
- targetDevice, sourceColumn.toString(), targetMeasurement);
+ intoDeviceMeasurementDescriptor.specifyTargetDeviceMeasurement(
+ sourceDevice, targetDevice, sourceColumn.toString(), targetMeasurement);
intoDeviceMeasurementIterator.nextMeasurement();
}
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java b/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java
index c4f9ddf867..dc28cae4e2 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java
@@ -1645,7 +1645,7 @@ public class ASTVisitor extends IoTDBSqlParserBaseVisitor<Statement> {
private void checkNodeName(String src) {
// node name could start with * and end with *
if (!TsFileConstant.NODE_NAME_PATTERN.matcher(src).matches()) {
- throw new SQLParserException(
+ throw new SemanticException(
String.format(
"%s is illegal, unquoted node name can only consist of digits, characters and underscore, or start or end with wildcard",
src));
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/parameter/IntoDeviceMeasurementDescriptor.java b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/parameter/IntoDeviceMeasurementDescriptor.java
index c0a0ec120e..abfdca58a5 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/parameter/IntoDeviceMeasurementDescriptor.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/parameter/IntoDeviceMeasurementDescriptor.java
@@ -21,37 +21,42 @@ package org.apache.iotdb.db.mpp.plan.planner.plan.parameter;
import org.apache.iotdb.commons.path.PartialPath;
import org.apache.iotdb.db.exception.sql.SemanticException;
+import org.apache.iotdb.tsfile.utils.Pair;
import java.util.HashMap;
import java.util.Map;
-import static org.apache.iotdb.db.mpp.plan.statement.component.IntoComponent.DUPLICATE_TARGET_DEVICE_ERROR_MSG;
import static org.apache.iotdb.db.mpp.plan.statement.component.IntoComponent.DUPLICATE_TARGET_PATH_ERROR_MSG;
-public class IntoDeviceMeasurementDescriptor extends IntoPathDescriptor {
+public class IntoDeviceMeasurementDescriptor {
- private final Map<PartialPath, PartialPath> targetDeviceToSourceDeviceMap;
+ private final Map<PartialPath, Map<String, Pair<PartialPath, String>>> targetPathToSourceMap;
+ protected final Map<PartialPath, Boolean> deviceToAlignedMap;
public IntoDeviceMeasurementDescriptor() {
- super();
- this.targetDeviceToSourceDeviceMap = new HashMap<>();
+ this.targetPathToSourceMap = new HashMap<>();
+ this.deviceToAlignedMap = new HashMap<>();
}
- public void specifyTargetDevice(PartialPath sourceDevice, PartialPath targetDevice) {
- if (targetDeviceToSourceDeviceMap.containsKey(targetDevice)
- && !targetDeviceToSourceDeviceMap.get(targetDevice).equals(sourceDevice)) {
- throw new SemanticException(DUPLICATE_TARGET_DEVICE_ERROR_MSG);
- }
- targetDeviceToSourceDeviceMap.put(targetDevice, sourceDevice);
- }
-
- public void specifyTargetMeasurement(
- PartialPath targetDevice, String sourceColumn, String targetMeasurement) {
- Map<String, String> measurementToSourceColumnMap =
+ public void specifyTargetDeviceMeasurement(
+ PartialPath sourceDevice,
+ PartialPath targetDevice,
+ String sourceColumn,
+ String targetMeasurement) {
+ Map<String, Pair<PartialPath, String>> measurementToSourceColumnMap =
targetPathToSourceMap.computeIfAbsent(targetDevice, key -> new HashMap<>());
if (measurementToSourceColumnMap.containsKey(targetMeasurement)) {
throw new SemanticException(DUPLICATE_TARGET_PATH_ERROR_MSG);
}
- measurementToSourceColumnMap.put(targetMeasurement, sourceColumn);
+ measurementToSourceColumnMap.put(targetMeasurement, new Pair<>(sourceDevice, sourceColumn));
+ }
+
+ public void specifyDeviceAlignment(PartialPath targetDevice, boolean isAligned) {
+ if (deviceToAlignedMap.containsKey(targetDevice)
+ && deviceToAlignedMap.get(targetDevice) != isAligned) {
+ throw new SemanticException(
+ "select into: alignment property must be the same for the same device.");
+ }
+ deviceToAlignedMap.put(targetDevice, isAligned);
}
}
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/component/IntoComponent.java b/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/component/IntoComponent.java
index 223e10602f..240a5333e4 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/component/IntoComponent.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/component/IntoComponent.java
@@ -39,8 +39,6 @@ public class IntoComponent extends StatementNode {
"select into: the number of source devices and the number of target devices should be the same.";
public static String PATH_NUM_MISMATCH_ERROR_MSG =
"select into: the number of source columns and the number of target paths should be the same.";
- public static String DUPLICATE_TARGET_DEVICE_ERROR_MSG =
- "select into: target devices in into clause should be different.";
public static String DUPLICATE_TARGET_PATH_ERROR_MSG =
"select into: target paths in into clause should be different.";
@@ -196,6 +194,9 @@ public class IntoComponent extends StatementNode {
public void nextMeasurement() {
if (!intoItems.get(deviceIndex).isMeasurementsExistPlaceholder()) {
measurementIndex++;
+ if (measurementIndex == intoItems.get(deviceIndex).getIntoMeasurements().size()) {
+ measurementIndex = 0;
+ }
}
}
}
diff --git a/tsfile/src/main/java/org/apache/iotdb/tsfile/common/constant/TsFileConstant.java b/tsfile/src/main/java/org/apache/iotdb/tsfile/common/constant/TsFileConstant.java
index 956a34a953..7917c3a1cb 100644
--- a/tsfile/src/main/java/org/apache/iotdb/tsfile/common/constant/TsFileConstant.java
+++ b/tsfile/src/main/java/org/apache/iotdb/tsfile/common/constant/TsFileConstant.java
@@ -41,7 +41,7 @@ public class TsFileConstant {
private static final String IDENTIFIER_MATCHER = "([a-zA-Z0-9_\\u2E80-\\u9FFF]+)";
public static final Pattern IDENTIFIER_PATTERN = Pattern.compile(IDENTIFIER_MATCHER);
- private static final String NODE_NAME_MATCHER = "(\\*{0,2}[a-zA-Z0-9_\\u2E80-\\u9FFF]+\\*{0,2})";
+ private static final String NODE_NAME_MATCHER = "(\\*{0,2}[a-zA-Z0-9_\\u2E80-\\u9FFF]*\\*{0,2})";
public static final Pattern NODE_NAME_PATTERN = Pattern.compile(NODE_NAME_MATCHER);
private static final String NODE_NAME_IN_INTO_PATH_MATCHER = "([a-zA-Z0-9_${}\\u2E80-\\u9FFF]+)";