-
Notifications
You must be signed in to change notification settings - Fork 28.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial support for using ParquetTableScan to read HiveMetaStore tables.
- Loading branch information
Showing
4 changed files
with
250 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
sql/hive/src/test/scala/org/apache/spark/sql/parquet/ParquetMetastoreSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
|
||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark.sql.parquet | ||
|
||
import java.io.File | ||
|
||
import org.scalatest.BeforeAndAfterAll | ||
|
||
import scala.reflect.ClassTag | ||
|
||
import org.apache.spark.sql.{SQLConf, QueryTest} | ||
import org.apache.spark.sql.execution.{BroadcastHashJoin, ShuffledHashJoin} | ||
import org.apache.spark.sql.hive.test.TestHive | ||
import org.apache.spark.sql.hive.test.TestHive._ | ||
|
||
case class ParquetData(intField: Int, stringField: String) | ||
|
||
/** | ||
* Tests for our SerDe -> Native parquet scan conversion. | ||
*/ | ||
class ParquetMetastoreSuite extends QueryTest with BeforeAndAfterAll { | ||
|
||
override def beforeAll(): Unit = { | ||
setConf("spark.sql.hive.convertMetastoreParquet", "true") | ||
} | ||
|
||
override def afterAll(): Unit = { | ||
setConf("spark.sql.hive.convertMetastoreParquet", "false") | ||
} | ||
|
||
val partitionedTableDir = File.createTempFile("parquettests", "sparksql") | ||
partitionedTableDir.delete() | ||
partitionedTableDir.mkdir() | ||
|
||
(1 to 10).foreach { p => | ||
val partDir = new File(partitionedTableDir, s"p=$p") | ||
sparkContext.makeRDD(1 to 10) | ||
.map(i => ParquetData(i, s"part-$p")) | ||
.saveAsParquetFile(partDir.getCanonicalPath) | ||
} | ||
|
||
sql(s""" | ||
create external table partitioned_parquet | ||
( | ||
intField INT, | ||
stringField STRING | ||
) | ||
PARTITIONED BY (p int) | ||
ROW FORMAT SERDE 'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe' | ||
STORED AS | ||
INPUTFORMAT 'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat' | ||
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat' | ||
location '${partitionedTableDir.getCanonicalPath}' | ||
""") | ||
|
||
sql(s""" | ||
create external table normal_parquet | ||
( | ||
intField INT, | ||
stringField STRING | ||
) | ||
ROW FORMAT SERDE 'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe' | ||
STORED AS | ||
INPUTFORMAT 'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat' | ||
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat' | ||
location '${new File(partitionedTableDir, "p=1").getCanonicalPath}' | ||
""") | ||
|
||
(1 to 10).foreach { p => | ||
sql(s"ALTER TABLE partitioned_parquet ADD PARTITION (p=$p)") | ||
} | ||
|
||
test("simple count") { | ||
checkAnswer( | ||
sql("SELECT COUNT(*) FROM partitioned_parquet"), | ||
100) | ||
} | ||
|
||
test("pruned count") { | ||
checkAnswer( | ||
sql("SELECT COUNT(*) FROM partitioned_parquet WHERE p = 1"), | ||
10) | ||
} | ||
|
||
test("multi-partition pruned count") { | ||
checkAnswer( | ||
sql("SELECT COUNT(*) FROM partitioned_parquet WHERE p IN (1,2,3)"), | ||
30) | ||
} | ||
|
||
test("non-partition predicates") { | ||
checkAnswer( | ||
sql("SELECT COUNT(*) FROM partitioned_parquet WHERE intField IN (1,2,3)"), | ||
30) | ||
} | ||
|
||
test("sum") { | ||
checkAnswer( | ||
sql("SELECT SUM(intField) FROM partitioned_parquet WHERE intField IN (1,2,3) AND p = 1"), | ||
1 + 2 + 3 | ||
) | ||
} | ||
|
||
test("non-part select(*)") { | ||
checkAnswer( | ||
sql("SELECT COUNT(*) FROM normal_parquet"), | ||
10 | ||
) | ||
} | ||
} |