|
| 1 | +SET datestyle = 'ISO'; |
| 2 | +CREATE SERVER binary_json_loopback FOREIGN DATA WRAPPER clickhouse_fdw OPTIONS(dbname 'json_test', driver 'binary'); |
| 3 | +CREATE SERVER http_json_loopback FOREIGN DATA WRAPPER clickhouse_fdw OPTIONS(dbname 'json_test', driver 'http'); |
| 4 | +CREATE USER MAPPING FOR CURRENT_USER SERVER binary_json_loopback; |
| 5 | +CREATE USER MAPPING FOR CURRENT_USER SERVER http_json_loopback; |
| 6 | +SELECT clickhouse_raw_query('DROP DATABASE IF EXISTS json_test'); |
| 7 | + clickhouse_raw_query |
| 8 | +---------------------- |
| 9 | + |
| 10 | +(1 row) |
| 11 | + |
| 12 | +SELECT clickhouse_raw_query('CREATE DATABASE json_test'); |
| 13 | + clickhouse_raw_query |
| 14 | +---------------------- |
| 15 | + |
| 16 | +(1 row) |
| 17 | + |
| 18 | +SELECT clickhouse_raw_query($$ |
| 19 | + CREATE TABLE json_test.things ( |
| 20 | + id Int32 NOT NULL, |
| 21 | + data JSON NOT NULL |
| 22 | + ) ENGINE = MergeTree PARTITION BY id ORDER BY (id); |
| 23 | +$$); |
| 24 | + clickhouse_raw_query |
| 25 | +---------------------- |
| 26 | + |
| 27 | +(1 row) |
| 28 | + |
| 29 | +CREATE SCHEMA bin; |
| 30 | +CREATE SCHEMA http; |
| 31 | +IMPORT FOREIGN SCHEMA "json_test" FROM SERVER binary_json_loopback INTO bin; |
| 32 | +\d bin.things |
| 33 | + Foreign table "bin.things" |
| 34 | + Column | Type | Collation | Nullable | Default | FDW options |
| 35 | +--------+---------+-----------+----------+---------+------------- |
| 36 | + id | integer | | not null | | |
| 37 | + data | json | | not null | | |
| 38 | +Server: binary_json_loopback |
| 39 | +FDW options: (database 'json_test', table_name 'things', engine 'MergeTree') |
| 40 | + |
| 41 | +IMPORT FOREIGN SCHEMA "json_test" FROM SERVER http_json_loopback INTO http; |
| 42 | +\d http.things |
| 43 | + Foreign table "http.things" |
| 44 | + Column | Type | Collation | Nullable | Default | FDW options |
| 45 | +--------+---------+-----------+----------+---------+------------- |
| 46 | + id | integer | | not null | | |
| 47 | + data | json | | not null | | |
| 48 | +Server: http_json_loopback |
| 49 | +FDW options: (database 'json_test', table_name 'things', engine 'MergeTree') |
| 50 | + |
| 51 | +-- Fails pending https://github.com/ClickHouse/clickhouse-cpp/issues/422 |
| 52 | +INSERT INTO bin.things VALUES |
| 53 | + (1, '{"id": 1, "name": "widget", "size": "large", "stocked": true}'), |
| 54 | + (2, '{"id": 2, "name": "sprocket", "size": "small", "stocked": true}') |
| 55 | +; |
| 56 | +ERROR: pg_clickhouse: could not prepare insert - unsupported column type: JSON |
| 57 | +INSERT INTO http.things VALUES |
| 58 | + (1, '{"id": 1, "name": "widget", "size": "large", "stocked": true}'), |
| 59 | + (2, '{"id": 2, "name": "sprocket", "size": "small", "stocked": true}'), |
| 60 | + (3, '{"id": 3, "name": "gizmo", "size": "medium", "stocked": true}'), |
| 61 | + (4, '{"id": 4, "name": "doodad", "size": "large", "stocked": false}') |
| 62 | +; |
| 63 | +SELECT * FROM bin.things ORDER BY id; |
| 64 | +ERROR: pg_clickhouse: unsupported column type: JSON |
| 65 | +DETAIL: Remote Query: SELECT id, data FROM json_test.things ORDER BY id ASC |
| 66 | +SELECT * FROM http.things ORDER BY id; |
| 67 | + id | data |
| 68 | +----+------------------------------------------------------------ |
| 69 | + 1 | {"id":"1","name":"widget","size":"large","stocked":true} |
| 70 | + 2 | {"id":"2","name":"sprocket","size":"small","stocked":true} |
| 71 | + 3 | {"id":"3","name":"gizmo","size":"medium","stocked":true} |
| 72 | + 4 | {"id":"4","name":"doodad","size":"large","stocked":false} |
| 73 | +(4 rows) |
| 74 | + |
| 75 | +SELECT clickhouse_raw_query('DROP DATABASE json_test'); |
| 76 | + clickhouse_raw_query |
| 77 | +---------------------- |
| 78 | + |
| 79 | +(1 row) |
| 80 | + |
| 81 | +DROP USER MAPPING FOR CURRENT_USER SERVER binary_json_loopback; |
| 82 | +DROP USER MAPPING FOR CURRENT_USER SERVER http_json_loopback; |
| 83 | +DROP SERVER binary_json_loopback CASCADE; |
| 84 | +NOTICE: drop cascades to foreign table bin.things |
| 85 | +DROP SERVER http_json_loopback CASCADE; |
| 86 | +NOTICE: drop cascades to foreign table http.things |
0 commit comments