Files and storage
Ursa reads files where they are: a file is a table. This page covers reading and writing files, files in S3, GCS and Azure, the formats ursa prints, and the .ursa database file that keeps your work between sessions.
Read a file
Section titled “Read a file”Name a file in FROM, with its path or URL in quotes. A relative path is relative to the current directory. The format comes from the extension:
| Extension | Format |
|---|---|
.parquet |
Parquet |
.csv |
CSV, with a header line |
.json, .jsonl, .ndjson |
JSON, one object per line (NDJSON) |
.arrow |
Arrow IPC |
SELECT count(*) AS ties FROM 'karate_edges.csv';┌───────┐│ ties ││ Int64 │├───────┤│ 78 │└───────┘CSV and JSON files may be compressed: .csv.gz, .jsonl.zst, and .bz2 and .xz too. A directory or a glob ('edges/*.parquet') reads every file in it, and a year=2024/ directory becomes a year column. To use a file in several queries, name it as a view:
CREATE VIEW ties AS SELECT * FROM 'karate_edges.csv';A view reads the file each time a query uses it, so it always sees the file’s current contents.
read_parquet, read_csv and read_json
Section titled “read_parquet, read_csv and read_json”read_parquet, read_csv and read_json read a file in the format they name, whatever its extension, with options, as in DuckDB. They take a path, a glob, a directory, a URL, or a list of them:
SELECT count(*) AS ties FROM read_csv('karate_edges.csv', header => true, delim => ',');┌───────┐│ ties ││ Int64 │├───────┤│ 78 │└───────┘| Function | Options |
|---|---|
read_parquet |
none |
read_csv |
header (true or false), delim (one character), quote, compression |
read_json |
compression; format: 'newline_delimited' (the default) or 'array', for a file that holds one JSON array of objects |
compression is 'auto' (from the extension, the default), 'none', 'gzip', 'bzip2', 'xz' or 'zstd'. Options are named with =>, or with = as DuckDB writes them.
Write a file with COPY
Section titled “Write a file with COPY”COPY … TO writes a query’s rows to a file, in the format its extension names, and prints how many rows it wrote:
COPY (SELECT * FROM ties) TO 'ties.jsonl';┌────────┐│ count ││ UInt64 │├────────┤│ 78 │└────────┘STORED AS CSV (or PARQUET, JSON, ARROW) names the format when the extension does not. DuckDB’s option list works too: COPY … TO 'ties.txt' (FORMAT csv, HEADER false, DELIMITER '|').
In Ursa Shell in the browser, which has no disk, COPY … TO 'ties.parquet' keeps the file in the session: FROM 'ties.parquet' reads it and .files lists it, until the page is closed.
Object storage
Section titled “Object storage”Anything that works with a local path works with an s3://, gs://, az:// or https:// URL:
CREATE VIEW follows AS SELECT * FROM 's3://my-bucket/social/follows/*.parquet';
CREATE PROPERTY GRAPH social EDGE TABLES (follows SOURCE KEY (follower) DESTINATION KEY (followee));
SELECT * FROM pagerank(social) ORDER BY pagerank DESC LIMIT 10;Ursa reads only the columns a query needs, and stores the graph index in the database file, so the second query does not read the edges again.
Ursa finds credentials where each cloud’s own tools do, and uses the first place that has them. Nothing is stored in the database file.
S3, in this order:
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEY, plusAWS_SESSION_TOKENfor temporary credentials.- An AWS profile in
~/.aws/credentialsand~/.aws/config: the oneAWS_PROFILEnames, ordefault. It can hold access keys, an SSO login (runaws sso loginfirst), a role to assume, or acredential_process. - Web identity (
AWS_WEB_IDENTITY_TOKEN_FILEandAWS_ROLE_ARN, as on EKS), container credentials (as on ECS), or the EC2 instance’s role.
AWS_PROFILE=analytics ursa -c "SELECT count(*) FROM 's3://my-bucket/follows/*.parquet'"The region comes from AWS_REGION or AWS_DEFAULT_REGION, or else Ursa asks S3 where the bucket is. For an S3-compatible store (MinIO, R2), set AWS_ENDPOINT. For a public bucket, set AWS_SKIP_SIGNATURE=true.
Google Cloud Storage: a service account key (GOOGLE_SERVICE_ACCOUNT, or its JSON in GOOGLE_SERVICE_ACCOUNT_KEY), application default credentials (gcloud auth application-default login), or the instance’s service account.
Azure Blob Storage: set AZURE_STORAGE_ACCOUNT_NAME, then an account key (AZURE_STORAGE_ACCOUNT_KEY), workload identity, a service principal, a SAS token, the Azure CLI’s login (AZURE_USE_AZURE_CLI=true), or a managed identity.
HTTPS URLs are read without credentials.
Output formats
Section titled “Output formats”The shell prints tables. --format sets the format on the command line, and .mode in the shell or a script: table (the default), csv, tsv, json, ndjson, markdown, line and arrow. DuckDB’s names duckbox, box and jsonlines work too.
ursa club.ursa --format json -c "SELECT * FROM degree(karate) ORDER BY id LIMIT 2"[{"id":0,"degree":16},{"id":1,"degree":8}]A table shows at most 40 rows. The other formats write every row and never cut a value.
- For a program, or an agent, read
jsonorndjson. Every row object has every column, withnullfor a null; a list is a JSON array and a struct a JSON object. - For files and spreadsheets,
csvandtsvwrite as DuckDB does..headers offleaves out the header row. - To paste into an issue or a document,
markdownwrites a Markdown table. - For a wide row,
linewrites onecolumn = valueline per column. - For another program,
--format arrowwrites an Arrow IPC stream. It works only with-cor-f, for one query that returns rows.
A script can hold dot-commands, one a line, as at the prompt:
.mode csvSELECT count(*) AS edges FROM 'karate_edges.csv';ursa -f q.sqledges78Errors go to stderr, and so do notices (lines starting ursa: ), so stdout holds only results. With --format json or ndjson, an error is one line of JSON on stderr, for a program to read.
The database file
Section titled “The database file”A .ursa file is a database. It keeps two things between sessions: the views, external tables and graphs you define, and the graph indexes Ursa builds from them. Name the file when you start ursa:
ursa club.ursa # the shellursa club.ursa -c "SHOW GRAPHS" # one commandThe file is created if it does not exist, and its name must end in .ursa. Without a file, ursa runs in memory and keeps nothing. In an in-memory session that has not defined anything yet, ATTACH 'club.ursa' (or the shell’s .open) opens one.
The file stores statements, not rows. Opening the database runs them again, so a view over a file always reads the file’s current contents. DROP removes an object’s statement, and CREATE OR REPLACE replaces it. Statements that create tables with data, or change them, are refused in a database session.
Stored graph indexes
Section titled “Stored graph indexes”The first query over a graph builds its index: the graph’s edges, laid out for the algorithms. Ursa writes it next to the database, and later queries, in this process or another, load it instead of building it again. An index is stored under a key made from the plan that produces the edges and the identity of every file it reads (its location, size and modification time). So:
- if a source file changes, Ursa builds a new index;
- a weight is not part of the key, so trying several weightings reuses one index;
- a database moved together with its data still finds its indexes.
Edges that are not read from files, such as an in-memory table, have no stable key. Their index is built once per session and not stored.
Read-only and sharing
Section titled “Read-only and sharing”One process at a time may have a database open for writing. A second one waits two seconds, then fails with an error that names the process that has it. --readonly opens a database without taking that lock, to query it meanwhile. It refuses any statement that defines or drops something:
ursa club.ursa --readonly -c "SELECT * FROM degree(karate) LIMIT 3"