use of io.crate.metadata.view.ViewMetadata in project crate by crate.
the class Schemas method resolveView.
/**
* @throws RelationUnknown if the view cannot be resolved against the search path.
*/
public Tuple<ViewMetadata, RelationName> resolveView(QualifiedName ident, SearchPath searchPath) {
ViewsMetadata views = clusterService.state().metadata().custom(ViewsMetadata.TYPE);
ViewMetadata view = null;
RelationName viewRelationName = null;
String identSchema = schemaName(ident);
String viewName = relationName(ident);
if (views != null) {
if (identSchema == null) {
for (String pathSchema : searchPath) {
SchemaInfo schemaInfo = schemas.get(pathSchema);
if (schemaInfo != null) {
viewRelationName = new RelationName(pathSchema, viewName);
view = views.getView(viewRelationName);
if (view != null) {
break;
}
}
}
} else {
viewRelationName = new RelationName(identSchema, viewName);
view = views.getView(viewRelationName);
}
}
if (view == null) {
throw new RelationUnknown(viewName);
}
return Tuple.tuple(view, viewRelationName);
}
use of io.crate.metadata.view.ViewMetadata in project crate by crate.
the class RelationAnalyzer method visitTable.
@Override
protected AnalyzedRelation visitTable(Table<?> node, StatementAnalysisContext context) {
QualifiedName tableQualifiedName = node.getName();
SearchPath searchPath = context.sessionContext().searchPath();
AnalyzedRelation relation;
TableInfo tableInfo;
try {
tableInfo = schemas.resolveTableInfo(tableQualifiedName, context.currentOperation(), context.sessionContext().sessionUser(), searchPath);
if (tableInfo instanceof DocTableInfo) {
// Dispatching of doc relations is based on the returned class of the schema information.
relation = new DocTableRelation((DocTableInfo) tableInfo);
} else {
relation = new TableRelation(tableInfo);
}
} catch (RelationUnknown e) {
Tuple<ViewMetadata, RelationName> viewMetadata;
try {
viewMetadata = schemas.resolveView(tableQualifiedName, searchPath);
} catch (RelationUnknown e1) {
// don't shadow original exception, as looking for the view is just a fallback
throw e;
}
ViewMetadata view = viewMetadata.v1();
AnalyzedRelation resolvedView = SqlParser.createStatement(view.stmt()).accept(this, context);
relation = new AnalyzedView(viewMetadata.v2(), view.owner(), resolvedView);
}
context.currentRelationContext().addSourceRelation(relation);
return relation;
}
Aggregations