Search in sources :

Example 6 with QualifiedName

use of io.crate.sql.tree.QualifiedName in project crate by crate.

the class NodeStatsCollectSourceTest method filterNodes.

private List<DiscoveryNode> filterNodes(String where) throws NoSuchFieldException, IllegalAccessException {
    // build where clause with id = ?
    SysNodesTableInfo tableInfo = mock(SysNodesTableInfo.class);
    when(tableInfo.ident()).thenReturn(new TableIdent("sys", "nodes"));
    when(tableInfo.getReference(new ColumnIdent("id"))).thenReturn(new Reference(new ReferenceIdent(new TableIdent("sys", "nodes"), "id"), RowGranularity.DOC, DataTypes.STRING));
    when(tableInfo.getReference(SysNodesTableInfo.Columns.NAME)).thenReturn(new Reference(new ReferenceIdent(SysNodesTableInfo.IDENT, SysNodesTableInfo.Columns.NAME), RowGranularity.DOC, DataTypes.STRING));
    when(tableInfo.getReference(SysNodesTableInfo.Columns.HOSTNAME)).thenReturn(new Reference(new ReferenceIdent(SysNodesTableInfo.IDENT, SysNodesTableInfo.Columns.HOSTNAME), RowGranularity.DOC, DataTypes.STRING));
    TableRelation tableRelation = new TableRelation(tableInfo);
    Map<QualifiedName, AnalyzedRelation> tableSources = ImmutableMap.<QualifiedName, AnalyzedRelation>of(new QualifiedName("sys.nodes"), tableRelation);
    SqlExpressions sqlExpressions = new SqlExpressions(tableSources, tableRelation);
    WhereClause whereClause = new WhereClause(sqlExpressions.normalize(sqlExpressions.asSymbol(where)));
    List<DiscoveryNode> nodes = Lists.newArrayList(NodeStatsCollectSource.nodeIds(whereClause, discoveryNodes, getFunctions()));
    Collections.sort(nodes, new Comparator<DiscoveryNode>() {

        @Override
        public int compare(DiscoveryNode o1, DiscoveryNode o2) {
            return o1.getId().compareTo(o2.getId());
        }
    });
    return nodes;
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) SysNodesTableInfo(io.crate.metadata.sys.SysNodesTableInfo) QualifiedName(io.crate.sql.tree.QualifiedName) WhereClause(io.crate.analyze.WhereClause) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) TableRelation(io.crate.analyze.relations.TableRelation) SqlExpressions(io.crate.testing.SqlExpressions)

Example 7 with QualifiedName

use of io.crate.sql.tree.QualifiedName 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)

Example 8 with QualifiedName

use of io.crate.sql.tree.QualifiedName 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 9 with QualifiedName

use of io.crate.sql.tree.QualifiedName in project crate by crate.

the class FieldProviderTest method testTooManyPartsNameFieldResolver.

@Test
public void testTooManyPartsNameFieldResolver() throws Exception {
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("Column reference \"a.b\" has too many parts. A column must not have a schema or a table here.");
    FieldProvider<Field> resolver = new NameFieldProvider(dummyRelation);
    resolver.resolveField(new QualifiedName(Arrays.asList("a", "b")), 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)

Example 10 with QualifiedName

use of io.crate.sql.tree.QualifiedName 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<QualifiedName>, 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<QualifiedName> tr1AndTr2 = Sets.newHashSet(tr1, tr2);
    assertThat(split.containsKey(tr1AndTr2), is(true));
    assertThat(split.get(tr1AndTr2), is(t1t2));
    Set<QualifiedName> tr2AndTr3 = Sets.newHashSet(tr2, tr3);
    assertThat(split.containsKey(tr2AndTr3), is(true));
    assertThat(split.get(tr2AndTr3), is(t2t3));
}
Also used : Set(java.util.Set) Symbol(io.crate.analyze.symbol.Symbol) QualifiedName(io.crate.sql.tree.QualifiedName) Test(org.junit.Test)

Aggregations

QualifiedName (io.crate.sql.tree.QualifiedName)28 Test (org.junit.Test)15 CrateUnitTest (io.crate.test.integration.CrateUnitTest)12 Field (io.crate.analyze.symbol.Field)8 SqlExpressions (io.crate.testing.SqlExpressions)7 DocTableInfo (io.crate.metadata.doc.DocTableInfo)6 DummyRelation (io.crate.testing.DummyRelation)6 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)5 TableRelation (io.crate.analyze.relations.TableRelation)5 WhereClause (io.crate.analyze.WhereClause)4 TableIdent (io.crate.metadata.TableIdent)4 Before (org.junit.Before)4 ArrayType (io.crate.types.ArrayType)3 DocTableRelation (io.crate.analyze.relations.DocTableRelation)2 JoinPair (io.crate.analyze.relations.JoinPair)2 Symbol (io.crate.analyze.symbol.Symbol)2 PartitionName (io.crate.metadata.PartitionName)2 TableInfo (io.crate.metadata.table.TableInfo)2 Set (java.util.Set)2 Nullable (javax.annotation.Nullable)2