Skip to content

Conversation

@fordN
Copy link
Contributor

@fordN fordN commented Jan 19, 2026

Adds an interactive SQL query panel to ampcc for exploring dataset data

Features

  • SQL syntax highlighting - Color-coded query input for readability
  • Query history - Navigate previous queries with Up/Down arrows, persisted across sessions
  • Per-dataset history - Query history is scoped to each dataset
  • History search - Ctrl+R to search through query history
  • Favorite queries - Star frequently used queries for quick access
  • Query templates - Pre-built SQL templates with context-aware placeholders
  • CSV export - Export query results to CSV files
  • Column sorting - Click column headers to sort results
  • Auto column sizing - Columns resize based on content width
  • Local version listing - Uses admin API for version discovery

Documentation

  • Added query panel user documentation
  • Added developer documentation for extending the panel

fordN and others added 13 commits January 19, 2026 11:56
Previously, expanding a dataset in Local mode would show no versions
because fetch_versions() returned an empty vector. This fix calls the
admin-client's list_versions() API to fetch actual version data.

Changes:
- Construct FQN from namespace/name for the API call
- Map VersionsResponse to VersionEntry structs
- Determine latest version using special_tags.latest
- Handle errors gracefully with eprintln and empty fallback

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Add ability to export SQL query results to CSV files:
- Press E in QueryResult pane to export results
- CSV includes headers and all rows
- Filename includes timestamp (query_results_YYYYMMDD_HHMMSS.csv)
- Success message displays for 3 seconds (green)
- Error handling for write failures and empty results
- Export hint shown in QueryResult title and footer

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Add shell-style query history to the SQL query panel, allowing users to
recall and reuse previously executed queries during their session.

Features:
- Up/Down arrows navigate through query history
- Current input preserved as draft when entering history
- Consecutive duplicate queries are not added
- History capped at 100 entries (oldest removed first)
- UI shows history position and entry count
- Editing resets navigation to current input

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Save query history to ~/.config/ampcc/history.json on shutdown and
load on startup. History survives across sessions, respects the 100
entry limit, and handles errors gracefully without crashing.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Add ability to export SQL query results to CSV files:
- Press E in QueryResult pane to export results
- CSV includes headers and all rows
- Filename includes timestamp (query_results_YYYYMMDD_HHMMSS.csv)
- Success message displays for 3 seconds (green)
- Error handling for write failures and empty results
- Export hint shown in QueryResult title and footer

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Add syntax highlighting for SQL queries in the query input panel:
- SQL keywords highlighted in purple (The Graph accent color)
- String literals highlighted in green
- Numbers highlighted in yellow
- Operators and punctuation in secondary gray
- Identifiers in primary white

Includes tokenizer that handles:
- SQL keywords (SELECT, FROM, WHERE, etc.)
- String literals (single and double quoted)
- Numbers (integers and decimals)
- Operators (=, <, >, !=, <=, >=, <>, +, -, *, /, %)
- Punctuation (parentheses, commas, semicolons, dots)

The highlight_sql_with_cursor() function integrates with the
existing multiline input system to show both highlighting and
cursor position.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Add automatic column width calculation based on data content:
- Columns auto-size based on header and cell content widths
- Minimum width of 5 chars, maximum of 50 chars
- Proportional scaling when total exceeds available space
- Column numbers shown in headers (e.g., "[1] column_name")
- Cell truncation respects calculated column widths

This replaces the previous fixed-percentage/minimum width approach
with a more adaptive layout that better handles varying data widths.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Add query template system for common SQL patterns:
- 6 built-in templates (preview, count, filter, group by, distinct, describe)
- Placeholders auto-filled from current dataset context
- Template picker popup (press T in query mode)
- Up/Down navigation, Enter to select, Esc to cancel

Templates include:
- "SELECT * FROM {table} LIMIT 10" - Preview data
- "SELECT COUNT(*) FROM {table}" - Row count
- "SELECT * FROM {table} WHERE {column} = '?'" - Filter by column
- "SELECT {column}, COUNT(*) FROM {table} GROUP BY {column}" - Group by
- "SELECT DISTINCT {column} FROM {table}" - Unique values
- "DESCRIBE {table}" - Table schema

Placeholders {table} and {column} are resolved using the current
dataset's schema information.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Add interactive sorting for SQL query results:
- Press 's' in QueryResult pane to enter sort mode
- Press 1-9 to sort by that column number
- Press same column number again to reverse sort direction
- Press 'S' to clear sorting and restore original order

Features:
- Numeric-aware sorting (numbers sorted numerically, not lexically)
- Sort indicators in column headers (▲ ascending, ▼ descending)
- Sort info shown in title bar
- Context-sensitive footer hints

The sorted indices are computed on-demand and applied during
rendering, preserving the original data order for export.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Add ability to save and manage favorite SQL queries:
- Press * or F in query mode to toggle favorite status
- Press Ctrl+F to open favorites panel (if any favorites exist)
- Favorites panel supports Up/Down navigation, Enter to load, d to delete
- Star indicator (★) in query title when current query is favorited

Features:
- Favorites persisted to ~/.config/ampcc/favorites.json
- Favorites loaded on startup, saved on quit
- Empty favorites handled gracefully with helpful message
- Query truncation in favorites panel for long queries

The favorites complement query history by providing explicit
user-curated list of frequently used queries.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Store query history separately for each dataset instead of globally.
History is now keyed by dataset name, with "global" as fallback.

Changes:
- Update HistoryFile to version 2 with dataset_history HashMap
- Add current_history_key() and current_history() methods
- Add add_to_history() method for dataset-aware history management
- Update load_history() to migrate from v1 format
- Update main.rs to use new per-dataset history methods
- Update ui.rs to use current_history() for display

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Add bash-style reverse history search to the SQL query panel:
- Ctrl+R enters search mode, cycles through matches
- Case-insensitive filtering of query history
- Works with per-dataset history (with global fallback)
- Shows match count (e.g., "1/5") or "failing" when no matches
- Enter accepts, Esc cancels and restores original input

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Add user-facing documentation for the SQL query panel features:
- Multi-line input and keyboard shortcuts
- SQL syntax highlighting
- Query history with per-dataset support
- Query templates with placeholder resolution
- Favorite queries
- Result sorting and CSV export
- Column auto-sizing

Also add CLAUDE.md with developer documentation covering:
- Architecture and module structure
- Key components and data flow
- Development guidelines
- Troubleshooting guide

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@fordN fordN self-assigned this Jan 19, 2026
@fordN fordN added the ampcc label Jan 19, 2026
@shiyasmohd
Copy link
Contributor

Nice! Some concerns,

  • There is a known issue of using Ctrl+Enter which doesn't work in some terminals as expected, I tried in Warp and Mac's native terminal, both didn't execute queries, instead added new line. So we might need to change it to a different key.
  • When writing SQL, I was not able to type SELECT, since when entering T, the template tab would open.
  • It would be nice if namespace also included when selecting a template query, now, only table name is included.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants