Skip to content

Query Command

Interactive shell and CLI for querying data from CSV, TSV, NDJSON files with format conversion.

Usage

bash
# Interactive shell mode
grpctestify query

# CLI mode with query
grpctestify query -q "users status=active" data/users.csv

# With stdin input
cat data.csv | grpctestify query -q "stdin status=active" -

# Output to file (format auto-detected from extension)
grpctestify query -q "users status=active" data/users.csv --output active_users.ndjson

Query Syntax

text
<source> [col<op>value]...

Where:

  • <source> — file name without extension, or stdin
  • col<op>value — filter expression

Filter Operators

OperatorDescriptionExample
=Equalsstatus=active
!=Not equalsstatus!=pending
>=Greater or equalage>=18
<=Less or equalage<=65
>Greaterscore>100
<Lessscore<50
~globGlob patternname~glob"*John*"
~re:Regexmsg~re:"error|warn"
= with commasIn list (matches any value)status=active,pending

Examples

bash
# Simple equality
grpctestify query -q "users status=active" users.csv

# Multiple filters (AND)
grpctestify query -q "users status=active age>=18" users.csv

# Glob pattern
grpctestify query -q 'users name~glob"*John*"' users.csv

# Regex
grpctestify query -q 'logs msg~re:"error|warn|debug"' logs.ndjson

# IN list
grpctestify query -q "users status=active,pending,suspended" users.csv

CLI Options

OptionShortDescriptionDefault
--query-qQuery expression-
--shell-sForce interactive shellfalse
--indexed-by-iIndex column-
--format-fOutput format (json, csv, table, line, tsv)table
--limit-nMax rows to return100
--offset-oSkip N rows0
--columns-cOutput columns (comma-separated)all
--order-bySort column (prefix - for DESC)-
--outputOutput file (format from extension)stdout
--no-headerSkip header row in outputfalse

Output Formats

bash
# Table (default)
grpctestify query -q "users id=1" users.csv
# ┌─────┬───────┬──────────┐
# │ id  │ name  │ status   │
# ├─────┼───────┼──────────┤
# │ 1   │ alice │ active   │
# └─────┴───────┴──────────┘

# JSON
grpctestify query -q "users id=1" users.csv -f json
# {"id":"1","name":"alice","status":"active"}

# CSV
grpctestify query -q "users id=1" users.csv -f csv
# id,name,status
# 1,alice,active

# Line (key=value pairs, space-separated, one row per line)
grpctestify query -q "users id=1" users.csv -f line
# id=1 name=alice status=active

Interactive Shell

bash
grpctestify query users.csv another.tsv

Shell Commands

CommandDescription
.helpShow help
.quitExit shell
.tablesList loaded sources
.schema <name>Show source columns
.indexes <name>Show index info
.infoShow all sources summary
.count <name>Count rows
.sample <name> [n]Show sample rows (default: 5)
.load <file.gctf>Load sources from .gctf file
.add <name> <file>Add file as source
.remove <name>Remove source
.mode <format>Set output format
.headers <on|off>Toggle headers
.output <file>Set output file

Shell Example

text
$ grpctestify query users.csv
grpctestify query shell
Type '.help' for available commands

query> .tables
  users

query> .schema users
Schema for 'users':
  id
  name
  status
  age

query> .info
Sources: 1
  users: 4 columns

query> status=active
┌─────┬───────┬──────────┐
│ id  │ name  │ status   │
├─────┼───────┼──────────┤
│ 1   │ alice │ active   │
│ 3   │ charlie │ active │
└─────┴───────┴──────────┘

query> .quit

Supported Formats

FormatExtensionsAuto-detect
CSV.csvBy content (comma-separated, no tabs)
TSV.tsvBy content (tab-separated)
NDJSON.ndjson, .jsonlBy content (lines starting with {)
JSON.jsonBy extension only

Format Detection

When reading from stdin (-), format is auto-detected:

  • Lines contain tabs but no commas → TSV
  • Lines start with { → NDJSON
  • Lines contain commas → CSV

File Loading

Files are loaded by extension:

  • .gctf — parsed as gRPC test file, sources extracted
  • .csv, .tsv, .ndjson, .json — data file, source name = file stem

Directories can be specified — all .gctf files are loaded.

bash
# Load directory of gctf files
grpctestify query ./tests/data/

# Multiple files
grpctestify query users.csv orders.csv products.ndjson

Released under the MIT License.