1717
1818package com .spotify .scio .testing .parquet
1919
20+ import com .google .common .base .CaseFormat
2021import com .spotify .scio .avro .{Account , AccountStatus }
21- import org .apache .avro .SchemaBuilder
22+ import org .apache .avro .{ Schema , SchemaBuilder }
2223import org .apache .avro .generic .GenericRecordBuilder
2324import org .apache .parquet .filter2 .predicate .FilterApi
2425import org .scalatest .flatspec .AnyFlatSpec
@@ -29,6 +30,7 @@ import org.tensorflow.proto._
2930import scala .jdk .CollectionConverters ._
3031
3132case class SomeRecord (id : Int )
33+ case class SomeRecordWithList (id : Int , arrayField : List [Int ])
3234
3335class ParquetTestUtilsTest extends AnyFlatSpec with Matchers {
3436
@@ -108,22 +110,40 @@ class ParquetTestUtilsTest extends AnyFlatSpec with Matchers {
108110
109111 it should " be projectable via case class" in {
110112 import com .spotify .scio .testing .parquet .avro ._
113+ import magnolify .parquet ._
114+ import magnolify .shared .CaseMapper
115+
116+ // AvroCompat is deprecated, but keep for backwards-compat testing purposes until removed
117+ // Todo eventually replace with MagnolifyParquetProperties
118+ import magnolify .parquet .ParquetArray .AvroCompat ._
119+
120+ // Map `arrayField` -> `array_field` and test that the implicitly scoped ParquetType is used to project
121+ implicit val caseMappedParquetType : ParquetType [SomeRecordWithList ] =
122+ ParquetType [SomeRecordWithList ](
123+ CaseMapper (CaseFormat .LOWER_CAMEL .converterTo(CaseFormat .LOWER_UNDERSCORE ).convert _)
124+ )
111125
112126 val recordSchema = SchemaBuilder
113127 .record(" TestRecord" )
114128 .fields()
115129 .requiredInt(" id" )
116130 .optionalString(" string_field" )
131+ .name(" array_field" )
132+ .`type`(Schema .createArray(Schema .create(Schema .Type .INT )))
133+ .noDefault()
117134 .endRecord()
118135
119136 val records = (1 to 10 ).map(i =>
120137 new GenericRecordBuilder (recordSchema)
121138 .set(" id" , i)
122139 .set(" string_field" , i.toString)
140+ .set(" array_field" , List (i).asJava)
123141 .build()
124142 )
125143
126- records.withProjection[SomeRecord ] should contain theSameElementsAs (1 to 10 ).map(SomeRecord )
144+ records.withProjection[SomeRecordWithList ] should contain theSameElementsAs (1 to 10 ).map(i =>
145+ SomeRecordWithList (i, List (i))
146+ )
127147 }
128148
129149 " Case classes" should " be filterable" in {
0 commit comments