I’m trying to use a union in a join, but I don’t see the alias as available
(I get an error that the alias/field does not exist on the line of the
below left join). The error shows available alias/fields and I see the
union id fields but the alias is an empty set aliases:[]. Is this possible?
Thank you!
Eric
List tableScans = new ArrayList<>();
for (String tableName : tablesToUnion) {
RelNode tableScan = builder
.scan(tableName)
.project(builder.field("id"), builder.field("field1"))
.build();
tableScans.add(tableScan);
}
// Use pushAll to add all table scans to the stack and create a UNION ALL
builder.pushAll(tableScans);
RelNode union = builder.union(true, tableScans.size());
// Start with the union as the initial part of the join
RelNode current = builder.push(union).as("core").build();
// Iterate over the tables to join
for (String joinTable : tablesToJoin) {
current = builder
.push(current)
.scan(joinTable)
.join(JoinRelType.LEFT,
builder.equals( builder.field(2, "core", "id"),
builder.field(joinTable, "id")))
.project(builder.fields())
.build();
}