Skip to content
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

[Spark] Get rid of duplicated replaceCharWithVarchar function #3684

Merged
Show file tree
Hide file tree
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 @@ -154,7 +154,8 @@ case class WriteIntoDelta(
// If READ_SIDE_CHAR_PADDING is not enabled, CHAR type is the same as VARCHAR. The change
// below makes DESC TABLE to show VARCHAR instead of CHAR.
CharVarcharUtils.replaceCharVarcharWithStringInSchema(
replaceCharWithVarchar(CharVarcharUtils.getRawSchema(data.schema)).asInstanceOf[StructType])
CharVarcharUtils.replaceCharWithVarchar(CharVarcharUtils.getRawSchema(data.schema))
.asInstanceOf[StructType])
}
val finalSchema = schemaInCatalog.getOrElse(dataSchema)
if (txn.metadata.schemaString != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,6 @@ trait WriteIntoDeltaLike {
txn.registerSQLMetrics(spark, sqlMetrics)
}

import org.apache.spark.sql.types.{ArrayType, CharType, DataType, MapType, VarcharType}
protected def replaceCharWithVarchar(dt: DataType): DataType = dt match {
case ArrayType(et, nullable) =>
ArrayType(replaceCharWithVarchar(et), nullable)
case MapType(kt, vt, nullable) =>
MapType(replaceCharWithVarchar(kt), replaceCharWithVarchar(vt), nullable)
case StructType(fields) =>
StructType(fields.map { field =>
field.copy(dataType = replaceCharWithVarchar(field.dataType))
})
case CharType(length) => VarcharType(length)
case _ => dt
}

protected def extractConstraints(
sparkSession: SparkSession,
expr: Seq[Expression]): Seq[Constraint] = {
Expand Down
Loading