Search in sources :

Example 6 with ColumnName

use of io.confluent.ksql.name.ColumnName in project ksql by confluentinc.

the class KsqlStructuredDataOutputNode method validate.

private static void validate(final PlanNode source, final SourceName sinkName) {
    if (!(source instanceof VerifiableNode)) {
        throw new IllegalArgumentException("VerifiableNode required");
    }
    ((VerifiableNode) source).validateKeyPresent(sinkName);
    final LogicalSchema schema = source.getSchema();
    final String duplicates = schema.columns().stream().map(Column::name).collect(Collectors.groupingBy(Function.identity(), Collectors.counting())).entrySet().stream().filter(e -> e.getValue() > 1).map(Entry::getKey).map(ColumnName::toString).collect(Collectors.joining(", "));
    if (!duplicates.isEmpty()) {
        throw new IllegalArgumentException("Value columns clash with key columns: " + duplicates);
    }
}
Also used : SchemaKStream(io.confluent.ksql.structured.SchemaKStream) ColumnName(io.confluent.ksql.name.ColumnName) SourceName(io.confluent.ksql.name.SourceName) QueryContext(io.confluent.ksql.execution.context.QueryContext) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) OptionalInt(java.util.OptionalInt) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) TimestampColumn(io.confluent.ksql.execution.timestamp.TimestampColumn) Objects.requireNonNull(java.util.Objects.requireNonNull) KsqlTopic(io.confluent.ksql.execution.ddl.commands.KsqlTopic) Entry(java.util.Map.Entry) Optional(java.util.Optional) Column(io.confluent.ksql.schema.ksql.Column) Entry(java.util.Map.Entry) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema)

Example 7 with ColumnName

use of io.confluent.ksql.name.ColumnName in project ksql by confluentinc.

the class PreJoinProjectNode method buildSchema.

private static LogicalSchema buildSchema(final SourceName alias, final LogicalSchema parentSchema) {
    final LogicalSchema.Builder builder = LogicalSchema.builder();
    parentSchema.columns().forEach(c -> {
        final ColumnName aliasedName = ColumnNames.generatedJoinColumnAlias(alias, c.name());
        if (c.namespace() == Namespace.KEY) {
            builder.keyColumn(aliasedName, c.type());
        } else {
            builder.valueColumn(aliasedName, c.type());
        }
    });
    return builder.build();
}
Also used : ColumnName(io.confluent.ksql.name.ColumnName) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema)

Example 8 with ColumnName

use of io.confluent.ksql.name.ColumnName in project ksql by confluentinc.

the class PreJoinProjectNodeTest method shouldNotAddAliasOnResolveSelectStarWhenNotAliased.

@Test
public void shouldNotAddAliasOnResolveSelectStarWhenNotAliased() {
    // Given:
    final ColumnName unknown = ColumnName.of("unknown");
    when(source.resolveSelectStar(any())).thenReturn(ImmutableList.of(K, unknown).stream());
    // When:
    final Stream<ColumnName> result = projectNode.resolveSelectStar(Optional.empty());
    // Then:
    final List<ColumnName> columns = result.collect(Collectors.toList());
    assertThat(columns, contains(K, unknown));
}
Also used : ColumnName(io.confluent.ksql.name.ColumnName) Test(org.junit.Test)

Example 9 with ColumnName

use of io.confluent.ksql.name.ColumnName in project ksql by confluentinc.

the class ColumnReferenceParserTest method shouldParseQuotedIdentifier.

@Test
public void shouldParseQuotedIdentifier() {
    // When:
    final ColumnName result = ColumnReferenceParser.parse("`foo`");
    // Then:
    assertThat(result, is(ColumnName.of("foo")));
}
Also used : ColumnName(io.confluent.ksql.name.ColumnName) Test(org.junit.Test)

Example 10 with ColumnName

use of io.confluent.ksql.name.ColumnName in project ksql by confluentinc.

the class ColumnReferenceParserTest method shouldParseUnquotedIdentifier.

@Test
public void shouldParseUnquotedIdentifier() {
    // When:
    final ColumnName result = ColumnReferenceParser.parse("foo");
    // Then:
    assertThat(result, is(ColumnName.of("FOO")));
}
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