Skip to content

Full Exports (TPT)

When executing queries with :TDO or :TDV, BTEQ fetches a limited result set (capped by retlimit, default 100 rows) to keep Neovim fast and responsive.

For large or multi-million-row queries, vim-teradata provides background full-result exports powered by Teradata Parallel Transporter (TPT / tbuild). The data streams directly into a delimited CSV file on disk without loading large amounts of data into Neovim memory.


Quick Workflow

  1. Run query: Execute your query as usual with :TDO or :TDV. If the result set exceeds retlimit, a warning indicates that results are truncated and mentions F.
  2. Trigger export:
    • Press F inside the result grid buffer.
    • Or run :TDExport from any buffer to export the latest output query.
    • To export an older query from history, pass its ID: :TDExport <id> (supports completion from query history).
  3. Confirm: A confirmation dialog displays the query ID, user, row count (if known), estimated file size, destination file path, and selected TPT operator route. Press y to start (n, q, or <Esc> cancels).
  4. Monitor: The export runs asynchronously in the background. Track progress in the Job Manager (:TDJ), where the job is marked with operation export and status TPT running.
  5. Inspect: Once complete, press <CR> on the job in :TDJ to open the first rows in a read-only preview grid.

Triggering an Export

Keymap in Result Buffers (F)

Inside any result grid produced by :TDO or :TDV, pressing F starts a full export for that query.

  • The F key is local to result buffers (it shadows Vim's F{char} motion inside result buffers only).
  • You can change the keymap via export.keymap (for example to "gF"), or set it to false to disable the key.
  • F is disabled on EXPLAIN and SHOW grids, on grids showing export previews, and while the result buffer is in Edit Mode.

Command: :TDExport

Available globally across any buffer:

:TDExport        " Export latest query result
:TDExport 42     " Export history entry 42

Confirmation Dialog

Before starting the export, a confirmation window displays key job metadata:

Export full result with TPT?
  Query:    42
  User:     USER @ HOST
  Rows:     ~1,250,000
  Size:     ~140 MB
  File:     ~/.local/share/nvim/teradata/history/exports/42.csv
  Operator: EXPORT (FastExport protocol, 4 sessions)

[y] Export with TPT   [n] Cancel
  • Press y to begin.
  • Press n, q, or <Esc> to cancel.
  • <CR> does nothing, preventing accidental confirmation.
  • To bypass confirmation and start exports immediately, set export.confirm = false.

TPT Operator Routing: EXPORT vs. SELECTOR

TPT exports use one of two routes depending on the query structure and configuration:

                       ┌─────────────────────────────┐
                       │   Eligible for wrapper?     │
                       └──────────────┬──────────────┘
                                      │
                       ┌──────────────┴──────────────┐
                      YES                            NO
                       │                             │
                       ▼                             ▼
              ┌──────────────────┐          ┌──────────────────┐
              │  Route W: EXPORT │          │ Route R: SELECTOR│
              │   (FastExport)   │          │  (Report Mode)   │
              │  Multi-session   │          │  Single session  │
              └────────┬─────────┘          └──────────────────┘
                       │
             Fails on data type?
            (LOB, JSON, UDT, etc.)
                       │
                       ▼ (Automatic Retry)
              ┌──────────────────┐
              │ Route R: SELECTOR│
              │  (Report Mode)   │
              └──────────────────┘

Route W: EXPORT Operator (Default)

The query is automatically wrapped so that every column is converted to text:

SELECT TRIM(t.c1) AS c1, ..., TRIM(t.cN) AS cN
FROM (<query>) AS t (c1, ..., cN);
  • Formatting fidelity: TRIM formats numbers and dates according to each column's Teradata FORMAT definition, matching BTEQ output.
  • High throughput: Uses Teradata's multi-session FastExport protocol (governed by export.max_sessions, default 4).
  • Modifier preservation: A leading LOCKING ... FOR ACCESS clause is automatically hoisted outside the wrapper.

Route R: SELECTOR Operator (Report Mode)

Submits the query unchanged using a single utility session in report mode. Route R is automatically chosen when:

  • The query contains a top-level ORDER BY (including TOP n ... ORDER BY and set operations ending with ORDER BY).
  • The query uses WITH (Common Table Expressions / CTEs).
  • The query uses an unrecognized LOCKING clause.
  • Result preview headers are unavailable or the Tree-sitter parser is not loaded.
  • export.operator is set to "selector" in your configuration.

Automatic Fallback & Retry

The high-performance EXPORT operator does not support certain complex Teradata data types (such as CLOB, BLOB, JSON, XML, PERIOD, BYTE, VARBYTE, or UDT).

If Route W fails with error codes TPT12108, TPT02639, or a TRIM failure on these types, vim-teradata automatically retries the export once using Route R (SELECTOR) within the same :TDJ job and notifies you.

To force SELECTOR mode from the start (useful on systems without FastExport utility session privileges), set:

export = {
  operator = "selector",
}

Persistent Sessions (:TDSession)

Because TPT initiates its own independent database sessions via tbuild, it cannot access objects stored exclusively in a buffer's persistent BTEQ session (such as volatile tables, session-level query bands, or default databases set via DATABASE <name>;).

When an export is triggered for a query that ran in a persistent session:

  1. Warning: The confirmation dialog flags that the query ran inside a persistent session.
  2. Volatile table detection: If the query references volatile or temporary tables, TPT export is blocked. The dialog instead offers:
    [b] Export with BTEQ inside the session
    
  3. Selecting [b] streams the full result through the buffer's existing BTEQ session with no row limits directly into the export file. While slower than TPT, this allows exporting volatile tables without data loss.

Managing Exports in Job Manager (:TDJ)

Full exports integrate directly into the Job Manager:

  • Status indicator: Displays TPT running during export, and reports the total exported row count when finished.
  • Previewing output (<CR>): Press <CR> on a finished export job to open the first rows (export.head_lines, defaults to retlimit) in a read-only grid. A hint line displays total rows and destination path.
  • Canceling (x): Pressing x terminates the export. When twbkill and twbrmcp utilities are available on $PATH, the job is terminated on Teradata, checkpoint files are purged, and the partial export file is cleaned up.
  • Deleting export files (d): Pressing d on a completed export job prompts to delete the exported .csv file from disk. The source query (queries/<id>.sql) is preserved.

Output Format & Storage

  • Location: Files are stored under <history_dir>/exports/<id>.csv (the subfolder name is configurable via exports_dir_name).
  • Delimiter: Uses the configured field separator sep (default "~"). Newlines and single quotes are not permitted in sep for exports.
  • NULL values: Written as empty fields (differing from the preview token null_token).
  • Disk retention: Export files are managed and pruned alongside query history based on history_max.

Troubleshooting TPT Exports

  • View full TPT log: If an export fails, the job details in :TDJ display relevant error lines. If the TPT job ID is known, run the following in your terminal to view the full TPT execution log:
    tlogview -j <jobid> -f '*' -g
    
  • Verify TTU utilities: Run :checkhealth vim-teradata to verify that tbuild, twbkill, twbrmcp, and tlogview are detected on your $PATH.