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());
}
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());
}
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));
}
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));
}
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);
}
Aggregations