What you will be able to do
- Query ORC, JSON, CSV, text and Delta data in place with the format.
pathsyntax, without creating a table - Pick read_files or a temporary view defined with USING when a file needs reader options such as header or a schema
- Explain why delta.
pathreads a Delta table through its transaction log, and how time travel is tied to the delta format - Predict what append, overwrite, ignore and errorifexists do when the target already exists, and name the default
- Map the save modes onto INSERT INTO and INSERT OVERWRITE, including how a PARTITION clause limits an overwrite
Key concept
A path used as a table name — In Spark SQL, FROM accepts a file format followed by a backquoted storage path, such as orc./mnt/archive/clicks/. The files at that location are read as one relation, and you can filter, aggregate and join it like any table, all without registering one first.
1.Querying a file path as a table with format.path
Raw files usually arrive before anyone has defined a table for them: a drop of JSON events, an archive of ORC files, a folder of log lines. Spark SQL can query that data where it already sits. In the FROM clause, write a file format, a dot, and the storage path in backticks, for example json./mnt/raw/events/``. Spark resolves that identifier to the files at the path and returns rows. Nothing is added to the catalog, and nothing remains once the query finishes.
-- Referencing a path as a table requires back ticks
> SELECT * FROM delta.`somedir/delta_table`;
> SELECT * FROM `csv`.`spreadsheets/data.csv`;Only a fixed set of words can go before the dot: json, csv, avro, parquet, orc, binaryFile, text and delta, matched case-insensitively. The part after the dot is the location of the table in the file system. That location is usually a directory, so json./mnt/raw/events/` reads every file in it as a single relation. With three files of 100 records each, count(*) returns 300. For self-describing formats such as JSON, ORC and Parquet, the schema comes from the file contents, so no column list is required. The caller also needs the ANY_FILE` permission to use this syntax.
The relation behaves like any other table once it is resolved. SELECT count(*) FROM orc./mnt/archive/clicks/ WHERE event_date = '2026-01-15' filters ORC rows the same way it would filter a catalog table. The format word always goes before the path. Spark SQL has no read_orc() or ORC_TABLE() function, no LOAD ORC statement, and no FROM "path" USING orc clause. The only table-valued function for reading files is read_files, and it takes the format as an option.
The text format is the exception among file formats because it does no parsing. Each line of the file becomes one row in a single value column of type string, so text./logs/app/`` returns one row per log line, ready for string functions to split. Use it for line-oriented data such as logs. When the data is delimited, CSV parsing into columns is the better fit.
Checkpoint 1 of 9· Check yourself
An application writes plain log lines into /logs/app/. What does SELECT * FROM text./logs/app/ return?
The text format does no parsing. Each line becomes one row in a single string column named value, and string functions can split it afterwards. text is one of the accepted format words, so the query does not fail.
“The text format reads each line of a text file as a row in a DataFrame with a single value column of type StringType.”Source: docs.databricks.com
Checkpoint 2 of 9· Exam question
A data engineer has a directory of newline-delimited JSON files at /mnt/raw/events/ and wants to inspect the data without first creating a table or DataFrame. They run:
SELECT count(*) FROM json.`/mnt/raw/events/`
The directory contains 3 files, each holding 100 valid JSON records that share a consistent schema. What does this query return?
Correct answer: B — 300, because json.path`` treats the whole directory as one relation and Spark infers a merged schema from a sample of records across all files it lists
- A. No table registration step is required; the
format.path`syntax lets Spark SQL read a directory of files directly as a relation without aCREATE TABLE` statement. - B. Referencing
json.path`` in SQL treats the whole directory as a single relation, and Spark infers one schema by sampling records across the files before scanning all of them, so all 300 matching rows are counted. - C. The directory reference is not limited to a single file; Spark lists and reads every file under the path that matches the format, so all three files contribute rows.
- D. Schema inference samples records to build one schema, but it does not silently drop files with mismatched schemas during the count; a genuinely incompatible file would typically surface a read error rather than being skipped quietly.
- E. No such
WITH SCHEMAclause exists for this syntax; schema is inferred automatically from the JSON content unless the caller supplies an explicit schema through the DataFrame reader API instead.
Checkpoint 3 of 9· Exam question
A team stores historical clickstream data as ORC files under /mnt/archive/clicks/ and wants a quick row count for a specific event_date partition column without creating a table. Which SQL statement queries the ORC files directly and filters on that column?
Correct answer: D — SELECT count(*) FROM orc./mnt/archive/clicks/ WHERE event_date = '2026-01-15', treating the path as a relation and filtering the resulting rows
- A. There is no
ORC_TABLEtable-valued function in Spark SQL; file-based relations for built-in formats are addressed with theformat.path`` syntax, not a function call. - B.
read_orcis not a Spark SQL function; reading files by format from SQL uses theformat.path`relation syntax rather than a reader function invoked in theFROM` clause. - C. There is no
LOAD ORC ... ASstatement in Spark SQL; loading a file-based relation for querying is done with theformat.path`` syntax, not a two-step load-then-alias statement. - D. Spark SQL supports
format.path`syntax for several built-in formats including ORC, so prefixing the path withorc.and backticks turns the directory into a queryable relation that a normalWHERE` clause can filter. - E. Format is not declared with a trailing
USINGclause on a quoted path string; the format name is prefixed onto the backticked path itself, as inorc.path``.
2.When a file needs options: the limits of direct queries and read_files
The backtick syntax is short, and the cost of that is configuration. A direct query cannot pass reader options or a schema. For CSV this causes real problems. A CSV file with a header line comes back with the header as an ordinary data row, and with no inferSchema every column is a string. Rewriting the query as csv./mnt/raw/sales.csv` fixes neither problem, because the direct path cannot carry header or inferSchema` either. The fix is to set both options on the reader.
# Read the CSV file into a DataFrame
df = (spark.read
.format("csv")
.option("header", "true")
.option("inferSchema", "true")
.load("/Volumes/<catalog>/<schema>/<volume>/reviews_csv"))In SQL, read_files covers the same need. It is a table-valued function that takes a path and then options as named parameters (format => 'csv', header => true), and it reads JSON, CSV, XML, TEXT, BINARYFILE, PARQUET, AVRO and ORC. It can detect the format and infer one unified schema across all the files. Inference has a cost, though: without a schema, read_files has to read every file unless the query has a LIMIT. For large drops, supply the schema yourself. With CSV, the schema also has to follow the file's column order, because CSV fields are matched to schema fields by position.
SELECT * FROM read_files(
'/Volumes/<catalog>/<schema>/<volume>/reviews_csv',
format => 'csv',
header => true,
schema => 'review_id string, rating int, comment string'
)| Format | Resulting schema |
|---|---|
| TEXT | Fixed: one value column of type STRING |
| BINARYFILE | Fixed: path, modificationTime, length, content |
| JSON, CSV, XML, PARQUET, AVRO, ORC | Inferred from file contents, or set with the schema option |
read_files also understands Hive-style directory layouts. When files sit under folders such as /event_date=2026-01-15/, it infers event_date as a partition column, so a WHERE clause can filter on it even though the value is not stored inside the files.
Checkpoint 4 of 9· Fill the gap
This reader should use the CSV's first line as column names and give numeric columns a numeric type instead of string. Which option name fills the blank?
# Read the CSV file into a DataFrame
df = (spark.read
.format("csv")
.option("header", "true")
.option(" ? ", "true")
.load("/Volumes/<catalog>/<schema>/<volume>/reviews_csv"))header only makes the first line supply column names. Without inferSchema, every CSV column is read as a string. A direct csv.path query cannot set either option, so you set both on the reader.
Checkpoint 5 of 9· Exam question
A engineer receives a CSV export where the first line holds column names and numeric columns should not be read as strings. They write:
df = spark.read.csv("/mnt/raw/sales.csv")
df.createOrReplaceTempView("sales")
spark.sql("SELECT avg(amount) FROM sales")
The query fails because amount is read as a string and the header row product,amount,region appears as a data row. Which change fixes both problems?
Correct answer: C — Add the header and inferSchema options to the CSV reader so the first row becomes column names and numeric columns are inferred as doubles rather than strings
- A. Casting inside the SQL string would fix the type for that one query, but the header row
product,amount,regionstill appears as a data row and pollutes the average, so the underlying read is still broken. - B. Reading as plain text and manually parsing commas abandons the structured CSV reader entirely and reintroduces the same header and typing problems by hand, with far more code to maintain.
- C. Setting
headertoTruetells the reader to treat the first line as column names rather than data, andinferSchemascans the data to assign numeric types such as double instead of defaulting every column to string. - D. Filtering out a row that matches the header text is a fragile workaround that still leaves every column as a string, so the average would still fail or return an incorrect result without an explicit cast.
- E. Querying
csv.path`` directly still applies Spark's CSV defaults, which do not treat the first line as a header or infer types unless those same reader options are supplied, so the failure would persist.
3.A temporary view over a file path with CREATE TEMPORARY VIEW ... USING
A temporary view is a session-scoped name for a query. Scope and lifetime are covered in Temporary views and global temporary views. For files, the useful form is CREATE TEMPORARY VIEW name USING format OPTIONS (path ..., ...). It records the path and the reader options together once. Every later query then reads the file by its short name, with the options already applied, and no permanent table is created.
CREATE TEMPORARY VIEW diamonds
USING CSV
OPTIONS (path "/databricks-datasets/Rdatasets/data-001/csv/ggplot2/diamonds.csv", header "true", mode "FAILFAST");
SELECT * FROM diamonds;Any reader option can go into OPTIONS. The mode option sets how malformed records are handled: PERMISSIVE, the default, puts nulls in fields that fail to parse, DROPMALFORMED drops those lines, and FAILFAST aborts the read. JSON that spans several lines per record needs multiline=true here. Without it, the default single-line reader expects exactly one object per line. The view lasts only for the current session. For a one-off query that also needs a schema, Databricks recommends read_files over USING JSON.
CREATE TEMPORARY VIEW multiLineJsonTable
USING json
OPTIONS (path="/Volumes/<catalog>/<schema>/<volume>/multi-line.json",multiline=true)Checkpoint 6 of 9· Match them up
You are writing the OPTIONS clause of a file-backed temporary view. Match each setting to what it does when the view is read.
Tap a term, then the definition that fits it.
The mode option sets how malformed records are handled. PERMISSIVE is the default and fills in nulls, DROPMALFORMED drops the bad lines, and FAILFAST aborts the read. multiline is a separate JSON option that the view sets once, so every query on the view reads multi-line records correctly.
“PERMISSIVE (default): nulls are inserted for fields that could not be parsed correctly”Source: docs.databricks.com
4.Querying a Delta table by path
A Delta table is more than a directory of files. Delta Lake keeps Parquet data files, and alongside them a file-based transaction log that records which changes have been committed. SELECT * FROM delta./path/to/table`` tells Spark to resolve the directory through that log. The result is the table's current committed version, the same data a query against the registered table name would return.
The log is also what makes time travel possible. A table reference can include a temporal specification, such as VERSION AS OF 3, TIMESTAMP AS OF an expression, or the @V3 shorthand, to read an earlier version. Only Delta keeps that history. Adding a temporal specification to a parquet.path` or orc.path reference raises an error. The same directory read with parquet` is just a set of data files with no transaction history behind it.
Checkpoint 7 of 9· Check yourself
A bad job overwrote rows in a Delta table stored at /lake/orders, and nobody registered it in the catalog. To see the data as it was at version 12, which query works?
Time travel depends on the Delta transaction log, so the path must be read as delta and given a temporal specification. A parquet reference or read_files sees only the data files with no history behind them, so a temporal specification there fails. A plain delta.path query returns the current version, not the earliest one.
“Delta Lake is the recommended Databricks-native format. It adds ACID transactions, schema enforcement, time travel, and optimized read performance on top of Parquet-based storage.”Source: docs.databricks.com
5.Save modes: what happens when the target already exists
Every write has to decide what to do when the target path or table already holds data. The save mode makes that decision, set with DataFrameWriter.mode() or the mode argument of save(). When no format is given, save() writes in the format set by spark.sql.sources.default.
| Mode | Behaviour when data exists |
|---|---|
| append | New rows are added to the existing data |
| overwrite | Existing data is replaced |
| error / errorifexists (default) | An exception is thrown |
| ignore | The write is silently skipped |
The default is the cautious choice. A scheduled job that runs twice by mistake fails loudly instead of doubling the data or wiping it. Use overwrite for full refreshes, append for incremental loads, and ignore for setup steps that should run only once, such as seeding a reference dataset. ignore gives no warning. If an ignore write was skipped because old data was there, nothing reports it.
import tempfile
with tempfile.TemporaryDirectory(prefix="mode") as d:
# Overwrite the path with a new Parquet file
spark.createDataFrame(
[{"age": 100, "name": "Alice"}]
).write.mode("overwrite").format("parquet").save(d)
# Append another DataFrame into the Parquet file
spark.createDataFrame(
[{"age": 120, "name": "Sue"}]
).write.mode("append").format("parquet").save(d)Checkpoint 8 of 9· Fill the gap
The first write puts Alice's row at path d. The second write must keep that row and add Sue's, so a later read of d returns both rows. Which save mode fills the blank?
import tempfile
with tempfile.TemporaryDirectory(prefix="mode") as d:
# Overwrite the path with a new Parquet file
spark.createDataFrame(
[{"age": 100, "name": "Alice"}]
).write.mode("overwrite").format("parquet").save(d)
# Append another DataFrame into the Parquet file
spark.createDataFrame(
[{"age": 120, "name": "Sue"}]
).write.mode(" ? ").format("parquet").save(d)append adds the new rows to the data already at the path, so the read returns both Alice and Sue. overwrite would leave only Sue. ignore would skip the write without a warning and leave only Alice. errorifexists, the default, would throw an exception because data already exists at d.
Source: docs.databricks.com6.The same choices in SQL: INSERT INTO and INSERT OVERWRITE
SQL has no mode keyword. The choice is built into the statement. INSERT INTO is append: the inserted rows are added to the rows already there. INSERT OVERWRITE is overwrite, and its scope depends on whether a PARTITION clause is present. Without one, the whole table is truncated before the first new row is written. With a partition spec, only the partitions that match it are truncated, and the rest of the table is kept.
| Save mode | SQL statement | Effect on existing rows |
|---|---|---|
| append | INSERT INTO table_name query | Kept; new rows are added |
| overwrite | INSERT OVERWRITE table_name query | Whole table truncated first |
| overwrite, partition-scoped | INSERT OVERWRITE table_name PARTITION (...) query | Only matching partitions truncated |
The partition rule is easy to get wrong. A nightly INSERT OVERWRITE sales SELECT ... WHERE day = current_date() with no PARTITION clause does not replace only today's data. It truncates the entire table and leaves just today's rows. To replace a single day, name the partition statically, for example PARTITION (day = '2026-10-21'). A dynamic partition spec in INSERT OVERWRITE requires the target to be a Delta Lake table. To write files from SQL in the first place, CREATE TABLE ... USING format AS SELECT creates a table of that format from a query result.
-- Write wanderbricks reviews to ORC format
CREATE TABLE reviews_orc
USING ORC
AS SELECT * FROM samples.wanderbricks.reviews;Checkpoint 9 of 9· Check yourself
Table sales is partitioned by day and holds a year of data. To fix one day's figures, a job runs INSERT OVERWRITE sales SELECT * FROM sales_fixed WHERE day = '2026-10-20'. What does sales contain afterwards?
Without a partition spec, INSERT OVERWRITE truncates the whole table before it inserts the first row, so only the rows the query returns remain. The WHERE clause filters the source rows and does not limit the truncation. To replace only that day, add PARTITION (day = '2026-10-20').
“Without a partition_spec the table is truncated before inserting the first row. Otherwise, all partitions matching the partition_spec are truncated before inserting the first row.”Source: docs.databricks.com
Sources9
Sources
(10)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“file_format: One of json, csv, avro, parquet, orc, binaryFile, text, delta (case insensitive).”
↩︎ Querying a file path as a table with format.path“path_to_table: The location of the table in the file system. You must have the ANY_FILE permission to use this syntax.”
↩︎ Querying a file path as a table with format.path“temporal_spec: When used references a Delta table at the specified point in time or version.”
↩︎ Querying a Delta table by path“Databricks raises an error if you use a temporal_spec for a table that is not in Delta Lake format.”
↩︎ Querying a Delta table by path“-- Referencing a path as a table requires back ticks”
↩︎ Key concept“Databricks raises an error if you use a temporal_spec for a table that is not in Delta Lake format.”
↩︎ Exam trap 5 - 2.
“The schema is inferred from the file contents, or provided explicitly using the schema option.”
↩︎ Querying a file path as a table with format.path“Can detect the file format automatically and infer a unified schema across all files.”
↩︎ When a file needs options: the limits of direct queries and read_files“This function requires named parameter invocation for the option keys.”
↩︎ When a file needs options: the limits of direct queries and read_files“read_files attempts to infer a unified schema across the discovered files, which requires reading all the files unless a LIMIT statement is used”
↩︎ When a file needs options: the limits of direct queries and read_files“read_files can also infer partitioning columns if files are stored under Hive-style partitioned directories, that is /column_name=column_value/.”
↩︎ When a file needs options: the limits of direct queries and read_files - 3.
“The text format reads each line of a text file as a row in a DataFrame with a single value column of type StringType.”
↩︎ Querying a file path as a table with format.path - 4.https://docs.databricks.com/aws/en/query/formats/csvOfficial docs
“You can't specify data source options.”
↩︎ When a file needs options: the limits of direct queries and read_files“You can't specify the schema for the data.”
↩︎ When a file needs options: the limits of direct queries and read_files“CSV has no column-name metadata, so Spark maps schema fields to columns by position”
↩︎ When a file needs options: the limits of direct queries and read_files“The view is visible only to the current session and is dropped when the session ends.”
↩︎ A temporary view over a file path with CREATE TEMPORARY VIEW ... USING“FAILFAST: aborts the reading if any malformed data is found”
↩︎ A temporary view over a file path with CREATE TEMPORARY VIEW ... USING“If you use SQL to read CSV data directly without using temporary views or read_files, the following limitations apply:”
↩︎ Exam trap 1“PERMISSIVE (default): nulls are inserted for fields that could not be parsed correctly”
↩︎ Checkpoint - 5.
“Databricks recommends using read_files instead of USING JSON because read_files allows the specification of schema and additional file processing options.”
↩︎ A temporary view over a file path with CREATE TEMPORARY VIEW ... USING - 6.https://docs.databricks.com/aws/en/deltaOfficial docs
“Delta Lake is open source software that extends Parquet data files with a file-based transaction log for ACID transactions and scalable metadata handling.”
↩︎ Querying a Delta table by path - 7.
“Specifies the behavior when data or table already exists.”
↩︎ Save modes: what happens when the target already exists“'ignore' (silently skip if data exists)”
↩︎ Save modes: what happens when the target already exists - 8.
“If format is not specified, the default data source configured by spark.sql.sources.default is used.”
↩︎ Save modes: what happens when the target already exists“Accepted values are 'append', 'overwrite', 'ignore', and 'error' or 'errorifexists' (default).”
↩︎ Exam trap 3“Accepted values are 'append', 'overwrite', 'ignore', and 'error' or 'errorifexists' (default).”
↩︎ Prediction - 9.
“If you specify INTO all rows inserted are additive to the existing rows.”
↩︎ The same choices in SQL: INSERT INTO and INSERT OVERWRITE“Otherwise, all partitions matching the partition_spec are truncated before inserting the first row.”
↩︎ The same choices in SQL: INSERT INTO and INSERT OVERWRITE“When specifying a dynamic partition for INSERT OVERWRITE, the table_name must be a Delta Lake table.”
↩︎ The same choices in SQL: INSERT INTO and INSERT OVERWRITE“Without a partition_spec the table is truncated before inserting the first row.”
↩︎ Exam trap 4“Without a partition_spec the table is truncated before inserting the first row. Otherwise, all partitions matching the partition_spec are truncated before inserting the first row.”
↩︎ Checkpoint
Also cited
- https://docs.databricks.com/aws/en/query/formats/orcOfficial docs
“Use read_files to query ORC files directly from cloud storage using SQL without creating a table.”
↩︎ Exam trap 2“Delta Lake is the recommended Databricks-native format. It adds ACID transactions, schema enforcement, time travel, and optimized read performance on top of Parquet-based storage.”
↩︎ Checkpoint