Search in sources :

Example 1 with NodeStatsContext

use of io.crate.expression.reference.sys.node.NodeStatsContext in project crate by crate.

the class NodeStatsCollectSource method filterNodes.

static Collection<DiscoveryNode> filterNodes(Collection<DiscoveryNode> nodes, Symbol predicate, NodeContext nodeCtx) {
    var expressions = SysNodesTableInfo.create().expressions();
    var nameExpr = expressions.get(SysNodesTableInfo.Columns.NAME).create();
    var idExpr = expressions.get(SysNodesTableInfo.Columns.ID).create();
    MapBackedRefResolver referenceResolver = new MapBackedRefResolver(Map.of(SysNodesTableInfo.Columns.NAME, nameExpr, SysNodesTableInfo.Columns.ID, idExpr));
    EvaluatingNormalizer normalizer = new EvaluatingNormalizer(nodeCtx, RowGranularity.DOC, referenceResolver, null);
    List<DiscoveryNode> newNodes = new ArrayList<>();
    for (DiscoveryNode node : nodes) {
        String nodeId = node.getId();
        NodeStatsContext statsContext = new NodeStatsContext(nodeId, node.getName());
        nameExpr.setNextRow(statsContext);
        idExpr.setNextRow(statsContext);
        Symbol normalized = normalizer.normalize(predicate, CoordinatorTxnCtx.systemTransactionContext());
        if (normalized.equals(predicate)) {
            // No local available sys nodes columns in where clause
            return nodes;
        }
        if (WhereClause.canMatch(normalized)) {
            newNodes.add(node);
        }
    }
    return newNodes;
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) MapBackedRefResolver(io.crate.metadata.MapBackedRefResolver) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) Symbol(io.crate.expression.symbol.Symbol) ArrayList(java.util.ArrayList) NodeStatsContext(io.crate.expression.reference.sys.node.NodeStatsContext)

Aggregations

EvaluatingNormalizer (io.crate.expression.eval.EvaluatingNormalizer)1 NodeStatsContext (io.crate.expression.reference.sys.node.NodeStatsContext)1 Symbol (io.crate.expression.symbol.Symbol)1 MapBackedRefResolver (io.crate.metadata.MapBackedRefResolver)1 ArrayList (java.util.ArrayList)1 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)1