scalarfs
Eine Sammlung virtueller Dateisysteme für die Arbeit mit Skalaren
Maintainer: teaguesterling
Installation und Laden
INSTALL scalarfs FROM community;LOAD scalarfs;Beispiel
LOAD scalarfs;
-- Read JSON from a variableSET VARIABLE config = '{"debug": true, "port": 8080}';SELECT * FROM read_json('variable:config');
-- Read CSV from inline contentSELECT * FROM read_csv('data+varchar:name,scoreAlice,95Bob,87');
-- Use a file path stored in a variableSET VARIABLE data_path = '/data/reports/monthly.csv';SELECT * FROM read_csv('pathvariable:data_path');
SET VARIABLE data_paths = ['/data/reports/monthly.csv', '/archive/reports/*.csv'];SELECT * FROM read_csv('pathvariable:data_paths');
-- Write query results to a variableCOPY (SELECT * FROM my_table WHERE active) TO 'variable:exported' (FORMAT json);SELECT getvariable('exported');
-- Store query results as native values (not serialized text)COPY (SELECT path FROM files WHERE active) TO 'variable:paths' (FORMAT variable);SELECT * FROM read_csv('pathvariable:paths'); -- Read all files from the list
-- Select which files to read via a catalog macro (pathmacro:)CREATE TABLE reports AS SELECT * FROM (VALUES ('west', '/data/west.csv'), ('east', '/data/east.csv')) t(region, path);CREATE MACRO region_files(p) AS (SELECT list(path) FROM reports WHERE region = p['region']);SET allowed_pathmacro_macros = 'region_files';SELECT * FROM read_csv('pathmacro:region_files?region=east'); -- reads only the east file
-- Build pathmacro: URLs safely (keys/values URL-encoded)SELECT to_pathmacro_url('region_files', {region: 'west'}); -- pathmacro:region_files?region=westÜber scalarfs
DuckDBs Dateifunktionen (read_csv, read_json, COPY TO usw.) erwarten Dateipfade. scalarfs schließt die Lücke, wenn Ihr Inhalt bereits im Speicher liegt, und lässt dieselben Funktionen mit Folgendem arbeiten:
Variablen — Speichern Sie Daten in DuckDB-Variablen und lesen/schreiben Sie sie als Dateien Pfadvariablen — Verwenden Sie in Variablen gespeicherte Dateipfade für dynamische Dateiauflösung Inline-Literale — Betten Sie Inhalte direkt in Ihre Abfragen ein, ohne temporäre Dateien Katalogmakros — Wählen Sie über ein Makro (pathmacro:), welche Dateien aus einem Index/Katalog gelesen werden
| Protocol | Purpose | Mode |
|---|---|---|
| variable: | DuckDB variable as file | Read/Write |
| pathvariable: | File path(s) stored in variable | Read/Write* |
| data: | RFC 2397 data URI (base64/url-encoded) | Read |
| data+varchar: | Raw VARCHAR content as file | Read |
| data+blob: | Escaped BLOB content as file | Read |
| decompress+gz: | Gzip decompression wrapper | Read |
| decompress+zstd: | Zstd decompression wrapper | Read |
| pathmacro: | Paths resolved by an allow-listed macro | Read/Write |
- Schreiben ist nur auf ein
pathvariable:möglich, das ein skalarer Pfad ist (keine Listen).
Die Hilfsfunktionen to_pathmacro_url() / from_pathmacro_url() erzeugen und parsen pathmacro:-URLs.
Die vollständige Dokumentation finden Sie unter: https://scalarfs.readthedocs.io/
Hinweis: Diese Erweiterung wurde überwiegend mit Claude und Claude Code als Übung in KI-gestützter Entwicklung geschrieben.
Hinzugefügte Funktionen
| function_name | function_type | description | comment | examples |
|---|---|---|---|---|
| from_blob_uri | scalar | NULL | NULL | |
| from_data_uri | scalar | NULL | NULL | |
| from_pathmacro_url | scalar | NULL | NULL | |
| from_scalarfs_uri | scalar | NULL | NULL | |
| from_varchar_uri | scalar | NULL | NULL | |
| to_blob_uri | scalar | NULL | NULL | |
| to_data_uri | scalar | NULL | NULL | |
| to_pathmacro_url | scalar | NULL | NULL | |
| to_scalarfs_uri | scalar | NULL | NULL | |
| to_varchar_uri | scalar | NULL | NULL |
Überladene Funktionen
Diese Erweiterung fügt keine Funktionsüberladungen hinzu.
Hinzugefügte Typen
Diese Erweiterung fügt keine Typen hinzu.
Hinzugefügte Einstellungen
| name | description | input_type | scope | aliases |
|---|---|---|---|---|
| allowed_pathmacros | Comma-separated list of scalar macros invokable via the pathmacro: filesystem | VARCHAR | GLOBAL | [] |
| scalarfs_max_decompressed_bytes | Maximum number of bytes a scalarfs decompress+ read may materialize (decompression-bomb guard; 0 disables the cap) | UBIGINT | GLOBAL | [] |