This repository was archived by the owner on Jun 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 116
Add spark session extension for Hyperspace #504
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fa80dba
add spark session extension
1d96573
update according to the reviews
paryoja 4bb381d
refactor enableHyperspace
paryoja d8a9c34
add comments
paryoja 20b824d
move helper function to package.scala
paryoja 4d2f1b8
move helper function to package.scala
paryoja 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
69 changes: 69 additions & 0 deletions
69
src/main/scala/com/microsoft/hyperspace/HyperspaceSparkSessionExtension.scala
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,69 @@ | ||
| /* | ||
| * Copyright (2020) The Hyperspace Project Authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.microsoft.hyperspace | ||
|
|
||
| import org.apache.spark.sql.{SparkSession, SparkSessionExtensions} | ||
| import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan | ||
| import org.apache.spark.sql.catalyst.rules.Rule | ||
|
|
||
| import com.microsoft.hyperspace.index.execution.BucketUnionStrategy | ||
| import com.microsoft.hyperspace.index.rules.ApplyHyperspace | ||
|
|
||
| /** | ||
| * An extension for Spark SQL to activate Hyperspace. | ||
| * | ||
| * Example to run a `spark-submit` with Hyperspace enabled: | ||
| * {{{ | ||
| * spark-submit -c spark.sql.extensions=com.microsoft.hyperspace.HyperspaceSparkSessionExtension | ||
| * }}} | ||
| * | ||
| * Example to create a `SparkSession` with Hyperspace enabled: | ||
| * {{{ | ||
| * val spark = SparkSession | ||
| * .builder() | ||
| * .appName("...") | ||
| * .master("...") | ||
| * .config("spark.sql.extensions", "com.microsoft.hyperspace.HyperspaceSparkSessionExtension") | ||
| * .getOrCreate() | ||
| * }}} | ||
| */ | ||
| class HyperspaceSparkSessionExtension extends (SparkSessionExtensions => Unit) { | ||
|
|
||
| /** | ||
| * If HyperspaceRule is injected directly to OptimizerRule with HyperspaceExtension, | ||
| * the order of applying rule is different from without HyperspaceExtension | ||
| * (i.e., explicitly calling enableHyperspace). To make behavior consistently, | ||
| * current implementation of HyperspaceExtension uses a trick to call enableHyperspace | ||
| * before rule is applied. Since the interface of injectOptimizerRule should return rule builder, | ||
| * it returns a dummy rule that does nothing. It may increase overhead slightly | ||
| * because enableHyperspace is called once for each evaluation of spark plan. | ||
| */ | ||
| private case object DummyRule extends Rule[LogicalPlan] { | ||
| override def apply(plan: LogicalPlan): LogicalPlan = { | ||
| plan | ||
| } | ||
| } | ||
|
|
||
| override def apply(extensions: SparkSessionExtensions): Unit = { | ||
| extensions.injectOptimizerRule { sparkSession => | ||
| // Enable Hyperspace to leverage indexes. | ||
| sparkSession.addOptimizationsIfNeeded() | ||
| // Return a dummy rule to fit in interface of injectOptimizerRule | ||
| DummyRule | ||
| } | ||
| } | ||
| } | ||
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
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
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
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
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.