use of io.confluent.ksql.execution.timestamp.TimestampColumn in project ksql by confluentinc.
the class TimestampExtractionPolicyFactoryTest method shouldCreateTimestampPolicyWhenTimestampFieldIsOfTypeTimestamp.
@Test
public void shouldCreateTimestampPolicyWhenTimestampFieldIsOfTypeTimestamp() {
// Given:
final String timestamp = "timestamp";
final LogicalSchema schema = schemaBuilder2.valueColumn(ColumnName.of(timestamp.toUpperCase()), SqlTypes.TIMESTAMP).build();
// When:
final TimestampExtractionPolicy result = TimestampExtractionPolicyFactory.create(ksqlConfig, schema, Optional.of(new TimestampColumn(ColumnName.of(timestamp.toUpperCase()), Optional.empty())));
// Then:
assertThat(result, instanceOf(TimestampColumnTimestampExtractionPolicy.class));
assertThat(result.getTimestampField(), equalTo(ColumnName.of(timestamp.toUpperCase())));
}
use of io.confluent.ksql.execution.timestamp.TimestampColumn in project ksql by confluentinc.
the class TimestampExtractionPolicyFactoryTest method shouldCreateStringTimestampPolicyWhenTimestampFieldIsStringTypeAndFormatProvided.
@Test
public void shouldCreateStringTimestampPolicyWhenTimestampFieldIsStringTypeAndFormatProvided() {
// Given:
final String field = "my_string_field";
final LogicalSchema schema = schemaBuilder2.valueColumn(ColumnName.of(field.toUpperCase()), SqlTypes.STRING).build();
// When:
final TimestampExtractionPolicy result = TimestampExtractionPolicyFactory.create(ksqlConfig, schema, Optional.of(new TimestampColumn(ColumnName.of(field.toUpperCase()), Optional.of("yyyy-MM-DD"))));
// Then:
assertThat(result, instanceOf(StringTimestampExtractionPolicy.class));
assertThat(result.getTimestampField(), equalTo(ColumnName.of(field.toUpperCase())));
}
use of io.confluent.ksql.execution.timestamp.TimestampColumn in project ksql by confluentinc.
the class SinkBuilder method build.
public static <K> void build(final LogicalSchema schema, final Formats formats, final Optional<TimestampColumn> timestampColumn, final String topicName, final KStream<K, GenericRow> stream, final ExecutionKeyFactory<K> executionKeyFactory, final QueryContext queryContext, final RuntimeBuildContext buildContext) {
final PhysicalSchema physicalSchema = PhysicalSchema.from(schema, formats.getKeyFeatures(), formats.getValueFeatures());
final Serde<K> keySerde = executionKeyFactory.buildKeySerde(formats.getKeyFormat(), physicalSchema, queryContext);
final Serde<GenericRow> valueSerde = buildContext.buildValueSerde(formats.getValueFormat(), physicalSchema, queryContext);
final Optional<TransformTimestamp<K>> tsTransformer = timestampTransformer(buildContext, queryContext, schema, timestampColumn);
final KStream<K, GenericRow> transformed = tsTransformer.map(t -> stream.transform(t, Named.as(TIMESTAMP_TRANSFORM_NAME + StreamsUtil.buildOpName(queryContext)))).orElse(stream);
transformed.to(topicName, Produced.with(keySerde, valueSerde));
}
use of io.confluent.ksql.execution.timestamp.TimestampColumn in project ksql by confluentinc.
the class SourceDescriptionFactoryTest method shouldReturnTimestampColumnIfPresent.
@Test
public void shouldReturnTimestampColumnIfPresent() {
// Given:
final String kafkaTopicName = "kafka";
final DataSource dataSource = buildDataSource(kafkaTopicName, Optional.of(new TimestampColumn(ColumnName.of("foo"), Optional.empty())));
// When
final SourceDescription sourceDescription = SourceDescriptionFactory.create(dataSource, true, Collections.emptyList(), Collections.emptyList(), Optional.empty(), Collections.emptyList(), Collections.emptyList(), new MetricCollectors());
// Then:
assertThat(sourceDescription.getTimestamp(), is("foo"));
}
use of io.confluent.ksql.execution.timestamp.TimestampColumn in project ksql by confluentinc.
the class TimestampExtractionPolicyFactoryTest method shouldThrowIfLongTimestampTypeAndFormatIsSupplied.
@Test
public void shouldThrowIfLongTimestampTypeAndFormatIsSupplied() {
// Given:
final String timestamp = "timestamp";
final LogicalSchema schema = schemaBuilder2.valueColumn(ColumnName.of(timestamp.toUpperCase()), SqlTypes.BIGINT).build();
// When:
assertThrows(KsqlException.class, () -> TimestampExtractionPolicyFactory.create(ksqlConfig, schema, Optional.of(new TimestampColumn(ColumnName.of(timestamp.toUpperCase()), Optional.of("b")))));
}
Aggregations