@@ -130,9 +130,34 @@ private[sql] object ParquetTestData {
130
130
|}
131
131
""" .stripMargin
132
132
133
+
134
+ val testNestedSchema2 =
135
+ """
136
+ |message TestNested2 {
137
+ |required int32 firstInt;
138
+ |optional int32 secondInt;
139
+ |optional group longs {
140
+ |repeated int64 values;
141
+ |}
142
+ |required group booleanNumberPairs {
143
+ |required double value;
144
+ |optional boolean truth;
145
+ |}
146
+ |required group outerouter {
147
+ |required group outer {
148
+ |required group inner {
149
+ |required int32 number;
150
+ |}
151
+ |}
152
+ |}
153
+ |}
154
+ """ .stripMargin
155
+
133
156
val testNestedDir1 = Utils .createTempDir()
157
+ val testNestedDir2 = Utils .createTempDir()
134
158
135
159
lazy val testNestedData1 = new ParquetRelation (testNestedDir1.toURI.toString)
160
+ lazy val testNestedData2 = new ParquetRelation (testNestedDir2.toURI.toString)
136
161
137
162
// Implicit
138
163
// TODO: get rid of this since it is confusing!
@@ -216,40 +241,50 @@ private[sql] object ParquetTestData {
216
241
val r2 = new SimpleGroup (schema)
217
242
r2.add(0 , " A. Nonymous" )
218
243
219
- // ParquetWriter initializes GroupWriteSupport with an empty configuration
220
- // (it is after all not intended to be used in this way?)
221
- // and members are private so we need to make our own
222
- val writeSupport = new WriteSupport [Group ] {
223
- var groupWriter : GroupWriter = null
224
- override def prepareForWrite (recordConsumer : RecordConsumer ): Unit = {
225
- groupWriter = new GroupWriter (recordConsumer, schema)
226
- }
227
- override def init (configuration : Configuration ): WriteContext = {
228
- new WriteContext (schema, new java.util.HashMap [String , String ]())
229
- }
230
- override def write (record : Group ) {
231
- groupWriter.write(record)
232
- }
233
- }
244
+ val writeSupport = new TestGroupWriteSupport (schema)
234
245
val writer = new ParquetWriter [Group ](path, writeSupport)
235
246
writer.write(r1)
236
247
writer.write(r2)
237
248
writer.close()
238
249
}
239
250
240
- def readNestedFile (): Unit = {
251
+ def writeNestedFile2 () {
252
+ testNestedDir2.delete()
253
+ val path : Path = testNestedDir2
254
+ val schema : MessageType = MessageTypeParser .parseMessageType(testNestedSchema2)
255
+
256
+ val r1 = new SimpleGroup (schema)
257
+ r1.add(0 , 1 )
258
+ r1.add(1 , 7 )
259
+ val longs = r1.addGroup(2 )
260
+ longs.add(" values" , 1 .toLong << 32 )
261
+ longs.add(" values" , 1 .toLong << 33 )
262
+ longs.add(" values" , 1 .toLong << 34 )
263
+ val booleanNumberPairs = r1.addGroup(3 )
264
+ booleanNumberPairs.add(" value" , 2.5 )
265
+ booleanNumberPairs.add(" truth" , false )
266
+ r1.addGroup(4 ).addGroup(0 ).addGroup(0 ).add(" number" , 7 )
267
+ r1.addGroup(4 ).addGroup(0 ).addGroup(0 ).add(" number" , 8 )
268
+ r1.addGroup(4 ).addGroup(0 ).addGroup(0 ).add(" number" , 9 )
269
+
270
+ val writeSupport = new TestGroupWriteSupport (schema)
271
+ val writer = new ParquetWriter [Group ](path, writeSupport)
272
+ writer.write(r1)
273
+ writer.close()
274
+ }
275
+
276
+
277
+ def readNestedFile (path : File , schemaString : String ): Unit = {
241
278
val configuration = new Configuration ()
242
- val fs : FileSystem = testNestedDir1.getFileSystem(configuration)
243
- val schema : MessageType = MessageTypeParser .parseMessageType(testNestedSchema1)
244
- val outputStatus : FileStatus = fs.getFileStatus(testNestedDir1)
279
+ val fs : FileSystem = path.getFileSystem(configuration)
280
+ val schema : MessageType = MessageTypeParser .parseMessageType(schemaString)
281
+ assert(schema != null )
282
+ val outputStatus : FileStatus = fs.getFileStatus(path)
245
283
val footers = ParquetFileReader .readFooter(configuration, outputStatus)
246
- val reader = new ParquetReader (testNestedDir1, new GroupReadSupport ())
284
+ assert(footers != null )
285
+ val reader = new ParquetReader (path, new GroupReadSupport ())
247
286
val first = reader.read()
248
287
assert(first != null )
249
- val second = reader.read()
250
- assert(second != null )
251
- assert(schema != null )
252
- assert(footers != null )
253
288
}
254
289
}
255
290
0 commit comments