-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[HUDI-6963] Fix class conflict of CreateIndex from Spark3.3 #9895
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -19,10 +19,9 @@ | |||
|
||||
package org.apache.spark.sql.hudi.command | ||||
|
||||
import com.fasterxml.jackson.annotation.{JsonAutoDetect, PropertyAccessor} | ||||
import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper} | ||||
import org.apache.hudi.HoodieConversionUtils.toScalaOption | ||||
import org.apache.hudi.common.table.HoodieTableMetaClient | ||||
import org.apache.hudi.common.util.JsonUtils | ||||
import org.apache.hudi.secondary.index.SecondaryIndexManager | ||||
import org.apache.spark.internal.Logging | ||||
import org.apache.spark.sql.catalyst.catalog.CatalogTable | ||||
|
@@ -32,23 +31,21 @@ import org.apache.spark.sql.hudi.HoodieSqlCommonUtils.getTableLocation | |||
import org.apache.spark.sql.{Row, SparkSession} | ||||
|
||||
import java.util | ||||
|
||||
import scala.collection.JavaConverters.{collectionAsScalaIterableConverter, mapAsJavaMapConverter} | ||||
|
||||
case class CreateIndexCommand(table: CatalogTable, | ||||
indexName: String, | ||||
indexType: String, | ||||
ignoreIfExists: Boolean, | ||||
columns: Seq[(Attribute, Map[String, String])], | ||||
options: Map[String, String], | ||||
override val output: Seq[Attribute]) extends IndexBaseCommand { | ||||
columns: Seq[(Seq[String], Map[String, String])], | ||||
options: Map[String, String]) extends IndexBaseCommand { | ||||
|
||||
override def run(sparkSession: SparkSession): Seq[Row] = { | ||||
val tableId = table.identifier | ||||
val metaClient = createHoodieTableMetaClient(tableId, sparkSession) | ||||
val columnsMap: java.util.LinkedHashMap[String, java.util.Map[String, String]] = | ||||
new util.LinkedHashMap[String, java.util.Map[String, String]]() | ||||
columns.map(c => columnsMap.put(c._1.name, c._2.asJava)) | ||||
columns.map(c => columnsMap.put(c._1.mkString("."), c._2.asJava)) | ||||
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. Why change this? for nested fields? 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. Now columns' name is Line 208 in 6eb38c5
UnresolvedAttribute is no need anymore, so here I directly use Seq[String] to represent the column name here
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. Got it. |
||||
|
||||
SecondaryIndexManager.getInstance().create( | ||||
metaClient, indexName, indexType, ignoreIfExists, columnsMap, options.asJava) | ||||
|
@@ -65,8 +62,7 @@ case class CreateIndexCommand(table: CatalogTable, | |||
|
||||
case class DropIndexCommand(table: CatalogTable, | ||||
indexName: String, | ||||
ignoreIfNotExists: Boolean, | ||||
override val output: Seq[Attribute]) extends IndexBaseCommand { | ||||
ignoreIfNotExists: Boolean) extends IndexBaseCommand { | ||||
|
||||
override def run(sparkSession: SparkSession): Seq[Row] = { | ||||
val tableId = table.identifier | ||||
|
@@ -90,7 +86,7 @@ case class ShowIndexesCommand(table: CatalogTable, | |||
val metaClient = createHoodieTableMetaClient(table.identifier, sparkSession) | ||||
val secondaryIndexes = SecondaryIndexManager.getInstance().show(metaClient) | ||||
|
||||
val mapper = getObjectMapper | ||||
val mapper = JsonUtils.getObjectMapper | ||||
toScalaOption(secondaryIndexes).map(x => | ||||
x.asScala.map(i => { | ||||
val colOptions = | ||||
|
@@ -100,18 +96,10 @@ case class ShowIndexesCommand(table: CatalogTable, | |||
i.getIndexType.name().toLowerCase, colOptions, options) | ||||
}).toSeq).getOrElse(Seq.empty[Row]) | ||||
} | ||||
|
||||
protected def getObjectMapper: ObjectMapper = { | ||||
val mapper = new ObjectMapper | ||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) | ||||
mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY) | ||||
mapper | ||||
} | ||||
} | ||||
|
||||
case class RefreshIndexCommand(table: CatalogTable, | ||||
indexName: String, | ||||
override val output: Seq[Attribute]) extends IndexBaseCommand { | ||||
indexName: String) extends IndexBaseCommand { | ||||
|
||||
override def run(sparkSession: SparkSession): Seq[Row] = { | ||||
val metaClient = createHoodieTableMetaClient(table.identifier, sparkSession) | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need some of these tokens for other SQL statements?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I checked and only remove unneeded.