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()))));
}
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")))));
}
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()))));
}
}
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())));
}
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")))));
}
Aggregations