File I/O with Snowpark Connect for Spark

With Snowpark Connect for Spark, you can read and write data in several file formats using the standard Spark DataFrame reader and writer APIs. You can use internal stages, external stages, and cloud storage locations as sources and destinations. For how to configure stages and cloud URIs, see External data sources with Snowpark Connect for Spark.

This page describes Snowpark Connect for Spark 1.51.0 and later. For 1.50.0 and earlier, see File I/O with Snowpark Connect for Spark 1.50.0 and earlier.

CSV, JSON, and XML options that you set with .option() (such as header, sep, or dateFormat) are applied with Apache Spark semantics. Parquet and text options are translated into the corresponding Snowflake file format options before Snowpark Connect for Spark executes the operation. The tables in the Format-specific options section describe each option.

Supported formats

FormatReadWrite
CSVSupportedSupported
JSONSupportedSupported
ParquetSupportedSupported
TextSupportedSupported
XMLSupportedNot supported
AvroNot supportedNot supported
ORCNot supportedNot supported

Next generation file reader and writer (Preview)

Starting in version 1.51.0, Snowpark Connect for Spark uses the next generation file reader and writer, which are designed to match Apache Spark behavior more closely. They handle these operations:

  • CSV: reads and writes
  • JSON: reads and writes
  • XML: reads

Parquet and text reads and writes work the same as in 1.50.0 and earlier. XML writes aren’t supported.

For more information, see:

Reading data

Use the standard Spark read API with format short-hands or .format(). Paths can be Snowflake stage notation (for example, @my_stage/path/), cloud URIs configured for your account, or local file paths on the machine where Snowpark Connect for Spark is running. Chain .option() calls to control format behavior.

# Read from a Snowflake stage
df = spark.read.csv("@my_stage/data/")
df = spark.read.json("@my_stage/events/")
df = spark.read.parquet("@my_stage/warehouse/")
df = spark.read.text("@my_stage/logs/")

# Read from a local file
df = spark.read.csv("/tmp/local_data.csv")

# XML supports schema inference, or you can provide an explicit schema.
# Set rowTag to the element that wraps each row.
df = spark.read.format("xml").option("rowTag", "record").load("@my_stage/exports/")
df = spark.read.format("xml").option("rowTag", "record").schema(schema).load("@my_stage/exports/")

# Set format options
df = (
    spark.read.option("header", "true")
    .option("delimiter", ";")
    .option("dateFormat", "yyyy-MM-dd")
    .csv("@my_stage/data/")
)

# Apply an explicit schema
df = spark.read.schema(my_schema).csv("@my_stage/data/")

Using input_file_name() on file reads

