Works with v1.11+
This recipe demonstrates how to configure a Spice dataset to connect to SMB (Server Message Block) network shares and query data files using federated SQL queries.
- An SMB/CIFS file server (Windows Server, Samba, NAS device, or Azure Files)
- Network access to the SMB server (port 445 by default)
- User credentials with read access to the target share
- Spice.ai runtime (Getting Started)
git clone https://github.com/spiceai/cookbook.git
cd cookbook/smbIf you don't have an existing SMB server, you can start one locally using Docker with Samba:
docker run -d --name samba \
-p 445:445 \
-v $(pwd)/data:/share \
-e USERID=1000 \
-e GROUPID=1000 \
dperson/samba \
-u "testuser;testpass" \
-s "data;/share;yes;no;no;testuser"This creates a share named data accessible with username testuser and password testpass.
Create a data directory with sample Parquet files:
mkdir -p dataYou can copy any Parquet or CSV files into the data directory, or use the Spice CLI to generate sample data.
Update the .env file with your SMB credentials:
SMB_USER=testuser
SMB_PASS=testpassspice runIf the configuration is correct, you should see output similar to:
INFO runtime::init::dataset: Dataset sales initializing...
INFO runtime::init::dataset: Dataset sales registered (smb://localhost/data/), results cache enabled.spice sqlTo show tables:
SHOW TABLES;To query your data:
SELECT * FROM sales LIMIT 10;| Parameter Name | Description | Default |
|---|---|---|
file_format |
Required when connecting to a directory. Parquet, CSV, JSON, etc. | - |
smb_user |
Username for SMB authentication. | - |
smb_pass |
Password for SMB authentication. | - |
smb_port |
SMB server port. | 445 |
client_timeout |
Connection timeout duration. E.g. 30s, 1m. |
- |
hive_partitioning_enabled |
Enable Hive-style partitioning from folder structure. | false |
- Parquet
- CSV
- JSON
- NDJSON
Connect to a Windows file share with credentials:
datasets:
- from: smb://fileserver.corp.local/shared/analytics/
name: analytics
params:
file_format: parquet
smb_user: ${secrets:smb_user}
smb_pass: ${secrets:smb_pass}For Windows domain environments, include the domain in the username:
datasets:
- from: smb://fileserver/data/reports/
name: reports
params:
file_format: csv
csv_has_header: true
smb_user: DOMAIN\username
smb_pass: ${secrets:smb_pass}The domain can be specified as DOMAIN\user or user@domain.
When pointing to a specific file, the format is inferred from the file extension:
datasets:
- from: smb://nas.local/backups/database_export.parquet
name: database_export
params:
smb_user: ${secrets:smb_user}
smb_pass: ${secrets:smb_pass}Configure a timeout for slow or unreliable network connections:
datasets:
- from: smb://remote-server.example.com/data/
name: remote_data
params:
file_format: parquet
smb_user: ${secrets:smb_user}
smb_pass: ${secrets:smb_pass}
client_timeout: 60sConnect to SMB servers running on non-standard ports:
datasets:
- from: smb://custom-server.local/share/
name: custom_data
params:
file_format: parquet
smb_port: 4450
smb_user: ${secrets:smb_user}
smb_pass: ${secrets:smb_pass}Enable Hive-style partitioning to automatically extract partition columns from the folder structure:
datasets:
- from: smb://datalake.corp.local/warehouse/events/
name: events
params:
file_format: parquet
smb_user: ${secrets:smb_user}
smb_pass: ${secrets:smb_pass}
hive_partitioning_enabled: trueGiven a folder structure like:
/events/
region=us/
year=2024/
data.parquet
region=eu/
year=2024/
data.parquet
Queries can filter on partition columns:
SELECT * FROM events WHERE region = 'us' AND year = '2024';Load different datasets from multiple shares on the same server:
datasets:
- from: smb://fileserver/sales/
name: sales
params:
file_format: parquet
smb_user: ${secrets:smb_user}
smb_pass: ${secrets:smb_pass}
- from: smb://fileserver/inventory/
name: inventory
params:
file_format: csv
smb_user: ${secrets:smb_user}
smb_pass: ${secrets:smb_pass}Enable local acceleration for faster repeated queries:
datasets:
- from: smb://archive.corp.local/historical/
name: historical_data
params:
file_format: parquet
smb_user: ${secrets:smb_user}
smb_pass: ${secrets:smb_pass}
acceleration:
enabled: true
engine: duckdb
refresh_check_interval: 1hAcceleration is recommended for frequently queried data, as SMB operations involve network round-trips for directory listing and file reads.
The SMB connector supports SMB protocols 2.0, 2.1, 3.0, and 3.1.1, and is compatible with:
- Windows Server file shares
- Samba servers (Linux/Unix)
- NAS devices (Synology, QNAP, etc.)
- Azure Files
- Read-only: The connector does not support write operations (INSERT, UPDATE, DELETE)
- Authentication: Only username/password authentication is supported. Kerberos and NTLM ticket-based authentication are not available
- Network access: Direct network access to the SMB server is required; proxy connections are not supported
- Firewall: The firewall must permit SMB traffic (port 445 by default)
If connections frequently timeout, increase the client_timeout value:
params:
client_timeout: 120sVerify network connectivity to the server and check that firewall rules permit port 445.
Common causes of authentication failures:
- Domain not specified: For domain-joined servers, include the domain:
DOMAIN\usernameorusername@domain - Incorrect credentials: Verify username and password are correctly stored in your secret store
- Permission denied: Ensure the user has read access to the share and files
- Account locked: Check if the SMB account is not locked on the server
If you receive "share not found" errors:
- Verify the share name is correct (share names are case-insensitive on Windows)
- Ensure the share exists and is accessible from the network where Spice is running
- Check firewall rules: SMB uses TCP port 445
- Confirm the user has permission to access the share
For additional troubleshooting information, enable debug logging:
SPICED_LOG="runtime=debug,spice_cloud=debug" spice runTo stop and remove the Samba container:
docker stop samba
docker rm samba