Search in sources :

Example 1 with TimestampLiteral

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

the class InterpretedExpressionTest method shouldEvaluateCastToTime.

@Test
public void shouldEvaluateCastToTime() {
    // Given:
    final Expression cast1 = new Cast(new TimestampLiteral(Timestamp.from(Instant.ofEpochMilli(1000))), new Type(SqlPrimitiveType.of("TIME")));
    final Expression cast2 = new Cast(new StringLiteral("23:59:58"), new Type(SqlPrimitiveType.of("TIME")));
    final Expression cast3 = new Cast(new TimeLiteral(new Time(1000)), new Type(SqlPrimitiveType.of("TIME")));
    // When:
    InterpretedExpression interpreter1 = interpreter(cast1);
    InterpretedExpression interpreter2 = interpreter(cast2);
    InterpretedExpression interpreter3 = interpreter(cast3);
    // Then:
    assertThat(interpreter1.evaluate(ROW), is(new Time(1000L)));
    assertThat(interpreter2.evaluate(ROW), is(new Time(86398000)));
    assertThat(interpreter3.evaluate(ROW), is(new Time(1000L)));
}
Also used : Cast(io.confluent.ksql.execution.expression.tree.Cast) LambdaType(io.confluent.ksql.function.types.LambdaType) IntegerType(io.confluent.ksql.function.types.IntegerType) GenericType(io.confluent.ksql.function.types.GenericType) SqlPrimitiveType(io.confluent.ksql.schema.ksql.types.SqlPrimitiveType) IntervalUnitType(io.confluent.ksql.function.types.IntervalUnitType) Type(io.confluent.ksql.execution.expression.tree.Type) ArrayType(io.confluent.ksql.function.types.ArrayType) TimestampLiteral(io.confluent.ksql.execution.expression.tree.TimestampLiteral) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) SubscriptExpression(io.confluent.ksql.execution.expression.tree.SubscriptExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) Time(java.sql.Time) TimeLiteral(io.confluent.ksql.execution.expression.tree.TimeLiteral) Test(org.junit.Test)

Example 2 with TimestampLiteral

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

the class InterpretedExpressionTest method shouldEvaluateCastToDate.

@Test
public void shouldEvaluateCastToDate() {
    // Given:
    final Expression cast1 = new Cast(new TimestampLiteral(Timestamp.from(Instant.ofEpochMilli(864000500))), new Type(SqlPrimitiveType.of("DATE")));
    final Expression cast2 = new Cast(new StringLiteral("2017-11-13"), new Type(SqlPrimitiveType.of("DATE")));
    final Expression cast3 = new Cast(new DateLiteral(new Date(864000000)), new Type(SqlPrimitiveType.of("DATE")));
    // When:
    InterpretedExpression interpreter1 = interpreter(cast1);
    InterpretedExpression interpreter2 = interpreter(cast2);
    InterpretedExpression interpreter3 = interpreter(cast3);
    // Then:
    assertThat(interpreter1.evaluate(ROW), is(new Date(864000000)));
    assertThat(interpreter2.evaluate(ROW), is(new Date(1510531200000L)));
    assertThat(interpreter3.evaluate(ROW), is(new Date(864000000)));
}
Also used : Cast(io.confluent.ksql.execution.expression.tree.Cast) LambdaType(io.confluent.ksql.function.types.LambdaType) IntegerType(io.confluent.ksql.function.types.IntegerType) GenericType(io.confluent.ksql.function.types.GenericType) SqlPrimitiveType(io.confluent.ksql.schema.ksql.types.SqlPrimitiveType) IntervalUnitType(io.confluent.ksql.function.types.IntervalUnitType) Type(io.confluent.ksql.execution.expression.tree.Type) ArrayType(io.confluent.ksql.function.types.ArrayType) TimestampLiteral(io.confluent.ksql.execution.expression.tree.TimestampLiteral) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) DateLiteral(io.confluent.ksql.execution.expression.tree.DateLiteral) ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) SubscriptExpression(io.confluent.ksql.execution.expression.tree.SubscriptExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) Date(java.sql.Date) Test(org.junit.Test)

Example 3 with TimestampLiteral

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

the class InterpretedExpressionTest method shouldEvaluateCastToTimestamp.

