use of io.confluent.ksql.parser.tree.AllColumns in project ksql by confluentinc.
the class AstBuilder method getSelectStartItems.
private List<SelectItem> getSelectStartItems(final SelectItem selectItem, final Relation from) {
List<SelectItem> selectItems = new ArrayList<>();
AllColumns allColumns = (AllColumns) selectItem;
if (from instanceof Join) {
Join join = (Join) from;
AliasedRelation left = (AliasedRelation) join.getLeft();
StructuredDataSource leftDataSource = dataSourceExtractor.getMetaStore().getSource(left.getRelation().toString());
if (leftDataSource == null) {
throw new InvalidColumnReferenceException(left.getRelation().toString() + " does not exist.");
}
AliasedRelation right = (AliasedRelation) join.getRight();
StructuredDataSource rightDataSource = dataSourceExtractor.getMetaStore().getSource(right.getRelation().toString());
if (rightDataSource == null) {
throw new InvalidColumnReferenceException(right.getRelation().toString() + " does not exist.");
}
for (Field field : leftDataSource.getSchema().fields()) {
QualifiedNameReference qualifiedNameReference = new QualifiedNameReference(allColumns.getLocation().get(), QualifiedName.of(left.getAlias() + "." + field.name()));
SingleColumn newSelectItem = new SingleColumn(qualifiedNameReference, left.getAlias() + "_" + field.name());
selectItems.add(newSelectItem);
}
for (Field field : rightDataSource.getSchema().fields()) {
QualifiedNameReference qualifiedNameReference = new QualifiedNameReference(allColumns.getLocation().get(), QualifiedName.of(right.getAlias() + "." + field.name()));
SingleColumn newSelectItem = new SingleColumn(qualifiedNameReference, right.getAlias() + "_" + field.name());
selectItems.add(newSelectItem);
}
} else {
AliasedRelation fromRel = (AliasedRelation) from;
StructuredDataSource fromDataSource = dataSourceExtractor.getMetaStore().getSource(((Table) fromRel.getRelation()).getName().getSuffix());
if (fromDataSource == null) {
throw new InvalidColumnReferenceException(((Table) fromRel.getRelation()).getName().getSuffix() + " does not exist.");
}
for (Field field : fromDataSource.getSchema().fields()) {
QualifiedNameReference qualifiedNameReference = new QualifiedNameReference(allColumns.getLocation().get(), QualifiedName.of(fromDataSource.getName() + "." + field.name()));
SingleColumn newSelectItem = new SingleColumn(qualifiedNameReference, field.name());
selectItems.add(newSelectItem);
}
}
return selectItems;
}
use of io.confluent.ksql.parser.tree.AllColumns in project ksql by confluentinc.
the class Analyzer method visitSelect.
@Override
protected Node visitSelect(final Select node, final AnalysisContext context) {
for (SelectItem selectItem : node.getSelectItems()) {
if (selectItem instanceof AllColumns) {
// expand * and T.*
AllColumns allColumns = (AllColumns) selectItem;
if ((this.analysis.getFromDataSources() == null) || (this.analysis.getFromDataSources().isEmpty())) {
throw new KsqlException("FROM clause was not resolved!");
}
if (analysis.getJoin() != null) {
JoinNode joinNode = analysis.getJoin();
for (Field field : joinNode.getLeft().getSchema().fields()) {
QualifiedNameReference qualifiedNameReference = new QualifiedNameReference(allColumns.getLocation().get(), QualifiedName.of(joinNode.getLeftAlias() + "." + field.name()));
analysis.addSelectItem(qualifiedNameReference, joinNode.getLeftAlias() + "_" + field.name());
}
for (Field field : joinNode.getRight().getSchema().fields()) {
QualifiedNameReference qualifiedNameReference = new QualifiedNameReference(allColumns.getLocation().get(), QualifiedName.of(joinNode.getRightAlias() + "." + field.name()));
analysis.addSelectItem(qualifiedNameReference, joinNode.getRightAlias() + "_" + field.name());
}
} else {
for (Field field : this.analysis.getFromDataSources().get(0).getLeft().getSchema().fields()) {
QualifiedNameReference qualifiedNameReference = new QualifiedNameReference(allColumns.getLocation().get(), QualifiedName.of(this.analysis.getFromDataSources().get(0).getRight() + "." + field.name()));
analysis.addSelectItem(qualifiedNameReference, field.name());
}
}
} else if (selectItem instanceof SingleColumn) {
SingleColumn column = (SingleColumn) selectItem;
analysis.addSelectItem(column.getExpression(), column.getAlias().get());
} else {
throw new IllegalArgumentException("Unsupported SelectItem type: " + selectItem.getClass().getName());
}
}
return null;
}
Aggregations