Skip to content

Commit 7e27a50

Browse files
Enable create table writable rest catalog
Signed-off-by: Onder KALACI <[email protected]>
1 parent 63339b4 commit 7e27a50

File tree

3 files changed

+22
-28
lines changed

3 files changed

+22
-28
lines changed

pg_lake_table/src/ddl/create_table.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -656,18 +656,19 @@ ProcessCreateIcebergTableFromForeignTableStmt(ProcessUtilityParams * params)
656656

657657
bool hasRestCatalogOption = HasRestCatalogTableOption(createStmt->options);
658658
bool hasObjectStoreCatalogOption = HasObjectStoreCatalogTableOption(createStmt->options);
659-
bool hasExternalCatalogReadOnlyOption = HasReadOnlyOption(createStmt->options);
660659

661-
/*
662-
* Read-only external catalog tables are a special case of Iceberg tables.
663-
* They are recognized as Iceberg tables, but are not registered in any
664-
* internal catalogs (e.g., lake_iceberg.tables). Instead, the table is
665-
* created only in PostgreSQL’s system catalogs. When the table is
666-
* queried, its metadata is fetched on demand from the external catalog.
667-
*/
668-
if ((hasObjectStoreCatalogOption ||
669-
(hasRestCatalogOption && hasExternalCatalogReadOnlyOption)))
660+
if (hasObjectStoreCatalogOption || hasRestCatalogOption)
670661
{
662+
/*
663+
* Read-only external catalog tables are a special case of Iceberg
664+
* tables. They are recognized as Iceberg tables, but are not
665+
* registered in any internal catalogs (e.g., lake_iceberg.tables).
666+
* Instead, the table is created only in PostgreSQL’s system
667+
* catalogs. When the table is queried, its metadata is fetched on
668+
* demand from the external catalog.
669+
*/
670+
bool hasExternalCatalogReadOnlyOption = HasReadOnlyOption(createStmt->options);
671+
671672
char *metadataLocation = NULL;
672673
char *catalogNamespace = NULL;
673674
char *catalogTableName = NULL;
@@ -725,7 +726,7 @@ ProcessCreateIcebergTableFromForeignTableStmt(ProcessUtilityParams * params)
725726
catalogName = catalogNameProvided;
726727
}
727728

728-
if (hasRestCatalogOption)
729+
if (hasRestCatalogOption && hasExternalCatalogReadOnlyOption)
729730
{
730731
ErrorIfRestNamespaceDoesNotExist(catalogName, catalogNamespace);
731732

@@ -742,7 +743,7 @@ ProcessCreateIcebergTableFromForeignTableStmt(ProcessUtilityParams * params)
742743
catalogTableName);
743744
}
744745

745-
if (hasObjectStoreCatalogOption && !hasExternalCatalogReadOnlyOption)
746+
if (!hasExternalCatalogReadOnlyOption)
746747
{
747748
/*
748749
* For writable object store catalog tables, we need to continue
@@ -757,11 +758,11 @@ ProcessCreateIcebergTableFromForeignTableStmt(ProcessUtilityParams * params)
757758
catalogNameProvided != NULL)
758759
{
759760
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
760-
errmsg("writable object store catalog iceberg tables do not "
761-
"allow explicit catalog options")));
761+
errmsg("writable %s catalog iceberg tables do not "
762+
"allow explicit catalog options", hasObjectStoreCatalogOption ? "object store" : "REST")));
762763
}
763764
}
764-
else if (createStmt->base.tableElts == NIL)
765+
else if (createStmt->base.tableElts == NIL && hasExternalCatalogReadOnlyOption)
765766
{
766767
List *dataFileColumns =
767768
DescribeColumnsFromIcebergMetadataURI(metadataLocation, false);

pg_lake_table/src/fdw/option.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -835,12 +835,6 @@ pg_lake_iceberg_validator(PG_FUNCTION_ARGS)
835835
!readOnlyExternalCatalogTable)
836836
icebergCatalogType = OBJECT_STORE_READ_WRITE;
837837

838-
if (catalog == ForeignTableRelationId &&
839-
icebergCatalogType == REST_CATALOG_READ_WRITE)
840-
ereport(ERROR,
841-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
842-
errmsg("rest catalog iceberg tables are read only, use CREATE TABLE ... WITH (catalog = 'rest', read_only=true) to create a read-only table")));
843-
844838
if (catalog == ForeignTableRelationId && locationProvided == false &&
845839
(icebergCatalogType == POSTGRES_CATALOG || icebergCatalogType == OBJECT_STORE_READ_WRITE))
846840
ereport(ERROR,
@@ -857,8 +851,7 @@ pg_lake_iceberg_validator(PG_FUNCTION_ARGS)
857851

858852
if (catalog == ForeignTableRelationId)
859853
{
860-
if (icebergCatalogType == REST_CATALOG_READ_ONLY || icebergCatalogType == REST_CATALOG_READ_WRITE ||
861-
icebergCatalogType == OBJECT_STORE_READ_ONLY)
854+
if (icebergCatalogType == REST_CATALOG_READ_ONLY || icebergCatalogType == OBJECT_STORE_READ_ONLY)
862855
{
863856
/*
864857
* catalog_namespace, catalog_table_name and catalog_name is
@@ -887,17 +880,17 @@ pg_lake_iceberg_validator(PG_FUNCTION_ARGS)
887880
if (catalogNamespace)
888881
ereport(ERROR,
889882
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
890-
errmsg("\"catalog_namespace\" option is only valid for catalog=\"rest\"")));
883+
errmsg("\"catalog_namespace\" option is only valid for writable catalog=\"rest\"")));
891884

892885
if (catalogTableName)
893886
ereport(ERROR,
894887
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
895-
errmsg("\"catalog_table_name\" option is only valid for catalog=\"rest\"")));
888+
errmsg("\"catalog_table_name\" option is only valid for writable catalog=\"rest\"")));
896889

897890
if (catalogName)
898891
ereport(ERROR,
899892
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
900-
errmsg("\"catalog_name\" option is only valid for catalog=\"rest\"")));
893+
errmsg("\"catalog_name\" option is only valid for writable catalog=\"rest\"")));
901894

902895
}
903896
}

pg_lake_table/tests/pytests/test_polaris_catalog.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@ def test_create_namespace(
9898
pg_conn,
9999
raise_error=False,
100100
)
101-
assert "rest catalog iceberg tables are read only" in str(res)
101+
assert "writable REST catalog iceberg tables do not" in str(res)
102102
pg_conn.rollback()
103103

104104
res = run_command(
105105
f"""CREATE TABLE "{namespace}".tbl_err(a int) USING iceberg WITH (catalog='rest', catalog_name='none')""",
106106
pg_conn,
107107
raise_error=False,
108108
)
109-
assert "rest catalog iceberg tables are read only" in str(res)
109+
assert "writable REST catalog iceberg tables do not" in str(res)
110110
pg_conn.rollback()
111111

112112
run_command(f"""DROP SCHEMA "{namespace}" CASCADE""", pg_conn)

0 commit comments

Comments
 (0)