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