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 d2f66d0f42 [IOTDB-5736] remove old syntax of the string function
substring and beginPosition must be greater than 0
d2f66d0f42 is described below
commit d2f66d0f4205c1ee773f629bd307de2be9f880f0
Author: Zhijia Cao <[email protected]>
AuthorDate: Tue Apr 4 16:14:53 2023 +0800
[IOTDB-5736] remove old syntax of the string function substring and
beginPosition must be greater than 0
---
.../scalar/IoTDBSubStringFunctionIT.java | 82 +++++-----------------
.../builtin/helper/SubStringFunctionHelper.java | 35 +++++----
2 files changed, 40 insertions(+), 77 deletions(-)
diff --git
a/integration-test/src/test/java/org/apache/iotdb/db/it/builtinfunction/scalar/IoTDBSubStringFunctionIT.java
b/integration-test/src/test/java/org/apache/iotdb/db/it/builtinfunction/scalar/IoTDBSubStringFunctionIT.java
index aff2fe3d14..0f0ab5c94e 100644
---
a/integration-test/src/test/java/org/apache/iotdb/db/it/builtinfunction/scalar/IoTDBSubStringFunctionIT.java
+++
b/integration-test/src/test/java/org/apache/iotdb/db/it/builtinfunction/scalar/IoTDBSubStringFunctionIT.java
@@ -98,20 +98,6 @@ public class IoTDBSubStringFunctionIT {
expectedHeader,
retArray);
- // negative start position
- expectedHeader =
- new String[] {
-
"Time,root.sg.s1,SUBSTRING(root.sg.s1,-1),SUBSTRING(root.sg.s1,-1,3),SUBSTRING(root.sg.s1
FROM -1),SUBSTRING(root.sg.s1 FROM -1 FOR 3)"
- };
- retArray =
- new String[] {
- "1,abcd,abcd,a,abcd,a,", "2,test,test,t,test,t,",
"3,abcdefg,abcdefg,a,abcdefg,a,",
- };
- resultSetEqualTest(
- "select s1,SUBSTRING(s1,-1),SUBSTRING(s1,-1,3),SUBSTRING(s1 from
-1),SUBSTRING(s1 from -1 for 3) from root.sg",
- expectedHeader,
- retArray);
-
// param 1 greater than input series length
expectedHeader =
new String[] {
@@ -125,22 +111,6 @@ public class IoTDBSubStringFunctionIT {
"select s1,SUBSTRING(s1,11),SUBSTRING(s1,11,13),SUBSTRING(s1 from
11),SUBSTRING(s1 from 11 for 13) from root.sg",
expectedHeader,
retArray);
-
- // param 2 greater than input series length
- expectedHeader =
- new String[] {
-
"Time,root.sg.s1,SUBSTRING(root.sg.s1,-1),SUBSTRING(root.sg.s1,-1,13),SUBSTRING(root.sg.s1
FROM -1),SUBSTRING(root.sg.s1 FROM -1 FOR 13)"
- };
- retArray =
- new String[] {
- "1,abcd,abcd,abcd,abcd,abcd,",
- "2,test,test,test,test,test,",
- "3,abcdefg,abcdefg,abcdefg,abcdefg,abcdefg,",
- };
- resultSetEqualTest(
- "select s1,SUBSTRING(s1,-1),SUBSTRING(s1,-1,13),SUBSTRING(s1 from
-1),SUBSTRING(s1 from -1 for 13) from root.sg",
- expectedHeader,
- retArray);
}
@Test
@@ -161,22 +131,6 @@ public class IoTDBSubStringFunctionIT {
expectedHeader,
retArray);
- // negative start position
- expectedHeader =
- new String[] {
-
"Time,root.sg.s1,change_points(root.sg.s1),SUBSTRING(root.sg.s1,-1),SUBSTRING(root.sg.s1,-1,3),SUBSTRING(root.sg.s1
FROM -1),SUBSTRING(root.sg.s1 FROM -1 FOR 3)"
- };
- retArray =
- new String[] {
- "1,abcd,abcd,abcd,a,abcd,a,",
- "2,test,test,test,t,test,t,",
- "3,abcdefg,abcdefg,abcdefg,a,abcdefg,a,",
- };
- resultSetEqualTest(
- "select
s1,change_points(s1),SUBSTRING(s1,-1),SUBSTRING(s1,-1,3),SUBSTRING(s1 from
-1),SUBSTRING(s1 from -1 for 3) from root.sg",
- expectedHeader,
- retArray);
-
// param 1 greater than input series length
expectedHeader =
new String[] {
@@ -190,22 +144,6 @@ public class IoTDBSubStringFunctionIT {
"select
s1,change_points(s1),SUBSTRING(s1,11),SUBSTRING(s1,11,13),SUBSTRING(s1 from
11),SUBSTRING(s1 from 11 for 13) from root.sg",
expectedHeader,
retArray);
-
- // param 2 greater than input series length
- expectedHeader =
- new String[] {
-
"Time,root.sg.s1,change_points(root.sg.s1),SUBSTRING(root.sg.s1,-1),SUBSTRING(root.sg.s1,-1,13),SUBSTRING(root.sg.s1
FROM -1),SUBSTRING(root.sg.s1 FROM -1 FOR 13)"
- };
- retArray =
- new String[] {
- "1,abcd,abcd,abcd,abcd,abcd,abcd,",
- "2,test,test,test,test,test,test,",
- "3,abcdefg,abcdefg,abcdefg,abcdefg,abcdefg,abcdefg,",
- };
- resultSetEqualTest(
- "select
s1,change_points(s1),SUBSTRING(s1,-1),SUBSTRING(s1,-1,13),SUBSTRING(s1 from
-1),SUBSTRING(s1 from -1 for 13) from root.sg",
- expectedHeader,
- retArray);
}
@Test
@@ -262,6 +200,24 @@ public class IoTDBSubStringFunctionIT {
assertTestFail(
"select SUBSTRING(s1,1,-10) from root.**",
TSStatusCode.EXECUTE_STATEMENT_ERROR.getStatusCode()
- + ": Argument exception,the scalar function [SUBSTRING] substring
length has to be greater than 0");
+ + ": Argument exception,the scalar function [SUBSTRING]
beginPosition and length must be greater than 0");
+
+ // negative characters begin
+ assertTestFail(
+ "select SUBSTRING(s1,-1,10) from root.**",
+ TSStatusCode.EXECUTE_STATEMENT_ERROR.getStatusCode()
+ + ": Argument exception,the scalar function [SUBSTRING]
beginPosition and length must be greater than 0");
+
+ // negative characters begin
+ assertTestFail(
+ "select SUBSTRING(s1 from -1 for 10) from root.**",
+ TSStatusCode.EXECUTE_STATEMENT_ERROR.getStatusCode()
+ + ": Argument exception,the scalar function [SUBSTRING]
beginPosition and length must be greater than 0");
+
+ // negative characters begin
+ assertTestFail(
+ "select SUBSTRING(s1,'start'='1','to'='2') from root.**",
+ TSStatusCode.SEMANTIC_ERROR.getStatusCode()
+ + ": Syntax error,please check that the parameters of the function
are correct");
}
}
diff --git
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/expression/multi/builtin/helper/SubStringFunctionHelper.java
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/expression/multi/builtin/helper/SubStringFunctionHelper.java
index b6b8ce41fa..d6c647c9cb 100644
---
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/expression/multi/builtin/helper/SubStringFunctionHelper.java
+++
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/expression/multi/builtin/helper/SubStringFunctionHelper.java
@@ -43,6 +43,8 @@ public class SubStringFunctionHelper implements
BuiltInScalarFunctionHelper {
public static final String BLANK_STRING = " ";
public static final String COMMA_STRING = ",";
+ public static final String NULL_STRING = "null";
+
@Override
public void checkBuiltInScalarFunctionInputSize(FunctionExpression
functionExpression)
throws SemanticException {
@@ -51,6 +53,10 @@ public class SubStringFunctionHelper implements
BuiltInScalarFunctionHelper {
throw new SemanticException(
"Argument exception,the scalar function [SUBSTRING] needs at least
one argument,it must be a signed integer");
}
+ if (functionExpression.getExpressionString().contains(NULL_STRING)) {
+ throw new SemanticException(
+ "Syntax error,please check that the parameters of the function are
correct");
+ }
}
@Override
@@ -72,34 +78,35 @@ public class SubStringFunctionHelper implements
BuiltInScalarFunctionHelper {
public ColumnTransformer getBuiltInScalarFunctionColumnTransformer(
FunctionExpression expression, ColumnTransformer columnTransformer) {
LinkedHashMap<String, String> functionAttributes =
expression.getFunctionAttributes();
- String subStringLength =
- functionAttributes.getOrDefault(SUBSTRING_LENGTH,
String.valueOf(Integer.MAX_VALUE));
- if (Long.parseLong(subStringLength) < 0) {
+ int subStringLength =
+ Integer.parseInt(
+ functionAttributes.getOrDefault(SUBSTRING_LENGTH,
String.valueOf(Integer.MAX_VALUE)));
+ int subStringStart =
Integer.parseInt(functionAttributes.getOrDefault(SUBSTRING_START, "0"));
+ if (subStringLength < 0 || subStringStart < 0) {
throw new SemanticException(
- "Argument exception,the scalar function [SUBSTRING] substring length
has to be greater than 0");
+ "Argument exception,the scalar function [SUBSTRING] beginPosition
and length must be greater than 0");
}
return new SubStringFunctionColumnTransformer(
TypeFactory.getType(this.getBuiltInScalarFunctionReturnType(expression)),
columnTransformer,
- Integer.parseInt(functionAttributes.getOrDefault(SUBSTRING_START,
"0")),
- Integer.parseInt(subStringLength));
+ subStringStart,
+ subStringLength);
}
@Override
public Transformer getBuiltInScalarFunctionTransformer(
FunctionExpression expression, LayerPointReader layerPointReader) {
LinkedHashMap<String, String> functionAttributes =
expression.getFunctionAttributes();
- String subStringLength =
- functionAttributes.getOrDefault(SUBSTRING_LENGTH,
String.valueOf(Integer.MAX_VALUE));
- if (Long.parseLong(subStringLength) < 0) {
+ int subStringLength =
+ Integer.parseInt(
+ functionAttributes.getOrDefault(SUBSTRING_LENGTH,
String.valueOf(Integer.MAX_VALUE)));
+ int subStringStart =
Integer.parseInt(functionAttributes.getOrDefault(SUBSTRING_START, "0"));
+ if (subStringLength < 0 || subStringStart < 0) {
throw new SemanticException(
- "Argument exception,the scalar function [SUBSTRING] substring length
has to be greater than 0");
+ "Argument exception,the scalar function [SUBSTRING] beginPosition
and length must be greater than 0");
}
- return new SubStringFunctionTransformer(
- layerPointReader,
- Integer.parseInt(functionAttributes.getOrDefault(SUBSTRING_START,
"0")),
- Integer.parseInt(subStringLength));
+ return new SubStringFunctionTransformer(layerPointReader, subStringStart,
subStringLength);
}
@Override