Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@

import static com.google.common.base.Preconditions.checkArgument;
import static org.apache.iotdb.db.queryengine.plan.relational.analyzer.predicate.PredicatePushIntoMetadataChecker.isStringLiteral;
import static org.apache.iotdb.db.queryengine.plan.relational.metadata.TableMetadataImpl.isTimestampType;
import static org.apache.iotdb.db.queryengine.plan.relational.type.InternalTypeManager.getTSDataType;
import static org.apache.iotdb.db.queryengine.plan.relational.type.TypeSignatureTranslator.toTypeSignature;
import static org.apache.tsfile.read.common.type.BlobType.BLOB;
Expand Down Expand Up @@ -666,53 +665,50 @@ private ColumnTransformer getFunctionColumnTransformer(
} else if (TableBuiltinScalarFunction.UPPER.getFunctionName().equalsIgnoreCase(functionName)) {
ColumnTransformer first = this.process(children.get(0), context);
if (children.size() == 1) {
return new UpperColumnTransformer(first.getType(), first);
return new UpperColumnTransformer(STRING, first);
}
} else if (TableBuiltinScalarFunction.LOWER.getFunctionName().equalsIgnoreCase(functionName)) {
ColumnTransformer first = this.process(children.get(0), context);
if (children.size() == 1) {
return new LowerColumnTransformer(first.getType(), first);
return new LowerColumnTransformer(STRING, first);
}
} else if (TableBuiltinScalarFunction.TRIM.getFunctionName().equalsIgnoreCase(functionName)) {
ColumnTransformer first = this.process(children.get(0), context);
if (children.size() == 1) {
return new TrimColumnTransformer(first.getType(), first, " ");
return new TrimColumnTransformer(STRING, first, " ");
} else {
// children.size() == 2
if (isStringLiteral(children.get(1))) {
return new TrimColumnTransformer(
first.getType(), first, ((StringLiteral) children.get(1)).getValue());
STRING, first, ((StringLiteral) children.get(1)).getValue());
} else {
return new Trim2ColumnTransformer(
first.getType(), first, this.process(children.get(1), context));
return new Trim2ColumnTransformer(STRING, first, this.process(children.get(1), context));
}
}
} else if (TableBuiltinScalarFunction.LTRIM.getFunctionName().equalsIgnoreCase(functionName)) {
ColumnTransformer first = this.process(children.get(0), context);
if (children.size() == 1) {
return new LTrimColumnTransformer(first.getType(), first, " ");
return new LTrimColumnTransformer(STRING, first, " ");
} else {
// children.size() == 2
if (isStringLiteral(children.get(1))) {
return new LTrimColumnTransformer(
first.getType(), first, ((StringLiteral) children.get(1)).getValue());
STRING, first, ((StringLiteral) children.get(1)).getValue());
} else {
return new LTrim2ColumnTransformer(
first.getType(), first, this.process(children.get(1), context));
return new LTrim2ColumnTransformer(STRING, first, this.process(children.get(1), context));
}
}
} else if (TableBuiltinScalarFunction.RTRIM.getFunctionName().equalsIgnoreCase(functionName)) {
ColumnTransformer first = this.process(children.get(0), context);
if (children.size() == 1) {
return new RTrimColumnTransformer(first.getType(), first, " ");
return new RTrimColumnTransformer(STRING, first, " ");
} else {
// children.size() == 2
if (isStringLiteral(children.get(1))) {
return new RTrimColumnTransformer(
first.getType(), first, ((StringLiteral) children.get(1)).getValue());
STRING, first, ((StringLiteral) children.get(1)).getValue());
} else {
return new RTrim2ColumnTransformer(
first.getType(), first, this.process(children.get(1), context));
return new RTrim2ColumnTransformer(STRING, first, this.process(children.get(1), context));
}
}
} else if (TableBuiltinScalarFunction.REGEXP_LIKE
Expand Down Expand Up @@ -868,11 +864,7 @@ private ColumnTransformer getFunctionColumnTransformer(
} else if (TableBuiltinScalarFunction.SIGN.getFunctionName().equalsIgnoreCase(functionName)) {
ColumnTransformer first = this.process(children.get(0), context);
if (children.size() == 1) {
if (isTimestampType(first.getType())) {
return new SignColumnTransformer(INT64, first);
} else {
return new SignColumnTransformer(first.getType(), first);
}
return new SignColumnTransformer(first.getType(), first);
}
} else if (TableBuiltinScalarFunction.CEIL.getFunctionName().equalsIgnoreCase(functionName)) {
ColumnTransformer first = this.process(children.get(0), context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,15 @@ && isIntegerNumber(argumentTypes.get(2)))) {
+ functionName.toLowerCase(Locale.ENGLISH)
+ " only accepts one argument and it must be text or string data type.");
}
return argumentTypes.get(0);
return STRING;
} else if (TableBuiltinScalarFunction.LOWER.getFunctionName().equalsIgnoreCase(functionName)) {
if (!(argumentTypes.size() == 1 && isCharType(argumentTypes.get(0)))) {
throw new SemanticException(
"Scalar function "
+ functionName.toLowerCase(Locale.ENGLISH)
+ " only accepts one argument and it must be text or string data type.");
}
return argumentTypes.get(0);
return STRING;
} else if (TableBuiltinScalarFunction.TRIM.getFunctionName().equalsIgnoreCase(functionName)) {
if (!(argumentTypes.size() == 1 && isCharType(argumentTypes.get(0)))
&& !(argumentTypes.size() == 2 && isTwoCharType(argumentTypes))) {
Expand All @@ -225,7 +225,7 @@ && isIntegerNumber(argumentTypes.get(2)))) {
+ functionName.toLowerCase(Locale.ENGLISH)
+ " only accepts one or two arguments and they must be text or string data type.");
}
return argumentTypes.get(0);
return STRING;
} else if (TableBuiltinScalarFunction.LTRIM.getFunctionName().equalsIgnoreCase(functionName)) {
if (!(argumentTypes.size() == 1 && isCharType(argumentTypes.get(0)))
&& !(argumentTypes.size() == 2 && isTwoCharType(argumentTypes))) {
Expand All @@ -234,7 +234,7 @@ && isIntegerNumber(argumentTypes.get(2)))) {
+ functionName.toLowerCase(Locale.ENGLISH)
+ " only accepts one or two arguments and they must be text or string data type.");
}
return argumentTypes.get(0);
return STRING;
} else if (TableBuiltinScalarFunction.RTRIM.getFunctionName().equalsIgnoreCase(functionName)) {
if (!(argumentTypes.size() == 1 && isCharType(argumentTypes.get(0)))
&& !(argumentTypes.size() == 2 && isTwoCharType(argumentTypes))) {
Expand All @@ -243,7 +243,7 @@ && isIntegerNumber(argumentTypes.get(2)))) {
+ functionName.toLowerCase(Locale.ENGLISH)
+ " only accepts one or two arguments and they must be text or string data type.");
}
return argumentTypes.get(0);
return STRING;
} else if (TableBuiltinScalarFunction.REGEXP_LIKE
.getFunctionName()
.equalsIgnoreCase(functionName)) {
Expand Down Expand Up @@ -300,71 +300,71 @@ && isIntegerNumber(argumentTypes.get(2)))) {
}
return INT32;
} else if (TableBuiltinScalarFunction.SIN.getFunctionName().equalsIgnoreCase(functionName)) {
if (!(argumentTypes.size() == 1 && isNumericType(argumentTypes.get(0)))) {
if (!(argumentTypes.size() == 1 && isSupportedMathNumericType(argumentTypes.get(0)))) {
throw new SemanticException(
"Scalar function "
+ functionName.toLowerCase(Locale.ENGLISH)
+ " only accepts one argument and it must be TimeStamp, Double, Float, Int32 or Int64 data type.");
}
return DOUBLE;
} else if (TableBuiltinScalarFunction.COS.getFunctionName().equalsIgnoreCase(functionName)) {
if (!(argumentTypes.size() == 1 && isNumericType(argumentTypes.get(0)))) {
if (!(argumentTypes.size() == 1 && isSupportedMathNumericType(argumentTypes.get(0)))) {
throw new SemanticException(
"Scalar function "
+ functionName.toLowerCase(Locale.ENGLISH)
+ " only accepts one argument and it must be TimeStamp, Double, Float, Int32 or Int64 data type.");
}
return DOUBLE;
} else if (TableBuiltinScalarFunction.TAN.getFunctionName().equalsIgnoreCase(functionName)) {
if (!(argumentTypes.size() == 1 && isNumericType(argumentTypes.get(0)))) {
if (!(argumentTypes.size() == 1 && isSupportedMathNumericType(argumentTypes.get(0)))) {
throw new SemanticException(
"Scalar function "
+ functionName.toLowerCase(Locale.ENGLISH)
+ " only accepts one argument and it must be TimeStamp, Double, Float, Int32 or Int64 data type.");
}
return DOUBLE;
} else if (TableBuiltinScalarFunction.ASIN.getFunctionName().equalsIgnoreCase(functionName)) {
if (!(argumentTypes.size() == 1 && isNumericType(argumentTypes.get(0)))) {
if (!(argumentTypes.size() == 1 && isSupportedMathNumericType(argumentTypes.get(0)))) {
throw new SemanticException(
"Scalar function "
+ functionName.toLowerCase(Locale.ENGLISH)
+ " only accepts one argument and it must be TimeStamp, Double, Float, Int32 or Int64 data type.");
}
return DOUBLE;
} else if (TableBuiltinScalarFunction.ACOS.getFunctionName().equalsIgnoreCase(functionName)) {
if (!(argumentTypes.size() == 1 && isNumericType(argumentTypes.get(0)))) {
if (!(argumentTypes.size() == 1 && isSupportedMathNumericType(argumentTypes.get(0)))) {
throw new SemanticException(
"Scalar function "
+ functionName.toLowerCase(Locale.ENGLISH)
+ " only accepts one argument and it must be TimeStamp, Double, Float, Int32 or Int64 data type.");
}
return DOUBLE;
} else if (TableBuiltinScalarFunction.ATAN.getFunctionName().equalsIgnoreCase(functionName)) {
if (!(argumentTypes.size() == 1 && isNumericType(argumentTypes.get(0)))) {
if (!(argumentTypes.size() == 1 && isSupportedMathNumericType(argumentTypes.get(0)))) {
throw new SemanticException(
"Scalar function "
+ functionName.toLowerCase(Locale.ENGLISH)
+ " only accepts one argument and it must be TimeStamp, Double, Float, Int32 or Int64 data type.");
}
return DOUBLE;
} else if (TableBuiltinScalarFunction.SINH.getFunctionName().equalsIgnoreCase(functionName)) {
if (!(argumentTypes.size() == 1 && isNumericType(argumentTypes.get(0)))) {
if (!(argumentTypes.size() == 1 && isSupportedMathNumericType(argumentTypes.get(0)))) {
throw new SemanticException(
"Scalar function "
+ functionName.toLowerCase(Locale.ENGLISH)
+ " only accepts one argument and it must be TimeStamp, Double, Float, Int32 or Int64 data type.");
}
return DOUBLE;
} else if (TableBuiltinScalarFunction.COSH.getFunctionName().equalsIgnoreCase(functionName)) {
if (!(argumentTypes.size() == 1 && isNumericType(argumentTypes.get(0)))) {
if (!(argumentTypes.size() == 1 && isSupportedMathNumericType(argumentTypes.get(0)))) {
throw new SemanticException(
"Scalar function "
+ functionName.toLowerCase(Locale.ENGLISH)
+ " only accepts one argument and it must be TimeStamp, Double, Float, Int32 or Int64 data type.");
}
return DOUBLE;
} else if (TableBuiltinScalarFunction.TANH.getFunctionName().equalsIgnoreCase(functionName)) {
if (!(argumentTypes.size() == 1 && isNumericType(argumentTypes.get(0)))) {
if (!(argumentTypes.size() == 1 && isSupportedMathNumericType(argumentTypes.get(0)))) {
throw new SemanticException(
"Scalar function "
+ functionName.toLowerCase(Locale.ENGLISH)
Expand All @@ -374,7 +374,7 @@ && isIntegerNumber(argumentTypes.get(2)))) {
} else if (TableBuiltinScalarFunction.DEGREES
.getFunctionName()
.equalsIgnoreCase(functionName)) {
if (!(argumentTypes.size() == 1 && isNumericType(argumentTypes.get(0)))) {
if (!(argumentTypes.size() == 1 && isSupportedMathNumericType(argumentTypes.get(0)))) {
throw new SemanticException(
"Scalar function "
+ functionName.toLowerCase(Locale.ENGLISH)
Expand All @@ -384,75 +384,71 @@ && isIntegerNumber(argumentTypes.get(2)))) {
} else if (TableBuiltinScalarFunction.RADIANS
.getFunctionName()
.equalsIgnoreCase(functionName)) {
if (!(argumentTypes.size() == 1 && isNumericType(argumentTypes.get(0)))) {
if (!(argumentTypes.size() == 1 && isSupportedMathNumericType(argumentTypes.get(0)))) {
throw new SemanticException(
"Scalar function "
+ functionName.toLowerCase(Locale.ENGLISH)
+ " only accepts one argument and it must be TimeStamp, Double, Float, Int32 or Int64 data type.");
}
return DOUBLE;
} else if (TableBuiltinScalarFunction.ABS.getFunctionName().equalsIgnoreCase(functionName)) {
if (!(argumentTypes.size() == 1 && isNumericType(argumentTypes.get(0)))) {
if (!(argumentTypes.size() == 1 && isSupportedMathNumericType(argumentTypes.get(0)))) {
throw new SemanticException(
"Scalar function "
+ functionName.toLowerCase(Locale.ENGLISH)
+ " only accepts one argument and it must be TimeStamp, Double, Float, Int32 or Int64 data type.");
}
return argumentTypes.get(0);
} else if (TableBuiltinScalarFunction.SIGN.getFunctionName().equalsIgnoreCase(functionName)) {
if (!(argumentTypes.size() == 1 && isNumericType(argumentTypes.get(0)))) {
if (!(argumentTypes.size() == 1 && isSupportedMathNumericType(argumentTypes.get(0)))) {
throw new SemanticException(
"Scalar function "
+ functionName.toLowerCase(Locale.ENGLISH)
+ " only accepts one argument and it must be TimeStamp, Double, Float, Int32 or Int64 data type.");
}
if (isTimestampType(argumentTypes.get(0))) {
return INT64;
} else {
return argumentTypes.get(0);
}
return argumentTypes.get(0);
} else if (TableBuiltinScalarFunction.CEIL.getFunctionName().equalsIgnoreCase(functionName)) {
if (!(argumentTypes.size() == 1 && isNumericType(argumentTypes.get(0)))) {
if (!(argumentTypes.size() == 1 && isSupportedMathNumericType(argumentTypes.get(0)))) {
throw new SemanticException(
"Scalar function "
+ functionName.toLowerCase(Locale.ENGLISH)
+ " only accepts one argument and it must be TimeStamp, Double, Float, Int32 or Int64 data type.");
}
return DOUBLE;
} else if (TableBuiltinScalarFunction.FLOOR.getFunctionName().equalsIgnoreCase(functionName)) {
if (!(argumentTypes.size() == 1 && isNumericType(argumentTypes.get(0)))) {
if (!(argumentTypes.size() == 1 && isSupportedMathNumericType(argumentTypes.get(0)))) {
throw new SemanticException(
"Scalar function "
+ functionName.toLowerCase(Locale.ENGLISH)
+ " only accepts one argument and it must be TimeStamp, Double, Float, Int32 or Int64 data type.");
}
return DOUBLE;
} else if (TableBuiltinScalarFunction.EXP.getFunctionName().equalsIgnoreCase(functionName)) {
if (!(argumentTypes.size() == 1 && isNumericType(argumentTypes.get(0)))) {
if (!(argumentTypes.size() == 1 && isSupportedMathNumericType(argumentTypes.get(0)))) {
throw new SemanticException(
"Scalar function "
+ functionName.toLowerCase(Locale.ENGLISH)
+ " only accepts one argument and it must be TimeStamp, Double, Float, Int32 or Int64 data type.");
}
return DOUBLE;
} else if (TableBuiltinScalarFunction.LN.getFunctionName().equalsIgnoreCase(functionName)) {
if (!(argumentTypes.size() == 1 && isNumericType(argumentTypes.get(0)))) {
if (!(argumentTypes.size() == 1 && isSupportedMathNumericType(argumentTypes.get(0)))) {
throw new SemanticException(
"Scalar function "
+ functionName.toLowerCase(Locale.ENGLISH)
+ " only accepts one argument and it must be TimeStamp, Double, Float, Int32 or Int64 data type.");
}
return DOUBLE;
} else if (TableBuiltinScalarFunction.LOG10.getFunctionName().equalsIgnoreCase(functionName)) {
if (!(argumentTypes.size() == 1 && isNumericType(argumentTypes.get(0)))) {
if (!(argumentTypes.size() == 1 && isSupportedMathNumericType(argumentTypes.get(0)))) {
throw new SemanticException(
"Scalar function "
+ functionName.toLowerCase(Locale.ENGLISH)
+ " only accepts one argument and it must be TimeStamp, Double, Float, Int32 or Int64 data type.");
}
return DOUBLE;
} else if (TableBuiltinScalarFunction.SQRT.getFunctionName().equalsIgnoreCase(functionName)) {
if (!(argumentTypes.size() == 1 && isNumericType(argumentTypes.get(0)))) {
if (!(argumentTypes.size() == 1 && isSupportedMathNumericType(argumentTypes.get(0)))) {
throw new SemanticException(
"Scalar function "
+ functionName.toLowerCase(Locale.ENGLISH)
Expand Down Expand Up @@ -671,6 +667,10 @@ public static boolean isCharType(Type type) {
return TEXT.equals(type) || StringType.STRING.equals(type);
}

public static boolean isSupportedMathNumericType(Type type) {
return DOUBLE.equals(type) || FLOAT.equals(type) || INT32.equals(type) || INT64.equals(type);
}

public static boolean isNumericType(Type type) {
return DOUBLE.equals(type)
|| FLOAT.equals(type)
Expand All @@ -679,10 +679,6 @@ public static boolean isNumericType(Type type) {
|| TimestampType.TIMESTAMP.equals(type);
}

public static boolean isTimestampType(Type type) {
return TimestampType.TIMESTAMP.equals(type);
}

public static boolean isIntegerNumber(Type type) {
return INT32.equals(type) || INT64.equals(type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
import org.apache.iotdb.db.queryengine.plan.statement.crud.InsertRowsStatement;
import org.apache.iotdb.db.queryengine.plan.statement.sys.FlushStatement;
import org.apache.iotdb.db.queryengine.plan.statement.sys.SetConfigurationStatement;
import org.apache.iotdb.db.queryengine.transformation.dag.column.unary.scalar.TableBuiltinScalarFunction;
import org.apache.iotdb.db.relational.grammar.sql.RelationalSqlBaseVisitor;
import org.apache.iotdb.db.relational.grammar.sql.RelationalSqlLexer;
import org.apache.iotdb.db.relational.grammar.sql.RelationalSqlParser;
Expand Down Expand Up @@ -1429,7 +1430,7 @@ public Node visitArithmeticBinary(RelationalSqlParser.ArithmeticBinaryContext ct
public Node visitConcatenation(RelationalSqlParser.ConcatenationContext ctx) {
return new FunctionCall(
getLocation(ctx.CONCAT()),
QualifiedName.of("concat"),
QualifiedName.of(TableBuiltinScalarFunction.CONCAT.getFunctionName()),
ImmutableList.of((Expression) visit(ctx.left), (Expression) visit(ctx.right)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ protected void doTransform(Column column, ColumnBuilder columnBuilder) {
columnBuilder.writeDouble(Math.acos(column.getFloat(i)));
} else if (TSDataType.INT32.equals(column.getDataType())) {
columnBuilder.writeDouble(Math.acos(column.getInt(i)));
} else if (TSDataType.INT64.equals(column.getDataType())
|| TSDataType.TIMESTAMP.equals(column.getDataType())) {
} else if (TSDataType.INT64.equals(column.getDataType())) {
columnBuilder.writeDouble(Math.acos((double) column.getLong(i)));
}
} else {
Expand Down
Loading