While learning calcite, then during subsequent discussions, the legacy code
in the metadata sub-system caused significant understanding/discussion.
Currently to define a rel metadata type:
public class MyMetadata extends Metadata {
MetadataDef DEF = ...
VALUE myMethod1();
class Handler extends RelHandler<MyMetadata> {
VALUE myMethod2(RelNode, MetadataQuery)
}
}
However, it could be reduced to:
class MyMetadataHandler extends RelHandler {
VALUE myMethod(RelNode, MetadataQuery)
}
In BuiltInMetadata the resulting definitions would look like:
@Deprecated // to be removed before 2.0
public class MyMetadata extends Metadata {
MetadataDef DEF = ...
VALUE myMethod1();
@FunctionalInterface
@Deprecated // to be removed before 2.0
class Handler extends MyMetadataHandler {
@Deprecated // to be removed before 2.0
@Override default MetadataDef<MyMetadata> getDef() {
return DEF;
}
}
}
@FunctionalInterface
class MyMetadataHandler extends RelHandler {
VALUE myMethod(RelNode, MetadataQuery)
}
This would minimize breaks to downstream projects since reference to
existing handlers would not be broken and downstream projects could migrate
at their own leisure.
I would like to remove the generic from MetadataHandler as part of cleaning
up the boilerplate for defining Rel Metadata types[CALCITE-4942].
Currently, it refers to the sister Metadata class that is no longer used in
a non-deprecated code. Furthermore, it does not not provide type safety to
any code, as all usages of it are either <?> or <? extends Metadata>. This
would be a breaking change for downstream projects that have a custom
metadata type or have their own implementation of MetadataHandlerProvider.
Most downstream projects have neither of them, and if they do, removing the
generic should be straight forward. Alternatively, it could be left as is
and/or the "extends Metadata" constraint could be removed.
As part of this, I could also split all the Handlers into functional
interfaces, which would help with Jacques work to not use Janino.
My Draft request: https://github.com/apache/calcite/pull/2655
James