use of io.crate.analyze.symbol.Field in project crate by crate.
the class FetchFieldExtractor method process.
public static Set<Field> process(List<Symbol> symbols, Multimap<AnalyzedRelation, Symbol> subOutputs) {
HashSet<Field> canBeFetched = new HashSet<>();
Context ctx = new Context(subOutputs, canBeFetched);
for (Symbol symbol : symbols) {
FieldVisitor.INSTANCE.process(symbol, ctx);
}
return canBeFetched;
}
use of io.crate.analyze.symbol.Field in project crate by crate.
the class FullQualifedNameFieldProvider method resolveField.
public Field resolveField(QualifiedName qualifiedName, @Nullable List<String> path, Operation operation) {
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;
Field lastField = null;
for (Map.Entry<QualifiedName, AnalyzedRelation> entry : sources.entrySet()) {
List<String> sourceParts = entry.getKey().getParts();
String sourceSchema = null;
String sourceTableOrAlias;
if (sourceParts.size() == 1) {
sourceTableOrAlias = sourceParts.get(0);
} else if (sourceParts.size() == 2) {
sourceSchema = sourceParts.get(0);
sourceTableOrAlias = sourceParts.get(1);
} else {
throw new UnsupportedOperationException(String.format(Locale.ENGLISH, "sources key (QualifiedName) must have 1 or 2 parts, not %d", sourceParts.size()));
}
AnalyzedRelation sourceRelation = entry.getValue();
if (columnSchema != null && sourceSchema != null && !columnSchema.equals(sourceSchema)) {
continue;
}
schemaMatched = true;
if (columnTableName != null && !sourceTableOrAlias.equals(columnTableName)) {
continue;
}
tableNameMatched = true;
Field newField = sourceRelation.getField(columnIdent, operation);
if (newField != null) {
if (lastField != null) {
throw new AmbiguousColumnException(columnIdent);
}
lastField = newField;
}
}
if (lastField == null) {
if (!schemaMatched || !tableNameMatched) {
throw RelationUnknownException.of(columnSchema, columnTableName);
}
throw new ColumnUnknownException(columnIdent.sqlFqn());
}
return lastField;
}
use of io.crate.analyze.symbol.Field in project crate by crate.
the class NameFieldProvider method resolveField.
public Field resolveField(QualifiedName qualifiedName, @Nullable List<String> path, Operation operation) {
List<String> parts = qualifiedName.getParts();
ColumnIdent columnIdent = new ColumnIdent(parts.get(parts.size() - 1), path);
if (parts.size() != 1) {
throw new IllegalArgumentException(String.format(Locale.ENGLISH, "Column reference \"%s\" has too many parts. " + "A column must not have a schema or a table here.", qualifiedName));
}
Field field = relation.getField(columnIdent, operation);
if (field == null) {
throw new ColumnUnknownException(columnIdent.sqlFqn());
}
return field;
}
use of io.crate.analyze.symbol.Field in project crate by crate.
the class ResultToXContentBuilder method colTypes.
ResultToXContentBuilder colTypes(List<Field> fields) throws IOException {
builder.startArray(FIELDS.COLUMN_TYPES);
for (Field field : fields) {
toXContentNestedDataType(builder, field.valueType());
}
builder.endArray();
return this;
}
Aggregations