Skip to content
This repository was archived by the owner on Jun 14, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import org.apache.spark.sql.catalyst.util.TypeUtils
import org.apache.spark.sql.functions.{col, input_file_name, max, min}
import org.apache.spark.sql.types.{StructField, StructType}

import com.microsoft.hyperspace.HyperspaceException
import com.microsoft.hyperspace.{Hyperspace, HyperspaceException}
import com.microsoft.hyperspace.index.IndexLogEntry

case class MinMaxAnalysisResult(
colName: String,
Expand Down Expand Up @@ -777,4 +778,31 @@ object MinMaxAnalysisUtil extends MinMaxAnalysis {
def analyze(df: DataFrame, colNames: Seq[String]): String = {
analyze(df, colNames, "text")
}

private def latestIndexEntry(spark: SparkSession, indexName: String): IndexLogEntry = {
val idxManager = Hyperspace.getContext(spark).indexCollectionManager
val latestVer = idxManager.getIndexVersions(indexName, Seq("ACTIVE")).max
val indexEntry = idxManager.getIndex(indexName, latestVer).get

if (!Seq("CoveringIndex", "ZOrderCoveringIndex").contains(indexEntry.derivedDataset.kind)) {
throw HyperspaceException(s"Does not support index type: ${indexEntry.derivedDataset.kind}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if this is checked in the analyzeIndex? And is it possible to check supported index types more systemically?
If someone implement a new type of "CoveringIndex", it might be hard to come here to add it in the supported type.

}
indexEntry
}

def analyzeIndex(
spark: SparkSession,
indexName: String,
colNames: Seq[String],
format: String): String = {
val indexEntry = latestIndexEntry(spark, indexName)
val df = spark.read.parquet(indexEntry.content.files.map(_.toString): _*)
analyze(df, colNames, format)
}

def analyzeIndex(spark: SparkSession, indexName: String, format: String): String = {
val indexEntry = latestIndexEntry(spark, indexName)
val df = spark.read.parquet(indexEntry.content.files.map(_.toString): _*)
analyze(df, indexEntry.indexedColumns, format)
}
}