Search in sources :

Example 1 with Field

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

the class ExpressionAnalyzerTest method testInSelfJoinCaseFunctionsThatLookTheSameMustNotReuseFunctionAllocation.

@Test
public void testInSelfJoinCaseFunctionsThatLookTheSameMustNotReuseFunctionAllocation() throws Exception {
    TableInfo tableInfo = mock(TableInfo.class);
    when(tableInfo.getReference(new ColumnIdent("id"))).thenReturn(new Reference(new ReferenceIdent(new TableIdent("doc", "t"), "id"), RowGranularity.DOC, DataTypes.INTEGER));
    when(tableInfo.ident()).thenReturn(new TableIdent("doc", "t"));
    TableRelation tr1 = new TableRelation(tableInfo);
    TableRelation tr2 = new TableRelation(tableInfo);
    Map<QualifiedName, AnalyzedRelation> sources = ImmutableMap.of(new QualifiedName("t1"), tr1, new QualifiedName("t2"), tr2);
    ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(functions, SessionContext.SYSTEM_SESSION, paramTypeHints, new FullQualifedNameFieldProvider(sources), null);
    Function andFunction = (Function) expressionAnalyzer.convert(SqlParser.createExpression("not t1.id = 1 and not t2.id = 1"), context);
    Field t1Id = ((Field) ((Function) ((Function) andFunction.arguments().get(0)).arguments().get(0)).arguments().get(0));
    Field t2Id = ((Field) ((Function) ((Function) andFunction.arguments().get(1)).arguments().get(0)).arguments().get(0));
    assertTrue(t1Id.relation() != t2Id.relation());
}
Also used : AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) TableRelation(io.crate.analyze.relations.TableRelation) Function(io.crate.analyze.symbol.Function) SymbolMatchers.isField(io.crate.testing.SymbolMatchers.isField) Field(io.crate.analyze.symbol.Field) TableInfo(io.crate.metadata.table.TableInfo) FullQualifedNameFieldProvider(io.crate.analyze.relations.FullQualifedNameFieldProvider) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 2 with Field

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

the class ExpressionAnalyzerTest method testQuotedSubscriptExpression.

@Test
public void testQuotedSubscriptExpression() throws Exception {
    ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(functions, new SessionContext(0, EnumSet.of(Option.ALLOW_QUOTED_SUBSCRIPT), null), paramTypeHints, new FullQualifedNameFieldProvider(dummySources), null);
    ExpressionAnalysisContext expressionAnalysisContext = new ExpressionAnalysisContext();
    Field field1 = (Field) expressionAnalyzer.convert(SqlParser.createExpression("obj['x']"), expressionAnalysisContext);
    Field field2 = (Field) expressionAnalyzer.convert(SqlParser.createExpression("\"obj['x']\""), expressionAnalysisContext);
    assertEquals(field1, field2);
    Field field3 = (Field) expressionAnalyzer.convert(SqlParser.createExpression("\"myObj['x']\""), expressionAnalysisContext);
    assertEquals("myObj['x']", field3.path().toString());
    Field field4 = (Field) expressionAnalyzer.convert(SqlParser.createExpression("\"myObj['x']['AbC']\""), expressionAnalysisContext);
    assertEquals("myObj['x']['AbC']", field4.path().toString());
}
Also used : SymbolMatchers.isField(io.crate.testing.SymbolMatchers.isField) Field(io.crate.analyze.symbol.Field) SessionContext(io.crate.action.sql.SessionContext) FullQualifedNameFieldProvider(io.crate.analyze.relations.FullQualifedNameFieldProvider) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 3 with Field

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

the class FieldProviderTest method testMultipleSourcesWithDynamicReferenceAndReference.

@Test
public void testMultipleSourcesWithDynamicReferenceAndReference() throws Exception {
    AnalyzedRelation barT = new DummyRelation("name");
    AnalyzedRelation fooT = new DummyRelation("name");
    AnalyzedRelation fooA = new DummyRelation("name");
    AnalyzedRelation customT = new DummyRelation("tags");
    FieldProvider<Field> resolver = new FullQualifedNameFieldProvider(ImmutableMap.of(newQN("bar.t"), barT, newQN("foo.t"), fooT, newQN("foo.a"), fooA, newQN("custom.t"), customT));
    Field field = resolver.resolveField(newQN("foo.t.name"), Operation.READ);
    assertThat(field.relation(), equalTo(fooT));
    // reference > dynamicReference - not ambiguous
    Field tags = resolver.resolveField(newQN("tags"), Operation.READ);
    assertThat(tags.relation(), equalTo(customT));
    field = resolver.resolveField(newQN("a.name"), Operation.READ);
    assertThat(field.relation(), equalTo(fooA));
}
Also used : Field(io.crate.analyze.symbol.Field) DummyRelation(io.crate.testing.DummyRelation) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 4 with Field

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

the class FieldProviderTest method testAliasRelationNameResolver.

@Test
public void testAliasRelationNameResolver() throws Exception {
    AnalyzedRelation barT = new DummyRelation("name");
    FieldProvider<Field> resolver = new FullQualifedNameFieldProvider(ImmutableMap.of(newQN("\"Bar\""), barT));
    Field field = resolver.resolveField(newQN("\"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 5 with Field

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

the class FieldProviderTest method testSimpleResolverUnknownColumn.

@Test
public void testSimpleResolverUnknownColumn() throws Exception {
    expectedException.expect(ColumnUnknownException.class);
    expectedException.expectMessage("Column unknown unknown");
    AnalyzedRelation relation = new DummyRelation("name");
    FieldProvider<Field> resolver = new FullQualifedNameFieldProvider(ImmutableMap.of(newQN("doc.t"), relation));
    resolver.resolveField(new QualifiedName(Arrays.asList("unknown")), 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

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