(t *testing.T)
| 3 | import "testing" |
| 4 | |
| 5 | func TestRewriteDirectQuery(t *testing.T) { |
| 6 | c := &clientConn{ |
| 7 | server: &Server{ |
| 8 | cfg: Config{ |
| 9 | DuckLake: DuckLakeConfig{ |
| 10 | MetadataStore: "postgres:host=127.0.0.1 dbname=ducklake", |
| 11 | }, |
| 12 | }, |
| 13 | }, |
| 14 | database: "ducklake", |
| 15 | catalogUseRewrite: true, |
| 16 | } |
| 17 | |
| 18 | tests := []struct { |
| 19 | name string |
| 20 | query string |
| 21 | want string |
| 22 | }{ |
| 23 | { |
| 24 | // `USE ducklake` while currently in another catalog would |
| 25 | // otherwise resolve to a bogus <catalog>.ducklake — two-part fixes it. |
| 26 | name: "rewrites bare ducklake to two-part ducklake.main", |
| 27 | query: "USE ducklake", |
| 28 | want: "USE ducklake.main", |
| 29 | }, |
| 30 | { |
| 31 | name: "rewrites quoted ducklake to two-part ducklake.main", |
| 32 | query: `USE "ducklake"`, |
| 33 | want: "USE ducklake.main", |
| 34 | }, |
| 35 | { |
| 36 | name: "rewrites commented ducklake use", |
| 37 | query: "/* switch */ USE ducklake;", |
| 38 | want: "USE ducklake.main;", |
| 39 | }, |
| 40 | { |
| 41 | // Only `USE ducklake` is rewritten — any other catalog passes through. |
| 42 | name: "preserves bare use of a non-ducklake catalog", |
| 43 | query: "USE iceberg", |
| 44 | want: "USE iceberg", |
| 45 | }, |
| 46 | { |
| 47 | name: "preserves two-part use of a non-ducklake catalog", |
| 48 | query: "USE other.billing", |
| 49 | want: "USE other.billing", |
| 50 | }, |
| 51 | { |
| 52 | name: "preserves physical use command", |
| 53 | query: "USE memory", |
| 54 | want: "USE memory", |
| 55 | }, |
| 56 | { |
| 57 | // An arbitrary database name is no longer remapped onto a catalog. |
| 58 | name: "preserves use of an arbitrary name", |
| 59 | query: "USE analytics", |
| 60 | want: "USE analytics", |
| 61 | }, |
| 62 | { |
nothing calls this directly
no test coverage detected