use of io.crate.metadata.RelationName in project crate by crate.
the class RelationAnalyzer method visitAliasedRelation.
@Override
protected AnalyzedRelation visitAliasedRelation(AliasedRelation node, StatementAnalysisContext context) {
context.startRelation(true);
AnalyzedRelation childRelation = node.getRelation().accept(this, context);
AnalyzedRelation aliasedRelation = new AliasedAnalyzedRelation(childRelation, new RelationName(null, node.getAlias()), node.getColumnNames());
context.endRelation();
context.currentRelationContext().addSourceRelation(aliasedRelation);
return aliasedRelation;
}
use of io.crate.metadata.RelationName in project crate by crate.
the class FullQualifiedNameFieldProvider method resolveField.
@Override
public Symbol resolveField(QualifiedName qualifiedName, @Nullable List<String> path, Operation operation, boolean errorOnUnknownObjectKey) {
List<String> parts = qualifiedName.getParts();
String columnSchema = null;
String columnTableName = null;
ColumnIdent columnIdent = new ColumnIdent(parts.get(parts.size() - 1), path);
switch(parts.size()) {
case 1:
break;
case 2:
columnTableName = parts.get(0);
break;
case 3:
columnSchema = parts.get(0);
columnTableName = parts.get(1);
break;
default:
throw new IllegalArgumentException("Column reference \"%s\" has too many parts. " + "A column reference can have at most 3 parts and must have one of the following formats: " + "\"<column>\", \"<table>.<column>\" or \"<schema>.<table>.<column>\"");
}
boolean schemaMatched = false;
boolean tableNameMatched = false;
Symbol lastField = null;
for (var entry : sources.entrySet()) {
RelationName relName = entry.getKey();
String sourceSchema = relName.schema();
String sourceTableOrAlias = relName.name();
if (columnSchema != null && !columnSchema.equals(sourceSchema)) {
continue;
}
schemaMatched = true;
if (columnTableName != null && !sourceTableOrAlias.equals(columnTableName)) {
continue;
}
tableNameMatched = true;
AnalyzedRelation sourceRelation = entry.getValue();
Symbol newField = sourceRelation.getField(columnIdent, operation, errorOnUnknownObjectKey);
if (newField != null) {
if (lastField != null) {
if (errorOnUnknownObjectKey == false) {
/* ex) CREATE TABLE c1 (obj object as (x int));
* CREATE TABLE c2 (obj object as (y int));
* select obj['x'] from c1, c2;
* --> ambiguous because c2.obj['x'] is another candidate with errorOnUnknownObjectKey = false
*/
return resolveField(qualifiedName, path, operation, true);
}
throw new AmbiguousColumnException(columnIdent, newField);
}
lastField = newField;
}
}
if (lastField == null) {
if (!schemaMatched || !tableNameMatched) {
String schema = columnSchema == null ? defaultSchema : columnSchema;
raiseUnsupportedFeatureIfInParentScope(columnSchema, columnTableName, schema);
RelationName relationName = new RelationName(schema, columnTableName);
throw new RelationUnknown(relationName);
}
RelationName relationName = sources.entrySet().iterator().next().getKey();
throw new ColumnUnknownException(columnIdent.sqlFqn(), relationName);
}
return lastField;
}
use of io.crate.metadata.RelationName in project crate by crate.
the class FetchRewrite method createFetchSources.
public Map<RelationName, FetchSource> createFetchSources() {
HashMap<RelationName, FetchSource> fetchSources = new HashMap<>();
List<Symbol> outputs = plan.outputs();
for (int i = 0; i < outputs.size(); i++) {
Symbol output = outputs.get(i);
if (output instanceof FetchMarker) {
FetchMarker fetchMarker = (FetchMarker) output;
RelationName tableName = fetchMarker.fetchId().ident().tableIdent();
FetchSource fetchSource = fetchSources.get(tableName);
if (fetchSource == null) {
fetchSource = new FetchSource();
fetchSources.put(tableName, fetchSource);
}
fetchSource.addFetchIdColumn(new InputColumn(i, fetchMarker.valueType()));
for (Reference fetchRef : fetchMarker.fetchRefs()) {
fetchSource.addRefToFetch(fetchRef);
}
}
}
return fetchSources;
}
use of io.crate.metadata.RelationName in project crate by crate.
the class JoinOrdering method buildBestOrderByJoinConditions.
private static void buildBestOrderByJoinConditions(List<Set<RelationName>> sets, LinkedHashSet<RelationName> bestOrder) {
Iterator<Set<RelationName>> setsIterator = sets.iterator();
while (setsIterator.hasNext()) {
Set<RelationName> set = setsIterator.next();
for (RelationName name : set) {
if (bestOrder.contains(name)) {
bestOrder.addAll(set);
setsIterator.remove();
setsIterator = sets.iterator();
break;
}
}
}
// Add the rest of the relations to the end of the collection
sets.forEach(bestOrder::addAll);
}
use of io.crate.metadata.RelationName in project crate by crate.
the class JoinPlanBuilder method hasAdditionalDependencies.
private static boolean hasAdditionalDependencies(JoinPair joinPair) {
Symbol condition = joinPair.condition();
if (condition == null) {
return false;
}
boolean[] hasAdditionalDependencies = { false };
FieldsVisitor.visitFields(condition, scopedSymbol -> {
RelationName relation = scopedSymbol.relation();
if (!relation.equals(joinPair.left()) && !relation.equals(joinPair.right())) {
hasAdditionalDependencies[0] = true;
}
});
return hasAdditionalDependencies[0];
}
Aggregations