Skip to content

[SPARK-4553] [SPARK-5767] [SQL] Wires Parquet data source with the newly introduced write support for data source API #4563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ class SQLContext(@transient val sparkContext: SparkContext)
baseRelationToDataFrame(parquet.ParquetRelation2(path +: paths, Map.empty)(this))
} else {
DataFrame(this, parquet.ParquetRelation(
paths.mkString(","), Some(sparkContext.hadoopConfiguration), this))
(path +: paths).mkString(","), Some(sparkContext.hadoopConfiguration), this))
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,6 @@ private[parquet] object FileSystemHelper {
sys.error("ERROR: attempting to append to set of Parquet files and found file" +
s"that does not match name pattern: $other")
case _ => 0
}.reduceLeft((a, b) => if (a < b) b else a)
}.reduceOption(_ max _).getOrElse(0)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import scala.reflect.ClassTag
import scala.reflect.runtime.universe.TypeTag
import scala.util.Try

import org.apache.spark.sql.{DataFrame, SQLContext}
import org.apache.spark.sql.catalyst.util
import org.apache.spark.sql.{DataFrame, SQLContext, SaveMode}
import org.apache.spark.util.Utils

/**
Expand All @@ -37,7 +37,8 @@ import org.apache.spark.util.Utils
trait ParquetTest {
val sqlContext: SQLContext

import sqlContext._
import sqlContext.implicits.{localSeqToDataFrameHolder, rddToDataFrameHolder}
import sqlContext.{conf, sparkContext}

protected def configuration = sparkContext.hadoopConfiguration

Expand All @@ -49,11 +50,11 @@ trait ParquetTest {
*/
protected def withSQLConf(pairs: (String, String)*)(f: => Unit): Unit = {
val (keys, values) = pairs.unzip
val currentValues = keys.map(key => Try(getConf(key)).toOption)
(keys, values).zipped.foreach(setConf)
val currentValues = keys.map(key => Try(conf.getConf(key)).toOption)
(keys, values).zipped.foreach(conf.setConf)
try f finally {
keys.zip(currentValues).foreach {
case (key, Some(value)) => setConf(key, value)
case (key, Some(value)) => conf.setConf(key, value)
case (key, None) => conf.unsetConf(key)
}
}
Expand Down Expand Up @@ -88,7 +89,6 @@ trait ParquetTest {
protected def withParquetFile[T <: Product: ClassTag: TypeTag]
(data: Seq[T])
(f: String => Unit): Unit = {
import sqlContext.implicits._
withTempPath { file =>
sparkContext.parallelize(data).toDF().saveAsParquetFile(file.getCanonicalPath)
f(file.getCanonicalPath)
Expand All @@ -102,14 +102,14 @@ trait ParquetTest {
protected def withParquetRDD[T <: Product: ClassTag: TypeTag]
(data: Seq[T])
(f: DataFrame => Unit): Unit = {
withParquetFile(data)(path => f(parquetFile(path)))
withParquetFile(data)(path => f(sqlContext.parquetFile(path)))
}

/**
* Drops temporary table `tableName` after calling `f`.
*/
protected def withTempTable(tableName: String)(f: => Unit): Unit = {
try f finally dropTempTable(tableName)
try f finally sqlContext.dropTempTable(tableName)
}

/**
Expand All @@ -125,4 +125,26 @@ trait ParquetTest {
withTempTable(tableName)(f)
}
}

protected def makeParquetFile[T <: Product: ClassTag: TypeTag](
data: Seq[T], path: File): Unit = {
data.toDF().save(path.getCanonicalPath, "org.apache.spark.sql.parquet", SaveMode.Overwrite)
}

protected def makePartitionDir(
basePath: File,
defaultPartitionName: String,
partitionCols: (String, Any)*): File = {
val partNames = partitionCols.map { case (k, v) =>
val valueString = if (v == null || v == "") defaultPartitionName else v.toString
s"$k=$valueString"
}

val partDir = partNames.foldLeft(basePath) { (parent, child) =>
new File(parent, child)
}

assert(partDir.mkdirs(), s"Couldn't create directory $partDir")
partDir
}
}
Loading