Skip to content

Commit 59c9867

Browse files
committed
Fix GetRestCatalogName dead code
Signed-off-by: sfc-gh-npuka <naisila.puka@snowflake.com>
1 parent 489323c commit 59c9867

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

pg_lake_iceberg/src/rest_catalog/rest_catalog.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,8 +1549,9 @@ GetRestCatalogNamespace(Oid relationId)
15491549
* subsequent ALTER SERVER ? ADD/SET catalog_name cannot silently
15501550
* re-route an existing table to a different REST namespace.
15511551
*
1552-
* Read-only tables resolve from table option > server option, and
1553-
* must have catalog_name set on one of them.
1552+
* Read-only tables always have catalog_name baked into their table
1553+
* options at CREATE TABLE time (inherited from the server option or
1554+
* defaulted to the database name).
15541555
*/
15551556
char *
15561557
GetRestCatalogName(Oid relationId)
@@ -1569,15 +1570,7 @@ GetRestCatalogName(Oid relationId)
15691570
if (catalogName != NULL)
15701571
return catalogName;
15711572

1572-
RestCatalogOptions *opts = GetRestCatalogOptionsForRelation(relationId);
1573-
1574-
if (opts->catalogName != NULL)
1575-
return opts->catalogName;
1576-
1577-
ereport(ERROR,
1578-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1579-
errmsg("catalog_name is required for read-only REST catalog tables"),
1580-
errhint("Set catalog_name on the table or the server.")));
1573+
elog(ERROR, "catalog_name missing on read-only REST catalog table %u", relationId);
15811574
}
15821575

15831576

pg_lake_table/src/ddl/create_table.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,19 @@ ProcessCreateIcebergTableFromForeignTableStmt(ProcessUtilityParams * params)
817817

818818
if (catalogNameProvided == NULL && hasExternalCatalogReadOnlyOption)
819819
{
820-
catalogName = get_database_name(MyDatabaseId);
820+
if (hasRestCatalogOption)
821+
{
822+
char *catalogOptionValue =
823+
GetStringOption(createStmt->options, "catalog", false);
824+
RestCatalogOptions *opts =
825+
ResolveRestCatalogOptions(catalogOptionValue);
826+
827+
catalogName = opts->catalogName ? pstrdup(opts->catalogName)
828+
: get_database_name(MyDatabaseId);
829+
}
830+
else
831+
catalogName = get_database_name(MyDatabaseId);
832+
821833
createStmt->options =
822834
lappend(createStmt->options,
823835
makeDefElem("catalog_name", (Node *) makeString(catalogName), -1));

0 commit comments

Comments
 (0)