agentleFS
datafusion-contribdatafusion-contrib/datafusion-skills/skills/query/SKILL.md

query

Skill14 starsChanged 8 months agoApache-2.0View on GitHub

Run SQL queries against registered tables or ad-hoc against files using datafusion-cli. Accepts raw SQL or natural language questions. Supports Parquet, CSV, JSON, and Arrow IPC files.

38 other projects use a version of this, 4 of them edited.

Adopted by

Most recently taken up by

Used with

Projects with it also use attach-db, install-duckdb and 8 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • duckdbSkill

    attach-db

    Attach a DuckDB database file for use with /duckdb-skills:query. Explores the schema (tables, columns, row counts) and writes a SQL state file so subsequent queries can restore this session automatically via duckdb -init.

    Also in 3 projects that use this

  • carlopiSkill

    install-duckdb

    Install or update DuckDB extensions. Each argument is either a plain extension name (installs from core) or name@repo (e.g. magic@community). Pass --update to update extensions instead of installing.

    Also in 3 projects that use this

  • JaimeGBASkill

    ingest

    Digest an external source (article, paper, transcript, URL, book chapter) and integrate its content into the knowledge base

    Also in 18 projects that use this

  • Microsoft AzureSkill

    lint

    Run all linting and spell checking for TypeScript and Rust code. Run this before committing to catch style issues, clippy warnings, and misspellings.

    Also in 17 projects that use this

  • seongjaeryuSkill

    save

    Complete and save your current thinking to Bindly

    Also in 4 projects that use this

  • AnthropicSkill

    start

    Set up your bio-research environment and explore available tools. Use when first getting oriented with the plugin, checking which literature, drug-discovery, or visualization MCP servers are connected, or surveying available analysis skills before starting a new project.

    Also in 4 projects that use this

The file

Show its rules and text

We split this skill into the rules it gives an agent

15 rules. 0 are common, 7 are distinctive, and 8 are very specific to this project.

  • 0

    Common

    Most of the 31 edited versions we read keep these.

  • 7

    Distinctive

    This author's own choices. Worth a look.

  • 8

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Follow these steps in order.

    line 15
  2. Distinctive:

    Look for an existing state file:

    line 19
  3. Distinctive:

    If found, verify the state file is valid:

    line 29
  4. Very specific:

    Ad-hoc mode: if: the --file flag is present, or the SQL references file paths (e.g.

    line 37
  5. Very specific:

    Session mode: if: STATE_DIR is set and the input references table names, is natural language, or is SQL without file references.

    line 38
  6. Distinctive:

    If no state file exists and no file is referenced, fall back to ad-hoc mode.

    line 40
  7. Very specific:

    If not found, delegate to /datafusion-skills:install-datafusion and then continue.

    line 48
  8. Distinctive:

    If the input is natural language (not valid SQL), generate SQL.

    line 52
  9. Distinctive:

    When generating SQL, keep these DataFusion-specific features in mind:

    line 68
  10. Very specific:

    EXPLAIN: Use EXPLAIN or EXPLAIN ANALYZE to see query plans

    line 89
  11. Distinctive:

    Before executing, check if the query might produce too many rows.

    line 93
  12. Very specific:

    If the query has no LIMIT and might return a large result, wrap it:

    line 95
  13. Very specific:

    If total_rows > 1000, add LIMIT 100 and inform the user.

    line 101
  14. Very specific:

    Session state: If a state.sql exists, tables registered by /datafusion-skills:create-table are automatically available

    line 157
  15. Very specific:

    Error troubleshooting: Use /datafusion-skills:datafusion-docs for persistent errors

    line 158

“Common” is measured: kept by at least 6 in 10 of the 31 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

You are helping the user query data using Apache DataFusion.

Input: $@

Follow these steps in order.

Step 1 — Resolve state and determine the mode

Look for an existing state file:

STATE_DIR=""
test -f .datafusion-skills/state.sql && STATE_DIR=".datafusion-skills"
PROJECT_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || echo "$PWD")"
PROJECT_ID="$(echo "$PROJECT_ROOT" | tr '/' '-')"
test -f "$HOME/.datafusion-skills/$PROJECT_ID/state.sql" && STATE_DIR="$HOME/.datafusion-skills/$PROJECT_ID"

If found, verify the state file is valid:

datafusion-cli --file "$STATE_DIR/state.sql" -c "SELECT 1;"

Now determine the mode:

  • Ad-hoc mode if: the --file flag is present, or the SQL references file paths (e.g. FROM 'data.parquet'), or STATE_DIR is empty.
  • Session mode if: STATE_DIR is set and the input references table names, is natural language, or is SQL without file references.

