Search in sources :

Example 61 with ColumnName

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();
}
Also used : ExpressionTypeManager(io.confluent.ksql.execution.util.ExpressionTypeManager) ColumnName(io.confluent.ksql.name.ColumnName) Column(io.confluent.ksql.schema.ksql.Column) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) FunctionCall(io.confluent.ksql.execution.expression.tree.FunctionCall)

Example 62 with ColumnName

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()));
}
Also used : MigrationException(io.confluent.ksql.tools.migrations.MigrationException) AstBuilder(io.confluent.ksql.parser.AstBuilder) ColumnName(io.confluent.ksql.name.ColumnName) InsertValues(io.confluent.ksql.parser.tree.InsertValues) ParseFailedException(io.confluent.ksql.parser.exception.ParseFailedException)

Example 63 with ColumnName

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()));
}
Also used : ColumnName(io.confluent.ksql.name.ColumnName) Test(org.junit.Test)

Aggregations

ColumnName (io.confluent.ksql.name.ColumnName)63 Test (org.junit.Test)32 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)31 Expression (io.confluent.ksql.execution.expression.tree.Expression)23 KsqlException (io.confluent.ksql.util.KsqlException)13 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)11 Column (io.confluent.ksql.schema.ksql.Column)11 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)10 SqlType (io.confluent.ksql.schema.ksql.types.SqlType)9 ColumnReferenceExp (io.confluent.ksql.execution.expression.tree.ColumnReferenceExp)8 Optional (java.util.Optional)8 Collectors (java.util.stream.Collectors)8 FunctionCall (io.confluent.ksql.execution.expression.tree.FunctionCall)7 List (java.util.List)7 TimestampColumn (io.confluent.ksql.execution.timestamp.TimestampColumn)6 Builder (io.confluent.ksql.schema.ksql.LogicalSchema.Builder)6 Set (java.util.Set)6 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)5 QualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.QualifiedColumnReferenceExp)5 SelectExpression (io.confluent.ksql.execution.plan.SelectExpression)5