This is an automated email from the ASF dual-hosted git repository.
jackietien pushed a commit to branch ty/TableIT
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/ty/TableIT by this push:
new b03bd277fbc Add more IT
b03bd277fbc is described below
commit b03bd277fbc96f96a55aa4697388bb64f3cba89d
Author: JackieTien97 <[email protected]>
AuthorDate: Tue Jul 23 21:41:17 2024 +0800
Add more IT
---
.../scalar/IoTDBReplaceFunctionIT.java | 2 +-
.../scalar/IoTDBSubStringFunctionIT.java | 28 +++++++++++-----------
.../relational/metadata/TableMetadataImpl.java | 12 ++++++----
3 files changed, 23 insertions(+), 19 deletions(-)
diff --git
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBReplaceFunctionIT.java
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBReplaceFunctionIT.java
index 8d17c5507f1..d16ce0311be 100644
---
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBReplaceFunctionIT.java
+++
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBReplaceFunctionIT.java
@@ -49,7 +49,7 @@ public class IoTDBReplaceFunctionIT {
"CREATE DATABASE " + DATABASE_NAME,
"use " + DATABASE_NAME,
"create table table1(device_id STRING ID, s1 TEXT MEASUREMENT, s2
INT32 MEASUREMENT, s3 INT64 MEASUREMENT, s4 FLOAT MEASUREMENT, s5 DOUBLE
MEASUREMENT, s6 BOOLEAN MEASUREMENT, s7 DATE MEASUREMENT, s8 TIMESTAMP
MEASUREMENT, s9 STRING MEASUREMENT, s10 BLOB MEASUREMENT);",
- "INSERT INTO table1(Time,device_id,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10)
values(1, 'd1', 'abcd', 1, 1, 1, 1, true, '2021-10-01', 1633046400000,
'abcd','abcd')",
+ "INSERT INTO table1(Time,device_id,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10)
values(1, 'd1', 'abcd', 1, 1, 1, 1, true, '2021-10-01', 1633046400000, 'abcd',
X'abcd')",
"INSERT INTO table1(Time,device_id,s1) values(2, 'd1', 'test\\\\')",
"INSERT INTO table1(Time,device_id,s1) values(3, 'd1', 'abcd\\\\')",
"INSERT INTO table1(Time,device_id,s9)) values(2, 'd1', 'test\\\\')",
diff --git
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBSubStringFunctionIT.java
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBSubStringFunctionIT.java
index 0419f22d583..b021d75fb81 100644
---
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBSubStringFunctionIT.java
+++
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBSubStringFunctionIT.java
@@ -49,11 +49,11 @@ public class IoTDBSubStringFunctionIT {
"CREATE DATABASE " + DATABASE_NAME,
"use " + DATABASE_NAME,
"create table table1(device_id STRING ID, s1 TEXT MEASUREMENT, s2
INT32 MEASUREMENT, s3 INT64 MEASUREMENT, s4 FLOAT MEASUREMENT, s5 DOUBLE
MEASUREMENT, s6 BOOLEAN MEASUREMENT, s7 DATE MEASUREMENT, s8 TIMESTAMP
MEASUREMENT, s9 STRING MEASUREMENT, s10 BLOB MEASUREMENT);",
- "INSERT INTO table1(Time,device_id,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10)
values(1, 'd1', 'abcd', 1, 1, 1, 1, true, '2021-10-01', 1633046400000, 'abcd',
'abcd')",
+ "INSERT INTO table1(Time,device_id,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10)
values(1, 'd1', 'abcd', 1, 1, 1, 1, true, '2021-10-01', 1633046400000, 'abcd',
X'abcd')",
"INSERT INTO table1(Time,device_id,s1) values(2, 'd1', 'test')",
"INSERT INTO table1(Time,device_id,s1) values(3, 'd1', 'abcdefg')",
- "INSERT INTO table1(Time,device_id,s9)) values(2, 'd1', 'test')",
- "INSERT INTO table1(Time,device_id,s9)) values(3, 'd1', 'abcdefg')",
+ "INSERT INTO table1(Time,device_id,s9) values(2, 'd1', 'test')",
+ "INSERT INTO table1(Time,device_id,s9) values(3, 'd1', 'abcdefg')",
"flush"
};
@@ -130,76 +130,76 @@ public class IoTDBSubStringFunctionIT {
tableAssertTestFail(
"select s1,SUBSTRING(s1) from table1",
TSStatusCode.SEMANTIC_ERROR.getStatusCode()
- + ": Argument exception,the scalar function [SUBSTRING] needs at
least one argument,it must be a signed integer",
+ + ": Scalar function substring only accepts two or three arguments
and first must be text or string data type, second and third must be numeric
data types [INT32, INT64]",
DATABASE_NAME);
// Wrong input type
tableAssertTestFail(
"select SUBSTRING(s2 FROM 1 FOR 1) from table1",
TSStatusCode.SEMANTIC_ERROR.getStatusCode()
- + ": Unsupported data type INT32 for function SUBSTRING.",
+ + ": Scalar function substring only accepts two or three arguments
and first must be text or string data type, second and third must be numeric
data types [INT32, INT64]",
DATABASE_NAME);
// Wrong input type
tableAssertTestFail(
"select SUBSTRING(s3 FROM 1 FOR 1) from table1",
TSStatusCode.SEMANTIC_ERROR.getStatusCode()
- + ": Unsupported data type INT64 for function SUBSTRING.",
+ + ": Scalar function substring only accepts two or three arguments
and first must be text or string data type, second and third must be numeric
data types [INT32, INT64]",
DATABASE_NAME);
// Wrong input type
tableAssertTestFail(
"select SUBSTRING(s4 FROM 1 FOR 1) from table1",
TSStatusCode.SEMANTIC_ERROR.getStatusCode()
- + ": Unsupported data type FLOAT for function SUBSTRING.",
+ + ": Scalar function substring only accepts two or three arguments
and first must be text or string data type, second and third must be numeric
data types [INT32, INT64]",
DATABASE_NAME);
// Wrong input type
tableAssertTestFail(
"select SUBSTRING(s5 FROM 1 FOR 1) from table1",
TSStatusCode.SEMANTIC_ERROR.getStatusCode()
- + ": Unsupported data type DOUBLE for function SUBSTRING.",
+ + ": Scalar function substring only accepts two or three arguments
and first must be text or string data type, second and third must be numeric
data types [INT32, INT64]",
DATABASE_NAME);
// Wrong input type
tableAssertTestFail(
"select SUBSTRING(s6 FROM 1 FOR 1) from table1",
TSStatusCode.SEMANTIC_ERROR.getStatusCode()
- + ": Unsupported data type BOOLEAN for function SUBSTRING.",
+ + ": Scalar function substring only accepts two or three arguments
and first must be text or string data type, second and third must be numeric
data types [INT32, INT64]",
DATABASE_NAME);
// Wrong input type
tableAssertTestFail(
"select SUBSTRING(s7 FROM 1 FOR 1) from table1",
TSStatusCode.SEMANTIC_ERROR.getStatusCode()
- + ": Unsupported data type DATE for function SUBSTRING.",
+ + ": Scalar function substring only accepts two or three arguments
and first must be text or string data type, second and third must be numeric
data types [INT32, INT64]",
DATABASE_NAME);
// Wrong input type
tableAssertTestFail(
"select SUBSTRING(s8 FROM 1 FOR 1) from table1",
TSStatusCode.SEMANTIC_ERROR.getStatusCode()
- + ": Unsupported data type TIMESTAMP for function SUBSTRING.",
+ + ": Scalar function substring only accepts two or three arguments
and first must be text or string data type, second and third must be numeric
data types [INT32, INT64]",
DATABASE_NAME);
// Wrong input type
tableAssertTestFail(
"select SUBSTRING(s10 FROM 1 FOR 1) from table1",
TSStatusCode.SEMANTIC_ERROR.getStatusCode()
- + ": Unsupported data type BLOB for function SUBSTRING.",
+ + ": Scalar function substring only accepts two or three arguments
and first must be text or string data type, second and third must be numeric
data types [INT32, INT64]",
DATABASE_NAME);
// Using substring with float start position
tableAssertTestFail(
"select SUBSTRING(s1 FROM 1.0 FOR 1) from table1",
TSStatusCode.SEMANTIC_ERROR.getStatusCode()
- + ": Argument exception,the scalar function [SUBSTRING] needs at
least one argument,it must be a signed integer",
+ + ": Scalar function substring only accepts two or three arguments
and first must be text or string data type, second and third must be numeric
data types [INT32, INT64]",
DATABASE_NAME);
// Using substring with float start and length
tableAssertTestFail(
"select SUBSTRING(s1 FROM 1.0 FOR 1.1) from table1",
TSStatusCode.SEMANTIC_ERROR.getStatusCode()
- + ": Argument exception,the scalar function [SUBSTRING] needs at
least one argument,it must be a signed integer",
+ + ": Scalar function substring only accepts two or three arguments
and first must be text or string data type, second and third must be numeric
data types [INT32, INT64]",
DATABASE_NAME);
// Negative characters length
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java
index 2452c7dbfc1..5409feacf42 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java
@@ -176,15 +176,15 @@ public class TableMetadataImpl implements Metadata {
} else if
(BuiltinScalarFunction.SUBSTRING.getFunctionName().equalsIgnoreCase(functionName))
{
if (!(argumentTypes.size() == 2
&& isCharType(argumentTypes.get(0))
- && isNumericType(argumentTypes.get(1)))
+ && isIntegerNumber(argumentTypes.get(1)))
&& !(argumentTypes.size() == 3
&& isCharType(argumentTypes.get(0))
- && isNumericType(argumentTypes.get(1))
- && isNumericType(argumentTypes.get(2)))) {
+ && isIntegerNumber(argumentTypes.get(1))
+ && isIntegerNumber(argumentTypes.get(2)))) {
throw new SemanticException(
"Scalar function "
+ functionName.toLowerCase(Locale.ENGLISH)
- + " only supports text or string data type.");
+ + " only accepts two or three arguments and first must be text
or string data type, second and third must be numeric data types [INT32,
INT64]");
}
return argumentTypes.get(0);
}
@@ -407,6 +407,10 @@ public class TableMetadataImpl implements Metadata {
|| TimestampType.TIMESTAMP.equals(type);
}
+ public static boolean isIntegerNumber(Type type) {
+ return INT32.equals(type) || INT64.equals(type);
+ }
+
public static boolean isTwoTypeComparable(List<? extends Type>
argumentTypes) {
if (argumentTypes.size() != 2) {
return false;