use of io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression in project ksql by confluentinc.
the class ExpressionTreeRewriterTest method shouldRewriteArithmeticBinary.
@Test
public void shouldRewriteArithmeticBinary() {
// Given:
final ArithmeticBinaryExpression parsed = parseExpression("1 + 2");
when(processor.apply(parsed.getLeft(), context)).thenReturn(expr1);
when(processor.apply(parsed.getRight(), context)).thenReturn(expr2);
// When
final Expression rewritten = expressionRewriter.rewrite(parsed, context);
// Then:
assertThat(rewritten, equalTo(new ArithmeticBinaryExpression(parsed.getLocation(), parsed.getOperator(), expr1, expr2)));
}
use of io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression in project ksql by confluentinc.
the class AstSanitizerTest method shouldAllowDuplicateLambdaArgumentInSeparateExpression.
@Test
public void shouldAllowDuplicateLambdaArgumentInSeparateExpression() {
// Given:
final Statement stmt = givenQuery("SELECT TRANSFORM_ARRAY(Col4, X => X + 5, (X,Y) => Y + 5) FROM TEST1;");
// When:
final Query result = (Query) AstSanitizer.sanitize(stmt, META_STORE, true);
// Then:
assertThat(result.getSelect(), is(new Select(ImmutableList.of(new SingleColumn(new FunctionCall(FunctionName.of("TRANSFORM_ARRAY"), ImmutableList.of(column(TEST1_NAME, "COL4"), new LambdaFunctionCall(ImmutableList.of("X"), new ArithmeticBinaryExpression(Operator.ADD, new LambdaVariable("X"), new IntegerLiteral(5))), new LambdaFunctionCall(ImmutableList.of("X", "Y"), new ArithmeticBinaryExpression(Operator.ADD, new LambdaVariable("Y"), new IntegerLiteral(5))))), Optional.of(ColumnName.of("KSQL_COL_0")))))));
}
use of io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldGenerateCorrectCodeForDecimalMultiply.
@Test
public void shouldGenerateCorrectCodeForDecimalMultiply() {
// Given:
final ArithmeticBinaryExpression binExp = new ArithmeticBinaryExpression(Operator.MULTIPLY, new UnqualifiedColumnReferenceExp(ColumnName.of("COL8")), new UnqualifiedColumnReferenceExp(ColumnName.of("COL8")));
// When:
final String java = sqlToJavaVisitor.process(binExp);
// Then:
assertThat(java, is("(COL8.multiply(COL8, new MathContext(5, RoundingMode.UNNECESSARY)).setScale(2))"));
}
use of io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldGenerateCastLongToDecimalInBinaryExpression.
@Test
public void shouldGenerateCastLongToDecimalInBinaryExpression() {
// Given:
final ArithmeticBinaryExpression binExp = new ArithmeticBinaryExpression(Operator.ADD, new UnqualifiedColumnReferenceExp(ColumnName.of("COL8")), new UnqualifiedColumnReferenceExp(ColumnName.of("COL0")));
// When:
final String java = sqlToJavaVisitor.process(binExp);
// Then:
assertThat(java, containsString("DecimalUtil.cast(COL0, 19, 0)"));
}
use of io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldGenerateCorrectCodeForDecimalDivide.
@Test
public void shouldGenerateCorrectCodeForDecimalDivide() {
// Given:
final ArithmeticBinaryExpression binExp = new ArithmeticBinaryExpression(Operator.DIVIDE, new UnqualifiedColumnReferenceExp(ColumnName.of("COL8")), new UnqualifiedColumnReferenceExp(ColumnName.of("COL8")));
// When:
final String java = sqlToJavaVisitor.process(binExp);
// Then:
assertThat(java, is("(COL8.divide(COL8, new MathContext(8, RoundingMode.UNNECESSARY)).setScale(6))"));
}
Aggregations