Skip to content

Commit

Permalink
[Bug] Fix minus constant error in SQLTransform (#6533)
Browse files Browse the repository at this point in the history
  • Loading branch information
rewerma authored Mar 19, 2024
1 parent b0abbd2 commit eb46c48
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ transform {
Sql {
source_table_name = "fake"
result_table_name = "fake1"
query = "select abs(c1) as c1_1, acos(id) as id1, asin(c2) as c2_1, atan(c2) as c2_2, cos(c2) as c2_3, cosh(c2) as c2_4, sin(c2) as c2_5, sinh(c2) as c2_6, tan(c3/4) as c3_1, tanh(c2) as c2_7, mod(c4, 5) as c4_1, mod(c4, 5.4) as c4_2, ceil(c5) as c5_1, exp(c10) as c10_1, floor(c5) as c5_2, ln(c5) as c5_3, log(10,c5) as c5_4, log10(c6) as c6_1, radians(c7) as c7_1, sqrt(c8) as c8_1, pi() as pi, power(c5,2) as c5_5, rand() as rand, round(c9,2) as c9_1, sign(c1) as c1_2, trunc(c9,2) as c9_2 from fake"
query = "select abs(-10.3) as c0_1, abs(c1) as c1_1, acos(id) as id1, asin(c2) as c2_1, atan(c2) as c2_2, cos(c2) as c2_3, cosh(c2) as c2_4, sin(c2) as c2_5, sinh(c2) as c2_6, tan(c3/4) as c3_1, tanh(c2) as c2_7, mod(c4, 5) as c4_1, mod(c4, 5.4) as c4_2, ceil(c5) as c5_1, exp(c10) as c10_1, floor(c5) as c5_2, ln(c5) as c5_3, log(10,c5) as c5_4, log10(c6) as c6_1, radians(c7) as c7_1, sqrt(c8) as c8_1, pi() as pi, power(c5,2) as c5_5, rand() as rand, round(c9,2) as c9_1, sign(c1) as c1_2, trunc(c9,2) as c9_2 from fake"
}
}

Expand All @@ -62,6 +62,13 @@ sink {
source_table_name = "fake1"
rules = {
field_rules = [
{
field_name = "c0_1"
field_type = "double"
field_value = [
{equals_to = 10.3}
]
},
{
field_name = "c1_1"
field_type = "double"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import net.sf.jsqlparser.expression.LongValue;
import net.sf.jsqlparser.expression.NullValue;
import net.sf.jsqlparser.expression.Parenthesis;
import net.sf.jsqlparser.expression.SignedExpression;
import net.sf.jsqlparser.expression.StringValue;
import net.sf.jsqlparser.expression.TimeKeyExpression;
import net.sf.jsqlparser.expression.WhenClause;
Expand Down Expand Up @@ -187,6 +188,26 @@ public Object computeForValue(Expression expression, Object[] inputFields) {
if (expression instanceof NullValue) {
return null;
}
if (expression instanceof SignedExpression) {
SignedExpression signedExpression = (SignedExpression) expression;
if (signedExpression.getSign() == '-') {
Object value = computeForValue(signedExpression.getExpression(), inputFields);
if (value instanceof Integer) {
return -((Integer) value);
}
if (value instanceof Long) {
return -((Long) value);
}
if (value instanceof Double) {
return -((Double) value);
}
if (value instanceof Number) {
return -((Number) value).doubleValue();
}
} else {
return computeForValue(signedExpression, inputFields);
}
}
if (expression instanceof DoubleValue) {
return ((DoubleValue) expression).getValue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import net.sf.jsqlparser.expression.LongValue;
import net.sf.jsqlparser.expression.NullValue;
import net.sf.jsqlparser.expression.Parenthesis;
import net.sf.jsqlparser.expression.SignedExpression;
import net.sf.jsqlparser.expression.StringValue;
import net.sf.jsqlparser.expression.TimeKeyExpression;
import net.sf.jsqlparser.expression.WhenClause;
Expand Down Expand Up @@ -88,6 +89,9 @@ public SeaTunnelDataType<?> getExpressionType(Expression expression) {
if (expression instanceof NullValue) {
return BasicType.VOID_TYPE;
}
if (expression instanceof SignedExpression) {
return getExpressionType(((SignedExpression) expression).getExpression());
}
if (expression instanceof DoubleValue) {
return BasicType.DOUBLE_TYPE;
}
Expand Down

0 comments on commit eb46c48

Please sign in to comment.