Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Rename path to fieldNames.
  • Loading branch information
rdblue committed Jun 5, 2019
commit b1ac505120d3e29119f7507ad1a225ddb2577d24
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,21 @@ object CatalogV2Util {

private def replace(
struct: StructType,
path: Seq[String],
fieldNames: Seq[String],
update: StructField => Option[StructField]): StructType = {

val pos = struct.getFieldIndex(path.head)
.getOrElse(throw new IllegalArgumentException(s"Cannot find field: ${path.head}"))
val pos = struct.getFieldIndex(fieldNames.head)
.getOrElse(throw new IllegalArgumentException(s"Cannot find field: ${fieldNames.head}"))
val field = struct.fields(pos)
val replacement: Option[StructField] = if (path.tail.isEmpty) {
val replacement: Option[StructField] = if (fieldNames.tail.isEmpty) {
update(field)
} else {
field.dataType match {
case nestedStruct: StructType =>
val updatedType: StructType = replace(nestedStruct, path.tail, update)
val updatedType: StructType = replace(nestedStruct, fieldNames.tail, update)
Some(StructField(field.name, updatedType, field.nullable, field.metadata))
case _ =>
throw new IllegalArgumentException(s"Not a struct: ${path.head}")
throw new IllegalArgumentException(s"Not a struct: ${fieldNames.head}")
}
}

Expand Down