use of io.crate.expression.symbol.VoidReference in project crate by crate.
the class AnalyzedView method getField.
@Override
public Symbol getField(ColumnIdent column, Operation operation, boolean errorOnUnknownObjectKey) throws AmbiguousColumnException, ColumnUnknownException, UnsupportedOperationException {
Symbol field = relation.getField(column, operation, errorOnUnknownObjectKey);
if (field == null || field instanceof VoidReference) {
return field;
}
ScopedSymbol scopedSymbol = new ScopedSymbol(name, column, field.valueType());
int i = outputSymbols.indexOf(scopedSymbol);
if (i >= 0) {
return outputSymbols.get(i);
}
return scopedSymbol;
}
use of io.crate.expression.symbol.VoidReference in project crate by crate.
the class SymbolPrinterTest method testVoidReference.
@Test
public void testVoidReference() throws Exception {
Reference r = new VoidReference(new ReferenceIdent(new RelationName("schema", "table"), new ColumnIdent("column", Arrays.asList("path", "nested"))), RowGranularity.DOC, 0);
assertPrint(r, "schema.\"table\".\"column\"['path']['nested']");
}
use of io.crate.expression.symbol.VoidReference in project crate by crate.
the class AliasedAnalyzedRelation method getField.
@Override
public Symbol getField(ColumnIdent column, Operation operation, boolean errorOnUnknownObjectKey) throws AmbiguousColumnException, ColumnUnknownException, UnsupportedOperationException {
if (operation != Operation.READ) {
throw new UnsupportedOperationException(operation + " is not supported on " + alias);
}
ColumnIdent childColumnName = aliasToColumnMapping.get(column);
if (childColumnName == null) {
if (column.isTopLevel()) {
return null;
}
childColumnName = aliasToColumnMapping.get(column.getRoot());
if (childColumnName == null) {
// The column ident maybe a quoted subscript which points to an alias of a sub relation.
// Aliases are always strings but due to the support for quoted subscript expressions,
// the select column ident may already be expanded to a subscript.
var maybeQuotedSubscriptColumnAlias = new ColumnIdent(column.sqlFqn());
childColumnName = aliasToColumnMapping.get(maybeQuotedSubscriptColumnAlias);
if (childColumnName == null) {
return null;
}
column = maybeQuotedSubscriptColumnAlias;
} else {
childColumnName = new ColumnIdent(childColumnName.name(), column.path());
}
}
Symbol field = relation.getField(childColumnName, operation, errorOnUnknownObjectKey);
if (field == null || field instanceof VoidReference) {
return field;
}
ScopedSymbol scopedSymbol = new ScopedSymbol(alias, column, field.valueType());
// If the scopedSymbol exists already, return that instance.
// Otherwise (e.g. lazy-loaded subscript expression) it must be stored to comply with
// IdentityHashMap constraints.
int i = scopedSymbols.indexOf(scopedSymbol);
if (i >= 0) {
return scopedSymbols.get(i);
}
scopedSymbols.add(scopedSymbol);
return scopedSymbol;
}
use of io.crate.expression.symbol.VoidReference in project crate by crate.
the class DocTableInfo method getDynamic.
@Nullable
public DynamicReference getDynamic(ColumnIdent ident, boolean forWrite, boolean errorOnUnknownObjectKey) {
boolean parentIsIgnored = false;
ColumnPolicy parentPolicy = columnPolicy();
int position = 0;
if (!ident.isTopLevel()) {
// see if parent is strict object
ColumnIdent parentIdent = ident.getParent();
Reference parentInfo = null;
while (parentIdent != null) {
parentInfo = getReference(parentIdent);
if (parentInfo != null) {
break;
}
parentIdent = parentIdent.getParent();
}
if (parentInfo != null) {
parentPolicy = parentInfo.columnPolicy();
position = parentInfo.position();
}
}
switch(parentPolicy) {
case DYNAMIC:
if (!forWrite) {
if (!errorOnUnknownObjectKey) {
return new VoidReference(new ReferenceIdent(ident(), ident), rowGranularity(), position);
}
return null;
}
break;
case STRICT:
if (forWrite) {
throw new ColumnUnknownException(ident.sqlFqn(), ident());
}
return null;
case IGNORED:
parentIsIgnored = true;
break;
default:
break;
}
if (parentIsIgnored) {
return new DynamicReference(new ReferenceIdent(ident(), ident), rowGranularity(), ColumnPolicy.IGNORED, position);
}
return new DynamicReference(new ReferenceIdent(ident(), ident), rowGranularity(), position);
}
use of io.crate.expression.symbol.VoidReference in project crate by crate.
the class DocTableInfoTest method testGetColumnInfo.
@Test
public void testGetColumnInfo() throws Exception {
RelationName relationName = new RelationName(Schemas.DOC_SCHEMA_NAME, "dummy");
DocTableInfo info = new DocTableInfo(relationName, List.of(new Reference(new ReferenceIdent(relationName, new ColumnIdent("o", List.of())), RowGranularity.DOC, DataTypes.UNTYPED_OBJECT, 1, null)), List.of(), List.of(), List.of(), Map.of(), Map.of(), Map.of(), List.of(), List.of(), null, true, new String[0], new String[0], new IndexNameExpressionResolver(), 5, "0", Settings.EMPTY, List.of(), List.of(), ColumnPolicy.DYNAMIC, Version.CURRENT, null, false, Operation.ALL);
final ColumnIdent col = new ColumnIdent("o", List.of("foobar"));
Reference foobar = info.getReference(col);
assertNull(foobar);
// forWrite: false, errorOnUnknownObjectKey: true, parentPolicy: dynamic
DynamicReference reference = info.getDynamic(col, false, true);
assertNull(reference);
// forWrite: true, errorOnUnknownObjectKey: true, parentPolicy: dynamic
reference = info.getDynamic(col, true, true);
assertNotNull(reference);
assertSame(reference.valueType(), DataTypes.UNDEFINED);
// forWrite: true, errorOnUnknownObjectKey: false, parentPolicy: dynamic
reference = info.getDynamic(col, true, false);
assertNotNull(reference);
assertSame(reference.valueType(), DataTypes.UNDEFINED);
// forWrite: false, errorOnUnknownObjectKey: false, parentPolicy: dynamic
reference = info.getDynamic(col, false, false);
assertNotNull(reference);
assertTrue(reference instanceof VoidReference);
assertSame(reference.valueType(), DataTypes.UNDEFINED);
}
Aggregations