Skip to content
Open
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 @@ -121,7 +121,7 @@ object AssignmentUtils extends SQLConfHelper with CastSupport {
val actualAttr = restoreActualType(attr)
val value = matchingAssignments.head.value
TableOutputResolver.resolveUpdate(
"", value, actualAttr, conf, err => errors += err, colPath)
"", value, actualAttr, conf, err => errors += err, colPath, true)
}
Assignment(attr, resolvedValue)
}
Expand Down Expand Up @@ -165,7 +165,8 @@ object AssignmentUtils extends SQLConfHelper with CastSupport {
TableOutputResolver.checkNullability(colExpr, col, conf, colPath)
} else if (exactAssignments.nonEmpty) {
val value = exactAssignments.head.value
TableOutputResolver.resolveUpdate("", value, col, conf, addError, colPath)
TableOutputResolver.resolveUpdate("", value, col, conf, addError, colPath,
fillDefaultValue = true)
} else {
applyFieldAssignments(col, colExpr, fieldAssignments, addError, colPath)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ object TableOutputResolver extends SQLConfHelper with Logging {
col: Attribute,
conf: SQLConf,
addError: String => Unit,
colPath: Seq[String]): Expression = {
colPath: Seq[String],
fillDefaultValue: Boolean): Expression = {

(value.dataType, col.dataType) match {
// no need to reorder inner fields or cast if types are already compatible
Expand All @@ -140,17 +141,17 @@ object TableOutputResolver extends SQLConfHelper with Logging {
case (valueType: StructType, colType: StructType) =>
val resolvedValue = resolveStructType(
tableName, value, valueType, col, colType,
byName = true, conf, addError, colPath)
byName = true, conf, addError, colPath, fillDefaultValue)
resolvedValue.getOrElse(value)
case (valueType: ArrayType, colType: ArrayType) =>
val resolvedValue = resolveArrayType(
tableName, value, valueType, col, colType,
byName = true, conf, addError, colPath)
byName = true, conf, addError, colPath, fillDefaultValue)
resolvedValue.getOrElse(value)
case (valueType: MapType, colType: MapType) =>
val resolvedValue = resolveMapType(
tableName, value, valueType, col, colType,
byName = true, conf, addError, colPath)
byName = true, conf, addError, colPath, fillDefaultValue)
resolvedValue.getOrElse(value)
case _ =>
checkUpdate(tableName, value, col, conf, addError, colPath)
Expand Down Expand Up @@ -301,15 +302,15 @@ object TableOutputResolver extends SQLConfHelper with Logging {
case (matchedType: StructType, expectedType: StructType) =>
resolveStructType(
tableName, matchedCol, matchedType, actualExpectedCol, expectedType,
byName = true, conf, addError, newColPath)
byName = true, conf, addError, newColPath, fillDefaultValue)
case (matchedType: ArrayType, expectedType: ArrayType) =>
resolveArrayType(
tableName, matchedCol, matchedType, actualExpectedCol, expectedType,
byName = true, conf, addError, newColPath)
byName = true, conf, addError, newColPath, fillDefaultValue)
case (matchedType: MapType, expectedType: MapType) =>
resolveMapType(
tableName, matchedCol, matchedType, actualExpectedCol, expectedType,
byName = true, conf, addError, newColPath)
byName = true, conf, addError, newColPath, fillDefaultValue)
case _ =>
checkField(
tableName, actualExpectedCol, matchedCol, byName = true, conf, addError, newColPath)
Expand Down Expand Up @@ -421,13 +422,15 @@ object TableOutputResolver extends SQLConfHelper with Logging {
byName: Boolean,
conf: SQLConf,
addError: String => Unit,
colPath: Seq[String]): Option[NamedExpression] = {
colPath: Seq[String],
fillDefaultValue: Boolean = false): Option[NamedExpression] = {
val nullCheckedInput = checkNullability(input, expected, conf, colPath)
val fields = inputType.zipWithIndex.map { case (f, i) =>
Alias(GetStructField(nullCheckedInput, i, Some(f.name)), f.name)()
}
val resolved = if (byName) {
reorderColumnsByName(tableName, fields, toAttributes(expectedType), conf, addError, colPath)
reorderColumnsByName(tableName, fields, toAttributes(expectedType), conf, addError, colPath,
fillDefaultValue)
} else {
resolveColumnsByPosition(
tableName, fields, toAttributes(expectedType), conf, addError, colPath)
Expand All @@ -454,13 +457,15 @@ object TableOutputResolver extends SQLConfHelper with Logging {
byName: Boolean,
conf: SQLConf,
addError: String => Unit,
colPath: Seq[String]): Option[NamedExpression] = {
colPath: Seq[String],
fillDefaultValue: Boolean = false): Option[NamedExpression] = {
val nullCheckedInput = checkNullability(input, expected, conf, colPath)
val param = NamedLambdaVariable("element", inputType.elementType, inputType.containsNull)
val fakeAttr =
AttributeReference("element", expectedType.elementType, expectedType.containsNull)()
val res = if (byName) {
reorderColumnsByName(tableName, Seq(param), Seq(fakeAttr), conf, addError, colPath)
reorderColumnsByName(tableName, Seq(param), Seq(fakeAttr), conf, addError, colPath,
fillDefaultValue)
} else {
resolveColumnsByPosition(tableName, Seq(param), Seq(fakeAttr), conf, addError, colPath)
}
Expand Down Expand Up @@ -488,13 +493,15 @@ object TableOutputResolver extends SQLConfHelper with Logging {
byName: Boolean,
conf: SQLConf,
addError: String => Unit,
colPath: Seq[String]): Option[NamedExpression] = {
colPath: Seq[String],
fillDefaultValue: Boolean = false): Option[NamedExpression] = {
val nullCheckedInput = checkNullability(input, expected, conf, colPath)

val keyParam = NamedLambdaVariable("key", inputType.keyType, nullable = false)
val fakeKeyAttr = AttributeReference("key", expectedType.keyType, nullable = false)()
val resKey = if (byName) {
reorderColumnsByName(tableName, Seq(keyParam), Seq(fakeKeyAttr), conf, addError, colPath)
reorderColumnsByName(tableName, Seq(keyParam), Seq(fakeKeyAttr), conf, addError, colPath,
fillDefaultValue)
} else {
resolveColumnsByPosition(tableName, Seq(keyParam), Seq(fakeKeyAttr), conf, addError, colPath)
}
Expand All @@ -504,7 +511,8 @@ object TableOutputResolver extends SQLConfHelper with Logging {
val fakeValueAttr =
AttributeReference("value", expectedType.valueType, expectedType.valueContainsNull)()
val resValue = if (byName) {
reorderColumnsByName(tableName, Seq(valueParam), Seq(fakeValueAttr), conf, addError, colPath)
reorderColumnsByName(tableName, Seq(valueParam), Seq(fakeValueAttr), conf, addError, colPath,
fillDefaultValue)
} else {
resolveColumnsByPosition(
tableName, Seq(valueParam), Seq(fakeValueAttr), conf, addError, colPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -892,8 +892,8 @@ private class BufferedRowsReader(
if (arrayData == null) {
null
} else {
extractArrayValue(arrayData, elementType,
readSchema.fields(readIndex).dataType)
val writeType = writeSchema.fields(writeIndex).dataType.asInstanceOf[ArrayType]
Copy link
Member Author

Choose a reason for hiding this comment

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

fix a bug here in InMemoryDataSource schema evolution for struct within arrays

extractArrayValue(arrayData, elementType, writeType.elementType)
}

case dt =>
Expand Down
Loading