Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Fix minus constant error in SQLTransform #6533

Merged
merged 3 commits into from
Mar 19, 2024
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
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 @@ -40,6 +40,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 @@ -184,6 +185,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 @@ -38,6 +38,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 @@ -87,6 +88,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
Loading