Search in sources :

Example 1 with IntervalUnit

use of io.confluent.ksql.execution.expression.tree.IntervalUnit 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())))));
}
Also used : IntervalUnit(io.confluent.ksql.execution.expression.tree.IntervalUnit) Query(io.confluent.ksql.parser.tree.Query) SingleStatementContext(io.confluent.ksql.parser.SqlBaseParser.SingleStatementContext) Select(io.confluent.ksql.parser.tree.Select) SingleColumn(io.confluent.ksql.parser.tree.SingleColumn) LambdaFunctionCall(io.confluent.ksql.execution.expression.tree.LambdaFunctionCall) FunctionCall(io.confluent.ksql.execution.expression.tree.FunctionCall) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 2 with IntervalUnit

use of io.confluent.ksql.execution.expression.tree.IntervalUnit in project ksql by confluentinc.

the class SqlToJavaVisitorTest method shouldGenerateCorrectCodeForIntervalUnit.

@Test
public void shouldGenerateCorrectCodeForIntervalUnit() {
    // Given:
    final IntervalUnit intervalUnit = new IntervalUnit(TimeUnit.DAYS);
    // When:
    final String java = sqlToJavaVisitor.process(intervalUnit);
    // Then:
    assertThat(java, containsString("TimeUnit.DAYS"));
}
Also used : IntervalUnit(io.confluent.ksql.execution.expression.tree.IntervalUnit) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 3 with IntervalUnit

use of io.confluent.ksql.execution.expression.tree.IntervalUnit in project ksql by confluentinc.

the class InterpretedExpressionTest method shouldHandleFunctionCalls_intervalParam.

@Test
public void shouldHandleFunctionCalls_intervalParam() {
    // Given:
    final UdfFactory udfFactory = mock(UdfFactory.class);
    final KsqlScalarFunction udf = mock(KsqlScalarFunction.class);
    when(udf.newInstance(any())).thenReturn(new toMillisUdf());
    givenUdf("FOO", udfFactory, udf);
    when(udf.parameters()).thenReturn(ImmutableList.of(IntervalUnitType.INSTANCE, IntegerType.INSTANCE));
    // When:
    InterpretedExpression interpreter1 = interpreter(new FunctionCall(FunctionName.of("FOO"), ImmutableList.of(new IntervalUnit(TimeUnit.SECONDS), new IntegerLiteral(1))));
    final Object object = interpreter1.evaluate(ROW);
    // Then:
    assertThat(object, is(1000));
}
Also used : IntervalUnit(io.confluent.ksql.execution.expression.tree.IntervalUnit) KsqlScalarFunction(io.confluent.ksql.function.KsqlScalarFunction) UdfFactory(io.confluent.ksql.function.UdfFactory) LambdaFunctionCall(io.confluent.ksql.execution.expression.tree.LambdaFunctionCall) FunctionCall(io.confluent.ksql.execution.expression.tree.FunctionCall) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 4 with IntervalUnit

use of io.confluent.ksql.execution.expression.tree.IntervalUnit in project ksql by confluentinc.

the class ExpressionTreeRewriterTest method shouldRewriteIntervalUnitUsingPlugin.

@Test
public void shouldRewriteIntervalUnitUsingPlugin() {
    // Given:
    final IntervalUnit expression = new IntervalUnit(TimeUnit.DAYS);
    shouldRewriteUsingPlugin(expression);
}
Also used : IntervalUnit(io.confluent.ksql.execution.expression.tree.IntervalUnit) Test(org.junit.Test)

Aggregations

IntervalUnit (io.confluent.ksql.execution.expression.tree.IntervalUnit)4 Test (org.junit.Test)4 FunctionCall (io.confluent.ksql.execution.expression.tree.FunctionCall)2 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)2 LambdaFunctionCall (io.confluent.ksql.execution.expression.tree.LambdaFunctionCall)2 KsqlScalarFunction (io.confluent.ksql.function.KsqlScalarFunction)1 UdfFactory (io.confluent.ksql.function.UdfFactory)1 SingleStatementContext (io.confluent.ksql.parser.SqlBaseParser.SingleStatementContext)1 Query (io.confluent.ksql.parser.tree.Query)1 Select (io.confluent.ksql.parser.tree.Select)1 SingleColumn (io.confluent.ksql.parser.tree.SingleColumn)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1