fieldIndex 方法如何在 Spark SQL Row 对象中工作?

How does the fieldIndex method work in a Spark SQL Row object?

当我查看 Rowcode 时,我发现了这些,

def schema: StructType = null

def fieldIndex(name: String): Int = {
  throw new UnsupportedOperationException("fieldIndex on a Row without schema is undefined.")
}

这看起来不像是做他们应该做的事情的代码。所以我想知道它们实际上是如何工作的?也许实际的定义是在别处定义的?

如果 Row 的子类有一个模式,那么这个方法将被简单地覆盖。例如在 GenericRowWithSchema:

def fieldIndex(name: String): Int = schema.fieldIndex(name)