github.com/vc42/parquet-go@v0.0.0-20240320194221-1a9adb5f23f5/schema_test.go (about) 1 package parquet_test 2 3 import ( 4 "testing" 5 6 "github.com/vc42/parquet-go" 7 ) 8 9 func TestSchemaOf(t *testing.T) { 10 tests := []struct { 11 value interface{} 12 print string 13 }{ 14 { 15 value: new(struct{ Name string }), 16 print: `message { 17 required binary Name (STRING); 18 }`, 19 }, 20 21 { 22 value: new(struct { 23 X int 24 Y int 25 }), 26 print: `message { 27 required int64 X (INT(64,true)); 28 required int64 Y (INT(64,true)); 29 }`, 30 }, 31 32 { 33 value: new(struct { 34 X float32 35 Y float32 36 }), 37 print: `message { 38 required float X; 39 required float Y; 40 }`, 41 }, 42 43 { 44 value: new(struct { 45 Inner struct { 46 FirstName string `parquet:"first_name"` 47 LastName string `parquet:"last_name"` 48 } `parquet:"inner,optional"` 49 }), 50 print: `message { 51 optional group inner { 52 required binary first_name (STRING); 53 required binary last_name (STRING); 54 } 55 }`, 56 }, 57 58 { 59 value: new(struct { 60 Short float32 `parquet:"short,split"` 61 Long float64 `parquet:"long,split"` 62 }), 63 print: `message { 64 required float short; 65 required double long; 66 }`, 67 }, 68 69 { 70 value: new(struct { 71 Inner struct { 72 FirstName string `parquet:"first_name"` 73 ShouldNotBePresent string `parquet:"-"` 74 } `parquet:"inner,optional"` 75 }), 76 print: `message { 77 optional group inner { 78 required binary first_name (STRING); 79 } 80 }`, 81 }, 82 83 { 84 value: new(struct { 85 Inner struct { 86 FirstName string `parquet:"first_name"` 87 MyNameIsDash string `parquet:"-,"` 88 } `parquet:"inner,optional"` 89 }), 90 print: `message { 91 optional group inner { 92 required binary first_name (STRING); 93 required binary - (STRING); 94 } 95 }`, 96 }, 97 98 { 99 value: new(struct { 100 Inner struct { 101 TimestampMillis int64 `parquet:"timestamp_millis,timestamp"` 102 TimestampMicros int64 `parquet:"timestamp_micros,timestamp(microsecond)"` 103 } `parquet:"inner,optional"` 104 }), 105 print: `message { 106 optional group inner { 107 required int64 timestamp_millis (TIMESTAMP(isAdjustedToUTC=true,unit=MILLIS)); 108 required int64 timestamp_micros (TIMESTAMP(isAdjustedToUTC=true,unit=MICROS)); 109 } 110 }`, 111 }, 112 } 113 114 for _, test := range tests { 115 t.Run("", func(t *testing.T) { 116 schema := parquet.SchemaOf(test.value) 117 118 if s := schema.String(); s != test.print { 119 t.Errorf("\nexpected:\n\n%s\n\nfound:\n\n%s\n", test.print, s) 120 } 121 }) 122 } 123 }