-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement analyze skipping index statement (#284)
* dummy result test Signed-off-by: Rupal Mahajan <[email protected]> * Add grammar for analyze skipping index Signed-off-by: Rupal Mahajan <[email protected]> * Add analyze skippig index function Signed-off-by: Rupal Mahajan <[email protected]> * update analyze strategy Signed-off-by: Rupal Mahajan <[email protected]> * Update recommendations Signed-off-by: Rupal Mahajan <[email protected]> * Add test Signed-off-by: Rupal Mahajan <[email protected]> * Format code Signed-off-by: Rupal Mahajan <[email protected]> * Remove unused import Signed-off-by: Rupal Mahajan <[email protected]> * Update doc Signed-off-by: Rupal Mahajan <[email protected]> * Update doc Signed-off-by: Rupal Mahajan <[email protected]> * nit Signed-off-by: Rupal Mahajan <[email protected]> --------- Signed-off-by: Rupal Mahajan <[email protected]>
- Loading branch information
Showing
8 changed files
with
187 additions
and
1 deletion.
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
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
24 changes: 24 additions & 0 deletions
24
...n/scala/org/opensearch/flint/spark/skipping/recommendations/AnalyzeSkippingStrategy.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,24 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.opensearch.flint.spark.skipping.recommendations | ||
|
||
import org.apache.spark.sql.{Row, SparkSession} | ||
|
||
/** | ||
* Automate skipping index column and algorithm selection. | ||
*/ | ||
trait AnalyzeSkippingStrategy { | ||
|
||
/** | ||
* Recommend skipping index columns and algorithm. | ||
* | ||
* @param tableName | ||
* table name | ||
* @return | ||
* skipping index recommendation dataframe | ||
*/ | ||
def analyzeSkippingIndexColumns(tableName: String, spark: SparkSession): Seq[Row] | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
.../scala/org/opensearch/flint/spark/skipping/recommendations/DataTypeSkippingStrategy.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,63 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.flint.spark.skipping.recommendations | ||
|
||
import scala.collection.mutable.ArrayBuffer | ||
|
||
import org.opensearch.flint.spark.skipping.FlintSparkSkippingStrategy.SkippingKind.{BLOOM_FILTER, MIN_MAX, PARTITION, VALUE_SET} | ||
|
||
import org.apache.spark.sql.{Row, SparkSession} | ||
import org.apache.spark.sql.flint.{loadTable, parseTableName} | ||
|
||
class DataTypeSkippingStrategy extends AnalyzeSkippingStrategy { | ||
|
||
val rules = Map( | ||
"PARTITION" -> (PARTITION.toString, "PARTITION data structure is recommended for partition columns"), | ||
"BooleanType" -> (VALUE_SET.toString, "VALUE_SET data structure is recommended for BooleanType columns"), | ||
"IntegerType" -> (MIN_MAX.toString, "MIN_MAX data structure is recommended for IntegerType columns"), | ||
"LongType" -> (MIN_MAX.toString, "MIN_MAX data structure is recommended for LongType columns"), | ||
"ShortType" -> (MIN_MAX.toString, "MIN_MAX data structure is recommended for ShortType columns"), | ||
"DateType" -> (BLOOM_FILTER.toString, "BLOOM_FILTER data structure is recommended for DateType columns"), | ||
"TimestampType" -> (BLOOM_FILTER.toString, "BLOOM_FILTER data structure is recommended for TimestampType columns"), | ||
"StringType" -> (BLOOM_FILTER.toString, "BLOOM_FILTER data structure is recommended for StringType columns"), | ||
"VarcharType" -> (BLOOM_FILTER.toString, "BLOOM_FILTER data structure is recommended for VarcharType columns"), | ||
"CharType" -> (BLOOM_FILTER.toString, "BLOOM_FILTER data structure is recommended for CharType columns"), | ||
"StructType" -> (BLOOM_FILTER.toString, "BLOOM_FILTER data structure is recommended for StructType columns")) | ||
|
||
override def analyzeSkippingIndexColumns(tableName: String, spark: SparkSession): Seq[Row] = { | ||
val (catalog, ident) = parseTableName(spark, tableName) | ||
val table = loadTable(catalog, ident).getOrElse( | ||
throw new IllegalStateException(s"Table $tableName is not found")) | ||
|
||
val partitionFields = table.partitioning().flatMap { transform => | ||
transform | ||
.references() | ||
.collect({ case reference => | ||
reference.fieldNames() | ||
}) | ||
.flatten | ||
.toSet | ||
} | ||
|
||
val result = ArrayBuffer[Row]() | ||
table.schema().fields.map { field => | ||
if (partitionFields.contains(field.name)) { | ||
result += Row( | ||
field.name, | ||
field.dataType.typeName, | ||
rules("PARTITION")._1, | ||
rules("PARTITION")._2) | ||
} else if (rules.contains(field.dataType.toString)) { | ||
result += Row( | ||
field.name, | ||
field.dataType.typeName, | ||
rules(field.dataType.toString)._1, | ||
rules(field.dataType.toString)._2) | ||
} | ||
} | ||
result | ||
} | ||
} |
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