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/11/23 06:20:47 UTC
[iotdb] branch master updated: [IOTDB-4926] Add error message when the key of parameter attributes is not quoted (#8089)
This is an automated email from the ASF dual-hosted git repository.
hui 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 beb1ac2438 [IOTDB-4926] Add error message when the key of parameter attributes is not quoted (#8089)
beb1ac2438 is described below
commit beb1ac2438a4105866f350951dedd39249944223
Author: Liao Lanyu <14...@qq.com>
AuthorDate: Wed Nov 23 14:20:41 2022 +0800
[IOTDB-4926] Add error message when the key of parameter attributes is not quoted (#8089)
---
.../db/it/udf/IoTDBUDTFAlignByTimeQueryIT.java | 20 +++++++++++++++++
.../iotdb/db/mpp/plan/parser/ASTVisitor.java | 25 ++++++++++++++--------
.../iotdb/udf/api/collector/PointCollector.java | 4 ++--
3 files changed, 38 insertions(+), 11 deletions(-)
diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/udf/IoTDBUDTFAlignByTimeQueryIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/udf/IoTDBUDTFAlignByTimeQueryIT.java
index 99c2a21b44..8b530072ce 100644
--- a/integration-test/src/test/java/org/apache/iotdb/db/it/udf/IoTDBUDTFAlignByTimeQueryIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/db/it/udf/IoTDBUDTFAlignByTimeQueryIT.java
@@ -156,6 +156,26 @@ public class IoTDBUDTFAlignByTimeQueryIT {
}
}
+ @Test
+ public void queryWithUnquotedAttributes() {
+ try (Connection connection = EnvFactory.getEnv().getConnection();
+ Statement statement = connection.createStatement()) {
+ try {
+ statement.executeQuery("select sum_sec(s1, 'interval'=3) from root.udf.d1;");
+ } catch (SQLException e) {
+ assertTrue(e.getMessage().contains("Attributes of functions should be quoted"));
+ }
+ try {
+ statement.executeQuery(
+ "select sum_sec(s1, 'max_interval'=1, 'standard'=udf) from root.udf.d1;");
+ } catch (SQLException e) {
+ assertTrue(e.getMessage().contains("Attributes of functions should be quoted"));
+ }
+ } catch (Exception throwable) {
+ fail(throwable.getMessage());
+ }
+ }
+
@Test
public void queryWithoutValueFilter1() {
String sqlStr =
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 1be8cd3d0d..f2557cc6f3 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
@@ -2480,15 +2480,22 @@ public class ASTVisitor extends IoTDBSqlParserBaseVisitor<Statement> {
if (!subexpression.isConstantOperand()) {
hasNonPureConstantSubExpression = true;
}
- if (subexpression instanceof EqualToExpression
- && ((EqualToExpression) subexpression).getLeftExpression().isConstantOperand()
- && ((EqualToExpression) subexpression).getRightExpression().isConstantOperand()) {
- // parse attribute
- functionExpression.addAttribute(
- ((ConstantOperand) ((EqualToExpression) subexpression).getLeftExpression())
- .getValueString(),
- ((ConstantOperand) ((EqualToExpression) subexpression).getRightExpression())
- .getValueString());
+ if (subexpression instanceof EqualToExpression) {
+ Expression subLeftExpression = ((EqualToExpression) subexpression).getLeftExpression();
+ Expression subRightExpression = ((EqualToExpression) subexpression).getRightExpression();
+ if (subLeftExpression.isConstantOperand()
+ && (!(subRightExpression.isConstantOperand()
+ && ((ConstantOperand) subRightExpression).getDataType().equals(TSDataType.TEXT)))) {
+ throw new SQLParserException("Attributes of functions should be quoted with '' or \"\"");
+ }
+ if (subLeftExpression.isConstantOperand() && subRightExpression.isConstantOperand()) {
+ // parse attribute
+ functionExpression.addAttribute(
+ ((ConstantOperand) subLeftExpression).getValueString(),
+ ((ConstantOperand) subRightExpression).getValueString());
+ } else {
+ functionExpression.addExpression(subexpression);
+ }
} else {
functionExpression.addExpression(subexpression);
}
diff --git a/udf-api/src/main/java/org/apache/iotdb/udf/api/collector/PointCollector.java b/udf-api/src/main/java/org/apache/iotdb/udf/api/collector/PointCollector.java
index b5ed276d31..f168a2fdbc 100644
--- a/udf-api/src/main/java/org/apache/iotdb/udf/api/collector/PointCollector.java
+++ b/udf-api/src/main/java/org/apache/iotdb/udf/api/collector/PointCollector.java
@@ -31,9 +31,9 @@ import java.io.IOException;
/**
* Used to collect time series data points generated by {@link UDTF#transform(Row, PointCollector)},
+ * {@link UDTF#transform(RowWindow, PointCollector)} or {@link UDTF#terminate(PointCollector)}.
* Notice that one timestamp can not be put in the PointCollector more than once, or it may stop the
- * calculation. {@link UDTF#transform(RowWindow, PointCollector)} or {@link
- * UDTF#terminate(PointCollector)}.
+ * calculation.
*/
public interface PointCollector {