calcite-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yuzhao Chen <yuzhao....@gmail.com>
Subject [DISCUSSION] Extension of Metadata Query
Date Mon, 03 Jun 2019 06:19:25 GMT
Currently we provide answer to metadata query through RelMetadataProvider [1], there are some
sub-classes of it:

RelMetadataProvider
|
|- VolcanoRelMetadataProvider
|- ChainedRelMetadataProvider/DefaultRelMetadataProvider
|- HepRelMetadataProvider
|- CachingRelMetadataProvider
|- ReflectiveRelMetadataProvider
|- JaninoRelMetadataProvider

The RelMetadataProvider has two methods: #apply and #handlers, the #apply method seems a programming
interface and there is a demo code how we can use it:

RelMetadataProvider provider;
LogicalFilter filter;
RexNode predicate;
Function<RelNode, Metadata> function =
provider.apply(LogicalFilter.class, Selectivity.class};
Selectivity selectivity = function.apply(filter);
Double d = selectivity.selectivity(predicate);

But let's see our RelOptCluster's member variables[2], there are MetadataFactory and RelMetadataQuery
which all can be used to query the metadata, for MetadataFactory, there is a default impl
named MetadataFactoryImpl which will invoke RelMetadataProvider#apply internally, for RelMetadataQuery,
it will invoke RelMetadataProvider#handlers (finally composed and codeden by JaninoRelMetadataProvider).

In our planning phrase, we can invoke RelOptRuleCall#getMetadataQuery to get the MQ and query
the metadata.

For extension of metadata handlers, we can set our customized RelMetadataProvider in RelOptCluster[3].
But for RelMetadataQuery, we have no way to extend it now, because the RelOptCluster always
has a singleton instance [4] which is only the default implementation.


My question is as follows:

1. Why we have 2 methods in RelMetadataProvider, and why we need the MetadataFactory and RelMetadataProvider#apply
? It seems that it's function is already been overriden by RelMetadataQuery(The difference
is that MetadataFactory use Reflection and RelMetadataQuery use gened bytes code).
2. We should make the RelMetadataQuery in RelOptCluster pluggable.


[1] https://github.com/apache/calcite/blob/b0e83c469ff57257c1ea621ff943ca76f626a9b7/core/src/main/java/org/apache/calcite/rel/metadata/RelMetadataProvider.java#L38
[2] https://github.com/apache/calcite/blob/b0e83c469ff57257c1ea621ff943ca76f626a9b7/core/src/main/java/org/apache/calcite/plan/RelOptCluster.java#L49
[3] https://github.com/apache/calcite/blob/b0e83c469ff57257c1ea621ff943ca76f626a9b7/core/src/main/java/org/apache/calcite/plan/RelOptCluster.java#L135
[4] https://github.com/apache/calcite/blob/b0e83c469ff57257c1ea621ff943ca76f626a9b7/core/src/main/java/org/apache/calcite/plan/RelOptCluster.java#L151



Best,
Danny Chan

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message