Skip to content
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

Make sure that writeOptions is used when passed to the writeFiles function #652

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 @@ -154,7 +154,7 @@ trait DeltaReadOptions extends DeltaOptionParser {
*/
class DeltaOptions(
@transient protected[delta] val options: CaseInsensitiveMap[String],
@transient protected val sqlConf: SQLConf)
@transient protected[delta] val sqlConf: SQLConf)
extends DeltaWriteOptions with DeltaReadOptions with Serializable {

DeltaOptions.verifyOptions(options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.apache.spark.sql.delta.files

import scala.collection.mutable.ListBuffer

import org.apache.spark.sql.delta._
import org.apache.spark.sql.delta.actions._
import org.apache.spark.sql.delta.constraints.{Constraint, Constraints, DeltaInvariantCheckerExec}
Expand All @@ -26,13 +25,13 @@ import org.apache.spark.sql.delta.schema._
import org.apache.spark.sql.delta.sources.DeltaSQLConf
import org.apache.commons.lang3.exception.ExceptionUtils
import org.apache.hadoop.fs.Path

import org.apache.spark.SparkException
import org.apache.spark.sql.Dataset
import org.apache.spark.sql.catalyst.expressions.{Attribute, AttributeReference}
import org.apache.spark.sql.execution._
import org.apache.spark.sql.execution.datasources.{BasicWriteJobStatsTracker, FileFormatWriter, WriteJobStatsTracker}
import org.apache.spark.sql.types.{ArrayType, MapType, StructType}
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types.StructType
import org.apache.spark.util.SerializableConfiguration

/**
Expand Down Expand Up @@ -131,15 +130,11 @@ trait TransactionalWrite extends DeltaLogging { self: OptimisticTransactionImpl
partitionColumns
}

def writeFiles(data: Dataset[_], writeOptions: Option[DeltaOptions]): Seq[FileAction] = {
writeFiles(data)
}

/**
* Writes out the dataframe after performing schema validation. Returns a list of
* actions to append these files to the reservoir.
*/
def writeFiles(data: Dataset[_]): Seq[FileAction] = {
def writeFiles(data: Dataset[_], writeOptions: Option[DeltaOptions] = None): Seq[FileAction] = {
if (DeltaConfigs.CHANGE_DATA_CAPTURE.fromMetaData(metadata) ||
DeltaConfigs.CHANGE_DATA_CAPTURE_LEGACY.fromMetaData(metadata)) {
throw DeltaErrors.cdcWriteNotAllowedInThisVersion()
Expand All @@ -151,6 +146,11 @@ trait TransactionalWrite extends DeltaLogging { self: OptimisticTransactionImpl
val partitionSchema = metadata.partitionSchema
val outputPath = deltaLog.dataPath

val (options, _) = writeOptions match {
case None => (Map.empty[String, String], null.asInstanceOf[SQLConf])
case Some(writeOptions) => (writeOptions.options, writeOptions.sqlConf)
}

val (queryExecution, output, generatedColumnConstraints) =
normalizeData(deltaLog, data, metadata.partitionColumns)
val partitioningColumns =
Expand Down Expand Up @@ -189,7 +189,7 @@ trait TransactionalWrite extends DeltaLogging { self: OptimisticTransactionImpl
partitionColumns = partitioningColumns,
bucketSpec = None,
statsTrackers = statsTrackers,
options = Map.empty)
options = options)
} catch {
case s: SparkException =>
// Pull an InvariantViolationException up to the top level if it was the root cause.
Expand Down