Spark’s input_file_name() (https://spark.apache.org/docs/latest/api/python/reference/pyspark.sql/api/pyspark.sql.functions.input_file_name.html) function returns the path of the file that produced each row. In Snowpark Connect for Spark, file metadata isn’t populated by default. Set snowpark.populateFileMetadata to true on the read to enable input_file_name() for CSV, JSON, Parquet, and XML file reads via DataFrameReader. Text reads don’t support input_file_name().

If you omit this option, input_file_name() returns an empty string for every row rather than raising an error.

The returned path depends on the format:

  • CSV, JSON, and XML: the fully qualified stage path, for example @my_db.my_schema.my_stage/data/file.csv.
  • Parquet: the path relative to the stage (from METADATA$FILENAME), for example data/file.parquet.

Both forms differ from Spark’s full URI form (for example, s3china://bucket/path/file.csv).

Enabling file metadata on multi-file paths can increase read cost compared with bulk reads that don’t need per-row filenames.

from pyspark.sql.functions import input_file_name

df = (
    spark.read
    .option("snowpark.populateFileMetadata", "true")
    .option("header", "true")
    .csv("@my_stage/data/")
)
df.select("*", input_file_name()).show()

Reading files with SQL identifiers

In addition to the DataFrameReader API, you can read files directly from SQL using Spark’s format-prefix identifier syntax with spark.sql():

spark.sql("SELECT * FROM parquet.`@my_stage/sales/`").show()

spark.sql("SELECT count(*) FROM csv.`@my_stage/raw/orders.csv`").show()

spark.sql("""
  SELECT user_id, event_type
  FROM   json.`@my_stage/events/2025/01/`
  WHERE  event_type IN ('click', 'view')
""").show()

spark.sql("SELECT value FROM text.`@my_stage/logs/access.log`").show()

Supported prefixes: csv.…, `json.`..., parquet.…, `text.`....

The path inside the backticks is treated the same as it would be by spark.read.<format>(path). Snowflake stage paths (@stage/...), cloud URIs, and local paths all work. Default format options apply (no header for CSV, automatic schema inference, and so on). If you need non-default options, use spark.read instead because the SQL identifier form doesn’t accept per-call options.

You can combine these file reads with the rest of your SQL: joins, aggregations, CTEs, and subqueries all work on top of them.

Writing data

Use the DataFrame write API with the same format short-hands.

df.write.csv("@my_stage/out/csv/")
df.write.json("@my_stage/out/json/")
df.write.parquet("@my_stage/out/parquet/")
df.write.text("@my_stage/out/text/")

Reading from and writing to Snowflake tables

You can treat Snowflake tables as Spark DataFrame sources and sinks.

# Read
df = spark.read.table("my_database.my_schema.my_table")
df = spark.table("my_table")

# Write
df.write.saveAsTable("my_database.my_schema.my_table")
df.write.mode("overwrite").saveAsTable("my_table")

Save modes

Set mode on the writer to control how writes interact with existing data. Not all modes are available for every format or destination type.

df.write.mode("overwrite").parquet("@my_stage/out/")
ModeSpark nameBehavior in Snowpark Connect for Spark
Error if existserrorDefault. For table writes, fails if the table already exists. For CSV and JSON file writes, fails with PATH_ALREADY_EXISTS if the target path already contains files. For Parquet and text file writes, existing files aren’t detected, and new files are added alongside existing ones (the same behavior as append). The errorifexists alias isn’t supported. Use error instead.
OverwriteoverwriteRemoves existing files at the target path before writing. For table writes, replaces the table.
AppendappendAdds new files alongside existing ones. Each write adds a unique ID to its filenames to avoid conflicts.
IgnoreignoreFor table writes, and for CSV and JSON file writes, skips the write if the target already exists or already contains files. For Parquet file writes, the mode is accepted, but existing files aren’t detected and new files are added. Text file writes raise an error for this mode.

Controlling output file count and size

By default, Snowflake decides how to split your output into files. For Parquet and text writes, you can control this with standard Spark APIs and Snowpark Connect for Spark-specific options. CSV and JSON writes don’t support these controls: Snowflake always determines the file count and size.

coalesce(1) for a single output file

For Parquet and text writes, the most common Spark idiom for producing one output file is honored:

df.coalesce(1).write.parquet("@my_stage/single_output/")

When coalesce(1) is used without partitionBy, Snowpark Connect for Spark routes the write into a single Snowflake file. For CSV and JSON writes, coalesce(1) is ignored, and the write can produce more than one file.

repartition(n) and output file count

repartition(n) doesn’t control the number of output files for non-partitioned writes. Snowflake determines the file count:

df.repartition(8).write.parquet("@my_stage/8way_output/")

For Parquet and text writes, use snowflake_max_file_size to limit the size of each file, and coalesce(1) or the single option to produce a single file. When you combine repartition(n) with partitionBy, the per-partition directory layout takes precedence and Snowflake controls the file count inside each col=value/ directory.

single and snowflake_max_file_size write options

Snowpark Connect for Spark provides two additional write options for explicit control over output layout. These options are supported for Parquet and text writes. CSV and JSON writes don’t support them.

OptionDescription
singleSet to true to force a single output file regardless of how many input partitions the DataFrame has. Equivalent to coalesce(1) for non-partitioned writes. Ignored when used with partitionBy.
snowflake_max_file_sizeMaximum size in bytes per output file. Values below 1 MB (1048576) are treated as 1 MB. Larger values reduce the file count; smaller values produce more files. When single-file behavior is active and this option isn’t set, Snowpark Connect for Spark defaults the cap to 1 GB. With single set to true, the write fails if the output exceeds this size.
df.write \
    .option("single", "true") \
    .option("snowflake_max_file_size", str(256 * 1024 * 1024)) \
    .parquet("@my_stage/sized_output/")

Compression

Set compression through .option("compression", "<codec>"). For writes, the default is NONE for CSV, JSON, and text, and SNAPPY for Parquet. For reads, GZIP, BZ2, ZSTD, and DEFLATE compression is auto-detected if not specified. For BROTLI and RAW_DEFLATE files, set compression explicitly.

For best performance, use splittable compression formats such as BZ2 (or SNAPPY for Parquet). Splittable formats allow Snowflake to decompress and process file chunks in parallel, which is significantly faster for large files than non-splittable formats like GZIP.

For text, Snowpark Connect for Spark normalizes codec names: UNCOMPRESSED becomes NONE, and Spark’s BZIP2 becomes BZ2. For CSV and JSON writes, use Spark codec names: bzip2, not bz2. Parquet writes always use SNAPPY. Compression can also be inferred from file extensions (.gz, .bz2, .snappy, .deflate).

CSV / JSONTextParquet
GZIP, BZIP2, DEFLATE, NONE (writes); GZIP, BZ2, BROTLI, ZSTD, DEFLATE, RAW_DEFLATE, NONE (reads)GZIP, BZ2, BROTLI, ZSTD, DEFLATE, RAW_DEFLATE, NONESNAPPY (writes); SNAPPY, LZO, NONE (reads, auto-detected)

XML reads support compressed files such as .xml.gz.

Parallel file reads

Multiple files

When you read from a directory or pass a list of file paths, Snowpark Connect for Spark reads the files in parallel automatically. No additional configuration is required.

# Read all files in a directory in parallel
df = spark.read.parquet("@my_stage/data/")

# Read a specific list of files in parallel
df = spark.read.parquet(
    "@my_stage/data/part-001.parquet",
    "@my_stage/data/part-002.parquet",
    "@my_stage/data/part-003.parquet",
)

Single large file

Snowpark Connect for Spark can also split a single large file into chunks and read them in parallel, so one large file doesn’t become a bottleneck. This is supported for CSV, JSON, and XML.

CSV: The file must be uncompressed (compression set to none) and multiLine must be false (the default):

df = spark.read.format("csv") \
    .option("compression", "none") \
    .load("@my_stage/large_file.csv")

JSON: The file must be uncompressed (compression set to none) or BZ2-compressed, and multiLine must be false (the default):

df = spark.read.option("compression", "none") \
    .json("@my_stage/large_file.jsonl")

# BZ2-compressed NDJSON also reads in parallel
df = spark.read.option("compression", "bz2") \
    .json("@my_stage/large_file.jsonl.bz2")

XML: Parallel reads are enabled by default:

df = spark.read.format("xml") \
    .option("rowTag", "record") \
    .load("@my_stage/large_export.xml")

Automatic exclusion of metadata files

When you read from a directory, Snowpark Connect for Spark automatically skips files that Spark also skips, so you don’t have to filter them out manually:

Excluded patternReason
_SUCCESSSpark write-completion marker
_metadata, _common_metadataParquet metadata sidecars
.DS_Store, other .* filesmacOS and hidden files
Any file starting with _ or .General Hadoop convention

This exclusion applies to CSV, JSON, Parquet, and XML reads at any directory depth, including inside partition subdirectories (for example, year=2025/_SUCCESS is skipped). Files ending in .crc aren’t excluded unless their names start with _ or .. Remove them from the read path or exclude them with pathGlobFilter (for example, *.csv).

Snowpark Connect for Spark also anchors read paths so that files outside your requested prefix are never picked up. For example, reading from @stage/sales/ won’t accidentally include files from @stage/sales_archive/.

pathGlobFilter doesn’t override automatic exclusion: files whose names start with _ or . are always skipped, even if the pattern matches them.

Directory listing (recursiveFileLookup)

Starting in version 1.29.0, Snowpark Connect for Spark supports the Spark recursiveFileLookup DataFrameReader option for csv, json, parquet, text, and xml reads. The option controls whether reads descend into nested subdirectories when you pass a directory path.

  • true: list data files recursively under the read path. Hive-style partition discovery is skipped.
  • false: list only direct children of the read path (depth-0). Files under Hive-style partition directories (key=value/) are still read. For Parquet reads, the partition values are also added as columns. CSV, JSON, and XML reads don’t add partition columns. See Partitioned data.

When you omit recursiveFileLookup, Snowpark Connect for Spark lists only direct children of the read path (depth-0), matching Apache Spark 3.5. Earlier versions, starting with 1.29.0, listed files recursively by default.

If your workloads read nested data under a directory root that is not Hive-partitioned, set the option to true:

df = spark.read.option("recursiveFileLookup", "true").csv("@my_stage/sales/")

For more details about the default change, see Directory listing (recursiveFileLookup) in the compatibility guide.

Format-specific options

CSV, JSON, and XML options that you set through .option() are applied with Apache Spark semantics. Parquet and text options are translated into Snowflake file format options before Snowpark Connect for Spark executes the read or write operation; their tables show the Snowflake counterpart of each option.

CSV, JSON, and XML reader options that aren’t recognized are ignored without a warning. CSV and JSON writes don’t accept writer options that they don’t recognize. For Parquet and text, options that don’t have a Snowflake equivalent are ignored, and Snowpark Connect for Spark logs a warning for each unsupported option.

Snowpark Connect read options

These options are specific to Snowpark Connect for Spark and aren’t part of open-source Spark. They apply across CSV, JSON, Parquet, and XML DataFrameReader reads. See Using input_file_name() on file reads for usage details.

Spark optionDefaultNotes
snowpark.populateFileMetadatafalseSet to true to enable input_file_name() on CSV, JSON, Parquet, and XML reads.

CSV options

Spark optionNotes
sep / delimiterDefault ,. delimiter is an alias for sep. A single backslash isn’t allowed as the delimiter; pass two backslashes ("\\\\" in Python) instead.
headerWhen true, the reader uses column names from the first row. When writing, controls whether a header row is written.
quoteDefault ". An empty value turns off quoting. A doubled quote ("") inside a quoted field is unescaped only when escape is set to ". On write, values that contain the delimiter are enclosed in quotes, and embedded quotes are escaped with \.
escapeDefault \. A single \ and \\ behave the same.
nullValueDefault "". Empty fields, quoted or unquoted, are read as null, and null values are written as empty fields. \N is read as the literal string \N unless you set nullValue to \N.
lineSepDefault \n. The default also handles \r\n line endings on read.
encoding / charsetDefault UTF-8. charset is an alias for encoding.
multiLineDefault false. Set to true to read quoted fields that contain line breaks.
dateFormatJava datetime pattern, for example dd/MM/yyyy. Snowflake format tokens such as DD/MM/YYYY aren’t supported and raise an error. See Date and timestamp formats.
timestampFormatJava datetime pattern, as for dateFormat. The default write format is yyyy-MM-dd'T'HH:mm:ss.SSSXXX (for example, 2025-01-09T15:04:05.123-08:00).
compressionSee Compression.
inferSchemaDefault false (read only). When false, all columns are read as strings.
rowsToInferSchemaNot supported. The option is ignored without a warning, and the schema is inferred from all rows.
modeDefault PERMISSIVE. Controls error handling on read: PERMISSIVE, DROPMALFORMED, or FAILFAST, as in Apache Spark. In PERMISSIVE mode, malformed rows are stored in the _corrupt_record column when that column is in the schema.
ignoreLeadingWhiteSpace / ignoreTrailingWhiteSpaceEach option trims whitespace from its own side only.
mergeSchemaWhen true, Snowpark Connect for Spark produces a union schema across files. New columns across files become nullable. Type widening (for example, INT to STRING) is supported. Multi-file reads with header = true produce a union schema whether or not mergeSchema or inferSchema is set.
pathGlobFilterFilters which files to read, using a glob pattern such as *.csv. Regular expressions aren’t supported.
recursiveFileLookupControls whether reads descend into nested subdirectories. Defaults to depth-0 listing, matching Apache Spark. See Directory listing.

CSV reads treat backslashes in unquoted fields as literal characters, fill missing trailing fields with null, drop extra fields, and skip blank lines.

JSON options

Spark optionNotes
multiLineDefault false. When true, the reader handles files that contain a JSON array at the top level or a JSON document that spans multiple lines.
dateFormatJava datetime pattern, for example dd/MM/yyyy. Snowflake format tokens such as DD/MM/YYYY raise an error. Without this option, ISO dates are read into DATE columns of an explicit schema, but schema inference reads date strings as STRING.
timestampFormatJava datetime pattern, for example dd/MM/yyyy HH:mm:ss. Snowflake format tokens aren’t recognized, and values read with them are null, without an error.
encodingDefault UTF-8. Encodings other than UTF-8 require lineSep.
modeDefault PERMISSIVE. Controls error handling on read: PERMISSIVE, DROPMALFORMED, or FAILFAST, as in Apache Spark. In PERMISSIVE mode, malformed records are stored in the _corrupt_record column when that column is in the schema.
dropFieldIfAllNullWhen true, fields that are null in every sampled row are dropped from the inferred schema.
samplingRatioFraction of rows to sample when inferring the schema. rowsToInferSchema isn’t supported for JSON and raises an error; use samplingRatio instead.
pathGlobFilterFilters which files to read, using a glob pattern such as *.json. Regular expressions aren’t supported.
recursiveFileLookupControls whether reads descend into nested subdirectories. Defaults to depth-0 listing, matching Apache Spark. See Directory listing.
compressionSee Compression.

JSON writes apply compression, dateFormat, timestampFormat, and ignoreNullFields, as in Apache Spark. The default timestamp write format is yyyy-MM-dd'T'HH:mm:ss.SSSXXX. nullValue isn’t supported for JSON writes.

Parquet options

Spark optionSnowflake file format optionNotes
pathGlobFilterPATTERNFilters which files to read. The value is passed to Snowflake PATTERN and is interpreted as a regular expression, not a glob. For example, use .*\.parquet instead of *.parquet.
compressionCOMPRESSIONAUTO for reads. Parquet writes always use SNAPPY; the compression option is ignored on Parquet writes.
mergeSchema(internal)When true and reading from multiple paths, Snowpark Connect for Spark infers the schema from each file and produces a union schema. New columns are added; type widening across files (for example, INT to STRING) isn’t supported.
rowsToInferSchema(internal)Read only. Default 20000. Controls the sample size used by Snowpark Connect for Spark when discovering complex types (STRUCT, MAP, ARRAY) inside Parquet VARIANT columns.
nullValueNULL_IFWrite only. Passed to NULL_IF on unload. Parquet stores null values natively, so null values stay null in the output files and no string is written.
recursiveFileLookup(see Directory listing)Controls whether reads descend into nested subdirectories. Supported in 1.29.0+. Defaults to depth-0 listing, matching Apache Spark.

Snowpark Connect for Spark also sets these options automatically based on session configuration:

  • BINARY_AS_TEXT = False (always)
  • USE_LOGICAL_TYPE: controlled by snowpark.connect.parquet.useLogicalType

When writing Parquet, structured complex types (ARRAY, MAP, STRUCT) are cast to VARIANT before unload so that Snowflake’s COPY INTO can produce valid Parquet files.

Text options

Text I/O uses a CSV file format internally with FIELD_DELIMITER = NONE.

Spark optionSnowflake file format optionNotes
lineSep / linesepRECORD_DELIMITERDefault \n. Controls the line separator for both reads and writes.
wholetextRECORD_DELIMITER = NONEWhen true, each file is read as a single row.
compressionCOMPRESSIONDefault auto for reads, NONE for writes.
recursiveFileLookup(see Directory listing)Controls whether reads descend into nested subdirectories. Supported in 1.29.0+. Defaults to depth-0 listing, matching Apache Spark.

Text writes always set ESCAPE_UNENCLOSED_FIELD = NONE and FILE_EXTENSION = txt. The DataFrame must contain exactly one string column.

XML options (read only)

XML supports schema inference. If no schema is provided, Snowpark Connect for Spark infers the schema from the data by reading the files and merging field types across all input. XML options are applied with Apache Spark semantics.

Spark optionNotes
rowTagSpecifies the XML element that maps to a DataFrame row. Defaults to ROW if not set. If rowTag doesn’t match an element in your data, the read returns no rows.
inferSchemaDefault true. When a user schema is provided, Snowpark Connect for Spark forces inferSchema=false to keep the read single-pass.
samplingRatioDefault 1.0. Fraction of rows to sample when inferring the schema.
modeDefault PERMISSIVE. Controls error handling: PERMISSIVE, DROPMALFORMED, or FAILFAST. Values that can’t be converted to the specified schema type, and rows that fail rowValidationXSDPath validation, are handled according to the mode, as in Apache Spark.
columnNameOfCorruptRecordDefault _corrupt_record. Column name used to store malformed rows in PERMISSIVE mode.
attributePrefixDefault _. Prefix added to XML attribute names in the DataFrame schema. Can’t equal valueTag.
valueTagDefault _VALUE. Tag name for the text content of mixed-content elements. Can’t be empty.
encodingDefault UTF-8.
excludeAttributeDefault false. When true, attributes aren’t included in the DataFrame.
ignoreSurroundingSpacesDefault false. When true, whitespace around values is trimmed.
ignoreNamespaceDefault false. When true, namespace prefixes are removed from element names. For namespace-prefixed row tags, set rowTag to the prefixed name (for example, p:item).
nullValueString value to interpret as null. There’s no default, so empty elements are read as empty strings. Set nullValue to "" to read them as null.
pathGlobFilterFilters which files to read, using a glob pattern such as *.xml. Regular expressions aren’t supported.
recursiveFileLookupControls whether reads descend into nested subdirectories. Defaults to depth-0 listing, matching Apache Spark. See Directory listing.
rowValidationXSDPathPath to an XSD file on a stage (for example, @my_stage/schema.xsd) to validate each XML row against. Local XSD files are automatically uploaded to the stage. Rows that fail validation are handled according to the mode setting.

Date and timestamp formats

For CSV and JSON reads and writes, set dateFormat and timestampFormat to Java datetime patterns, as in Apache Spark. Snowflake format tokens such as DD/MM/YYYY aren’t supported: for dateFormat they raise an error, and for JSON timestampFormat they produce null values without an error.

The following table shows common patterns and their output for the timestamp 2025-01-09 15:04:05.123456 in the America/Los_Angeles time zone:

PatternMeaningOutput
yyyyFour-digit year2025
yyTwo-digit year25
MMZero-padded month01
MMMAbbreviated month nameJan
ddZero-padded day of month09
dDay of month, not padded9
EEEEFull day name (writes only; reads that use EEEE raise an error)Thursday
HH24-hour clock (00-23)15
hh12-hour clock (01-12)03
h12-hour clock, not padded3
mmMinutes04
ssSeconds05
SSSFractional seconds (milliseconds)123
SSSSSSFractional seconds (microseconds)123456
aAM/PM markerPM
ZTime zone offset without a colon-0800
XXX / xxxTime zone offset with a colon-08:00

When you don’t set timestampFormat, CSV and JSON writes use Spark’s default, yyyy-MM-dd'T'HH:mm:ss.SSSXXX (for example, 2025-01-09T15:04:05.123-08:00).

Partitioned data

Snowpark Connect for Spark supports Hive-style col=value/ directory layouts for Parquet reads and writes, and for CSV and JSON writes.

Note

CSV, JSON, and XML reads don’t support Hive-style partition discovery: files under col=value/ directories are read, but partition columns that exist only in directory names aren’t added to the DataFrame. Because Snowpark Connect for Spark writes the partition columns into the data files, CSV and JSON data that Snowpark Connect for Spark writes with partitionBy keeps those columns when you read it back. For other partitioned CSV and JSON data, see Migrate Snowpark Connect for Spark file I/O to version 1.51.0 (Preview).

Writing partitioned data

Use the standard partitionBy(...) API. Snowpark Connect for Spark produces the same col=value/ directory tree that Spark does:

df.write.partitionBy("year", "month").parquet("@my_stage/out/partitioned/")

Note

Unlike open-source Spark, Snowpark Connect for Spark includes the partition columns in the written data files themselves, not only in the directory structure. The output files contain all columns of the DataFrame, including the ones used for partitioning.

Reading partitioned data

Point the reader at the root directory and Snowpark Connect for Spark discovers partition columns from the directory names automatically:

df = spark.read.parquet("@my_stage/out/partitioned/")
df.printSchema()

# Read a specific partition directly by path
df = spark.read.parquet("@my_stage/out/partitioned/year=2025/month=1/")

# Read all partitions and filter on a partition column
df = spark.read.parquet("@my_stage/out/partitioned/")
recent = df.filter(df["year"] == 2025)
recent.show()

Partition discovery behavior:

  • Partition columns appear at the end of the schema, in the order they appear in the directory tree.
  • Partition value types are inferred from the observed values: all integers become LongType, all floating-point values become DoubleType, otherwise StringType. You can override a partition column’s type by supplying a .schema(...) that includes it.
  • null values in a partition column are written as the directory segment __HIVE_DEFAULT_PARTITION__ and read back as null.
  • Mixed-depth or conflicting layouts (for example, the same key at two different depths) raise an error rather than producing incorrect values.

Important

Filters on partition columns don’t reduce the number of files read. Snowpark Connect for Spark reads all files in the directory subtree and applies filters after loading.

Dynamic partition overwrite

When writing partitioned data to a stage, you can overwrite only the partitions that appear in the current DataFrame instead of deleting all existing data. Set the spark.sql.sources.partitionOverwriteMode session configuration to dynamic:

spark.conf.set("spark.sql.sources.partitionOverwriteMode", "dynamic")

df.write.mode("overwrite") \
    .partitionBy("year", "month") \
    .parquet("@my_stage/out/partitioned/")

This removes only the partition subdirectories that match the DataFrame. See Snowpark Connect for Spark properties for more on this configuration property.

Note

The .option("overwrite-mode", "dynamic") writer option is supported only for Iceberg table writes. For stage-based file writes, use the session configuration shown in the previous example.