use of io.confluent.ksql.planner.RequiredColumns in project ksql by confluentinc.
the class FinalProjectNode method validateProjection.
/**
* Called to validate that columns referenced in the projection are valid.
*
* <p>This is necessary as some joins can create synthetic key columns that do not come
* from any data source. This means the normal column validation done during analysis can not
* fail on unknown column with generated column names.
*
* <p>Once the logical model has been built the synthetic key names are known and generated
* column names can be validated.
*/
private void validateProjection() {
// Validate any column in the projection that might be a synthetic
// Only really need to include any that might be, but we include all:
final RequiredColumns requiredColumns = RequiredColumns.builder().addAll(projection.singleExpressions()).build();
final Set<ColumnReferenceExp> unknown = getSource().validateColumns(requiredColumns);
if (!unknown.isEmpty()) {
final String errors = unknown.stream().map(columnRef -> NodeLocation.asPrefix(columnRef.getLocation()) + "Column '" + columnRef + "' cannot be resolved.").collect(Collectors.joining(System.lineSeparator()));
throw new KsqlException(errors);
}
}
use of io.confluent.ksql.planner.RequiredColumns in project ksql by confluentinc.
the class JoinNode method validateColumns.
@Override
protected Set<ColumnReferenceExp> validateColumns(final RequiredColumns requiredColumns) {
final boolean noSyntheticKey = !finalJoin || !joinKey.isSynthetic();
final RequiredColumns updated = noSyntheticKey ? requiredColumns : requiredColumns.asBuilder().remove(new UnqualifiedColumnReferenceExp(getOnlyElement(schema.key()).name())).build();
final Set<ColumnReferenceExp> leftUnknown = left.validateColumns(updated);
final Set<ColumnReferenceExp> rightUnknown = right.validateColumns(updated);
return Sets.intersection(leftUnknown, rightUnknown);
}
use of io.confluent.ksql.planner.RequiredColumns in project ksql by confluentinc.
the class PreJoinProjectNode method validateColumns.
@Override
protected Set<ColumnReferenceExp> validateColumns(final RequiredColumns requiredColumns) {
final List<? extends ColumnReferenceExp> aliased = requiredColumns.get().stream().filter(columnRef -> columnRef instanceof UnqualifiedColumnReferenceExp).filter(columnRef -> aliases.inverse().containsKey(columnRef.getColumnName())).collect(Collectors.toList());
final Builder builder = requiredColumns.asBuilder();
aliased.forEach(columnRef -> {
builder.remove(columnRef);
builder.add(new UnqualifiedColumnReferenceExp(columnRef.getLocation(), aliases.inverse().get(columnRef.getColumnName())));
});
return super.validateColumns(builder.build());
}
Aggregations