use of io.confluent.ksql.metastore.model.DataSource in project ksql by confluentinc.
the class DataSourceNodeTest method before.
@Before
@SuppressWarnings("unchecked")
public void before() {
realBuilder = new StreamsBuilder();
when(buildContext.getKsqlConfig()).thenReturn(realConfig);
when(buildContext.getFunctionRegistry()).thenReturn(functionRegistry);
when(buildContext.buildNodeContext(any())).thenAnswer(inv -> new QueryContext.Stacker().push(inv.getArgument(0).toString()));
when(executeContext.getKsqlConfig()).thenReturn(realConfig);
when(executeContext.getStreamsBuilder()).thenReturn(realBuilder);
when(executeContext.getProcessingLogger(any())).thenReturn(processingLogger);
when(executeContext.buildKeySerde(any(), any(), any())).thenReturn((Serde) keySerde);
when(executeContext.buildValueSerde(any(), any(), any())).thenReturn(rowSerde);
when(rowSerde.serializer()).thenReturn(mock(Serializer.class));
when(rowSerde.deserializer()).thenReturn(mock(Deserializer.class));
when(dataSource.getKsqlTopic()).thenReturn(topic);
when(dataSource.getDataSourceType()).thenReturn(DataSourceType.KTABLE);
when(schemaKStreamFactory.create(any(), any(), any())).thenAnswer(inv -> inv.<DataSource>getArgument(1).getDataSourceType() == DataSourceType.KSTREAM ? stream : table);
givenWindowedSource(false);
when(ksqlConfig.getBoolean(KsqlConfig.KSQL_ROWPARTITION_ROWOFFSET_ENABLED)).thenReturn(true);
node = new DataSourceNode(PLAN_NODE_ID, SOME_SOURCE, SOME_SOURCE.getName(), false, ksqlConfig);
}
use of io.confluent.ksql.metastore.model.DataSource in project ksql by confluentinc.
the class QueryBuilderTest method shouldStartCreateSourceQueryWithMaterializationProvider.
@Test
public void shouldStartCreateSourceQueryWithMaterializationProvider() {
when(ksqlConfig.getBoolean(KsqlConfig.KSQL_SHARED_RUNTIME_ENABLED)).thenReturn(true);
// Given:
final DataSource source = givenSource("foo");
when(source.getSchema()).thenReturn(SINK_SCHEMA);
when(source.getKsqlTopic()).thenReturn(ksqlTopic);
final PersistentQueryMetadata queryMetadata = buildPersistentQuery(ImmutableSet.of(source), KsqlConstants.PersistentQueryType.CREATE_SOURCE, QUERY_ID, Optional.empty());
queryMetadata.initialize();
queryMetadata.register();
queryMetadata.start();
// When:
final Optional<Materialization> result = queryMetadata.getMaterialization(QUERY_ID, stacker);
// Then:
assertThat(result.get(), is(materialization));
}
use of io.confluent.ksql.metastore.model.DataSource in project ksql by confluentinc.
the class QueryBuilderTest method givenSource.
private static DataSource givenSource(final String name) {
final DataSource source = Mockito.mock(DataSource.class);
when(source.getName()).thenReturn(SourceName.of(name));
return source;
}
use of io.confluent.ksql.metastore.model.DataSource in project ksql by confluentinc.
the class QueryBuilderTest method shouldBuildTransientQueryCorrectly.
@Test
public void shouldBuildTransientQueryCorrectly() {
// Given:
givenTransientQuery();
// When:
final TransientQueryMetadata queryMetadata = queryBuilder.buildTransientQuery(STATEMENT_TEXT, QUERY_ID, SOURCES.stream().map(DataSource::getName).collect(Collectors.toSet()), physicalPlan, SUMMARY, TRANSIENT_SINK_SCHEMA, LIMIT, Optional.empty(), false, queryListener, streamsBuilder, Optional.empty(), new MetricCollectors());
queryMetadata.initialize();
// Then:
assertThat(queryMetadata.getStatementString(), equalTo(STATEMENT_TEXT));
assertThat(queryMetadata.getSourceNames(), equalTo(SOURCES.stream().map(DataSource::getName).collect(Collectors.toSet())));
assertThat(queryMetadata.getExecutionPlan(), equalTo(SUMMARY));
assertThat(queryMetadata.getTopology(), is(topology));
assertThat(queryMetadata.getOverriddenProperties(), equalTo(OVERRIDES));
verify(kafkaStreamsBuilder).build(any(), propertyCaptor.capture());
assertThat(queryMetadata.getStreamsProperties(), equalTo(propertyCaptor.getValue()));
}
use of io.confluent.ksql.metastore.model.DataSource in project ksql by confluentinc.
the class InsertValuesExecutor method execute.
// Part of required API.
@SuppressWarnings("unused")
public void execute(final ConfiguredStatement<InsertValues> statement, final SessionProperties sessionProperties, final KsqlExecutionContext executionContext, final ServiceContext serviceContext) {
final InsertValues insertValues = statement.getStatement();
final MetaStore metaStore = executionContext.getMetaStore();
final KsqlConfig config = statement.getSessionConfig().getConfig(true);
final DataSource dataSource = getDataSource(config, metaStore, insertValues);
validateInsert(insertValues.getColumns(), dataSource);
final ProducerRecord<byte[], byte[]> record = buildRecord(statement, metaStore, dataSource, serviceContext);
try {
producer.sendRecord(record, serviceContext, config.getProducerClientConfigProps());
} catch (final TopicAuthorizationException e) {
// TopicAuthorizationException does not give much detailed information about why it failed,
// except which topics are denied. Here we just add the ACL to make the error message
// consistent with other authorization error messages.
final Exception rootCause = new KsqlTopicAuthorizationException(AclOperation.WRITE, e.unauthorizedTopics());
throw new KsqlException(createInsertFailedExceptionMessage(insertValues), rootCause);
} catch (final Exception e) {
throw new KsqlException(createInsertFailedExceptionMessage(insertValues), e);
}
}
Aggregations