Search in sources :

Example 66 with RelationName

use of io.crate.metadata.RelationName 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)

Example 67 with RelationName

use of io.crate.metadata.RelationName in project crate by crate.

the class DocTableRelationTest method testUpdatingCompoundPrimaryKeyThrowsCorrectException.

@Test
public void testUpdatingCompoundPrimaryKeyThrowsCorrectException() {
    DocTableInfo tableInfo = SQLExecutor.tableInfo(new RelationName("doc", "t1"), "create table doc.t1 (i int, j int, primary key (i, j))", clusterService);
    DocTableRelation rel = new DocTableRelation(tableInfo);
    expectedException.expect(ColumnValidationException.class);
    expectedException.expectMessage("Validation failed for i: Updating a primary key is not supported");
    rel.ensureColumnCanBeUpdated(new ColumnIdent("i"));
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) DocTableInfo(io.crate.metadata.doc.DocTableInfo) RelationName(io.crate.metadata.RelationName) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 68 with RelationName

use of io.crate.metadata.RelationName in project crate by crate.

the class FieldProviderTest method testMultipleSourcesWithDynamicReferenceAndReference.

@Test
public void testMultipleSourcesWithDynamicReferenceAndReference() throws Exception {
    AnalyzedRelation barT = new DummyRelation(new RelationName("bar", "t"), "name");
    AnalyzedRelation fooT = new DummyRelation(new RelationName("foo", "t"), "name");
    AnalyzedRelation fooA = new DummyRelation(new RelationName("foo", "a"), "name");
    AnalyzedRelation customT = new DummyRelation(new RelationName("custom", "t"), "tags");
    FieldProvider<Symbol> resolver = newFQFieldProvider(Map.of(newQN("bar.t"), barT, newQN("foo.t"), fooT, newQN("foo.a"), fooA, newQN("custom.t"), customT));
    Symbol field = resolver.resolveField(newQN("foo.t.name"), null, Operation.READ, DEFAULT_ERROR_ON_UNKNOWN_OBJECT_KEY);
    assertThat(field, isField("name", fooT.relationName()));
    Symbol tags = resolver.resolveField(newQN("tags"), null, Operation.READ, DEFAULT_ERROR_ON_UNKNOWN_OBJECT_KEY);
    assertThat(tags, isField("tags", customT.relationName()));
    field = resolver.resolveField(newQN("a.name"), null, Operation.READ, DEFAULT_ERROR_ON_UNKNOWN_OBJECT_KEY);
    assertThat(field, isField("name", fooA.relationName()));
}
Also used : Symbol(io.crate.expression.symbol.Symbol) RelationName(io.crate.metadata.RelationName) DummyRelation(io.crate.testing.DummyRelation) Test(org.junit.Test)

Example 69 with RelationName

use of io.crate.metadata.RelationName in project crate by crate.

the class FieldProviderTest method testAliasRelationNameResolver.

@Test
public void testAliasRelationNameResolver() throws Exception {
    AnalyzedRelation barT = new DummyRelation(new RelationName("doc", "Bar"), "name");
    FieldProvider<Symbol> resolver = newFQFieldProvider(Map.of(newQN("\"Bar\""), barT));
    Symbol field = resolver.resolveField(newQN("\"Bar\".name"), null, Operation.READ, DEFAULT_ERROR_ON_UNKNOWN_OBJECT_KEY);
    assertThat(field, isField("name", barT.relationName()));
}
Also used : Symbol(io.crate.expression.symbol.Symbol) RelationName(io.crate.metadata.RelationName) DummyRelation(io.crate.testing.DummyRelation) Test(org.junit.Test)

Example 70 with RelationName

use of io.crate.metadata.RelationName in project crate by crate.

the class QuerySplitterTest method testSplitQueryWith3Relations.

@Test
public void testSplitQueryWith3Relations() throws Exception {
    Symbol symbol = asSymbol("t1.a = t2.b and t2.b = t3.c");
    Map<Set<RelationName>, Symbol> split = QuerySplitter.split(symbol);
    assertThat(split.size(), is(2));
    Symbol t1t2 = asSymbol("t1.a = t2.b");
    Symbol t2t3 = asSymbol("t2.b = t3.c");
    Set<RelationName> tr1AndTr2 = Set.of(tr1, tr2);
    assertThat(split.containsKey(tr1AndTr2), is(true));
    assertThat(split.get(tr1AndTr2), is(t1t2));
    Set<RelationName> tr2AndTr3 = Set.of(tr2, tr3);
    assertThat(split.containsKey(tr2AndTr3), is(true));
    assertThat(split.get(tr2AndTr3), is(t2t3));
}
Also used : Set(java.util.Set) Symbol(io.crate.expression.symbol.Symbol) RelationName(io.crate.metadata.RelationName) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Aggregations

RelationName (io.crate.metadata.RelationName)180 Test (org.junit.Test)100 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)55 PartitionName (io.crate.metadata.PartitionName)47 Symbol (io.crate.expression.symbol.Symbol)42 Reference (io.crate.metadata.Reference)37 ColumnIdent (io.crate.metadata.ColumnIdent)31 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)21 ReferenceIdent (io.crate.metadata.ReferenceIdent)21 DocTableInfo (io.crate.metadata.doc.DocTableInfo)21 Map (java.util.Map)20 HashMap (java.util.HashMap)19 SqlExpressions (io.crate.testing.SqlExpressions)18 ArrayList (java.util.ArrayList)18 List (java.util.List)17 Before (org.junit.Before)17 DocTableRelation (io.crate.analyze.relations.DocTableRelation)13 SQLExecutor (io.crate.testing.SQLExecutor)11 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)10 IndexTemplateMetadata (org.elasticsearch.cluster.metadata.IndexTemplateMetadata)10