use of io.confluent.ksql.parser.tree.InsertValues 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);
}
}
use of io.confluent.ksql.parser.tree.InsertValues in project ksql by confluentinc.
the class CommandParser method getInsertValuesStatement.
private static SqlInsertValues getInsertValuesStatement(final String sql, final Map<String, String> variables) {
final InsertValues parsedStatement;
try {
final String substituted = VariableSubstitutor.substitute(KSQL_PARSER.parse(sql).get(0), variables);
parsedStatement = (InsertValues) new AstBuilder(TypeRegistry.EMPTY).buildStatement(KSQL_PARSER.parse(substituted).get(0).getStatement());
} catch (ParseFailedException e) {
throw new MigrationException(String.format("Failed to parse INSERT VALUES statement. Statement: %s. Reason: %s", sql, e.getMessage()));
}
return new SqlInsertValues(sql, preserveCase(parsedStatement.getTarget().text()), parsedStatement.getValues(), parsedStatement.getColumns().stream().map(ColumnName::text).collect(Collectors.toList()));
}
Aggregations