use of org.apache.calcite.rel.metadata.UnboundMetadata in project calcite by apache.
the class HepRelMetadataProvider method apply.
public <M extends Metadata> UnboundMetadata<M> apply(Class<? extends RelNode> relClass, final Class<? extends M> metadataClass) {
return new UnboundMetadata<M>() {
public M bind(RelNode rel, RelMetadataQuery mq) {
if (!(rel instanceof HepRelVertex)) {
return null;
}
HepRelVertex vertex = (HepRelVertex) rel;
final RelNode rel2 = vertex.getCurrentRel();
UnboundMetadata<M> function = rel.getCluster().getMetadataProvider().apply(rel2.getClass(), metadataClass);
return function.bind(rel2, mq);
}
};
}
use of org.apache.calcite.rel.metadata.UnboundMetadata in project calcite by apache.
the class VolcanoRelMetadataProvider method apply.
public <M extends Metadata> UnboundMetadata<M> apply(Class<? extends RelNode> relClass, final Class<? extends M> metadataClass) {
if (relClass != RelSubset.class) {
// let someone else further down the chain sort it out
return null;
}
return new UnboundMetadata<M>() {
public M bind(RelNode rel, RelMetadataQuery mq) {
final RelSubset subset = (RelSubset) rel;
final RelMetadataProvider provider = rel.getCluster().getMetadataProvider();
// this query, treat it as the most reliable.
if (subset.best != null) {
final UnboundMetadata<M> function = provider.apply(subset.best.getClass(), metadataClass);
if (function != null) {
final M metadata = function.bind(subset.best, mq);
if (metadata != null) {
return metadata;
}
}
}
// granularity).
if (subset.set.inMetadataQuery) {
return null;
}
subset.set.inMetadataQuery = true;
try {
for (RelNode relCandidate : subset.set.rels) {
final UnboundMetadata<M> function = provider.apply(relCandidate.getClass(), metadataClass);
if (function != null) {
final M result = function.bind(relCandidate, mq);
if (result != null) {
return result;
}
}
}
} finally {
subset.set.inMetadataQuery = false;
}
// Give up.
return null;
}
};
}
Aggregations