The File Data Connector enables federated SQL queries on files stored by locally accessible filesystems. It supports querying individual files or entire directories, where all child files within the directory will be loaded and queried.
File formats are specified using the file_format parameter, as described in File Formats (opens in a new tab).
Example spicepod.yml
fromThe from field for the File connector takes the form file://path where path is the path to the file to read from. See the examples (opens in a new tab) below for examples of relative and absolute paths
nameThe dataset name. This will be used as the table name within Spice.
Example:
The dataset name cannot be a reserved keyword (opens in a new tab).
params| Parameter name | Description |
|---|---|
file_format | Specifies the data file format. Required if the format cannot be inferred from the from path. Refer to File Formats (opens in a new tab) for details. |
hive_partitioning_enabled | Enable partitioning using hive-style partitioning from the folder structure. Defaults to false |
schema_source_path | Specifies the path used to infer the dataset schema. Default to the most recently modified file |
For additional CSV, JSON, and Parquet specific parameters, see File Formats (opens in a new tab).
In addition to standard Data Refresh (opens in a new tab), a data refresh can also be triggered when the source file is modified. The File Data Connector uses a file system watcher to be notified the file has changed. The file watcher is disabled by default and can be enabled by setting the file_watcher parameter to enabled in the acceleration parameters.
When the file is modified, the acceleration will be refreshed and will include the latest data.
For a single-file dataset, the watcher watches the file's parent directory and reacts only to events for that file name, so a file replaced atomically (written to a temporary file, then renamed over the original) still triggers a refresh, as do later writes to the replacement. For a directory dataset, it watches the directory recursively. Creating, modifying, or removing the file triggers a refresh; reading it does not.
The refresh starts 400 ms after the last change event. Each new event restarts the wait, so a truncate-then-write or a burst of appends whose writes are less than 400 ms apart is loaded as one change. A writer that pauses for longer than 400 ms partway through can still have a refresh read the empty or partial file, so when a refresh must read a complete file, write a temporary file and rename it over the original. Events that arrive while a refresh runs trigger one more refresh after it finishes.
Detecting an atomic replacement needs read permission on the parent directory. When the runtime cannot watch the directory, it logs a warning and watches the file only, which picks up in-place writes but not a replacement.
In v2.4.2 and earlier, the watcher watched only the file path, so on Linux, writes made after an atomic replacement could go undetected. It also refreshed on the first event and ignored events that arrived within 100 ms of the previous refresh, so the trailing write of a burst could be missed.
For a dataset of structured files, such as Parquet, CSV, or JSON, when the from path no longer exists or lists no data files, a query or refresh that reads it fails instead of returning zero rows:
Spice logs the same message as a warning. A federated query returns the error, and a refresh fails, so an accelerated dataset keeps the rows it last loaded. When the files are restored, the next refresh loads them. An append (opens in a new tab) refresh fails the same way, so an append dataset whose path is still empty reports an error on each refresh until its first file arrives. An existing file with no rows, such as a header-only CSV or a zero-row Parquet file, still reads as zero rows. A path with no data files when Spice starts already fails the dataset load, and the runtime retries until the source data becomes available.
The same check applies to the other connectors that read files from a path or an object store prefix, such as S3 (opens in a new tab). A query that names objects with a _location (opens in a new tab) = or IN condition, such as a refresh_sql that filters on _location, reads those objects without listing the path and is not checked. A full refresh of such a dataset can still replace the accelerated data with an empty result when the named objects are gone. Document formats, such as md, txt, pdf, or docx, are not checked either: when their files are gone, a query returns zero rows and a full refresh replaces the accelerated documents with an empty table. In v2.4.2 and earlier, a query of a deleted path returned zero rows, and a full refresh replaced the accelerated data with an empty table.
Refer to Object Store Data Types (opens in a new tab) for data type mapping from object store files to arrow data type.
In this example, path is an absolute path to the file on the filesystem.
In this example, the path is relative to the directory where the spicepod.yaml is located.
:::warning[Performance Considerations]
When using the File Data connector without acceleration, data is loaded into memory during query execution. Ensure sufficient memory is available, including overhead for queries and the runtime, especially with concurrent queries.
Memory limitations can be mitigated by storing acceleration data on disk, which is supported by duckdb (opens in a new tab) and sqlite (opens in a new tab) accelerators by specifying mode: file.
:::
Refer to the File cookbook recipe (opens in a new tab) to see an example of the File connector in use.