private[samplers] def getAvroField()

in ratatool-sampling/src/main/scala/com/spotify/ratatool/samplers/BigSamplerAvro.scala [98:124]


  private[samplers] def getAvroField(
    r: GenericRecord,
    fieldPath: List[String],
    schema: Schema
  ): Any = {

    val (fieldName, fieldSchema, fieldValue) = getField(r, fieldPath, schema)

    if (fieldValue == null) {
      log.debug(
        s"Field `${fieldName}` of type ${fieldSchema.getType} is null, will not look" +
          " for nested values"
      )
      null
    } else {
      fieldSchema.getType match {
        case Type.RECORD if fieldPath.tail.nonEmpty =>
          getAvroField(fieldValue.asInstanceOf[GenericRecord], fieldPath.tail, fieldSchema)
        case Type.ARRAY | Type.MAP =>
          throw new UnsupportedOperationException(
            s"Type `${fieldSchema.getType}` of `${fieldName}` is not supported as stratification " +
              s"key!"
          )
        case _ => fieldValue
      }
    }
  }