use of io.crate.metadata.MapBackedRefResolver 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;
}
use of io.crate.metadata.MapBackedRefResolver in project crate by crate.
the class ShardReferenceResolver method createPartitionColumnResolver.
private static ReferenceResolver<NestableInput<?>> createPartitionColumnResolver(Index index, Schemas schemas) {
PartitionName partitionName;
try {
partitionName = PartitionName.fromIndexOrTemplate(index.getName());
} catch (IllegalArgumentException e) {
throw new UnhandledServerException(String.format(Locale.ENGLISH, "Unable to load PARTITIONED BY columns from partition %s", index.getName()), e);
}
RelationName relationName = partitionName.relationName();
MapBuilder<ColumnIdent, NestableInput> builder = MapBuilder.newMapBuilder();
try {
DocTableInfo info = schemas.getTableInfo(relationName);
assert info.isPartitioned() : "table must be partitioned";
int i = 0;
int numPartitionedColumns = info.partitionedByColumns().size();
List<String> partitionValue = partitionName.values();
assert partitionValue.size() == numPartitionedColumns : "invalid number of partitioned columns";
for (Reference partitionedInfo : info.partitionedByColumns()) {
builder.put(partitionedInfo.column(), constant(partitionedInfo.valueType().implicitCast(partitionValue.get(i))));
i++;
}
} catch (Exception e) {
if (e instanceof ResourceUnknownException) {
LOGGER.error("Orphaned partition '{}' with missing table '{}' found", index, relationName.fqn());
} else {
throw e;
}
}
return new MapBackedRefResolver(builder.immutableMap());
}
use of io.crate.metadata.MapBackedRefResolver in project crate by crate.
the class EvaluatingNormalizerTest method prepare.
@Before
public void prepare() throws Exception {
Map<ColumnIdent, NestableInput> referenceImplementationMap = new HashMap<>(1, 1);
ReferenceIdent dummyLoadIdent = new ReferenceIdent(new RelationName("test", "dummy"), "load");
dummyLoadInfo = new Reference(dummyLoadIdent, RowGranularity.NODE, DataTypes.DOUBLE, 0, null);
referenceImplementationMap.put(dummyLoadIdent.columnIdent(), constant(0.08d));
nodeCtx = createNodeContext();
referenceResolver = new MapBackedRefResolver(referenceImplementationMap);
}
Aggregations