Skip to content

Commit

Permalink
Implement methods instead of lazy vals
Browse files Browse the repository at this point in the history
  • Loading branch information
adeet1 committed Mar 28, 2024
1 parent 9fdc188 commit c7f8231
Showing 1 changed file with 25 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,38 +107,39 @@ class ParquetConverterFactory
}

private def computeTransformFunction(name: String, path: String, descriptor: AttributeDescriptor, schemaVersion: Int): String = {
// Make both expression vals lazy so that we only compute the one we need to, once we determine what the schema version is
lazy val expressionV2 = ObjectType.selectType(descriptor) match {
case Seq(ObjectType.GEOMETRY, ObjectType.POINT) => s"point(avroPath($$0, '/$name'))"
case Seq(ObjectType.GEOMETRY, ObjectType.MULTIPOINT) => s"multipoint(avroPath($$0, '/$name'))"
case Seq(ObjectType.GEOMETRY, ObjectType.LINESTRING) => s"linestring(avroPath($$0, '/$name'))"
case Seq(ObjectType.GEOMETRY, ObjectType.MULTILINESTRING) => s"multilinestring(avroPath($$0, '/$name'))"
case Seq(ObjectType.GEOMETRY, ObjectType.POLYGON) => s"polygon(avroPath($$0, '/$name'))"
case Seq(ObjectType.GEOMETRY, ObjectType.MULTIPOLYGON) => s"multipolygon(avroPath($$0, '/$name'))"
case Seq(ObjectType.UUID) => s"avroBinaryUuid($path)"
case _ => path
def expressionV2(name: String, path: String, descriptor: AttributeDescriptor): String = {
ObjectType.selectType(descriptor) match {
case Seq(ObjectType.GEOMETRY, ObjectType.POINT) => s"point(avroPath($$0, '/$name'))"
case Seq(ObjectType.GEOMETRY, ObjectType.MULTIPOINT) => s"multipoint(avroPath($$0, '/$name'))"
case Seq(ObjectType.GEOMETRY, ObjectType.LINESTRING) => s"linestring(avroPath($$0, '/$name'))"
case Seq(ObjectType.GEOMETRY, ObjectType.MULTILINESTRING) => s"multilinestring(avroPath($$0, '/$name'))"
case Seq(ObjectType.GEOMETRY, ObjectType.POLYGON) => s"polygon(avroPath($$0, '/$name'))"
case Seq(ObjectType.GEOMETRY, ObjectType.MULTIPOLYGON) => s"multipolygon(avroPath($$0, '/$name'))"
case Seq(ObjectType.UUID) => s"avroBinaryUuid($path)"
case _ => path
}
}

lazy val expressionV0V1 = ObjectType.selectType(descriptor) match {
case Seq(ObjectType.GEOMETRY, ObjectType.POINT) => s"parquetPoint($$0, '/$name')"
case Seq(ObjectType.GEOMETRY, ObjectType.MULTIPOINT) => s"parquetMultiPoint($$0, '/$name')"
case Seq(ObjectType.GEOMETRY, ObjectType.LINESTRING) => s"parquetLineString($$0, '/$name')"
case Seq(ObjectType.GEOMETRY, ObjectType.MULTILINESTRING) => s"parquetMultiLineString($$0, '/$name')"
case Seq(ObjectType.GEOMETRY, ObjectType.POLYGON) => s"parquetPolygon($$0, '/$name')"
case Seq(ObjectType.GEOMETRY, ObjectType.MULTIPOLYGON) => s"parquetMultiPolygon($$0, '/$name')"
case Seq(ObjectType.UUID) => s"avroBinaryUuid($path)"
case _ => path
def expressionV0V1(name: String, path: String, descriptor: AttributeDescriptor): String = {
ObjectType.selectType(descriptor) match {
case Seq(ObjectType.GEOMETRY, ObjectType.POINT) => s"parquetPoint($$0, '/$name')"
case Seq(ObjectType.GEOMETRY, ObjectType.MULTIPOINT) => s"parquetMultiPoint($$0, '/$name')"
case Seq(ObjectType.GEOMETRY, ObjectType.LINESTRING) => s"parquetLineString($$0, '/$name')"
case Seq(ObjectType.GEOMETRY, ObjectType.MULTILINESTRING) => s"parquetMultiLineString($$0, '/$name')"
case Seq(ObjectType.GEOMETRY, ObjectType.POLYGON) => s"parquetPolygon($$0, '/$name')"
case Seq(ObjectType.GEOMETRY, ObjectType.MULTIPOLYGON) => s"parquetMultiPolygon($$0, '/$name')"
case Seq(ObjectType.UUID) => s"avroBinaryUuid($path)"
case _ => path
}
}

schemaVersion match {
case 2 => expressionV2
case 1 => expressionV0V1
case 0 => expressionV0V1
case 2 => expressionV2(name, path, descriptor)
case 1 => expressionV0V1(name, path, descriptor)
case 0 => expressionV0V1(name, path, descriptor)
case v => throw new IllegalArgumentException(s"Unknown SimpleFeatureParquetSchema version: $v")
}
}


}

object ParquetConverterFactory {
Expand Down

0 comments on commit c7f8231

Please sign in to comment.