Search in sources :

Example 36 with DataSource

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

the class DeprecatedStatementsCheckerTest method setup.

@Before
public void setup() {
    statementsChecker = new DeprecatedStatementsChecker(metaStore);
    final DataSource streamSource1 = newKsqlStream(STREAM_1);
    when(metaStore.getSource(STREAM_1)).thenReturn(streamSource1);
    final DataSource streamSource2 = newKsqlStream(STREAM_2);
    when(metaStore.getSource(STREAM_2)).thenReturn(streamSource2);
    final DataSource streamSource3 = newKsqlStream(STREAM_3);
    when(metaStore.getSource(STREAM_3)).thenReturn(streamSource3);
    final DataSource tableSource1 = newKsqlTable(TABLE_1);
    when(metaStore.getSource(TABLE_1)).thenReturn(tableSource1);
}
Also used : DataSource(io.confluent.ksql.metastore.model.DataSource) Before(org.junit.Before)

Example 37 with DataSource

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

the class DistributingExecutorTest method shouldThrowExceptionWhenInsertIntoReadOnlyTopic.

@Test
public void shouldThrowExceptionWhenInsertIntoReadOnlyTopic() {
    // 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);
    doReturn(dataSource).when(metaStore).getSource(SourceName.of("s1"));
    when(dataSource.getKafkaTopicName()).thenReturn("_confluent-ksql-default__command-topic");
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> distributor.execute(configured, executionContext, mock(KsqlSecurityContext.class)));
    // Then:
    assertThat(e.getMessage(), containsString("Cannot insert into read-only topic: " + "_confluent-ksql-default__command-topic"));
}
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) 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 38 with DataSource

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

the class DistributingExecutorTest method shouldThrowExceptionWhenInsertIntoProcessingLogTopic.

@Test
public void shouldThrowExceptionWhenInsertIntoProcessingLogTopic() {
    // 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);
    doReturn(dataSource).when(metaStore).getSource(SourceName.of("s1"));
    when(dataSource.getKafkaTopicName()).thenReturn("default_ksql_processing_log");
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> distributor.execute(configured, executionContext, mock(KsqlSecurityContext.class)));
    // Then:
    assertThat(e.getMessage(), containsString("Cannot insert into read-only topic: " + "default_ksql_processing_log"));
}
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) 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 39 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 40 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