Search in sources :

Example 1 with ValuesResolver

use of io.crate.analyze.ValuesResolver in project crate by crate.

the class ExcludedFieldProviderTest method testResolveFieldsAndValues.

@Test
public void testResolveFieldsAndValues() {
    QualifiedName normalField1 = QualifiedName.of("field1");
    QualifiedName normalField2 = QualifiedName.of("normal", "field2");
    QualifiedName excludedName = QualifiedName.of("excluded", "field3");
    FieldProvider<?> fieldProvider = (qualifiedName, path, operation, errorOnUnknownObjectKey) -> new ScopedSymbol(new RelationName("doc", "dummy"), new ColumnIdent(qualifiedName.toString()), DataTypes.INTEGER);
    ValuesResolver valuesResolver = argumentColumn -> {
        assertThat(argumentColumn, isField("field3"));
        return Literal.of(42);
    };
    ExcludedFieldProvider excludedFieldProvider = new ExcludedFieldProvider(fieldProvider, valuesResolver);
    assertThat(excludedFieldProvider.resolveField(normalField1, null, Operation.READ, DEFAULT_ERROR_ON_UNKNOWN_OBJECT_KEY), isField(normalField1.toString()));
    assertThat(excludedFieldProvider.resolveField(normalField2, null, Operation.READ, DEFAULT_ERROR_ON_UNKNOWN_OBJECT_KEY), isField(normalField2.toString()));
    assertThat(excludedFieldProvider.resolveField(excludedName, null, Operation.READ, DEFAULT_ERROR_ON_UNKNOWN_OBJECT_KEY), isLiteral(42));
}
Also used : Assert.assertThat(org.junit.Assert.assertThat) Literal(io.crate.expression.symbol.Literal) SymbolMatchers.isField(io.crate.testing.SymbolMatchers.isField) RelationName(io.crate.metadata.RelationName) DataTypes(io.crate.types.DataTypes) ColumnIdent(io.crate.metadata.ColumnIdent) ScopedSymbol(io.crate.expression.symbol.ScopedSymbol) ValuesResolver(io.crate.analyze.ValuesResolver) Test(org.junit.Test) Operation(io.crate.metadata.table.Operation) QualifiedName(io.crate.sql.tree.QualifiedName) SymbolMatchers.isLiteral(io.crate.testing.SymbolMatchers.isLiteral) ValuesResolver(io.crate.analyze.ValuesResolver) ColumnIdent(io.crate.metadata.ColumnIdent) QualifiedName(io.crate.sql.tree.QualifiedName) RelationName(io.crate.metadata.RelationName) ScopedSymbol(io.crate.expression.symbol.ScopedSymbol) Test(org.junit.Test)

Aggregations

ValuesResolver (io.crate.analyze.ValuesResolver)1 Literal (io.crate.expression.symbol.Literal)1 ScopedSymbol (io.crate.expression.symbol.ScopedSymbol)1 ColumnIdent (io.crate.metadata.ColumnIdent)1 RelationName (io.crate.metadata.RelationName)1 Operation (io.crate.metadata.table.Operation)1 QualifiedName (io.crate.sql.tree.QualifiedName)1 SymbolMatchers.isField (io.crate.testing.SymbolMatchers.isField)1 SymbolMatchers.isLiteral (io.crate.testing.SymbolMatchers.isLiteral)1 DataTypes (io.crate.types.DataTypes)1 Assert.assertThat (org.junit.Assert.assertThat)1 Test (org.junit.Test)1