Search in sources :

Example 1 with MapBackedRefResolver

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

Example 2 with MapBackedRefResolver

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());
}
Also used : NestableInput(io.crate.expression.NestableInput) DocTableInfo(io.crate.metadata.doc.DocTableInfo) Reference(io.crate.metadata.Reference) ResourceUnknownException(io.crate.exceptions.ResourceUnknownException) ResourceUnknownException(io.crate.exceptions.ResourceUnknownException) UnhandledServerException(io.crate.exceptions.UnhandledServerException) PartitionName(io.crate.metadata.PartitionName) ColumnIdent(io.crate.metadata.ColumnIdent) MapBackedRefResolver(io.crate.metadata.MapBackedRefResolver) UnhandledServerException(io.crate.exceptions.UnhandledServerException) RelationName(io.crate.metadata.RelationName)

Example 3 with MapBackedRefResolver

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);
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) NestableInput(io.crate.expression.NestableInput) MapBackedRefResolver(io.crate.metadata.MapBackedRefResolver) HashMap(java.util.HashMap) Reference(io.crate.metadata.Reference) RelationName(io.crate.metadata.RelationName) ReferenceIdent(io.crate.metadata.ReferenceIdent) Before(org.junit.Before)

Aggregations

MapBackedRefResolver (io.crate.metadata.MapBackedRefResolver)3 NestableInput (io.crate.expression.NestableInput)2 ColumnIdent (io.crate.metadata.ColumnIdent)2 Reference (io.crate.metadata.Reference)2 RelationName (io.crate.metadata.RelationName)2 ResourceUnknownException (io.crate.exceptions.ResourceUnknownException)1 UnhandledServerException (io.crate.exceptions.UnhandledServerException)1 EvaluatingNormalizer (io.crate.expression.eval.EvaluatingNormalizer)1 NodeStatsContext (io.crate.expression.reference.sys.node.NodeStatsContext)1 Symbol (io.crate.expression.symbol.Symbol)1 PartitionName (io.crate.metadata.PartitionName)1 ReferenceIdent (io.crate.metadata.ReferenceIdent)1 DocTableInfo (io.crate.metadata.doc.DocTableInfo)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)1 Before (org.junit.Before)1