Search in sources :

Example 1 with VoidReference

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;
}
Also used : VoidReference(io.crate.expression.symbol.VoidReference) Symbol(io.crate.expression.symbol.Symbol) ScopedSymbol(io.crate.expression.symbol.ScopedSymbol) ScopedSymbol(io.crate.expression.symbol.ScopedSymbol)

Example 2 with VoidReference

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']");
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) VoidReference(io.crate.expression.symbol.VoidReference) DynamicReference(io.crate.expression.symbol.DynamicReference) FetchReference(io.crate.expression.symbol.FetchReference) Reference(io.crate.metadata.Reference) SymbolMatchers.isReference(io.crate.testing.SymbolMatchers.isReference) VoidReference(io.crate.expression.symbol.VoidReference) RelationName(io.crate.metadata.RelationName) ReferenceIdent(io.crate.metadata.ReferenceIdent) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 3 with VoidReference

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;
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) VoidReference(io.crate.expression.symbol.VoidReference) Symbol(io.crate.expression.symbol.Symbol) ScopedSymbol(io.crate.expression.symbol.ScopedSymbol) ScopedSymbol(io.crate.expression.symbol.ScopedSymbol)

Example 4 with VoidReference

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);
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) ColumnPolicy(io.crate.sql.tree.ColumnPolicy) VoidReference(io.crate.expression.symbol.VoidReference) ColumnUnknownException(io.crate.exceptions.ColumnUnknownException) IndexReference(io.crate.metadata.IndexReference) DynamicReference(io.crate.expression.symbol.DynamicReference) GeneratedReference(io.crate.metadata.GeneratedReference) Reference(io.crate.metadata.Reference) VoidReference(io.crate.expression.symbol.VoidReference) DynamicReference(io.crate.expression.symbol.DynamicReference) CheckConstraint(io.crate.sql.tree.CheckConstraint) ReferenceIdent(io.crate.metadata.ReferenceIdent) Nullable(javax.annotation.Nullable)

Example 5 with VoidReference

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);
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) VoidReference(io.crate.expression.symbol.VoidReference) Reference(io.crate.metadata.Reference) DynamicReference(io.crate.expression.symbol.DynamicReference) VoidReference(io.crate.expression.symbol.VoidReference) DynamicReference(io.crate.expression.symbol.DynamicReference) RelationName(io.crate.metadata.RelationName) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) ReferenceIdent(io.crate.metadata.ReferenceIdent) Test(org.junit.Test)

Aggregations

VoidReference (io.crate.expression.symbol.VoidReference)5 ColumnIdent (io.crate.metadata.ColumnIdent)4 DynamicReference (io.crate.expression.symbol.DynamicReference)3 Reference (io.crate.metadata.Reference)3 ReferenceIdent (io.crate.metadata.ReferenceIdent)3 ScopedSymbol (io.crate.expression.symbol.ScopedSymbol)2 Symbol (io.crate.expression.symbol.Symbol)2 RelationName (io.crate.metadata.RelationName)2 Test (org.junit.Test)2 ColumnUnknownException (io.crate.exceptions.ColumnUnknownException)1 FetchReference (io.crate.expression.symbol.FetchReference)1 GeneratedReference (io.crate.metadata.GeneratedReference)1 IndexReference (io.crate.metadata.IndexReference)1 CheckConstraint (io.crate.sql.tree.CheckConstraint)1 ColumnPolicy (io.crate.sql.tree.ColumnPolicy)1 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)1 SymbolMatchers.isReference (io.crate.testing.SymbolMatchers.isReference)1 Nullable (javax.annotation.Nullable)1 IndexNameExpressionResolver (org.elasticsearch.cluster.metadata.IndexNameExpressionResolver)1