This repository was archived by the owner on Jun 14, 2024. It is now read-only.
-
Couldn't load subscription status.
- Fork 115
Support filter over indexes on nested fields #380
Open
andrei-ionescu
wants to merge
7
commits into
microsoft:master
Choose a base branch
from
andrei-ionescu:nested_fields_filter
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 all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4523625
Support filter on indexes with nested fields
andrei-ionescu f960e4a
Add aliasing from index nested field back back to original name
andrei-ionescu 671c4b0
Integrated feedback
andrei-ionescu 5f5034d
Add Spark 3 support related changes
andrei-ionescu d3fe005
Integrate feedback (2)
andrei-ionescu 374fbb3
Integrate feedback (3)
andrei-ionescu 3c476ab
Rebase over master
andrei-ionescu 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
590 changes: 590 additions & 0 deletions
590
src/main/scala/com/microsoft/hyperspace/index/rules/BaseRuleHelper.scala
Large diffs are not rendered by default.
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
34 changes: 34 additions & 0 deletions
34
src/main/scala/com/microsoft/hyperspace/index/rules/IndexPlanApplyHelper.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,34 @@ | ||
| /* | ||
| * Copyright (2021) 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.index.rules | ||
|
|
||
| import com.microsoft.hyperspace.index.IndexLogEntry | ||
| import com.microsoft.hyperspace.index.rules.FilterIndexRule.spark | ||
| import com.microsoft.hyperspace.util.ResolverUtils | ||
|
|
||
| object IndexPlanApplyHelper { | ||
| def apply(indexLogEntry: IndexLogEntry): BaseRuleHelper = { | ||
| // Detect whether the index contains nested fields. | ||
| val indexHasNestedColumns = (indexLogEntry.indexedColumns ++ indexLogEntry.includedColumns) | ||
| .exists(ResolverUtils.ResolvedColumn(_).isNested) | ||
| if (indexHasNestedColumns) { | ||
| new NestedRuleHelper(spark) | ||
| } else { | ||
| new BaseRuleHelper(spark) | ||
| } | ||
| } | ||
| } |
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 |
|---|---|---|
|
|
@@ -61,17 +61,16 @@ object JoinIndexRule | |
| getBestIndexPair(l, r, condition) | ||
| .map { | ||
| case (lIndex, rIndex) => | ||
| val ruleHelper = new BaseRuleHelper(spark) | ||
|
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. Changes in this file are mainly due to |
||
| val updatedPlan = | ||
| join | ||
| .copy( | ||
| left = RuleUtils.transformPlanToUseIndex( | ||
| spark, | ||
| left = ruleHelper.transformPlanToUseIndex( | ||
| lIndex, | ||
| l, | ||
| useBucketSpec = true, | ||
| useBucketUnionForAppended = true), | ||
| right = RuleUtils.transformPlanToUseIndex( | ||
| spark, | ||
| right = ruleHelper.transformPlanToUseIndex( | ||
| rIndex, | ||
| r, | ||
| useBucketSpec = true, | ||
|
|
@@ -109,11 +108,11 @@ object JoinIndexRule | |
| private def isApplicable(l: LogicalPlan, r: LogicalPlan, condition: Expression): Boolean = { | ||
| // The given plan is eligible if it is supported and index has not been applied. | ||
| def isEligible(optRel: Option[FileBasedRelation]): Boolean = { | ||
| optRel.map(!RuleUtils.isIndexApplied(_)).getOrElse(false) | ||
| optRel.exists(!RuleUtils.isIndexApplied(_)) | ||
| } | ||
|
|
||
| lazy val optLeftRel = RuleUtils.getRelation(spark, l) | ||
| lazy val optRightRel = RuleUtils.getRelation(spark, r) | ||
| lazy val optLeftRel = RuleUtils.getRelation(l) | ||
| lazy val optRightRel = RuleUtils.getRelation(r) | ||
|
|
||
| isJoinConditionSupported(condition) && | ||
| isPlanLinear(l) && isPlanLinear(r) && | ||
|
|
@@ -284,7 +283,8 @@ object JoinIndexRule | |
| left: LogicalPlan, | ||
| right: LogicalPlan, | ||
| joinCondition: Expression): Option[(IndexLogEntry, IndexLogEntry)] = { | ||
| val indexManager = Hyperspace.getContext(spark).indexCollectionManager | ||
| val hyperspaceContext = Hyperspace.getContext(spark) | ||
| val indexManager = hyperspaceContext.indexCollectionManager | ||
|
|
||
| // TODO: the following check only considers indexes in ACTIVE state for usage. Update | ||
| // the code to support indexes in transitioning states as well. | ||
|
|
@@ -294,10 +294,10 @@ object JoinIndexRule | |
| // TODO: we can write an extractor that applies `isApplicable` so that we don't have to | ||
| // get relations twice. Note that `getRelation` should always succeed since this has | ||
| // been already checked in `isApplicable`. | ||
| val leftRelation = RuleUtils.getRelation(spark, left).get | ||
| val rightRelation = RuleUtils.getRelation(spark, right).get | ||
| val lBaseAttrs = leftRelation.output.map(_.name) | ||
| val rBaseAttrs = rightRelation.output.map(_.name) | ||
| val leftRelation = RuleUtils.getRelation(left).get | ||
| val rightRelation = RuleUtils.getRelation(right).get | ||
| val lBaseAttrs = leftRelation.plan.output.map(_.name) | ||
| val rBaseAttrs = rightRelation.plan.output.map(_.name) | ||
|
|
||
| // Map of left resolved columns with their corresponding right resolved | ||
| // columns from condition. | ||
|
|
@@ -316,14 +316,15 @@ object JoinIndexRule | |
| val lUsable = getUsableIndexes(allIndexes, lRequiredIndexedCols, lRequiredAllCols) | ||
| val rUsable = getUsableIndexes(allIndexes, rRequiredIndexedCols, rRequiredAllCols) | ||
|
|
||
| val leftRel = RuleUtils.getRelation(spark, left).get | ||
| val rightRel = RuleUtils.getRelation(spark, right).get | ||
| val leftRel = RuleUtils.getRelation(left).get | ||
| val rightRel = RuleUtils.getRelation(right).get | ||
|
|
||
| // Get candidate via file-level metadata validation. This is performed after pruning | ||
| // by column schema, as this might be expensive when there are numerous files in the | ||
| // relation or many indexes to be checked. | ||
| val lIndexes = RuleUtils.getCandidateIndexes(spark, lUsable, leftRel) | ||
| val rIndexes = RuleUtils.getCandidateIndexes(spark, rUsable, rightRel) | ||
| val ruleHelper = new BaseRuleHelper(spark) | ||
| val lIndexes = ruleHelper.getCandidateIndexes(lUsable, leftRel) | ||
| val rIndexes = ruleHelper.getCandidateIndexes(rUsable, rightRel) | ||
|
|
||
| val compatibleIndexPairs = getCompatibleIndexPairs(lIndexes, rIndexes, lRMap) | ||
|
|
||
|
|
||
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.