If no state file exists and no file is referenced, fall back to ad-hoc mode.

Step 2 — Check datafusion-cli is installed

command -v datafusion-cli

If not found, delegate to /datafusion-skills:install-datafusion and then continue.

Step 3 — Generate SQL if needed

If the input is natural language (not valid SQL), generate SQL.

In session mode, first retrieve the schema to inform query generation:

datafusion-cli --file "$STATE_DIR/state.sql" -c "SHOW TABLES;"

Then for relevant tables:

datafusion-cli --file "$STATE_DIR/state.sql" -c "DESCRIBE <table_name>;"

DataFusion SQL reference

When generating SQL, keep these DataFusion-specific features in mind:

  • File queries: SELECT * FROM 'path/to/file.parquet' works for Parquet files directly
  • CREATE EXTERNAL TABLE: Register any file as a table
    CREATE EXTERNAL TABLE t STORED AS PARQUET LOCATION 'data.parquet';
    CREATE EXTERNAL TABLE t STORED AS CSV LOCATION 'data.csv' OPTIONS ('has_header' 'true');
    CREATE EXTERNAL TABLE t STORED AS JSON LOCATION 'data.json';
    CREATE EXTERNAL TABLE t STORED AS ARROW LOCATION 'data.arrow';
    CREATE EXTERNAL TABLE t STORED AS AVRO LOCATION 'data.avro';
  • COPY TO: Export query results to files
    COPY (SELECT * FROM t WHERE x > 10) TO 'output.parquet' STORED AS PARQUET;
  • Window functions: Full support for ROW_NUMBER, RANK, LAG, LEAD, etc.
  • CTEs: WITH clauses are fully supported
  • UNNEST: Expand arrays into rows
  • Aggregate functions: COUNT, SUM, AVG, MIN, MAX, MEDIAN, APPROX_PERCENTILE_CONT, etc.
  • String functions: LENGTH, LOWER, UPPER, TRIM, SUBSTR, REGEXP_MATCH, etc.
  • Date/time: NOW(), DATE_TRUNC, DATE_PART, INTERVAL, TO_TIMESTAMP, etc.
  • EXPLAIN: Use EXPLAIN or EXPLAIN ANALYZE to see query plans

Step 4 — Estimate result size

Before executing, check if the query might produce too many rows.

If the query has no LIMIT and might return a large result, wrap it:

SELECT COUNT(*) AS total_rows FROM (<original_query>);

If total_rows > 1000, add LIMIT 100 and inform the user.

Step 5 — Execute the query

Important: datafusion-cli -c only accepts one SQL statement per flag. Use multiple -c flags for multiple statements, or write a .sql file and use --file.

Session mode:

datafusion-cli --file "$STATE_DIR/state.sql" -c "<SQL_QUERY>"

Ad-hoc mode with file:

DataFusion v44+ can query Parquet, CSV, and JSON files directly by path:

datafusion-cli -c "SELECT * FROM '<file_path>' LIMIT 10;"

For Arrow IPC or Avro, create a temporary external table using a .sql file:

cat > /tmp/_df_query.sql << SQL
CREATE EXTERNAL TABLE _tmp STORED AS ARROW LOCATION '<file_path>';
<SQL_QUERY using _tmp>;
SQL
datafusion-cli --file /tmp/_df_query.sql

Ad-hoc mode without file:

datafusion-cli -c "<SQL_QUERY>"

Step 6 — Handle errors

  • datafusion-cli: command not found → invoke /datafusion-skills:install-datafusion and retry
  • File not found → check the path, suggest using absolute path
  • Schema error → run DESCRIBE on the table/file and show the user available columns
  • Unsupported file format → suggest creating an external table with explicit format
  • Persistent or unclear error → use /datafusion-skills:datafusion-docs <error keywords> to search documentation

Step 7 — Present results

Present the query results clearly. If the result is a table, format it nicely.

Suggest next steps if appropriate:

  • For exploratory queries → suggest more specific filters or aggregations
  • For ad-hoc file queries → suggest /datafusion-skills:create-table to register the file for repeated use
  • For complex pipelines → suggest /datafusion-skills:materialized-view to persist results

Cross-skill integration

  • Session state: If a state.sql exists, tables registered by /datafusion-skills:create-table are automatically available
  • Error troubleshooting: Use /datafusion-skills:datafusion-docs for persistent errors
  • Performance: Suggest /datafusion-skills:explain-plan for slow queries

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.