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

[HUDI-4093] Fix NPE when insert records that partition column is null #5573

Closed
wants to merge 1 commit into from
Closed
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 @@ -610,7 +610,7 @@ public static Option<String> getNullableValAsString(GenericRecord rec, String fi
* @return field value either converted (for certain data types) or as it is.
*/
public static Object convertValueForSpecificDataTypes(Schema fieldSchema, Object fieldValue, boolean consistentLogicalTimestampEnabled) {
if (fieldSchema == null) {
if (fieldSchema == null || fieldValue == null) {
Copy link
Member

Choose a reason for hiding this comment

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

Would this be fixed by #7349?

return fieldValue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,16 @@ object Spark3ParsePartitionUtil extends SparkParsePartitionUtil {
(dateFormatter, timestampFormatter)
})

val (partitionValues, _) = parsePartition(path, typeInference, basePaths, userSpecifiedDataTypes,
validatePartitionValues, tz.toZoneId, dateFormatter, timestampFormatter)
var partitionStr = path.toString
userSpecifiedDataTypes.keySet.foreach { name =>
val dataType = userSpecifiedDataTypes.get(name).getOrElse("")
if (!dataType.isInstanceOf[StringType]) {
partitionStr = partitionStr.replace(s"$name=default", s"$name=__HIVE_DEFAULT_PARTITION__")
Copy link
Member

Choose a reason for hiding this comment

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

Why this is needed only for Spark3?

Copy link
Member

Choose a reason for hiding this comment

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

Please also consider adding a test for this scenario.

}
}

val (partitionValues, _) = parsePartition(new Path(partitionStr), typeInference, basePaths, userSpecifiedDataTypes,
validatePartitionValues, tz.toZoneId, dateFormatter, timestampFormatter)
partitionValues.map {
case PartitionValues(columnNames: Seq[String], typedValues: Seq[TypedPartValue]) =>
val rowValues = columnNames.zip(typedValues).map { case (columnName, typedValue) =>
Expand Down