Search in sources :

Example 11 with TimestampColumn

use of io.confluent.ksql.execution.timestamp.TimestampColumn in project ksql by confluentinc.

the class TimestampExtractionPolicyFactoryTest method shouldFailIfStringTimestampTypeAndFormatNotSupplied.

@Test
public void shouldFailIfStringTimestampTypeAndFormatNotSupplied() {
    // Given:
    final String field = "my_string_field";
    final LogicalSchema schema = schemaBuilder2.valueColumn(ColumnName.of(field.toUpperCase()), SqlTypes.STRING).build();
    // When:
    assertThrows(KsqlException.class, () -> TimestampExtractionPolicyFactory.create(ksqlConfig, schema, Optional.of(new TimestampColumn(ColumnName.of(field.toUpperCase()), Optional.empty()))));
}
Also used : TimestampColumn(io.confluent.ksql.execution.timestamp.TimestampColumn) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 12 with TimestampColumn

use of io.confluent.ksql.execution.timestamp.TimestampColumn in project ksql by confluentinc.

the class TimestampExtractionPolicyFactoryTest method shouldThrowIfTimestampTypeAndFormatIsSupplied.

@Test
public void shouldThrowIfTimestampTypeAndFormatIsSupplied() {
    // Given:
    final String timestamp = "timestamp";
    final LogicalSchema schema = schemaBuilder2.valueColumn(ColumnName.of(timestamp.toUpperCase()), SqlTypes.TIMESTAMP).build();
    // When:
    assertThrows(KsqlException.class, () -> TimestampExtractionPolicyFactory.create(ksqlConfig, schema, Optional.of(new TimestampColumn(ColumnName.of(timestamp.toUpperCase()), Optional.of("b")))));
}
Also used : TimestampColumn(io.confluent.ksql.execution.timestamp.TimestampColumn) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 13 with TimestampColumn

use of io.confluent.ksql.execution.timestamp.TimestampColumn in project ksql by confluentinc.

the class TimestampExtractionPolicyFactoryTest method shouldThrowIfTimestampFieldTypeIsNotLongOrTimestampOrString.

@Test
public void shouldThrowIfTimestampFieldTypeIsNotLongOrTimestampOrString() {
    final Set<SqlPrimitiveType> allowedTypes = Sets.newHashSet(SqlTypes.BIGINT, SqlTypes.STRING, SqlTypes.TIMESTAMP);
    for (SqlPrimitiveType sqlType : SqlTypes.ALL) {
        if (allowedTypes.contains(sqlType)) {
            continue;
        }
        // Given:
        final String field = "blah_" + sqlType.toString();
        final LogicalSchema schema = schemaBuilder2.valueColumn(ColumnName.of(field.toUpperCase()), sqlType).build();
        // When:
        assertThrows(KsqlException.class, () -> TimestampExtractionPolicyFactory.create(ksqlConfig, schema, Optional.of(new TimestampColumn(ColumnName.of(field), Optional.empty()))));
    }
}
Also used : SqlPrimitiveType(io.confluent.ksql.schema.ksql.types.SqlPrimitiveType) TimestampColumn(io.confluent.ksql.execution.timestamp.TimestampColumn) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 14 with TimestampColumn

use of io.confluent.ksql.execution.timestamp.TimestampColumn in project ksql by confluentinc.

the class TimestampExtractionPolicyFactoryTest method shouldCreateLongTimestampPolicyWhenTimestampFieldIsOfTypeLong.

@Test
public void shouldCreateLongTimestampPolicyWhenTimestampFieldIsOfTypeLong() {
    // Given:
    final String timestamp = "timestamp";
    final LogicalSchema schema = schemaBuilder2.valueColumn(ColumnName.of(timestamp.toUpperCase()), SqlTypes.BIGINT).build();
    // When:
    final TimestampExtractionPolicy result = TimestampExtractionPolicyFactory.create(ksqlConfig, schema, Optional.of(new TimestampColumn(ColumnName.of(timestamp.toUpperCase()), Optional.empty())));
    // Then:
    assertThat(result, instanceOf(LongColumnTimestampExtractionPolicy.class));
    assertThat(result.getTimestampField(), equalTo(ColumnName.of(timestamp.toUpperCase())));
}
Also used : TimestampColumn(io.confluent.ksql.execution.timestamp.TimestampColumn) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 15 with TimestampColumn

use of io.confluent.ksql.execution.timestamp.TimestampColumn in project ksql by confluentinc.

the class CreateSourceFactoryTest method shouldBuildTimestampColumnWithFormat.

@Test
public void shouldBuildTimestampColumnWithFormat() {
    // Given:
    givenProperties(ImmutableMap.of(CommonCreateConfigs.TIMESTAMP_NAME_PROPERTY, new StringLiteral(quote(ELEMENT1.getName().text())), CommonCreateConfigs.TIMESTAMP_FORMAT_PROPERTY, new StringLiteral("%s")));
    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(ELEMENT1.getName(), Optional.of("%s")))));
}
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)

Aggregations

TimestampColumn (io.confluent.ksql.execution.timestamp.TimestampColumn)20 Test (org.junit.Test)12 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)11 Matchers.containsString (org.hamcrest.Matchers.containsString)7 CreateStreamCommand (io.confluent.ksql.execution.ddl.commands.CreateStreamCommand)3 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)3 DataSource (io.confluent.ksql.metastore.model.DataSource)3 ColumnName (io.confluent.ksql.name.ColumnName)3 KsqlException (io.confluent.ksql.util.KsqlException)3 QueryContext (io.confluent.ksql.execution.context.QueryContext)2 CreateTableCommand (io.confluent.ksql.execution.ddl.commands.CreateTableCommand)2 TimestampExtractionPolicy (io.confluent.ksql.execution.streams.timestamp.TimestampExtractionPolicy)2 SourceName (io.confluent.ksql.name.SourceName)2 CreateSourceProperties (io.confluent.ksql.parser.properties.with.CreateSourceProperties)2 CreateStream (io.confluent.ksql.parser.tree.CreateStream)2 Column (io.confluent.ksql.schema.ksql.Column)2 Named (org.apache.kafka.streams.kstream.Named)2 GenericRow (io.confluent.ksql.GenericRow)1 Into (io.confluent.ksql.analyzer.Analysis.Into)1 KsqlTopic (io.confluent.ksql.execution.ddl.commands.KsqlTopic)1