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