use of io.confluent.ksql.schema.ksql.Column 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.Column in project ksql by confluentinc.
the class SelectionUtil method resolveSingleColumn.
private static Stream<SelectExpression> resolveSingleColumn(final int idx, final PlanNode parentNode, final SingleColumn column, final Optional<Column> targetColumn) {
final Expression expression = parentNode.resolveSelect(idx, column.getExpression());
final ColumnName alias = column.getAlias().orElseThrow(() -> new IllegalStateException("Alias should be present by this point"));
return Stream.of(SelectExpression.of(alias, targetColumn.map(col -> ImplicitlyCastResolver.resolve(expression, col.type())).orElse(expression)));
}
use of io.confluent.ksql.schema.ksql.Column in project ksql by confluentinc.
the class JoinNode method validateKeyPresent.
@Override
void validateKeyPresent(final SourceName sinkName, final Projection projection) {
if (joinKey.isForeignKey()) {
final DataSourceNode leftInputTable = getLeftmostSourceNode();
final SourceName leftInputTableName = leftInputTable.getAlias();
final List<Column> leftInputTableKeys = leftInputTable.getDataSource().getSchema().key();
final List<Column> missingKeys = leftInputTableKeys.stream().filter(k -> !projection.containsExpression(new QualifiedColumnReferenceExp(leftInputTableName, k.name())) && !projection.containsExpression(new UnqualifiedColumnReferenceExp(ColumnNames.generatedJoinColumnAlias(leftInputTableName, k.name())))).collect(Collectors.toList());
if (!missingKeys.isEmpty()) {
throwMissingKeyColumnForFkJoinException(missingKeys, leftInputTableName);
}
} else {
final boolean atLeastOneKey = joinKey.getAllViableKeys(schema).stream().anyMatch(projection::containsExpression);
if (!atLeastOneKey) {
final boolean synthetic = joinKey.isSynthetic();
final List<? extends Expression> viable = joinKey.getOriginalViableKeys(schema);
throwKeysNotIncludedError(sinkName, "join expression", viable, false, synthetic);
}
}
}
use of io.confluent.ksql.schema.ksql.Column 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.Column in project ksql by confluentinc.
the class ProjectOperator method createRowForSelectStar.
// Optimization for select star, to avoid having to do code generation
private List<?> createRowForSelectStar(final GenericRow intermediate) {
final List<Object> rowList = new ArrayList<>();
for (SelectExpression selectExpression : logicalNode.getSelectExpressions()) {
final Optional<Column> column = logicalNode.getIntermediateSchema().findValueColumn(selectExpression.getAlias());
if (!column.isPresent()) {
throw new IllegalStateException("Couldn't find alias in intermediate schema " + selectExpression.getAlias());
}
final int i = column.get().index();
rowList.add(intermediate.get(i));
}
return rowList;
}
Aggregations