@Test
public void shouldEvaluateCastToTimestamp() {
    // Given:
    final Expression cast1 = new Cast(new TimestampLiteral(Timestamp.from(Instant.ofEpochMilli(1000))), new Type(SqlPrimitiveType.of("TIMESTAMP")));
    final Expression cast2 = new Cast(new StringLiteral("2017-11-13T23:59:58"), new Type(SqlPrimitiveType.of("TIMESTAMP")));
    final Expression cast3 = new Cast(new DateLiteral(new Date(864000000)), new Type(SqlPrimitiveType.of("TIMESTAMP")));
    // When:
    InterpretedExpression interpreter1 = interpreter(cast1);
    InterpretedExpression interpreter2 = interpreter(cast2);
    InterpretedExpression interpreter3 = interpreter(cast3);
    // Then:
    assertThat(interpreter1.evaluate(ROW), is(new Timestamp(1000L)));
    assertThat(interpreter2.evaluate(ROW), is(new Timestamp(1510617598000L)));
    assertThat(interpreter3.evaluate(ROW), is(new Timestamp(864000000)));
}
Also used : Cast(io.confluent.ksql.execution.expression.tree.Cast) LambdaType(io.confluent.ksql.function.types.LambdaType) IntegerType(io.confluent.ksql.function.types.IntegerType) GenericType(io.confluent.ksql.function.types.GenericType) SqlPrimitiveType(io.confluent.ksql.schema.ksql.types.SqlPrimitiveType) IntervalUnitType(io.confluent.ksql.function.types.IntervalUnitType) Type(io.confluent.ksql.execution.expression.tree.Type) ArrayType(io.confluent.ksql.function.types.ArrayType) TimestampLiteral(io.confluent.ksql.execution.expression.tree.TimestampLiteral) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) DateLiteral(io.confluent.ksql.execution.expression.tree.DateLiteral) ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) SubscriptExpression(io.confluent.ksql.execution.expression.tree.SubscriptExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) Timestamp(java.sql.Timestamp) Date(java.sql.Date) Test(org.junit.Test)

Example 4 with TimestampLiteral

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

the class InterpretedExpressionTest method shouldEvaluateComparisons_time.

@Test
public void shouldEvaluateComparisons_time() {
    // Given:
    final Expression expression1 = new ComparisonExpression(ComparisonExpression.Type.GREATER_THAN, TIMESTAMPCOL, new TimestampLiteral(new Timestamp(1000)));
    final Expression expression2 = new ComparisonExpression(ComparisonExpression.Type.LESS_THAN, TIMESTAMPCOL, new StringLiteral("2017-11-13T23:59:58"));
    final Expression expression3 = new ComparisonExpression(ComparisonExpression.Type.EQUAL, TIMESTAMPCOL, new DateLiteral(new Date(864000000)));
    final Expression expression4 = new ComparisonExpression(ComparisonExpression.Type.NOT_EQUAL, TIMECOL, new TimeLiteral(new Time(1000)));
    final Expression expression5 = new ComparisonExpression(ComparisonExpression.Type.LESS_THAN_OR_EQUAL, TIMECOL, new StringLiteral("00:01:32"));
    final Expression expression6 = new ComparisonExpression(ComparisonExpression.Type.GREATER_THAN_OR_EQUAL, DATECOL, new StringLiteral("1970-01-20"));
    final Expression expression7 = new ComparisonExpression(ComparisonExpression.Type.GREATER_THAN_OR_EQUAL, DATECOL, new DateLiteral(new Date(864000000)));
    final Expression expression8 = new ComparisonExpression(ComparisonExpression.Type.EQUAL, DATECOL, new TimestampLiteral(new Timestamp(864000005)));
    // When:
    InterpretedExpression interpreter1 = interpreter(expression1);
    InterpretedExpression interpreter2 = interpreter(expression2);
    InterpretedExpression interpreter3 = interpreter(expression3);
    InterpretedExpression interpreter4 = interpreter(expression4);
    InterpretedExpression interpreter5 = interpreter(expression5);
    InterpretedExpression interpreter6 = interpreter(expression6);
    InterpretedExpression interpreter7 = interpreter(expression7);
    InterpretedExpression interpreter8 = interpreter(expression8);
    // Then:
    assertThat(interpreter1.evaluate(make(10, new Timestamp(1001))), is(true));
    assertThat(interpreter2.evaluate(make(10, new Timestamp(151061759799L))), is(true));
    assertThat(interpreter3.evaluate(make(10, new Timestamp(864000000))), is(true));
    assertThat(interpreter4.evaluate(make(12, new Time(1000))), is(false));
    assertThat(interpreter5.evaluate(make(12, new Time(4))), is(true));
    assertThat(interpreter6.evaluate(make(13, new Date(86400000))), is(false));
    assertThat(interpreter7.evaluate(make(13, new Date(864000000))), is(true));
    assertThat(interpreter8.evaluate(make(13, new Date(864000000))), is(false));
}
Also used : ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) TimestampLiteral(io.confluent.ksql.execution.expression.tree.TimestampLiteral) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) DateLiteral(io.confluent.ksql.execution.expression.tree.DateLiteral) ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) SubscriptExpression(io.confluent.ksql.execution.expression.tree.SubscriptExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) Time(java.sql.Time) Timestamp(java.sql.Timestamp) Date(java.sql.Date) TimeLiteral(io.confluent.ksql.execution.expression.tree.TimeLiteral) Test(org.junit.Test)

Aggregations

ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)4 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)4 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)4 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)4 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)4 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)4 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)4 Expression (io.confluent.ksql.execution.expression.tree.Expression)4 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)4 LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)4 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)4 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)4 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)4 TimestampLiteral (io.confluent.ksql.execution.expression.tree.TimestampLiteral)4 Test (org.junit.Test)4 Cast (io.confluent.ksql.execution.expression.tree.Cast)3 DateLiteral (io.confluent.ksql.execution.expression.tree.DateLiteral)3 Type (io.confluent.ksql.execution.expression.tree.Type)3 ArrayType (io.confluent.ksql.function.types.ArrayType)3 GenericType (io.confluent.ksql.function.types.GenericType)3