Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 57 additions & 1 deletion documentation/reference/api/rest.md
Original file line number Diff line number Diff line change
Expand Up @@ -591,15 +591,33 @@ returned in a tabular form to be saved and reused as opposed to JSON.
`/exp` is expecting an HTTP GET request with following parameters:

| Parameter | Required | Description |
| :-------- | :------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|:----------|:---------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `query` | Yes | URL encoded query text. It can be multi-line. |
| `limit` | No | Paging opp parameter. For example, `limit=10,20` will return row numbers 10 through to 20 inclusive and `limit=20` will return first 20 rows, which is equivalent to `limit=0,20`. `limit=-20` will return the last 20 rows. |
| `nm` | No | `true` or `false`. Skips the metadata section of the response when set to `true`. |
| `fmt` | No | Export format. Valid values: `parquet`, `csv`. When set to `parquet`, exports data in Parquet format instead of CSV. |

#### Parquet Export Parameters

When `fmt=parquet`, the following additional parameters are supported:

| Parameter | Required | Default | Description |
|:---------------------|:---------|:----------------|:----------------------------------------------------------------------------------------------------|
| `partition_by` | No | `NONE` | Partition unit: `NONE`, `HOUR`, `DAY`, `WEEK`, `MONTH`, or `YEAR`. |
| `compression_codec` | No | `LZ4_RAW` | Compression algorithm: `UNCOMPRESSED`, `SNAPPY`, `GZIP`, `LZ4`, `ZSTD`, `LZ4_RAW`, `BROTLI`, `LZO`. |
| `compression_level` | No | Codec-dependent | Compression level (codec-specific). Higher values = better compression but slower. |
| `row_group_size` | No | `100000` | Number of rows per Parquet row group. |
| `data_page_size` | No | `1048576` | Size of data pages in bytes (default 1MB). |
| `statistics_enabled` | No | `true` | Enable Parquet column statistics: `true` or `false`. |
| `parquet_version` | No | `2` | Parquet format version: `1` (v1.0) or `2` (v2.0). |
| `raw_array_encoding` | No | `true` | Use raw encoding for arrays: `true` or `false`. |

The parameters must be URL encoded.

### Examples

#### CSV Export (default)

Considering the query:

```shell
Expand All @@ -620,6 +638,44 @@ A HTTP status code of `200` is returned with the following response body:
200501BS00005,"2005-01-10T00:00:00.000Z",21:13
```

#### Parquet Export

Export query results to Parquet format:

```shell
curl -G \
--data-urlencode "query=SELECT * FROM trades WHERE timestamp IN today()" \
--data-urlencode "fmt=parquet" \
http://localhost:9000/exp > trades_today.parquet
```

#### Parquet Export with Custom Options

Export with custom compression and partitioning:

```shell
curl -G \
--data-urlencode "query=SELECT * FROM trades" \
--data-urlencode "fmt=parquet" \
--data-urlencode "partition_by=DAY" \
--data-urlencode "compression_codec=ZSTD" \
--data-urlencode "compression_level=9" \
--data-urlencode "row_group_size=1000000" \
http://localhost:9000/exp > trades.parquet
```

#### Parquet Export with LZ4 Compression

Export with LZ4_RAW compression for faster export:

```shell
curl -G \
--data-urlencode "query=SELECT symbol, price, amount FROM trades WHERE timestamp > dateadd('h', -1, now())" \
--data-urlencode "fmt=parquet" \
--data-urlencode "compression_codec=LZ4_RAW" \
http://localhost:9000/exp > recent_trades.parquet
```

## Error responses

### Malformed queries
Expand Down
44 changes: 44 additions & 0 deletions documentation/reference/function/meta.md
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,50 @@ If you want to re-read metadata for all user tables, simply use an asterisk:
SELECT hydrate_table_metadata('*');
```

## copy_export_log

`copy_export_log()` or `sys.copy_export_log` returns the export log for `COPY TO` operations.

**Arguments:**

- `copy_export_log()` does not require arguments.

**Return value:**

Returns metadata on `COPY TO` export operations for the last three days, including columns such as:

- `ts` - timestamp of the log event
- `id` - export identifier that can be used to track export progress
- `table` - source table name (or 'query' for subquery exports)
- `destination` - destination directory path for the export
- `format` - export format (currently only 'PARQUET')
- `status` - event status: 'started', 'finished', 'failed', or 'cancelled'
- `message` - error message when status is 'failed'
- `rows_exported` - total number of exported rows (shown in final log row)
- `partition` - partition name for partitioned exports (null for non-partitioned)

Comment on lines +604 to +613
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs fixing

**Examples:**

```questdb-sql
SELECT * FROM copy_export_log();
```

| ts | id | table | destination | format | status | message | rows_exported | partition |
| --------------------------- | ---------------- | ------ | ------------- | ------- | -------- | ------- | ------------- | ---------- |
| 2024-10-01T14:23:15.123456Z | 7f3a9c2e1b456789 | trades | trades_export | PARQUET | started | | 0 | null |
| 2024-10-01T14:25:42.987654Z | 7f3a9c2e1b456789 | trades | trades_export | PARQUET | finished | | 1000000 | null |
Comment on lines +619 to +623
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs fixing


```questdb-sql title="Track specific export"
SELECT * FROM copy_export_log() WHERE id = '7f3a9c2e1b456789';
```

```questdb-sql title="View recent failed exports"
SELECT ts, table, destination, message
FROM copy_export_log()
WHERE status = 'failed'
ORDER BY ts DESC;
```

## flush_query_cache()

`flush_query_cache' invalidates cached query execution plans.
Expand Down
Loading
Loading