Search in sources :

Example 46 with DataSource

use of io.confluent.ksql.metastore.model.DataSource in project ksql by confluentinc.

the class DistributingExecutorTest method shouldThrowExceptionWhenInsertIntoSourceWithHeaders.

@Test
public void shouldThrowExceptionWhenInsertIntoSourceWithHeaders() {
    // Given
    final PreparedStatement<Statement> preparedStatement = PreparedStatement.of("", new InsertInto(SourceName.of("s1"), mock(Query.class)));
    final ConfiguredStatement<Statement> configured = ConfiguredStatement.of(preparedStatement, SessionConfig.of(KSQL_CONFIG, ImmutableMap.of()));
    final DataSource dataSource = mock(DataSource.class);
    final LogicalSchema schema = mock(LogicalSchema.class);
    doReturn(dataSource).when(metaStore).getSource(SourceName.of("s1"));
    doReturn(schema).when(dataSource).getSchema();
    doReturn(ImmutableList.of(ColumnName.of("a"))).when(schema).headers();
    when(dataSource.getKafkaTopicName()).thenReturn("topic");
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> distributor.execute(configured, executionContext, mock(KsqlSecurityContext.class)));
    // Then:
    assertThat(e.getMessage(), is("Cannot insert into s1 because it has header columns"));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) Statement(io.confluent.ksql.parser.tree.Statement) PreparedStatement(io.confluent.ksql.parser.KsqlParser.PreparedStatement) InsertInto(io.confluent.ksql.parser.tree.InsertInto) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) KsqlTopicAuthorizationException(io.confluent.ksql.exception.KsqlTopicAuthorizationException) ProducerFencedException(org.apache.kafka.common.errors.ProducerFencedException) KsqlRestException(io.confluent.ksql.rest.server.resources.KsqlRestException) KsqlException(io.confluent.ksql.util.KsqlException) TimeoutException(org.apache.kafka.common.errors.TimeoutException) KsqlServerException(io.confluent.ksql.util.KsqlServerException) DataSource(io.confluent.ksql.metastore.model.DataSource) Test(org.junit.Test)

Example 47 with DataSource

use of io.confluent.ksql.metastore.model.DataSource in project ksql by confluentinc.

the class DistributingExecutorTest method shouldNotEnqueueRedundantIfNotExists.

@Test
public void shouldNotEnqueueRedundantIfNotExists() {
    // Given:
    final PreparedStatement<Statement> preparedStatement = PreparedStatement.of("", new CreateStream(SourceName.of("TEST"), TableElements.of(), false, true, CreateSourceProperties.from(ImmutableMap.of(CommonCreateConfigs.KAFKA_TOPIC_NAME_PROPERTY, new StringLiteral("topic"), CommonCreateConfigs.VALUE_FORMAT_PROPERTY, new StringLiteral("json"))), false));
    final ConfiguredStatement<Statement> configured = ConfiguredStatement.of(preparedStatement, SessionConfig.of(KSQL_CONFIG, ImmutableMap.of()));
    final DataSource dataSource = mock(DataSource.class);
    doReturn(dataSource).when(metaStore).getSource(SourceName.of("TEST"));
    // When:
    final StatementExecutorResponse response = distributor.execute(configured, executionContext, securityContext);
    // Then:
    assertThat("Should be present", response.getEntity().isPresent());
    assertThat(((WarningEntity) response.getEntity().get()).getMessage(), containsString(""));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) Statement(io.confluent.ksql.parser.tree.Statement) PreparedStatement(io.confluent.ksql.parser.KsqlParser.PreparedStatement) CreateStream(io.confluent.ksql.parser.tree.CreateStream) StatementExecutorResponse(io.confluent.ksql.rest.server.execution.StatementExecutorResponse) DataSource(io.confluent.ksql.metastore.model.DataSource) Test(org.junit.Test)

Example 48 with DataSource

use of io.confluent.ksql.metastore.model.DataSource in project ksql by confluentinc.

the class InsertValuesExecutorTest method givenDataSourceWithSchema.

private void givenDataSourceWithSchema(final String topicName, final LogicalSchema schema, final SerdeFeatures keyFeatures, final SerdeFeatures valFeatures, final FormatInfo keyFormat, final FormatInfo valueFormat, final boolean table, final boolean isSource) {
    final KsqlTopic topic = new KsqlTopic(topicName, KeyFormat.nonWindowed(keyFormat, keyFeatures), ValueFormat.of(valueFormat, valFeatures));
    final DataSource dataSource;
    if (table) {
        dataSource = new KsqlTable<>("", SourceName.of("TOPIC"), schema, Optional.empty(), false, topic, isSource);
    } else {
        dataSource = new KsqlStream<>("", SourceName.of("TOPIC"), schema, Optional.empty(), false, topic, isSource);
    }
    final MetaStoreImpl metaStore = new MetaStoreImpl(TestFunctionRegistry.INSTANCE.get());
    metaStore.putSource(dataSource, false);
    when(engine.getMetaStore()).thenReturn(metaStore);
}
Also used : MetaStoreImpl(io.confluent.ksql.metastore.MetaStoreImpl) KsqlTopic(io.confluent.ksql.execution.ddl.commands.KsqlTopic) DataSource(io.confluent.ksql.metastore.model.DataSource)

