Search in sources :

Example 6 with DummyRelation

use of io.crate.testing.DummyRelation in project crate by crate.

the class FieldProviderTest method testSimpleFieldResolver.

@Test
public void testSimpleFieldResolver() throws Exception {
    // select name from doc.t
    AnalyzedRelation relation = new DummyRelation("name");
    FieldProvider<Field> resolver = new NameFieldProvider(relation);
    Field field = resolver.resolveField(new QualifiedName(Arrays.asList("name")), Operation.READ);
    assertThat(field.relation(), equalTo(relation));
}
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 7 with DummyRelation

use of io.crate.testing.DummyRelation in project crate by crate.

the class FieldProviderTest method testRelationOutputFromSingleColumnName.

@Test
public void testRelationOutputFromSingleColumnName() throws Exception {
    // select name from t
    AnalyzedRelation relation = new DummyRelation("name");
    FieldProvider<Field> resolver = new FullQualifedNameFieldProvider(ImmutableMap.of(newQN("doc.t"), relation));
    Field field = resolver.resolveField(newQN("name"), Operation.READ);
    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 8 with DummyRelation

use of io.crate.testing.DummyRelation in project crate by crate.

the class FieldProviderTest method testRelationFromTwoTables.

@Test
public void testRelationFromTwoTables() throws Exception {
    // select name from doc.t, custom.t
    FieldProvider<Field> resolver = new FullQualifedNameFieldProvider(ImmutableMap.<QualifiedName, AnalyzedRelation>of(new QualifiedName(Arrays.asList("custom", "t")), new DummyRelation("address"), 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 9 with DummyRelation

use of io.crate.testing.DummyRelation 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 10 with DummyRelation

use of io.crate.testing.DummyRelation 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)

Aggregations

DummyRelation (io.crate.testing.DummyRelation)12 Field (io.crate.analyze.symbol.Field)10 CrateUnitTest (io.crate.test.integration.CrateUnitTest)10 Test (org.junit.Test)10 QualifiedName (io.crate.sql.tree.QualifiedName)6 Before (org.junit.Before)2 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)1 SqlExpressions (io.crate.testing.SqlExpressions)1