MATIH Platform is in active MVP development. Documentation reflects current implementation status.
9. Query Engine & SQL
Export
CSV Export

CSV Export

CSV export is the most commonly used format for result delivery to spreadsheets, BI tools, and ETL pipelines.


Endpoint

POST /v1/queries/{executionId}/export

Request

curl -X POST http://query-engine:8080/v1/queries/a1b2c3d4-e5f6-7890/export \
  -H "Content-Type: application/json" \
  -H "X-Tenant-ID: 550e8400-e29b-41d4-a716-446655440000" \
  -H "Authorization: Bearer $JWT_TOKEN" \
  -d '{
    "format": "CSV",
    "includeHeader": true,
    "csvDelimiter": ",",
    "csvQuoteChar": "\"",
    "compress": false,
    "maxRows": 50000
  }'

Export Request Options

FieldTypeDefaultDescription
formatString--CSV, JSON, JSON_LINES, PARQUET
includeHeaderBooleantrueInclude column headers as first row
csvDelimiterString,Field delimiter character
csvQuoteCharString"Quote character for values containing delimiters
compressBooleanfalseGZIP compress the output
maxRowsInteger1,000,000Maximum rows to export

Response

{
  "exportId": "e1f2a3b4-c5d6-7890-abcd-ef1234567890",
  "executionId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "status": "COMPLETED",
  "format": "CSV",
  "fileName": "export-a1b2c3d4-12345.csv",
  "fileSize": 245760,
  "rowCount": 5000,
  "completedAt": "2026-02-12T10:30:05Z"
}

CSV Value Formatting

Values are quoted when they contain the delimiter, newline characters, or the quote character itself. The quoting follows RFC 4180:

private String formatCsvValue(Object value, String quoteChar, String delimiter) {
    if (value == null) return "";
    String str = value.toString();
    if (str.contains(delimiter) || str.contains("\n") || str.contains("\r")
            || str.contains(quoteChar)) {
        str = str.replace(quoteChar, quoteChar + quoteChar);
        return quoteChar + str + quoteChar;
    }
    return str;
}

Tab-Separated Values

For TSV output, set the delimiter to a tab character:

{
  "format": "CSV",
  "csvDelimiter": "\t",
  "includeHeader": true
}