This repository has been archived by the owner on Jun 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into whynot4
- Loading branch information
Showing
11 changed files
with
263 additions
and
124 deletions.
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
36 changes: 0 additions & 36 deletions
36
src/main/scala/com/microsoft/hyperspace/index/covering/CoveringIndexFilter.scala
This file was deleted.
Oops, something went wrong.
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
33 changes: 33 additions & 0 deletions
33
src/main/scala/com/microsoft/hyperspace/index/rules/ExtractRelation.scala
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,33 @@ | ||
/* | ||
* 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 org.apache.spark.sql.catalyst.plans.logical.LeafNode | ||
|
||
import com.microsoft.hyperspace.{ActiveSparkSession, Hyperspace} | ||
import com.microsoft.hyperspace.index.sources.FileBasedRelation | ||
|
||
object ExtractRelation extends ActiveSparkSession { | ||
def unapply(plan: LeafNode): Option[FileBasedRelation] = { | ||
val provider = Hyperspace.getContext(spark).sourceProviderManager | ||
if (provider.isSupportedRelation(plan)) { | ||
Some(provider.getRelation(plan)) | ||
} else { | ||
None | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/scala/com/microsoft/hyperspace/index/rules/IndexTypeFilter.scala
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,49 @@ | ||
/* | ||
* 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 scala.reflect.ClassTag | ||
|
||
import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan | ||
|
||
import com.microsoft.hyperspace.index.Index | ||
import com.microsoft.hyperspace.index.rules.ApplyHyperspace.PlanToIndexesMap | ||
|
||
object IndexTypeFilter { | ||
|
||
/** | ||
* Returns a [[QueryPlanIndexFilter]] that filters out indexes which are not T. | ||
*/ | ||
def apply[T <: Index: ClassTag](): QueryPlanIndexFilter = | ||
new QueryPlanIndexFilter { | ||
override def apply( | ||
plan: LogicalPlan, | ||
candidateIndexes: PlanToIndexesMap): PlanToIndexesMap = { | ||
candidateIndexes | ||
.map { | ||
case (plan, indexes) => | ||
plan -> indexes.filter { | ||
_.derivedDataset match { | ||
case _: T => true | ||
case _ => false | ||
} | ||
} | ||
} | ||
.filter { case (_, indexes) => indexes.nonEmpty } | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/main/scala/com/microsoft/hyperspace/index/rules/RuleUtils.scala
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,55 @@ | ||
/* | ||
* 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 org.apache.spark.sql.SparkSession | ||
import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan | ||
|
||
import com.microsoft.hyperspace.Hyperspace | ||
import com.microsoft.hyperspace.index.IndexConstants | ||
import com.microsoft.hyperspace.index.sources.FileBasedRelation | ||
|
||
object RuleUtils { | ||
|
||
/** | ||
* Check if an index was applied the given relation or not. | ||
* This can be determined by an identifier in [[FileBasedRelation]]'s options. | ||
* | ||
* @param relation FileBasedRelation to check if an index is already applied. | ||
* @return true if an index is applied to the given relation. Otherwise false. | ||
*/ | ||
def isIndexApplied(relation: FileBasedRelation): Boolean = { | ||
relation.options.exists(_.equals(IndexConstants.INDEX_RELATION_IDENTIFIER)) | ||
} | ||
|
||
/** | ||
* Extract the relation node if the given logical plan is linear. | ||
* | ||
* @param plan Logical plan to extract a relation node from. | ||
* @return If the plan is linear and the relation node is supported, the [[FileBasedRelation]] | ||
* object that wraps the relation node. Otherwise None. | ||
*/ | ||
def getRelation(spark: SparkSession, plan: LogicalPlan): Option[FileBasedRelation] = { | ||
val provider = Hyperspace.getContext(spark).sourceProviderManager | ||
val leaves = plan.collectLeaves() | ||
if (leaves.size == 1 && provider.isSupportedRelation(leaves.head)) { | ||
Some(provider.getRelation(leaves.head)) | ||
} else { | ||
None | ||
} | ||
} | ||
} |
Oops, something went wrong.