use of io.confluent.ksql.name.ColumnName in project ksql by confluentinc.
the class StreamFlatMapBuilder method buildSchema.
public static LogicalSchema buildSchema(final LogicalSchema inputSchema, final List<FunctionCall> tableFunctions, final FunctionRegistry functionRegistry) {
final LogicalSchema.Builder schemaBuilder = LogicalSchema.builder();
final List<Column> cols = inputSchema.value();
// We copy all the original columns to the output schema
schemaBuilder.keyColumns(inputSchema.key());
for (final Column col : cols) {
schemaBuilder.valueColumn(col);
}
final ExpressionTypeManager expressionTypeManager = new ExpressionTypeManager(inputSchema, functionRegistry);
// And add new columns representing the exploded values at the end
for (int i = 0; i < tableFunctions.size(); i++) {
final FunctionCall functionCall = tableFunctions.get(i);
final ColumnName colName = ColumnNames.synthesisedSchemaColumn(i);
final SqlType fieldType = expressionTypeManager.getExpressionSqlType(functionCall);
schemaBuilder.valueColumn(colName, fieldType);
}
return schemaBuilder.build();
}
use of io.confluent.ksql.name.ColumnName 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()));
}
use of io.confluent.ksql.name.ColumnName in project ksql by confluentinc.
the class JoinParamsFactoryTest method shouldBuildCorrectRightKeyedSchema.
@Test
public void shouldBuildCorrectRightKeyedSchema() {
// Given:
final ColumnName keyName = Iterables.getOnlyElement(RIGHT_SCHEMA.key()).name();
// When:
final JoinParams joinParams = JoinParamsFactory.create(keyName, LEFT_SCHEMA, RIGHT_SCHEMA);
// Then:
assertThat(joinParams.getSchema(), is(LogicalSchema.builder().keyColumn(ColumnName.of("R_K"), SqlTypes.STRING).valueColumn(ColumnName.of("L_BLUE"), SqlTypes.STRING).valueColumn(ColumnName.of("L_GREEN"), SqlTypes.INTEGER).valueColumn(ColumnName.of("L_K"), SqlTypes.STRING).valueColumn(ColumnName.of("R_RED"), SqlTypes.BIGINT).valueColumn(ColumnName.of("R_ORANGE"), SqlTypes.DOUBLE).valueColumn(ColumnName.of("R_K"), SqlTypes.STRING).build()));
}
Aggregations