Search in sources :

Example 16 with Field

use of io.crate.analyze.symbol.Field in project crate by crate.

the class FieldProviderTest method testColumnSchemaResolver.

@Test
public void testColumnSchemaResolver() throws Exception {
    AnalyzedRelation barT = new DummyRelation("\"Name\"");
    FieldProvider<Field> resolver = new FullQualifedNameFieldProvider(ImmutableMap.of(newQN("\"Bar\""), barT));
    Field field = resolver.resolveField(newQN("\"Foo\".\"Bar\".\"Name\""), Operation.READ);
    assertThat(field.relation(), equalTo(barT));
}
Also used : Field(io.crate.analyze.symbol.Field) DummyRelation(io.crate.testing.DummyRelation) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 17 with Field

use of io.crate.analyze.symbol.Field in project crate by crate.

the class FieldProviderTest method testRelationFromTwoTablesWithSameNameDifferentSchemaIsAmbiguous.

@Test
public void testRelationFromTwoTablesWithSameNameDifferentSchemaIsAmbiguous() throws Exception {
    // select t.name from custom.t.name, doc.t.name
    expectedException.expect(AmbiguousColumnException.class);
    expectedException.expectMessage("Column \"name\" is ambiguous");
    FieldProvider<Field> resolver = new FullQualifedNameFieldProvider(ImmutableMap.<QualifiedName, AnalyzedRelation>of(new QualifiedName(Arrays.asList("custom", "t")), new DummyRelation("name"), new QualifiedName(Arrays.asList("doc", "t")), new DummyRelation("name")));
    resolver.resolveField(new QualifiedName(Arrays.asList("t", "name")), Operation.READ);
}
Also used : Field(io.crate.analyze.symbol.Field) QualifiedName(io.crate.sql.tree.QualifiedName) DummyRelation(io.crate.testing.DummyRelation) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 18 with Field

use of io.crate.analyze.symbol.Field in project crate by crate.

the class FieldProviderTest method testRelationOutputFromAlias.

@Test
public void testRelationOutputFromAlias() throws Exception {
    // t.name from doc.foo t
    AnalyzedRelation relation = new DummyRelation("name");
    FieldProvider<Field> resolver = new FullQualifedNameFieldProvider(ImmutableMap.of(new QualifiedName(Arrays.asList("t")), relation));
    Field field = resolver.resolveField(newQN("t.name"), Operation.READ);
    assertThat(field.relation(), equalTo(relation));
    assertThat(field.path().outputName(), is("name"));
}
Also used : Field(io.crate.analyze.symbol.Field) QualifiedName(io.crate.sql.tree.QualifiedName) DummyRelation(io.crate.testing.DummyRelation) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 19 with Field

use of io.crate.analyze.symbol.Field in project crate by crate.

the class FieldProviderTest method testRelationOutputFromSchemaTableColumnName.

@Test
public void testRelationOutputFromSchemaTableColumnName() throws Exception {
    // doc.t.name from t.name
    AnalyzedRelation relation = new DummyRelation("name");
    FieldProvider<Field> resolver = new FullQualifedNameFieldProvider(ImmutableMap.of(newQN("doc.t"), relation));
    Field field = resolver.resolveField(newQN("doc.t.name"), Operation.INSERT);
    assertThat(field.relation(), equalTo(relation));
    assertThat(field.path().outputName(), is("name"));
}
Also used : Field(io.crate.analyze.symbol.Field) DummyRelation(io.crate.testing.DummyRelation) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 20 with Field

use of io.crate.analyze.symbol.Field in project crate by crate.

the class FieldProviderTest method testTooManyParts.

@Test
public void testTooManyParts() throws Exception {
    expectedException.expect(IllegalArgumentException.class);
    FieldProvider<Field> resolver = new FullQualifedNameFieldProvider(dummySources);
    resolver.resolveField(new QualifiedName(Arrays.asList("a", "b", "c", "d")), Operation.READ);
}
Also used : Field(io.crate.analyze.symbol.Field) QualifiedName(io.crate.sql.tree.QualifiedName) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

Field (io.crate.analyze.symbol.Field)24 CrateUnitTest (io.crate.test.integration.CrateUnitTest)14 Test (org.junit.Test)14 DummyRelation (io.crate.testing.DummyRelation)10 QualifiedName (io.crate.sql.tree.QualifiedName)8 Symbol (io.crate.analyze.symbol.Symbol)3 FullQualifedNameFieldProvider (io.crate.analyze.relations.FullQualifedNameFieldProvider)2 Function (io.crate.analyze.symbol.Function)2 ColumnUnknownException (io.crate.exceptions.ColumnUnknownException)2 ColumnIdent (io.crate.metadata.ColumnIdent)2 SymbolMatchers.isField (io.crate.testing.SymbolMatchers.isField)2 SessionContext (io.crate.action.sql.SessionContext)1 Analysis (io.crate.analyze.Analysis)1 QuerySpec (io.crate.analyze.QuerySpec)1 RelationSource (io.crate.analyze.RelationSource)1 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)1 TableRelation (io.crate.analyze.relations.TableRelation)1 AmbiguousColumnException (io.crate.exceptions.AmbiguousColumnException)1 TableInfo (io.crate.metadata.table.TableInfo)1 PGType (io.crate.protocols.postgres.types.PGType)1