use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.
the class LogicalPlanner method buildUserRepartitionNode.
private UserRepartitionNode buildUserRepartitionNode(final PlanNode currentNode, final PartitionBy partitionBy) {
final List<Expression> rewrittenPartitionBys = partitionBy.getExpressions().stream().map(exp -> ExpressionTreeRewriter.rewriteWith(refRewriter::process, exp)).collect(Collectors.toList());
final LogicalSchema schema = buildRepartitionedSchema(currentNode, rewrittenPartitionBys);
return new UserRepartitionNode(new PlanNodeId("PartitionBy"), currentNode, schema, partitionBy.getExpressions(), rewrittenPartitionBys, ksqlConfig);
}
use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.
the class SelectionUtil method resolveSelectItem.
private static Stream<SelectExpression> resolveSelectItem(final int idx, final List<? extends SelectItem> selectItems, final PlanNode parentNode, final Optional<LogicalSchema> targetSchema) {
final SelectItem selectItem = selectItems.get(idx);
if (selectItem instanceof SingleColumn) {
final SingleColumn column = (SingleColumn) selectItem;
// if the column we are trying to coerce into a target schema is beyond
// the target schema's max columns ignore it. this will generate a failure
// down the line when we check that the result schema is identical to
// the schema of the source we are attempting to fit
final Optional<Column> targetColumn = targetSchema.filter(schema -> schema.columns().size() > idx).map(schema -> schema.columns().get(idx));
return resolveSingleColumn(idx, parentNode, column, targetColumn);
}
if (selectItem instanceof AllColumns) {
return resolveAllColumns(parentNode, (AllColumns) selectItem);
}
throw new IllegalArgumentException("Unsupported SelectItem type: " + selectItem.getClass().getName());
}
use of io.confluent.ksql.schema.ksql.LogicalSchema 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);
}
}
use of io.confluent.ksql.schema.ksql.LogicalSchema 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();
}
use of io.confluent.ksql.schema.ksql.LogicalSchema in project ksql by confluentinc.
the class KsqlBareOutputNodeTest method shouldCreateCorrectSchema.
@Test
public void shouldCreateCorrectSchema() {
final LogicalSchema schema = stream.getSchema();
assertThat(schema.value(), contains(valueColumn(ColumnName.of("COL0"), SqlTypes.BIGINT), valueColumn(ColumnName.of("COL2"), SqlTypes.STRING), valueColumn(ColumnName.of("COL3"), SqlTypes.DOUBLE)));
}
Aggregations