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.
Refactoring for an extensible Index API: Part 3
- Move CoveringIndex specific code into the com.microsoft.hyperspace.index.types.covering package - Move traits/classes/objects in the com.microsoft.hyperspace.index.rules package into their own files - Add alias for CoveringIndexConfig for backward compatibility
- Loading branch information
Chungmin Lee
committed
Jun 28, 2021
1 parent
be09d41
commit f41e610
Showing
42 changed files
with
685 additions
and
442 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
34 changes: 34 additions & 0 deletions
34
src/main/scala/com/microsoft/hyperspace/index/package.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,34 @@ | ||
/* | ||
* 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 com.microsoft.hyperspace.index.types.covering.CoveringIndexConfig | ||
|
||
package object index { | ||
|
||
/** | ||
* IndexConfig is defined as an alias for [[CoveringIndexConfig]] for | ||
* backward compatibility. | ||
*/ | ||
type IndexConfig = CoveringIndexConfig | ||
|
||
/** | ||
* IndexConfig is defined as an alias for [[CoveringIndexConfig]] for | ||
* backward compatibility. | ||
*/ | ||
val IndexConfig = CoveringIndexConfig | ||
} |
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
60 changes: 60 additions & 0 deletions
60
src/main/scala/com/microsoft/hyperspace/index/rules/CandidateIndexCollector.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,60 @@ | ||
/* | ||
* 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, LogicalPlan} | ||
|
||
import com.microsoft.hyperspace.{ActiveSparkSession, Hyperspace} | ||
import com.microsoft.hyperspace.index.IndexLogEntry | ||
import com.microsoft.hyperspace.index.rules.ApplyHyperspace.PlanToIndexesMap | ||
|
||
/** | ||
* Collect candidate indexes for each source plan. | ||
*/ | ||
object CandidateIndexCollector extends ActiveSparkSession { | ||
private val sourceFilters: Seq[SourcePlanIndexFilter] = | ||
ColumnSchemaFilter :: FileSignatureFilter :: Nil | ||
|
||
private def initializePlanToIndexes( | ||
plan: LogicalPlan, | ||
indexes: Seq[IndexLogEntry]): PlanToIndexesMap = { | ||
val provider = Hyperspace.getContext(spark).sourceProviderManager | ||
plan.collect { | ||
case l: LeafNode if provider.isSupportedRelation(l) => | ||
(l.asInstanceOf[LogicalPlan], indexes) | ||
}.toMap | ||
} | ||
|
||
/** | ||
* Extract candidate indexes for each source plan in the given query plan. | ||
* | ||
* @param plan Original query plan | ||
* @param allIndexes All indexes | ||
* @return Map of source plan to candidate indexes | ||
*/ | ||
def apply(plan: LogicalPlan, allIndexes: Seq[IndexLogEntry]): PlanToIndexesMap = { | ||
val planToIndexes = initializePlanToIndexes(plan, allIndexes) | ||
planToIndexes.flatMap { | ||
case (node, allIndexes) => | ||
Some( | ||
node, | ||
sourceFilters.foldLeft(allIndexes) { (indexes, filter) => | ||
filter(node, indexes) | ||
}).filter(_._2.nonEmpty) | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/scala/com/microsoft/hyperspace/index/rules/ColumnSchemaFilter.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,44 @@ | ||
/* | ||
* 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.LogicalPlan | ||
|
||
import com.microsoft.hyperspace.index.IndexLogEntry | ||
import com.microsoft.hyperspace.util.ResolverUtils | ||
|
||
/** | ||
* Check if the given source plan contains all index columns. | ||
*/ | ||
object ColumnSchemaFilter extends SourcePlanIndexFilter { | ||
override def apply(plan: LogicalPlan, indexes: Seq[IndexLogEntry]): Seq[IndexLogEntry] = { | ||
val relationColumnNames = plan.output.map(_.name) | ||
|
||
indexes.filter { index => | ||
withFilterReasonTag( | ||
plan, | ||
index, | ||
"Column Schema does not match. " + | ||
s"Relation columns: [${relationColumnNames.mkString(", ")}], " + | ||
s"Index columns: [${(index.derivedDataset.referencedColumns).mkString(", ")}]") { | ||
ResolverUtils | ||
.resolve(spark, index.derivedDataset.referencedColumns, relationColumnNames) | ||
.isDefined | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.