Search in sources :

Example 31 with StringLiteral

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

the class GenericExpressionResolverTest method shouldParseTimestamp.

@Test
public void shouldParseTimestamp() {
    // Given:
    final SqlType type = SqlTypes.TIMESTAMP;
    final Expression exp = new StringLiteral("2021-01-09T04:40:02");
    // When:
    Object o = new GenericExpressionResolver(type, FIELD_NAME, registry, config, "insert value", false).resolve(exp);
    // Then:
    assertTrue(o instanceof Timestamp);
    assertThat(((Timestamp) o).getTime(), is(1610167202000L));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 32 with StringLiteral

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

the class GenericExpressionResolverTest method shouldParseTime.

@Test
public void shouldParseTime() {
    // Given:
    final SqlType type = SqlTypes.TIME;
    final Expression exp = new StringLiteral("04:40:02");
    // When:
    Object o = new GenericExpressionResolver(type, FIELD_NAME, registry, config, "insert value", false).resolve(exp);
    // Then:
    assertTrue(o instanceof Time);
    assertThat(((Time) o).getTime(), is(16802000L));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) Time(java.sql.Time) Test(org.junit.Test)

Example 33 with StringLiteral

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

the class CreateSourceFactoryTest method shouldThrowIfTimestampColumnDoesNotExistForStream.

@Test
public void shouldThrowIfTimestampColumnDoesNotExistForStream() {
    // Given:
    givenProperty(CommonCreateConfigs.TIMESTAMP_NAME_PROPERTY, new StringLiteral("`will-not-find-me`"));
    final CreateStream statement = new CreateStream(SOME_NAME, ONE_KEY_ONE_VALUE, false, true, withProperties, false);
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> createSourceFactory.createStreamCommand(statement, ksqlConfig));
    // Then:
    assertThat(e.getMessage(), containsString("The TIMESTAMP column set in the WITH clause does not exist in the schema: " + "'will-not-find-me'"));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) CreateStream(io.confluent.ksql.parser.tree.CreateStream) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 34 with StringLiteral

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

the class CreateSourceFactoryTest method shouldBuildTimestampColumnForStream.

@Test
public void shouldBuildTimestampColumnForStream() {
    // Given:
    givenProperty(CommonCreateConfigs.TIMESTAMP_NAME_PROPERTY, new StringLiteral(quote(ELEMENT2.getName().text())));
    final CreateStream statement = new CreateStream(SOME_NAME, STREAM_ELEMENTS, false, true, withProperties, false);
    // When:
    final CreateStreamCommand cmd = createSourceFactory.createStreamCommand(statement, ksqlConfig);
    // Then:
    assertThat(cmd.getTimestampColumn(), is(Optional.of(new TimestampColumn(ELEMENT2.getName(), Optional.empty()))));
}
Also used : CreateStreamCommand(io.confluent.ksql.execution.ddl.commands.CreateStreamCommand) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) CreateStream(io.confluent.ksql.parser.tree.CreateStream) TimestampColumn(io.confluent.ksql.execution.timestamp.TimestampColumn) Test(org.junit.Test)

Example 35 with StringLiteral

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

the class CreateSourceFactoryTest method shouldHandleValueAvroSchemaNameForStream.

@Test
public void shouldHandleValueAvroSchemaNameForStream() {
    // Given:
    givenCommandFactoriesWithMocks();
    givenProperty("VALUE_FORMAT", new StringLiteral("Avro"));
    givenProperty("value_avro_schema_full_name", new StringLiteral("full.schema.name"));
    final CreateStream statement = new CreateStream(SOME_NAME, ONE_KEY_ONE_VALUE, false, true, withProperties, false);
    // When:
    final CreateStreamCommand cmd = createSourceFactory.createStreamCommand(statement, ksqlConfig);
    // Then:
    assertThat(cmd.getFormats().getValueFormat(), is(FormatInfo.of(AVRO.name(), ImmutableMap.of(ConnectProperties.FULL_SCHEMA_NAME, "full.schema.name"))));
}
Also used : CreateStreamCommand(io.confluent.ksql.execution.ddl.commands.CreateStreamCommand) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) CreateStream(io.confluent.ksql.parser.tree.CreateStream) Test(org.junit.Test)

Aggregations

StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)204 Test (org.junit.Test)199 Expression (io.confluent.ksql.execution.expression.tree.Expression)95 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)70 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)66 KsqlException (io.confluent.ksql.util.KsqlException)64 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)63 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)63 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)63 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)61 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)53 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)51 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)49 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)43 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)36 LongLiteral (io.confluent.ksql.execution.expression.tree.LongLiteral)35 SimpleCaseExpression (io.confluent.ksql.execution.expression.tree.SimpleCaseExpression)34 LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)31 BooleanLiteral (io.confluent.ksql.execution.expression.tree.BooleanLiteral)28 Matchers.containsString (org.hamcrest.Matchers.containsString)27