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