|
| 1 | +<!-- |
| 2 | +
|
| 3 | + Licensed to the Apache Software Foundation (ASF) under one |
| 4 | + or more contributor license agreements. See the NOTICE file |
| 5 | + distributed with this work for additional information |
| 6 | + regarding copyright ownership. The ASF licenses this file |
| 7 | + to you under the Apache License, Version 2.0 (the |
| 8 | + "License"); you may not use this file except in compliance |
| 9 | + with the License. You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | + Unless required by applicable law or agreed to in writing, |
| 14 | + software distributed under the License is distributed on an |
| 15 | + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 | + KIND, either express or implied. See the License for the |
| 17 | + specific language governing permissions and limitations |
| 18 | + under the License. |
| 19 | +
|
| 20 | +--> |
| 21 | +## Pinot CLI |
| 22 | + |
| 23 | +An interactive and batch command-line client for Apache Pinot. It supports a rich interactive REPL, multiple output formats, history, pagination, configuration files, and batch execution. |
| 24 | + |
| 25 | +## Requirements |
| 26 | + |
| 27 | +- Java 11+ on PATH (Java 22+ recommended for performance) |
| 28 | + |
| 29 | +## Build |
| 30 | + |
| 31 | +From the repository root: |
| 32 | + |
| 33 | +```bash |
| 34 | +./mvnw -DskipTests -pl pinot-clients/pinot-cli -am package |
| 35 | +``` |
| 36 | + |
| 37 | +Artifacts: |
| 38 | + |
| 39 | +- `pinot-clients/pinot-cli/target/pinot-cli-*-executable.jar` (executable, recommended) |
| 40 | +- `pinot-clients/pinot-cli/target/pinot-cli-1.5.0-SNAPSHOT.jar` (thin) |
| 41 | + |
| 42 | +## Running |
| 43 | + |
| 44 | +### Interactive mode |
| 45 | + |
| 46 | +```bash |
| 47 | +pinot-clients/pinot-cli/target/pinot-cli-*-executable.jar \ |
| 48 | + -u jdbc:pinot://<controller-host>:<port> |
| 49 | +``` |
| 50 | + |
| 51 | +- Multi-line SQL is supported; end statements with `;` to execute. |
| 52 | +- Built-in commands: `help`, `clear`, `exit`, `quit`. |
| 53 | +- Default history file: `~/.pinot_history` (customize with `--history-file`). |
| 54 | +- Enable paging with a pager (e.g., `less`) via `--pager` or environment variables below. |
| 55 | + |
| 56 | +### Batch mode |
| 57 | + |
| 58 | +Execute a single statement: |
| 59 | + |
| 60 | +```bash |
| 61 | +pinot-clients/pinot-cli/target/pinot-cli-*-executable.jar \ |
| 62 | + -u jdbc:pinot://<controller-host>:<port> \ |
| 63 | + --output-format=CSV_HEADER \ |
| 64 | + --execute "SELECT * FROM myTable LIMIT 3;" |
| 65 | +``` |
| 66 | + |
| 67 | +Execute statements from a file: |
| 68 | + |
| 69 | +```bash |
| 70 | +pinot-clients/pinot-cli/target/pinot-cli-*-executable.jar \ |
| 71 | + -u jdbc:pinot://<controller-host>:<port> \ |
| 72 | + --output-format=JSON \ |
| 73 | + -f queries.sql |
| 74 | +``` |
| 75 | + |
| 76 | +## Options |
| 77 | + |
| 78 | +- `-u, --url` JDBC URL. Example: `jdbc:pinot://controller:9000` or `jdbc:pinotgrpc://controller:9000` (required) |
| 79 | +- `-n, --user` Username |
| 80 | +- `-p, --password` Password |
| 81 | +- `--header` Extra request header `key=value` (repeatable), e.g., `--header Authorization=Bearer <token>` |
| 82 | +- `--set` Query/session option `key=value` (repeatable). Forwarded as connection properties |
| 83 | +- `-e, --execute` Execute SQL and exit |
| 84 | +- `-f, --file` Execute SQL from file and exit |
| 85 | +- `-o, --output` Legacy: `table|csv|json` (backward compatibility). Prefer the formats below |
| 86 | +- `--output-format` Batch output format |
| 87 | +- `--output-format-interactive` Interactive output format (default: `ALIGNED`) |
| 88 | +- `--pager` Pager program used in interactive mode (e.g., `less -SRFXK`). Empty disables pagination |
| 89 | +- `--history-file` Path to history file for interactive mode (default: `~/.pinot_history`) |
| 90 | +- `--config` Path to a properties file with defaults (see Configuration below) |
| 91 | +- `--debug` Print stack traces and timing diagnostics to stderr |
| 92 | + |
| 93 | +### Output formats |
| 94 | + |
| 95 | +Available values for `--output-format` and `--output-format-interactive` (case-insensitive): |
| 96 | + |
| 97 | +- `CSV`, `CSV_HEADER`, `CSV_UNQUOTED`, `CSV_HEADER_UNQUOTED` |
| 98 | +- `TSV`, `TSV_HEADER` |
| 99 | +- `JSON` (one JSON object per line) |
| 100 | +- `ALIGNED` (ASCII table) |
| 101 | +- `VERTICAL` (record-oriented) |
| 102 | +- `AUTO` (chooses `ALIGNED` if it fits terminal width, otherwise `VERTICAL`) |
| 103 | +- `MARKDOWN` (Markdown table) |
| 104 | +- `NULL` (suppress normal results; useful for timing/error checks) |
| 105 | + |
| 106 | +## Configuration |
| 107 | + |
| 108 | +You can load defaults from a properties file using `--config` or via environment variables: |
| 109 | + |
| 110 | +- `PINOT_CONFIG` (preferred) |
| 111 | + |
| 112 | +Supported keys in the properties file (CLI flags take precedence): |
| 113 | + |
| 114 | +- `server` (maps to `--url`) |
| 115 | +- `user`, `password` |
| 116 | +- `output-format`, `output-format-interactive`, `output` |
| 117 | +- `pager`, `history-file`, `debug` |
| 118 | +- `headers.*` (e.g., `headers.Authorization=Bearer <token>`) -> becomes extra headers |
| 119 | +- Any other key is forwarded as a session option (equivalent to `--set key=value`) |
| 120 | + |
| 121 | +Example `pinot-cli.properties`: |
| 122 | + |
| 123 | +```properties |
| 124 | +server=jdbc:pinot://localhost:9000 |
| 125 | +user=alice |
| 126 | +output-format-interactive=AUTO |
| 127 | +pager=less -SRFXK |
| 128 | +history-file=/Users/alice/.pinot_history |
| 129 | +headers.Authorization=Bearer abc123 |
| 130 | +debug=true |
| 131 | +timeoutMs=60000 |
| 132 | +``` |
| 133 | + |
| 134 | +Run with: |
| 135 | + |
| 136 | +```bash |
| 137 | +PINOT_CONFIG=/path/to/pinot-cli.properties \ |
| 138 | +pinot-clients/pinot-cli/target/pinot-cli-*-executable.jar |
| 139 | +``` |
| 140 | + |
| 141 | +## Environment variables |
| 142 | + |
| 143 | +- `PINOT_CONFIG`: path to a config properties file |
| 144 | +- `PINOT_PAGER`: pager command for interactive mode (e.g., `less -SRFXK`) |
| 145 | + |
| 146 | +## Examples |
| 147 | + |
| 148 | +Interactive with AUTO format and pager: |
| 149 | + |
| 150 | +```bash |
| 151 | +pinot-clients/pinot-cli/target/pinot-cli-*-executable.jar \ |
| 152 | + -u jdbc:pinot://localhost:9000 \ |
| 153 | + --output-format-interactive=AUTO \ |
| 154 | + --pager "less -SRFXK" |
| 155 | +``` |
| 156 | + |
| 157 | +Batch to JSON: |
| 158 | + |
| 159 | +```bash |
| 160 | +pinot-clients/pinot-cli/target/pinot-cli-*-executable.jar \ |
| 161 | + -u jdbc:pinot://localhost:9000 \ |
| 162 | + --output-format=JSON \ |
| 163 | + --execute "SELECT col1, col2 FROM myTable LIMIT 3;" |
| 164 | +``` |
| 165 | + |
| 166 | +## Notes |
| 167 | + |
| 168 | +- CLI arguments take precedence over config file values. |
| 169 | +- Pager is only used in interactive mode. Batch mode prints directly to stdout. |
| 170 | + |
| 171 | + |
0 commit comments