Extend OctoSQL with external plugins
mainplugin_repository.json file. Refer to the Plugins section of the documentation for implementation details.repository·main·Indexed 26 days ago
https://github.com/cube2222/octosqlA CLI tool and dataflow engine that provides a unified SQL interface to query multiple databases and file formats, including JSON, CSV, and Parquet. OctoSQL enables cross-source JOIN operations, supports streaming data with Event Times and Watermarks, and allows extensibility through a plugin system for databases like PostgreSQL and MySQL.
plugin_repository.json file. Refer to the Plugins section of the documentation for implementation details.You can install OctoSQL using several methods depending on your environment:
brew install cube2222/octosql/octosqlNote: On macOS, you may need to allow the app in Preferences -> Security and Privacy if it is not notarized.
To install in your local nix-profile:
nix-env -iA nixpkgs.octosqlTo spawn an adhoc shell for testing:
nix-shell -p octosqlFor NixOS, add octosql to your systemPackages in your configuration.
Download the binary directly from the GitHub Releases page.
Requires Go version >= 1.18:
git clone https://github.com/cube2222/octosql
cd octosql
go installgo install command from within the root directory.go installOctoSQL is a CLI tool that allows you to query various databases and file formats using SQL. You can perform JOINs across different data sources (e.g., joining a JSON file with a PostgreSQL table).
octosql "SELECT * FROM ./path/to/file.json"--describe flag to see the schema of a file or table.--output flag. Supported values are live_table, batch_table, csv, and stream_native.octosql "SELECT * FROM ./myfile.json" --describe
octosql "SELECT invoices.id, address, amount
FROM invoices.csv JOIN db.customers ON invoices.customer_id = customers.id
ORDER BY amount DESC"OctoSQL supports several file formats out of the box: JSON (JSONLines), CSV, TSV, Parquet, and Lines.
If the file extension matches the format, use the path directly:
octosql "SELECT * FROM my/file/path.json"
If the extension is non-standard, use the notation `format.path`:
octosql "SELECT * FROM json.my/file/path.whatever"
Append query parameters to the file path to configure behavior:
header=true|false (default: true)tail=true|false (default: false)tail=true|false (default: false)Example: octosql "SELECT * FROM myfile.csv?header=false"
Pipe data into OctoSQL using the stdin.<file_type> table name.
echo '{"hello": "world"}' | octosql "SELECT * FROM stdin.json"
seq 100 | octosql "SELECT SUM(int(text)) FROM stdin.lines"To support databases like PostgreSQL or MySQL, you must install plugins. Plugins are managed via the octosql plugin command.
Install the latest version from the default core repository:
octosql plugin install <plugin_name>
To install a specific version from a specific repository:
octosql plugin install <repository>/<plugin_name>@<version>
OctoSQL provides several tables to inspect plugin metadata:
plugins.repositoriesplugins.available_pluginsplugins.available_versionsplugins.installed_pluginsplugins.installed_versionsoctosql plugin install postgres
octosql "SELECT name, description FROM plugins.available_plugins LIMIT 2"Plugins like postgres require configuration. Settings are stored in ~/.octosql/octosql.yml.
Example configuration for a PostgreSQL database:
databases:
- name: mydb
type: postgres
config:
host: localhost
port: 5432
database: postgres
user: postgres
password: mypasswordOctoSQL is a query engine that accepts a single SQL query as a command-line argument. It supports SELECT statements and can query various data sources including files (CSV, JSON, Parquet, etc.) and plugins.
Basic Usage:
octosql "SELECT * FROM myfile.json"
octosql "SELECT * FROM mydir/myfile.csv"octosql "SELECT * FROM myfile.json"~/.octosql/logs.txt. Note that only the logs from the most recent execution are preserved.OctoSQL is statically typed and supports union types (e.g., Float | String). To handle union types, you can use the following features:
value::type syntax to get a value only if it matches the specified type; otherwise, it evaluates to NULL. For example, age::Int extracts the integer value from a String | Int column.int(value) to attempt to convert types (e.g., converting a String to an Int).age of type String | Int, you can use COALESCE(age::int, int(age::string), 0) to return the integer, try to parse a string, or default to 0.Accessing complex types:
list[index]object->fieldOctoSQL is a dataflow engine that supports streaming data using Event Times and Watermarks. For GROUP BY queries, you can control when results are emitted using the TRIGGER clause.
Syntax: SELECT ... FROM ... GROUP BY ... TRIGGER [type] [args]
Supported Triggers:
n) arrive for a key.You can combine multiple triggers (e.g., TRIGGER COUNTING 300, ON WATERMARK).
SELECT window_end, user_id, COUNT(*)
FROM my_table
GROUP BY window_end, user_id
TRIGGER COUNTING 300, ON WATERMARKTable Valued Functions return a stream of Records. When using them, you must alias the result. You can specify arguments using the TABLE(...) operator for tables/subqueries and the DESCRIPTOR(...) operator for field descriptors.
Available Functions:
range(start, end): Constructs a sequence of integers from start (inclusive) to end (exclusive).poll(source, poll_interval?): Periodically polls a finite subquery.tumble(source, window_length, time_field?, offset?): Assigns records to tumbling windows.max_diff_watermark(source, max_diff, time_field, resolution?): Updates Event Times and emits Watermarks based on the max_diff interval before the latest seen Event Time.Usage Patterns:
TABLE(...) for simple table names or other TVFs: TABLE(range(start=>1, end=>10)).TABLE((SELECT ...)) for subqueries.