buildSessionMetadataSQL returns a single SQL script containing all the per-session catalog/metadata setup statements concatenated with semicolons. The DuckDB driver executes the script as a multi-statement batch in one ExecContext call (one Flight RPC from the control plane to the worker instead of
(database string)
| 130 | default: |
| 131 | return false, fmt.Errorf("duckdb_databases() count has unsupported type %T", rawCount) |
| 132 | } |
| 133 | return count > 0, rows.Err() |
| 134 | } |
| 135 | |
| 136 | // buildSessionMetadataSQL returns a single SQL script containing all the |
| 137 | // per-session catalog/metadata setup statements concatenated with semicolons. |
| 138 | // The DuckDB driver executes the script as a multi-statement batch in one |
| 139 | // ExecContext call (one Flight RPC from the control plane to the worker |
| 140 | // instead of N), which materially cuts session establishment latency on |
| 141 | // remote-worker setups where each round-trip is non-trivial. |
| 142 | // |
| 143 | // All statements are independent: each is CREATE OR REPLACE VIEW or |
| 144 | // CREATE TABLE IF NOT EXISTS, with no cross-statement dependencies that would |
| 145 | // require ordering beyond the order they appear in the script. |
| 146 | func buildSessionMetadataSQL(database string, accessPolicies ...*MetadataAccessPolicy) string { |
| 147 | var access *MetadataAccessPolicy |
| 148 | if len(accessPolicies) > 0 { |
| 149 | access = accessPolicies[0] |
| 150 | } |
| 151 | parts := []string{ |