-
Notifications
You must be signed in to change notification settings - Fork 188
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
ljfgem
wants to merge
4
commits into
linkedin:master
Choose a base branch
from
ljfgem:extract_common_classes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
coral-common/src/main/java/com/linkedin/coral/common/functions/FunctionResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Copyright 2018-2022 LinkedIn Corporation. All rights reserved. | ||
* Licensed under the BSD-2 Clause license. | ||
* See LICENSE in the project root for license information. | ||
*/ | ||
package com.linkedin.coral.common.functions; | ||
|
||
import java.util.Collection; | ||
|
||
|
||
/** | ||
* Class to resolve function names in SQL to Function. | ||
*/ | ||
public abstract class FunctionResolver { | ||
|
||
protected final FunctionRegistry registry; | ||
|
||
protected FunctionResolver(FunctionRegistry registry) { | ||
this.registry = registry; | ||
} | ||
|
||
/** | ||
* Resolves function to concrete operator case-insensitively. | ||
* @param functionName function name to resolve | ||
* @return list of matching Functions or empty list if there is no match | ||
*/ | ||
public abstract Collection<Function> resolve(String functionName); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,9 @@ | |
*/ | ||
package com.linkedin.coral.trino.trino2rel; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
import org.apache.calcite.adapter.java.JavaTypeFactory; | ||
import org.apache.calcite.plan.RelOptCluster; | ||
|
@@ -22,13 +22,14 @@ | |
import org.apache.calcite.sql2rel.SqlToRelConverter; | ||
import org.apache.hadoop.hive.metastore.api.Table; | ||
|
||
import com.linkedin.coral.common.CoralOperatorTable; | ||
import com.linkedin.coral.common.HiveMetastoreClient; | ||
import com.linkedin.coral.common.ToRelConverter; | ||
import com.linkedin.coral.hive.hive2rel.DaliOperatorTable; | ||
import com.linkedin.coral.common.functions.Function; | ||
import com.linkedin.coral.common.functions.FunctionResolver; | ||
import com.linkedin.coral.hive.hive2rel.HiveConvertletTable; | ||
import com.linkedin.coral.hive.hive2rel.HiveRelBuilder; | ||
import com.linkedin.coral.hive.hive2rel.HiveSqlValidator; | ||
import com.linkedin.coral.hive.hive2rel.functions.HiveFunctionResolver; | ||
import com.linkedin.coral.hive.hive2rel.functions.StaticHiveFunctionRegistry; | ||
import com.linkedin.coral.trino.trino2rel.parsetree.ParseTreeBuilder; | ||
import com.linkedin.coral.trino.trino2rel.parsetree.ParserVisitorContext; | ||
|
@@ -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()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the PR @ljfgem Can we write a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for suggestion, added. |
||
@Override | ||
public Collection<Function> resolve(String functionName) { | ||
return registry.lookup(functionName); | ||
} | ||
}; | ||
private final | ||
// The validator must be reused | ||
SqlValidator sqlValidator = new HiveSqlValidator(getOperatorTable(), getCalciteCatalogReader(), | ||
|
@@ -74,7 +79,7 @@ protected SqlValidator getSqlValidator() { | |
|
||
@Override | ||
protected SqlOperatorTable getOperatorTable() { | ||
return ChainedSqlOperatorTable.of(SqlStdOperatorTable.instance(), new DaliOperatorTable(functionResolver)); | ||
return ChainedSqlOperatorTable.of(SqlStdOperatorTable.instance(), new CoralOperatorTable(functionResolver)); | ||
} | ||
|
||
@Override | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 havexxxFunctionResolver
extendingFunctionResolver
for each xxx2rel module instead.And in practice, given
HiveFunctionResolver
uses many classes in Coral-Hive likeVersionedSqlUserDefinedFunction
,HiveRLikeOperator
andHiveGenericUDFReturnTypeInference
, we need to move all of them forHiveFunctionResolver
, which is not suitable in my opinion.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 thelanguage2rel
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.There was a problem hiding this comment.
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?
I think those are ultimately going to be Coral IR specific classes, and not Hive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wmoustafa Rests are
resolveUnaryOperator
andresolveBinaryOperator
which are only used in Hive'sParseTreeBuilder
, not used intrino2rel
becausetrino2rel
has its ownParseTreeBuilder
. So I would prefer to just keepresolve
inFunctionResolver
for now, we may add more common methods if there is in the future.