-
Notifications
You must be signed in to change notification settings - Fork 200
Coral-Spark: Migrate some operator transformers from RelNode layer to SqlNode layer #351
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
Merged
ljfgem
merged 5 commits into
linkedin:master
from
ljfgem:coral_spark_transformation_migration
Feb 10, 2023
+549
−525
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5340dee
Coral-Spark: Migrate some operator transformers from RelNode layer to…
ljfgem ad98949
Modify the overriden toSql
ljfgem 2c388fe
Rebase and address comments
ljfgem 4d30fe6
Modify comment for override
ljfgem 4308132
Fix javadoc issue
ljfgem 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 hidden or 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
49 changes: 0 additions & 49 deletions
49
coral-spark/src/main/java/com/linkedin/coral/spark/BuiltinUDFMap.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
164 changes: 164 additions & 0 deletions
164
coral-spark/src/main/java/com/linkedin/coral/spark/CoralToSparkSqlCallConverter.java
This file contains hidden or 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,164 @@ | ||
| /** | ||
| * Copyright 2023 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.spark; | ||
|
|
||
| import java.util.Set; | ||
|
|
||
| import org.apache.calcite.sql.SqlCall; | ||
| import org.apache.calcite.sql.SqlNode; | ||
| import org.apache.calcite.sql.fun.SqlStdOperatorTable; | ||
| import org.apache.calcite.sql.util.SqlShuttle; | ||
|
|
||
| import com.linkedin.coral.common.transformers.OperatorRenameSqlCallTransformer; | ||
| import com.linkedin.coral.common.transformers.SqlCallTransformers; | ||
| import com.linkedin.coral.spark.containers.SparkUDFInfo; | ||
| import com.linkedin.coral.spark.transformers.FallBackToLinkedInHiveUDFTransformer; | ||
| import com.linkedin.coral.spark.transformers.TransportUDFTransformer; | ||
|
|
||
| import static com.linkedin.coral.spark.transformers.TransportUDFTransformer.*; | ||
|
|
||
|
|
||
| /** | ||
| * This class extends the class of {@link org.apache.calcite.sql.util.SqlShuttle} and initialize a {@link com.linkedin.coral.common.transformers.SqlCallTransformers} | ||
| * which containing a list of {@link com.linkedin.coral.common.transformers.SqlCallTransformer} to traverse the hierarchy of a {@link org.apache.calcite.sql.SqlCall} | ||
| * and converts the functions from Coral operator to Spark operator if it is required | ||
| * | ||
| * In this converter, we need to apply {@link TransportUDFTransformer} before {@link FallBackToLinkedInHiveUDFTransformer} | ||
| * because we should try to transform a UDF to an equivalent Transport UDF before falling back to LinkedIn Hive UDF. | ||
| */ | ||
| public class CoralToSparkSqlCallConverter extends SqlShuttle { | ||
ljfgem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| private final SqlCallTransformers sqlCallTransformers; | ||
|
|
||
| public CoralToSparkSqlCallConverter(Set<SparkUDFInfo> sparkUDFInfos) { | ||
| this.sqlCallTransformers = SqlCallTransformers.of( | ||
| // Transport UDFs | ||
| new TransportUDFTransformer("com.linkedin.dali.udf.date.hive.DateFormatToEpoch", | ||
| "com.linkedin.stdudfs.daliudfs.spark.DateFormatToEpoch", DALI_UDFS_IVY_URL_SPARK_2_11, | ||
| DALI_UDFS_IVY_URL_SPARK_2_12, sparkUDFInfos), | ||
|
|
||
| new TransportUDFTransformer("com.linkedin.dali.udf.date.hive.EpochToDateFormat", | ||
| "com.linkedin.stdudfs.daliudfs.spark.EpochToDateFormat", DALI_UDFS_IVY_URL_SPARK_2_11, | ||
| DALI_UDFS_IVY_URL_SPARK_2_12, sparkUDFInfos), | ||
|
|
||
| new TransportUDFTransformer("com.linkedin.dali.udf.date.hive.EpochToEpochMilliseconds", | ||
| "com.linkedin.stdudfs.daliudfs.spark.EpochToEpochMilliseconds", DALI_UDFS_IVY_URL_SPARK_2_11, | ||
| DALI_UDFS_IVY_URL_SPARK_2_12, sparkUDFInfos), | ||
|
|
||
| new TransportUDFTransformer("com.linkedin.dali.udf.isguestmemberid.hive.IsGuestMemberId", | ||
| "com.linkedin.stdudfs.daliudfs.spark.IsGuestMemberId", DALI_UDFS_IVY_URL_SPARK_2_11, | ||
| DALI_UDFS_IVY_URL_SPARK_2_12, sparkUDFInfos), | ||
|
|
||
| new TransportUDFTransformer("com.linkedin.dali.udf.istestmemberid.hive.IsTestMemberId", | ||
| "com.linkedin.stdudfs.daliudfs.spark.IsTestMemberId", DALI_UDFS_IVY_URL_SPARK_2_11, | ||
| DALI_UDFS_IVY_URL_SPARK_2_12, sparkUDFInfos), | ||
|
|
||
| new TransportUDFTransformer("com.linkedin.dali.udf.maplookup.hive.MapLookup", | ||
| "com.linkedin.stdudfs.daliudfs.spark.MapLookup", DALI_UDFS_IVY_URL_SPARK_2_11, DALI_UDFS_IVY_URL_SPARK_2_12, | ||
| sparkUDFInfos), | ||
|
|
||
| new TransportUDFTransformer("com.linkedin.dali.udf.sanitize.hive.Sanitize", | ||
| "com.linkedin.stdudfs.daliudfs.spark.Sanitize", DALI_UDFS_IVY_URL_SPARK_2_11, DALI_UDFS_IVY_URL_SPARK_2_12, | ||
| sparkUDFInfos), | ||
|
|
||
| new TransportUDFTransformer("com.linkedin.dali.udf.watbotcrawlerlookup.hive.WATBotCrawlerLookup", | ||
| "com.linkedin.stdudfs.daliudfs.spark.WatBotCrawlerLookup", DALI_UDFS_IVY_URL_SPARK_2_11, | ||
| DALI_UDFS_IVY_URL_SPARK_2_12, sparkUDFInfos), | ||
|
|
||
| new TransportUDFTransformer("com.linkedin.stdudfs.daliudfs.hive.DateFormatToEpoch", | ||
| "com.linkedin.stdudfs.daliudfs.spark.DateFormatToEpoch", DALI_UDFS_IVY_URL_SPARK_2_11, | ||
| DALI_UDFS_IVY_URL_SPARK_2_12, sparkUDFInfos), | ||
|
|
||
| new TransportUDFTransformer("com.linkedin.stdudfs.daliudfs.hive.EpochToDateFormat", | ||
| "com.linkedin.stdudfs.daliudfs.spark.EpochToDateFormat", DALI_UDFS_IVY_URL_SPARK_2_11, | ||
| DALI_UDFS_IVY_URL_SPARK_2_12, sparkUDFInfos), | ||
|
|
||
| new TransportUDFTransformer("com.linkedin.stdudfs.daliudfs.hive.EpochToEpochMilliseconds", | ||
| "com.linkedin.stdudfs.daliudfs.spark.EpochToEpochMilliseconds", DALI_UDFS_IVY_URL_SPARK_2_11, | ||
| DALI_UDFS_IVY_URL_SPARK_2_12, sparkUDFInfos), | ||
|
|
||
| new TransportUDFTransformer("com.linkedin.stdudfs.daliudfs.hive.GetProfileSections", | ||
| "com.linkedin.stdudfs.daliudfs.spark.GetProfileSections", DALI_UDFS_IVY_URL_SPARK_2_11, | ||
| DALI_UDFS_IVY_URL_SPARK_2_12, sparkUDFInfos), | ||
|
|
||
| new TransportUDFTransformer("com.linkedin.stdudfs.stringudfs.hive.InitCap", | ||
| "com.linkedin.stdudfs.stringudfs.spark.InitCap", | ||
| "ivy://com.linkedin.standard-udfs-common-sql-udfs:standard-udfs-string-udfs:1.0.1?classifier=spark_2.11", | ||
| "ivy://com.linkedin.standard-udfs-common-sql-udfs:standard-udfs-string-udfs:1.0.1?classifier=spark_2.12", | ||
| sparkUDFInfos), | ||
|
|
||
| new TransportUDFTransformer("com.linkedin.stdudfs.daliudfs.hive.IsGuestMemberId", | ||
| "com.linkedin.stdudfs.daliudfs.spark.IsGuestMemberId", DALI_UDFS_IVY_URL_SPARK_2_11, | ||
| DALI_UDFS_IVY_URL_SPARK_2_12, sparkUDFInfos), | ||
|
|
||
| new TransportUDFTransformer("com.linkedin.stdudfs.daliudfs.hive.IsTestMemberId", | ||
| "com.linkedin.stdudfs.daliudfs.spark.IsTestMemberId", DALI_UDFS_IVY_URL_SPARK_2_11, | ||
| DALI_UDFS_IVY_URL_SPARK_2_12, sparkUDFInfos), | ||
|
|
||
| new TransportUDFTransformer("com.linkedin.stdudfs.daliudfs.hive.MapLookup", | ||
| "com.linkedin.stdudfs.daliudfs.spark.MapLookup", DALI_UDFS_IVY_URL_SPARK_2_11, DALI_UDFS_IVY_URL_SPARK_2_12, | ||
| sparkUDFInfos), | ||
|
|
||
| new TransportUDFTransformer("com.linkedin.stdudfs.daliudfs.hive.PortalLookup", | ||
| "com.linkedin.stdudfs.daliudfs.spark.PortalLookup", DALI_UDFS_IVY_URL_SPARK_2_11, | ||
| DALI_UDFS_IVY_URL_SPARK_2_12, sparkUDFInfos), | ||
|
|
||
| new TransportUDFTransformer("com.linkedin.stdudfs.daliudfs.hive.Sanitize", | ||
| "com.linkedin.stdudfs.daliudfs.spark.Sanitize", DALI_UDFS_IVY_URL_SPARK_2_11, DALI_UDFS_IVY_URL_SPARK_2_12, | ||
| sparkUDFInfos), | ||
|
|
||
| new TransportUDFTransformer("com.linkedin.stdudfs.userinterfacelookup.hive.UserInterfaceLookup", | ||
| "com.linkedin.stdudfs.userinterfacelookup.spark.UserInterfaceLookup", | ||
| "ivy://com.linkedin.standard-udf-userinterfacelookup:userinterfacelookup-std-udf:0.0.27?classifier=spark_2.11", | ||
| "ivy://com.linkedin.standard-udf-userinterfacelookup:userinterfacelookup-std-udf:0.0.27?classifier=spark_2.12", | ||
| sparkUDFInfos), | ||
|
|
||
| new TransportUDFTransformer("com.linkedin.stdudfs.daliudfs.hive.WatBotCrawlerLookup", | ||
| "com.linkedin.stdudfs.daliudfs.spark.WatBotCrawlerLookup", DALI_UDFS_IVY_URL_SPARK_2_11, | ||
| DALI_UDFS_IVY_URL_SPARK_2_12, sparkUDFInfos), | ||
|
|
||
| new TransportUDFTransformer("com.linkedin.jemslookup.udf.hive.JemsLookup", | ||
| "com.linkedin.jemslookup.udf.spark.JemsLookup", | ||
| "ivy://com.linkedin.jobs-udf:jems-udfs:2.1.7?classifier=spark_2.11", | ||
| "ivy://com.linkedin.jobs-udf:jems-udfs:2.1.7?classifier=spark_2.12", sparkUDFInfos), | ||
|
|
||
| new TransportUDFTransformer("com.linkedin.stdudfs.parsing.hive.UserAgentParser", | ||
| "com.linkedin.stdudfs.parsing.spark.UserAgentParser", | ||
| "ivy://com.linkedin.standard-udfs-parsing:parsing-stdudfs:3.0.3?classifier=spark_2.11", | ||
| "ivy://com.linkedin.standard-udfs-parsing:parsing-stdudfs:3.0.3?classifier=spark_2.12", sparkUDFInfos), | ||
|
|
||
| new TransportUDFTransformer("com.linkedin.stdudfs.parsing.hive.Ip2Str", | ||
| "com.linkedin.stdudfs.parsing.spark.Ip2Str", | ||
| "ivy://com.linkedin.standard-udfs-parsing:parsing-stdudfs:3.0.3?classifier=spark_2.11", | ||
| "ivy://com.linkedin.standard-udfs-parsing:parsing-stdudfs:3.0.3?classifier=spark_2.12", sparkUDFInfos), | ||
|
|
||
| new TransportUDFTransformer("com.linkedin.stdudfs.lookup.hive.BrowserLookup", | ||
| "com.linkedin.stdudfs.lookup.spark.BrowserLookup", | ||
| "ivy://com.linkedin.standard-udfs-parsing:parsing-stdudfs:3.0.3?classifier=spark_2.11", | ||
| "ivy://com.linkedin.standard-udfs-parsing:parsing-stdudfs:3.0.3?classifier=spark_2.12", sparkUDFInfos), | ||
|
|
||
| new TransportUDFTransformer("com.linkedin.jobs.udf.hive.ConvertIndustryCode", | ||
| "com.linkedin.jobs.udf.spark.ConvertIndustryCode", | ||
| "ivy://com.linkedin.jobs-udf:jobs-udfs:2.1.6?classifier=spark_2.11", | ||
| "ivy://com.linkedin.jobs-udf:jobs-udfs:2.1.6?classifier=spark_2.12", sparkUDFInfos), | ||
|
|
||
| // Transport UDF for unit test | ||
| new TransportUDFTransformer("com.linkedin.coral.hive.hive2rel.CoralTestUDF", | ||
| "com.linkedin.coral.spark.CoralTestUDF", | ||
| "ivy://com.linkedin.coral.spark.CoralTestUDF?classifier=spark_2.11", null, sparkUDFInfos), | ||
|
|
||
| // Built-in operator | ||
| new OperatorRenameSqlCallTransformer(SqlStdOperatorTable.CARDINALITY, 1, "size"), | ||
|
|
||
| // Fall back to the original Hive UDF defined in StaticHiveFunctionRegistry after failing to apply transformers above | ||
| new FallBackToLinkedInHiveUDFTransformer(sparkUDFInfos)); | ||
| } | ||
|
|
||
| @Override | ||
| public SqlNode visit(SqlCall call) { | ||
| final SqlCall transformedSqlCall = sqlCallTransformers.apply(call); | ||
| return super.visit(transformedSqlCall); | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.