Search in sources :

Example 1 with SysNodesTableInfo

use of io.crate.metadata.sys.SysNodesTableInfo in project crate by crate.

the class SysNodesTableInfoTest method testRegistered.

/**
     *  Ensures that all columns registered in SysNodesTableInfo can actually be resolved
     */
@Test
public void testRegistered() {
    SysNodesTableInfo info = new SysNodesTableInfo(clusterService);
    RowContextReferenceResolver referenceResolver = RowContextReferenceResolver.INSTANCE;
    Iterator<Reference> iter = info.iterator();
    while (iter.hasNext()) {
        assertNotNull(referenceResolver.getImplementation(iter.next()));
    }
}
Also used : SysNodesTableInfo(io.crate.metadata.sys.SysNodesTableInfo) RowContextReferenceResolver(io.crate.operation.reference.sys.RowContextReferenceResolver) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 2 with SysNodesTableInfo

use of io.crate.metadata.sys.SysNodesTableInfo 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)

Aggregations

SysNodesTableInfo (io.crate.metadata.sys.SysNodesTableInfo)2 WhereClause (io.crate.analyze.WhereClause)1 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)1 TableRelation (io.crate.analyze.relations.TableRelation)1 RowContextReferenceResolver (io.crate.operation.reference.sys.RowContextReferenceResolver)1 QualifiedName (io.crate.sql.tree.QualifiedName)1 CrateUnitTest (io.crate.test.integration.CrateUnitTest)1 SqlExpressions (io.crate.testing.SqlExpressions)1 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)1 Test (org.junit.Test)1