Example 49 with DataSource

use of io.confluent.ksql.metastore.model.DataSource in project ksql by confluentinc.

the class AssertExecutor method assertSourceMatch.

private static void assertSourceMatch(final KsqlExecutionContext engine, final KsqlConfig config, final CreateSource statement) {
    final SourceName source = statement.getName();
    final DataSource dataSource = engine.getMetaStore().getSource(source);
    MUST_MATCH.forEach(prop -> prop.compare(dataSource, statement, config));
}
Also used : SourceName(io.confluent.ksql.name.SourceName) DataSource(io.confluent.ksql.metastore.model.DataSource)

Example 50 with DataSource

use of io.confluent.ksql.metastore.model.DataSource in project ksql by confluentinc.

the class AssertExecutor method assertContent.

private static void assertContent(final KsqlExecutionContext engine, final KsqlConfig config, final InsertValues values, final TestDriverPipeline driverPipeline, final boolean isTombstone) {
    final boolean compareTimestamp = values.getColumns().stream().anyMatch(SystemColumns.ROWTIME_NAME::equals);
    final DataSource dataSource = engine.getMetaStore().getSource(values.getTarget());
    KsqlGenericRecord expected = new GenericRecordFactory(config, engine.getMetaStore(), System::currentTimeMillis).build(values.getColumns(), values.getValues(), dataSource.getSchema(), dataSource.getDataSourceType());
    if (isTombstone) {
        if (expected.value.values().stream().anyMatch(Objects::nonNull)) {
            throw new AssertionError("Unexpected value columns specified in ASSERT NULL VALUES.");
        }
        expected = KsqlGenericRecord.of(expected.key, null, expected.ts);
    }
    final Iterator<TestRecord<GenericKey, GenericRow>> records = driverPipeline.getRecordsForTopic(dataSource.getKafkaTopicName());
    if (!records.hasNext()) {
        throwAssertionError("Expected another record, but all records have already been read:", dataSource, expected, driverPipeline.getAllRecordsForTopic(dataSource.getKafkaTopicName()).stream().map(rec -> KsqlGenericRecord.of(rec.key(), rec.value(), rec.timestamp())).collect(Collectors.toList()));
    }
    final TestRecord<GenericKey, GenericRow> actualTestRecord = records.next();
    final KsqlGenericRecord actual = KsqlGenericRecord.of(actualTestRecord.key(), actualTestRecord.value(), compareTimestamp ? actualTestRecord.timestamp() : expected.ts);
    if (!actual.equals(expected)) {
        throwAssertionError("Expected record does not match actual.", dataSource, expected, ImmutableList.of(actual));
    }
}
Also used : GenericRow(io.confluent.ksql.GenericRow) GenericRecordFactory(io.confluent.ksql.engine.generic.GenericRecordFactory) Objects(java.util.Objects) GenericKey(io.confluent.ksql.GenericKey) TestRecord(org.apache.kafka.streams.test.TestRecord) DataSource(io.confluent.ksql.metastore.model.DataSource) KsqlGenericRecord(io.confluent.ksql.engine.generic.KsqlGenericRecord)

Aggregations

DataSource (io.confluent.ksql.metastore.model.DataSource)70 Test (org.junit.Test)25 KsqlException (io.confluent.ksql.util.KsqlException)24 SourceName (io.confluent.ksql.name.SourceName)21 KsqlTopic (io.confluent.ksql.execution.ddl.commands.KsqlTopic)12 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)12 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)10 MetricCollectors (io.confluent.ksql.metrics.MetricCollectors)9 Collectors (java.util.stream.Collectors)9 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)8 PreparedStatement (io.confluent.ksql.parser.KsqlParser.PreparedStatement)7 KsqlStatementException (io.confluent.ksql.util.KsqlStatementException)7 Optional (java.util.Optional)7 ImmutableList (com.google.common.collect.ImmutableList)6 GenericKey (io.confluent.ksql.GenericKey)6 QueryId (io.confluent.ksql.query.QueryId)6 ServiceContext (io.confluent.ksql.services.ServiceContext)6 KsqlConfig (io.confluent.ksql.util.KsqlConfig)6 Collections (java.util.Collections)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6