use of io.confluent.ksql.engine.generic.GenericRecordFactory 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));
}
}
use of io.confluent.ksql.engine.generic.GenericRecordFactory in project ksql by confluentinc.
the class KsqlTesterTest method pipeInput.
private void pipeInput(final ConfiguredStatement<InsertValues> statement) {
final InsertValues insertValues = statement.getStatement();
final DataSource dataSource = engine.getMetaStore().getSource(insertValues.getTarget());
if (dataSource == null) {
throw new KsqlException("Unknown data source " + insertValues.getTarget());
}
final KsqlGenericRecord record = new GenericRecordFactory(config, engine.getMetaStore(), System::currentTimeMillis).build(insertValues.getColumns(), insertValues.getValues(), dataSource.getSchema(), dataSource.getDataSourceType());
driverPipeline.pipeInput(dataSource.getKafkaTopicName(), record.key, record.value, record.ts);
}
use of io.confluent.ksql.engine.generic.GenericRecordFactory in project ksql by confluentinc.
the class InsertValuesExecutor method buildRecord.
private ProducerRecord<byte[], byte[]> buildRecord(final ConfiguredStatement<InsertValues> statement, final MetaStore metaStore, final DataSource dataSource, final ServiceContext serviceContext) {
throwIfDisabled(statement.getSessionConfig().getConfig(false));
final InsertValues insertValues = statement.getStatement();
final KsqlConfig config = statement.getSessionConfig().getConfig(true);
try {
final KsqlGenericRecord row = new GenericRecordFactory(config, metaStore, clock).build(insertValues.getColumns(), insertValues.getValues(), dataSource.getSchema(), dataSource.getDataSourceType());
final byte[] key = serializeKey(row.key, dataSource, config, serviceContext);
final byte[] value = serializeValue(row.value, dataSource, config, serviceContext);
final String topicName = dataSource.getKafkaTopicName();
return new ProducerRecord<>(topicName, null, row.ts, key, value);
} catch (final Exception e) {
throw new KsqlStatementException(createInsertFailedExceptionMessage(insertValues) + " " + e.getMessage(), statement.getStatementText(), e);
}
}
Aggregations