Search in sources :

Example 16 with TimestampColumn

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

the class CreateSourceFactoryTest method shouldBuildTimestampColumnForTable.

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

Example 17 with TimestampColumn

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

the class CreateSourceFactory method buildTimestampColumn.

private static Optional<TimestampColumn> buildTimestampColumn(final KsqlConfig ksqlConfig, final CreateSourceProperties properties, final LogicalSchema schema) {
    final Optional<ColumnName> timestampName = properties.getTimestampColumnName();
    final Optional<TimestampColumn> timestampColumn = timestampName.map(n -> new TimestampColumn(n, properties.getTimestampFormat()));
    // create the final extraction policy to validate that the ref/format are OK
    TimestampExtractionPolicyFactory.validateTimestampColumn(ksqlConfig, schema, timestampColumn);
    return timestampColumn;
}
Also used : ColumnName(io.confluent.ksql.name.ColumnName) TimestampColumn(io.confluent.ksql.execution.timestamp.TimestampColumn)

Example 18 with TimestampColumn

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

the class LogicalPlanner method buildOutputNode.

private OutputNode buildOutputNode(final PlanNode sourcePlanNode) {
    final LogicalSchema inputSchema = sourcePlanNode.getSchema();
    final Optional<TimestampColumn> timestampColumn = getTimestampColumn(inputSchema, analysis);
    if (!analysis.getInto().isPresent()) {
        return new KsqlBareOutputNode(new PlanNodeId("KSQL_STDOUT_NAME"), sourcePlanNode, inputSchema, analysis.getLimitClause(), timestampColumn, getWindowInfo());
    }
    final Into into = analysis.getInto().get();
    final KsqlTopic existingTopic = getSinkTopic(into, sourcePlanNode.getSchema());
    return new KsqlStructuredDataOutputNode(new PlanNodeId(into.getName().text()), sourcePlanNode, inputSchema, timestampColumn, existingTopic, analysis.getLimitClause(), into.isCreate(), into.getName(), analysis.getOrReplace());
}
Also used : PlanNodeId(io.confluent.ksql.planner.plan.PlanNodeId) Into(io.confluent.ksql.analyzer.Analysis.Into) KsqlBareOutputNode(io.confluent.ksql.planner.plan.KsqlBareOutputNode) TimestampColumn(io.confluent.ksql.execution.timestamp.TimestampColumn) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) KsqlStructuredDataOutputNode(io.confluent.ksql.planner.plan.KsqlStructuredDataOutputNode) KsqlTopic(io.confluent.ksql.execution.ddl.commands.KsqlTopic)

Example 19 with TimestampColumn

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

the class SourceBuilderUtils method timestampExtractor.

static TimestampExtractor timestampExtractor(final KsqlConfig ksqlConfig, final LogicalSchema sourceSchema, final Optional<TimestampColumn> timestampColumn, final SourceStep<?> streamSource, final RuntimeBuildContext buildContext) {
    final TimestampExtractionPolicy timestampPolicy = TimestampExtractionPolicyFactory.create(ksqlConfig, sourceSchema, timestampColumn);
    final Optional<Column> tsColumn = timestampColumn.map(TimestampColumn::getColumn).map(c -> sourceSchema.findColumn(c).orElseThrow(IllegalStateException::new));
    final QueryContext queryContext = streamSource.getProperties().getQueryContext();
    return timestampPolicy.create(tsColumn, ksqlConfig.getBoolean(KsqlConfig.KSQL_TIMESTAMP_THROW_ON_INVALID), buildContext.getProcessingLogger(queryContext));
}
Also used : TimestampColumn(io.confluent.ksql.execution.timestamp.TimestampColumn) Column(io.confluent.ksql.schema.ksql.Column) TimestampExtractionPolicy(io.confluent.ksql.execution.streams.timestamp.TimestampExtractionPolicy) QueryContext(io.confluent.ksql.execution.context.QueryContext)

Example 20 with TimestampColumn

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

the class SinkBuilderTest method shouldBuildStreamUsingTransformTimestampWhenTimestampIsSpecified.

@Test
public void shouldBuildStreamUsingTransformTimestampWhenTimestampIsSpecified() {
    // When
    SinkBuilder.build(SCHEMA, Formats.of(KEY_FORMAT, VALUE_FORMAT, SerdeFeatures.of(), SerdeFeatures.of()), Optional.of(new TimestampColumn(ColumnName.of("BLUE"), Optional.empty())), TOPIC, kStream, executionKeyFactory, queryContext, buildContext);
    // Then
    final InOrder inOrder = Mockito.inOrder(kStream);
    inOrder.verify(kStream).transform(any(), any(Named.class));
    inOrder.verify(kStream).to(eq(TOPIC), any());
    inOrder.verifyNoMoreInteractions();
}
Also used : Named(org.apache.kafka.streams.kstream.Named) InOrder(org.mockito.InOrder) 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