use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class InterpretedExpressionTest method shouldEvaluateLambda_functionCall.
@Test
public void shouldEvaluateLambda_functionCall() {
// Given:
final UdfFactory udfFactory = mock(UdfFactory.class);
final KsqlScalarFunction udf = mock(KsqlScalarFunction.class);
when(udf.newInstance(any())).thenReturn(new TransFormUdf());
givenUdf("TRANSFORM", udfFactory, udf);
when(udf.parameters()).thenReturn(ImmutableList.of(ArrayType.of(IntegerType.INSTANCE), LambdaType.of(ImmutableList.of(IntegerType.INSTANCE), IntegerType.INSTANCE)));
when(udf.getReturnType(any())).thenReturn(SqlTypes.array(SqlTypes.INTEGER));
// When:
InterpretedExpression interpreter1 = interpreter(new FunctionCall(FunctionName.of("TRANSFORM"), ImmutableList.of(new CreateArrayExpression(ImmutableList.of(new IntegerLiteral(1), new IntegerLiteral(2))), new LambdaFunctionCall(ImmutableList.of("X"), new ArithmeticBinaryExpression(Operator.ADD, new IntegerLiteral(1), new LambdaVariable("X"))))));
// Then:
assertThat(interpreter1.evaluate(ROW), is(ImmutableList.of(2, 3)));
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class KsqlParserTest method shouldParseNegativeInteger.
@Test
public void shouldParseNegativeInteger() {
final String queryStr = "SELECT -12345 FROM test1;";
final Statement statement = KsqlParserTestUtil.buildSingleAst(queryStr, metaStore).getStatement();
assertThat(statement, instanceOf(Query.class));
final Query query = (Query) statement;
final SingleColumn column0 = (SingleColumn) query.getSelect().getSelectItems().get(0);
assertThat(column0.getAlias().isPresent(), is(false));
assertThat(column0.getExpression(), instanceOf(IntegerLiteral.class));
final IntegerLiteral aue = (IntegerLiteral) column0.getExpression();
assertThat(aue.getValue(), equalTo(-12345));
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class AstBuilderTest method shouldBuildLambdaFunctionWithMultipleLambdas.
@Test
public void shouldBuildLambdaFunctionWithMultipleLambdas() {
// Given:
final SingleStatementContext stmt = givenQuery("SELECT TRANSFORM_ARRAY(Col4, X => X + 5, (X,Y) => X + Y) FROM TEST1;");
// When:
final Query result = (Query) builder.buildStatement(stmt);
// Then:
assertThat(result.getSelect(), is(new Select(ImmutableList.of(new SingleColumn(new FunctionCall(FunctionName.of("TRANSFORM_ARRAY"), ImmutableList.of(column("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("X"), new LambdaVariable("Y"))))), Optional.empty())))));
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class AstBuilderTest method shouldBuildIntervalUnit.
@Test
public void shouldBuildIntervalUnit() {
// Given:
final SingleStatementContext stmt = givenQuery("SELECT TIMESTAMPADD(MINUTES, 5, Col4) FROM TEST1;");
// When:
final Query result = (Query) builder.buildStatement(stmt);
// Then:
assertThat(result.getSelect(), is(new Select(ImmutableList.of(new SingleColumn(new FunctionCall(FunctionName.of("TIMESTAMPADD"), ImmutableList.of(new IntervalUnit(TimeUnit.MINUTES), new IntegerLiteral(5), column("COL4"))), Optional.empty())))));
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class AstBuilderTest method shouldBuildLambdaFunction.
@Test
public void shouldBuildLambdaFunction() {
// Given:
final SingleStatementContext stmt = givenQuery("SELECT TRANSFORM_ARRAY(Col4, X => X + 5) FROM TEST1;");
// When:
final Query result = (Query) builder.buildStatement(stmt);
// Then:
assertThat(result.getSelect(), is(new Select(ImmutableList.of(new SingleColumn(new FunctionCall(FunctionName.of("TRANSFORM_ARRAY"), ImmutableList.of(column("COL4"), new LambdaFunctionCall(ImmutableList.of("X"), new ArithmeticBinaryExpression(Operator.ADD, new LambdaVariable("X"), new IntegerLiteral(5))))), Optional.empty())))));
}
Aggregations