-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathpg_lake_iceberg--3.3--3.4.sql
More file actions
103 lines (94 loc) · 3.78 KB
/
pg_lake_iceberg--3.3--3.4.sql
File metadata and controls
103 lines (94 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
-- Upgrade script for pg_lake_iceberg from 3.3 to 3.4
/*
* iceberg_catalog foreign data wrapper: allows defining named catalog
* configurations via CREATE SERVER so that users are not limited to a
* single global REST catalog configured through GUC settings.
*
* Server options (non-secret): rest_endpoint, rest_auth_type,
* oauth_endpoint, scope, enable_vended_credentials, location_prefix,
* catalog_name.
* User mapping options (credentials): client_id, client_secret, scope.
*
* scope is accepted in both server and user mapping; user mapping wins.
*
* Credential resolution order:
* 1. CREATE USER MAPPING for the current user
* 2. $PGDATA/catalogs.conf (platform-provided)
* 3. GUC variables (backward compatibility)
*
* User-defined catalog example:
* CREATE SERVER my_polaris TYPE 'rest'
* FOREIGN DATA WRAPPER iceberg_catalog
* OPTIONS (rest_endpoint 'https://polaris.example.com');
*
* CREATE USER MAPPING FOR user1 SERVER my_polaris
* OPTIONS (client_id '...', client_secret '...');
*
* CREATE TABLE t (a int) USING iceberg WITH (catalog = 'my_polaris');
*
* Platform-provided catalog example:
* CREATE SERVER horizon TYPE 'rest'
* FOREIGN DATA WRAPPER iceberg_catalog
* OPTIONS (rest_endpoint 'https://horizon.example.com');
*
* -- Credentials in $PGDATA/catalogs.conf:
* -- horizon.client_id = 'platform_id'
* -- horizon.client_secret = 'platform_secret'
*/
CREATE FUNCTION lake_iceberg.iceberg_catalog_validator(text[], oid)
RETURNS void
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT;
CREATE FOREIGN DATA WRAPPER iceberg_catalog
NO HANDLER
VALIDATOR lake_iceberg.iceberg_catalog_validator;
GRANT USAGE ON FOREIGN DATA WRAPPER iceberg_catalog TO lake_write;
/*
* Built-in catalog servers.
*
* These three servers are pre-created as structural anchors for the
* pg_depend dependency edges that iceberg tables record against their
* catalog server. They are extension-owned and immutable: ALTER, DROP,
* RENAME, and OWNER changes on them are all blocked. Configuration
* for the built-in catalogs lives in GUCs, not in server options.
*
* Users keep typing the short names ('postgres', 'object_store', 'rest')
* as the catalog= option value on CREATE TABLE; ResolveCatalogServerName
* maps short -> long at server lookup time. The long names are prefixed
* so they cannot collide with names users may already have in their
* databases (e.g. a postgres_fdw server literally named 'postgres').
*
* Pre-flight: error early with a clear hint if any of the long names is
* already in use. This prevents a confusing "server already exists"
* mid-upgrade.
*/
DO $do$
DECLARE
conflicting text;
BEGIN
SELECT srvname INTO conflicting
FROM pg_foreign_server
WHERE srvname IN ('pg_lake_postgres_catalog',
'pg_lake_object_store_catalog',
'pg_lake_rest_catalog')
LIMIT 1;
IF conflicting IS NOT NULL THEN
RAISE EXCEPTION
'pg_lake_iceberg upgrade conflicts with existing foreign server %', conflicting
USING HINT = 'Drop or rename the server and re-run ALTER EXTENSION pg_lake_iceberg UPDATE. '
'pg_lake_iceberg reserves the names pg_lake_postgres_catalog, '
'pg_lake_object_store_catalog, and pg_lake_rest_catalog for internal use.';
END IF;
END $do$;
CREATE SERVER pg_lake_postgres_catalog
TYPE 'postgres'
FOREIGN DATA WRAPPER iceberg_catalog;
CREATE SERVER pg_lake_object_store_catalog
TYPE 'object_store'
FOREIGN DATA WRAPPER iceberg_catalog;
CREATE SERVER pg_lake_rest_catalog
TYPE 'rest'
FOREIGN DATA WRAPPER iceberg_catalog;
GRANT USAGE ON FOREIGN SERVER pg_lake_postgres_catalog TO lake_write;
GRANT USAGE ON FOREIGN SERVER pg_lake_object_store_catalog TO lake_write;
GRANT USAGE ON FOREIGN SERVER pg_lake_rest_catalog TO lake_write;