{
if (!table.getName().getPrefix().isPresent()) {
// is this a reference to a WITH query?
String name = table.getName().getSuffix();
Query query = context.getNamedQuery(name);
if (query != null) {
analysis.registerNamedQuery(table, query);
// re-alias the fields with the name assigned to the query in the WITH declaration
TupleDescriptor queryDescriptor = analysis.getOutputDescriptor(query);
ImmutableList.Builder<Field> fields = ImmutableList.builder();
for (Field field : queryDescriptor.getAllFields()) {
fields.add(Field.newQualified(QualifiedName.of(name), field.getName(), field.getType(), false));
}
TupleDescriptor descriptor = new TupleDescriptor(fields.build());
analysis.setOutputDescriptor(table, descriptor);
return descriptor;
}
}
QualifiedTableName name = MetadataUtil.createQualifiedTableName(session, table.getName());
Optional<ViewDefinition> optionalView = metadata.getView(session, name);
if (optionalView.isPresent()) {
ViewDefinition view = optionalView.get();
Query query = parseView(view.getOriginalSql(), name, table);
analysis.registerNamedQuery(table, query);
TupleDescriptor descriptor = analyzeView(query, name, view.getCatalog(), view.getSchema(), table);