Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move DaliOperatorTable to Coral-Common and rename it #276

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ljfgem
Copy link
Collaborator

@ljfgem ljfgem commented May 31, 2022

This PR is for #235.
DaliOperatorTable registers legal operators for Calcite to validate and convert the input SqlNode.
Given we convert other types of operators (like Trino operators) to Hive (Coral) operators in SqlNode phase, we use DaliOperatorTable for both Coral-Hive hive2rel, Coral-Trino trino2rel and all the future inputs, therefore, it makes more sense to move DaliOperatorTable to Coral-Common.
To move it, we need to create an abstract class FunctionResolver to be used in CoralOperatorTable.
cc: @wmoustafa

Tested by building and i-itest.

@@ -43,14 +44,13 @@
/**
* Class to resolve hive function names in SQL to Function.
*/
public class HiveFunctionResolver {
public class HiveFunctionResolver extends FunctionResolver {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why could not not this be moved to coral-common?

Copy link
Collaborator Author

@ljfgem ljfgem Jun 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HiveFunctionResolver is only used for Coral-Hive and contains many Coral-Hive specific methods like Generic UDF dynamic registration. Therefore, I don't think we need this class for all the other xxx2rel modules, we need to have xxxFunctionResolver extending FunctionResolver for each xxx2rel module instead.

And in practice, given HiveFunctionResolver uses many classes in Coral-Hive like VersionedSqlUserDefinedFunction, HiveRLikeOperator and HiveGenericUDFReturnTypeInference, we need to move all of them for HiveFunctionResolver, which is not suitable in my opinion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we are moving towards sqlNode translations, (coralSqlNode <-> *language*SqlNode), we can repurpose these *language*FunctionResolver classes to translate CoralFunctions to languagefunctions in this de-centralized manner.

Or we could maintain 1 registry and 1 function resolver in coral-common to fo coral <-> language translations in a centralized way.
I'm okay with sticking to the existing pattern.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wmoustafa do you have a preference between common function resolver vs language-specific function resolvers?

Copy link
Collaborator Author

@ljfgem ljfgem Jun 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure IIUC, I don't think we can use a common function resolver in coral-common to solve all the language2rel functions, given difference input languages may need different methods in their function resolvers, for example, hive2rel needs dynamic Hive generic UDF registration while trino2rel doesn't need.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think aside from the dynamic resolution, rest should be language independent and go to coral-common?

And in practice, given HiveFunctionResolver uses many classes in Coral-Hive like VersionedSqlUserDefinedFunction, HiveRLikeOperator and HiveGenericUDFReturnTypeInference, we need to move all of them for HiveFunctionResolver, which is not suitable in my opinion.

I think those are ultimately going to be Coral IR specific classes, and not Hive?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wmoustafa Rests are resolveUnaryOperator and resolveBinaryOperator which are only used in Hive's ParseTreeBuilder, not used in trino2rel because trino2rel has its own ParseTreeBuilder. So I would prefer to just keep resolve in FunctionResolver for now, we may add more common methods if there is in the future.

@@ -47,8 +48,12 @@
public class TrinoToRelConverter extends ToRelConverter {
private final ParseTreeBuilder parseTreeBuilder = new ParseTreeBuilder();
private final ParserVisitorContext parserVisitorContext = new ParserVisitorContext();
private final HiveFunctionResolver functionResolver =
new HiveFunctionResolver(new StaticHiveFunctionRegistry(), new ConcurrentHashMap<>());
private final FunctionResolver functionResolver = new FunctionResolver(new StaticHiveFunctionRegistry()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @ljfgem

Can we write a TrinoFunctionResolver similar to hiveFunctionResolver explicitly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for suggestion, added.

@@ -43,14 +44,13 @@
/**
* Class to resolve hive function names in SQL to Function.
*/
public class HiveFunctionResolver {
public class HiveFunctionResolver extends FunctionResolver {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we are moving towards sqlNode translations, (coralSqlNode <-> *language*SqlNode), we can repurpose these *language*FunctionResolver classes to translate CoralFunctions to languagefunctions in this de-centralized manner.

Or we could maintain 1 registry and 1 function resolver in coral-common to fo coral <-> language translations in a centralized way.
I'm okay with sticking to the existing pattern.

@ljfgem ljfgem requested a review from wmoustafa June 14, 2022 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants