@@ -20,7 +20,7 @@ import scala.collection.mutable.ArrayBuffer
2020
2121import org .apache .hadoop .fs .Path
2222
23- import org .apache .spark .sql .catalyst .expressions .Literal
23+ import org .apache .spark .sql .catalyst .expressions ._
2424import org .apache .spark .sql .parquet .ParquetRelation2 ._
2525import org .apache .spark .sql .test .TestSQLContext
2626import org .apache .spark .sql .types ._
@@ -40,6 +40,10 @@ class ParquetPartitionDiscoverySuite extends QueryTest with ParquetTest {
4040
4141 val defaultPartitionName = " __NULL__"
4242
43+ def create_row (values : Any * ): Row = {
44+ new GenericRow (values.map(Literal .convertToUTF8String).toArray)
45+ }
46+
4347 test(" column type inference" ) {
4448 def check (raw : String , literal : Literal ): Unit = {
4549 assert(inferPartitionColumnValue(raw, defaultPartitionName) === literal)
@@ -107,7 +111,7 @@ class ParquetPartitionDiscoverySuite extends QueryTest with ParquetTest {
107111 StructType (Seq (
108112 StructField (" a" , IntegerType ),
109113 StructField (" b" , StringType ))),
110- Seq (Partition (Row (10 , " hello" ), " hdfs://host:9000/path/a=10/b=hello" ))))
114+ Seq (Partition (create_row (10 , " hello" ), " hdfs://host:9000/path/a=10/b=hello" ))))
111115
112116 check(Seq (
113117 " hdfs://host:9000/path/a=10/b=20" ,
@@ -117,8 +121,8 @@ class ParquetPartitionDiscoverySuite extends QueryTest with ParquetTest {
117121 StructField (" a" , FloatType ),
118122 StructField (" b" , StringType ))),
119123 Seq (
120- Partition (Row (10 , " 20" ), " hdfs://host:9000/path/a=10/b=20" ),
121- Partition (Row (10.5 , " hello" ), " hdfs://host:9000/path/a=10.5/b=hello" ))))
124+ Partition (create_row (10 , " 20" ), " hdfs://host:9000/path/a=10/b=20" ),
125+ Partition (create_row (10.5 , " hello" ), " hdfs://host:9000/path/a=10.5/b=hello" ))))
122126
123127 check(Seq (
124128 s " hdfs://host:9000/path/a=10/b=20 " ,
@@ -128,8 +132,8 @@ class ParquetPartitionDiscoverySuite extends QueryTest with ParquetTest {
128132 StructField (" a" , IntegerType ),
129133 StructField (" b" , StringType ))),
130134 Seq (
131- Partition (Row (10 , " 20" ), s " hdfs://host:9000/path/a=10/b=20 " ),
132- Partition (Row (null , " hello" ), s " hdfs://host:9000/path/a= $defaultPartitionName/b=hello " ))))
135+ Partition (create_row (10 , " 20" ), s " hdfs://host:9000/path/a=10/b=20 " ),
136+ Partition (create_row (null , " hello" ), s " hdfs://host:9000/path/a= $defaultPartitionName/b=hello " ))))
133137
134138 check(Seq (
135139 s " hdfs://host:9000/path/a=10/b= $defaultPartitionName" ,
@@ -139,8 +143,8 @@ class ParquetPartitionDiscoverySuite extends QueryTest with ParquetTest {
139143 StructField (" a" , FloatType ),
140144 StructField (" b" , StringType ))),
141145 Seq (
142- Partition (Row (10 , null ), s " hdfs://host:9000/path/a=10/b= $defaultPartitionName" ),
143- Partition (Row (10.5 , null ), s " hdfs://host:9000/path/a=10.5/b= $defaultPartitionName" ))))
146+ Partition (create_row (10 , null ), s " hdfs://host:9000/path/a=10/b= $defaultPartitionName" ),
147+ Partition (create_row (10.5 , null ), s " hdfs://host:9000/path/a=10.5/b= $defaultPartitionName" ))))
144148 }
145149
146150 test(" read partitioned table - normal case" ) {
@@ -163,29 +167,29 @@ class ParquetPartitionDiscoverySuite extends QueryTest with ParquetTest {
163167 i <- 1 to 10
164168 pi <- Seq (1 , 2 )
165169 ps <- Seq (" foo" , " bar" )
166- } yield Row (i, i.toString, pi, ps))
170+ } yield create_row (i, i.toString, pi, ps))
167171
168172 checkAnswer(
169173 sql(" SELECT intField, pi FROM t" ),
170174 for {
171175 i <- 1 to 10
172176 pi <- Seq (1 , 2 )
173177 _ <- Seq (" foo" , " bar" )
174- } yield Row (i, pi))
178+ } yield create_row (i, pi))
175179
176180 checkAnswer(
177181 sql(" SELECT * FROM t WHERE pi = 1" ),
178182 for {
179183 i <- 1 to 10
180184 ps <- Seq (" foo" , " bar" )
181- } yield Row (i, i.toString, 1 , ps))
185+ } yield create_row (i, i.toString, 1 , ps))
182186
183187 checkAnswer(
184188 sql(" SELECT * FROM t WHERE ps = 'foo'" ),
185189 for {
186190 i <- 1 to 10
187191 pi <- Seq (1 , 2 )
188- } yield Row (i, i.toString, pi, " foo" ))
192+ } yield create_row (i, i.toString, pi, " foo" ))
189193 }
190194 }
191195 }
@@ -210,29 +214,29 @@ class ParquetPartitionDiscoverySuite extends QueryTest with ParquetTest {
210214 i <- 1 to 10
211215 pi <- Seq (1 , 2 )
212216 ps <- Seq (" foo" , " bar" )
213- } yield Row (i, pi, i.toString, ps))
217+ } yield create_row (i, pi, i.toString, ps))
214218
215219 checkAnswer(
216220 sql(" SELECT intField, pi FROM t" ),
217221 for {
218222 i <- 1 to 10
219223 pi <- Seq (1 , 2 )
220224 _ <- Seq (" foo" , " bar" )
221- } yield Row (i, pi))
225+ } yield create_row (i, pi))
222226
223227 checkAnswer(
224228 sql(" SELECT * FROM t WHERE pi = 1" ),
225229 for {
226230 i <- 1 to 10
227231 ps <- Seq (" foo" , " bar" )
228- } yield Row (i, 1 , i.toString, ps))
232+ } yield create_row (i, 1 , i.toString, ps))
229233
230234 checkAnswer(
231235 sql(" SELECT * FROM t WHERE ps = 'foo'" ),
232236 for {
233237 i <- 1 to 10
234238 pi <- Seq (1 , 2 )
235- } yield Row (i, pi, i.toString, " foo" ))
239+ } yield create_row (i, pi, i.toString, " foo" ))
236240 }
237241 }
238242 }
@@ -264,21 +268,21 @@ class ParquetPartitionDiscoverySuite extends QueryTest with ParquetTest {
264268 i <- 1 to 10
265269 pi <- Seq (1 , null .asInstanceOf [Integer ])
266270 ps <- Seq (" foo" , null .asInstanceOf [String ])
267- } yield Row (i, i.toString, pi, ps))
271+ } yield create_row (i, i.toString, pi, ps))
268272
269273 checkAnswer(
270274 sql(" SELECT * FROM t WHERE pi IS NULL" ),
271275 for {
272276 i <- 1 to 10
273277 ps <- Seq (" foo" , null .asInstanceOf [String ])
274- } yield Row (i, i.toString, null , ps))
278+ } yield create_row (i, i.toString, null , ps))
275279
276280 checkAnswer(
277281 sql(" SELECT * FROM t WHERE ps IS NULL" ),
278282 for {
279283 i <- 1 to 10
280284 pi <- Seq (1 , null .asInstanceOf [Integer ])
281- } yield Row (i, i.toString, pi, null ))
285+ } yield create_row (i, i.toString, pi, null ))
282286 }
283287 }
284288 }
@@ -309,14 +313,14 @@ class ParquetPartitionDiscoverySuite extends QueryTest with ParquetTest {
309313 i <- 1 to 10
310314 pi <- Seq (1 , 2 )
311315 ps <- Seq (" foo" , null .asInstanceOf [String ])
312- } yield Row (i, pi, i.toString, ps))
316+ } yield create_row (i, pi, i.toString, ps))
313317
314318 checkAnswer(
315319 sql(" SELECT * FROM t WHERE ps IS NULL" ),
316320 for {
317321 i <- 1 to 10
318322 pi <- Seq (1 , 2 )
319- } yield Row (i, pi, i.toString, null ))
323+ } yield create_row (i, pi, i.toString, null ))
320324 }
321325 }
322326 }
@@ -336,7 +340,7 @@ class ParquetPartitionDiscoverySuite extends QueryTest with ParquetTest {
336340 withTempTable(" t" ) {
337341 checkAnswer(
338342 sql(" SELECT * FROM t" ),
339- (1 to 10 ).map(i => Row (i, null , 1 )) ++ (1 to 10 ).map(i => Row (i, i.toString, 2 )))
343+ (1 to 10 ).map(i => create_row (i, null , 1 )) ++ (1 to 10 ).map(i => create_row (i, i.toString, 2 )))
340344 }
341345 }
342346 }
0 commit comments