Skip to content

Commit 02fcb9a

Browse files
Adjust the error, move to later stage
Signed-off-by: Onder KALACI <[email protected]>
1 parent 84b5719 commit 02fcb9a

File tree

4 files changed

+29
-30
lines changed

4 files changed

+29
-30
lines changed

pg_lake_iceberg/include/pg_lake/rest_catalog/rest_catalog.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ extern char *RestCatalogClientSecret;
3434
#define GET_REST_CATALOG_METADATA_LOCATION "%s/api/catalog/v1/%s/namespaces/%s/tables/%s"
3535

3636
extern PGDLLEXPORT char *RestCatalogFetchAccessToken(void);
37-
extern PGDLLEXPORT void RegisterNamespaceToRestCatalog(const char *catalogName, const char *namespaceName,
38-
bool hasRestCatalogReadOnlyOption);
37+
extern PGDLLEXPORT void RegisterNamespaceToRestCatalog(const char *catalogName, const char *namespaceName);
3938
extern PGDLLEXPORT void ErrorIfRestNamespaceDoesNotExist(const char *catalogName, const char *namespaceName);
4039
extern PGDLLEXPORT IcebergCatalogType GetIcebergCatalogType(Oid relationId);
4140
extern PGDLLEXPORT char *GetRestCatalogName(Oid relationId);

pg_lake_iceberg/src/rest_catalog/rest_catalog.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static void ReportHTTPError(HttpResult httpResult, int level);
5757
* allowed locations as part of the namespace.
5858
*/
5959
void
60-
RegisterNamespaceToRestCatalog(const char *catalogName, const char *namespaceName, bool hasRestCatalogReadOnlyOption)
60+
RegisterNamespaceToRestCatalog(const char *catalogName, const char *namespaceName)
6161
{
6262
/*
6363
* First, we need to check if the namespace already exists in Rest Catalog
@@ -107,8 +107,7 @@ RegisterNamespaceToRestCatalog(const char *catalogName, const char *namespaceNam
107107
* might have for internal iceberg tables. For external ones,
108108
* we don't have any control over.
109109
*/
110-
if (!hasRestCatalogReadOnlyOption &&
111-
(strlen(serverAllowedLocation) - strlen(defaultAllowedLocation) > 1 ||
110+
if ((strlen(serverAllowedLocation) - strlen(defaultAllowedLocation) > 1 ||
112111
strncmp(serverAllowedLocation, defaultAllowedLocation, strlen(defaultAllowedLocation)) != 0))
113112
{
114113
ereport(DEBUG1,

pg_lake_iceberg/src/test/rest_catalog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ register_namespace_to_rest_catalog(PG_FUNCTION_ARGS)
3737
char *catalogName = text_to_cstring(PG_GETARG_TEXT_P(0));
3838
char *namespaceName = text_to_cstring(PG_GETARG_TEXT_P(1));
3939

40-
RegisterNamespaceToRestCatalog(catalogName, namespaceName, false);
40+
RegisterNamespaceToRestCatalog(catalogName, namespaceName);
4141
PG_RETURN_VOID();
4242
}

pg_lake_table/src/ddl/create_table.c

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -761,30 +761,6 @@ ProcessCreateIcebergTableFromForeignTableStmt(ProcessUtilityParams * params)
761761
errmsg("writable %s catalog iceberg tables do not "
762762
"allow explicit catalog options", hasObjectStoreCatalogOption ? "object store" : "REST")));
763763
}
764-
765-
if (hasRestCatalogOption)
766-
{
767-
/*
768-
* For writable rest catalog iceberg tables, we register the
769-
* namespace in the rest catalog. We do that early in the
770-
* command processing so that any errors in the registration
771-
* are caught before we create the actual table.
772-
*
773-
* Note that registering a namespace is not a transactional
774-
* operation from pg_lake's perspective. If the subsequent
775-
* table creation fails, the namespace registration will
776-
* remain. We accept that tradeoff for simplicity as
777-
* re-registering an existing namespace is a no-op. For a
778-
* writable rest catalog iceberg table, the namespace is
779-
* always the table's schema name. Similarly, the catalog name
780-
* is always the database name. We normally encode that in
781-
* GetRestCatalogName() etc., but here we need to do it early
782-
* before the table is created.
783-
*/
784-
RegisterNamespaceToRestCatalog(get_database_name(MyDatabaseId),
785-
get_namespace_name(namespaceId),
786-
hasExternalCatalogReadOnlyOption);
787-
}
788764
}
789765
else if (createStmt->base.tableElts == NIL && hasExternalCatalogReadOnlyOption)
790766
{
@@ -930,6 +906,31 @@ ProcessCreateIcebergTableFromForeignTableStmt(ProcessUtilityParams * params)
930906
/* we currently only allow Iceberg tables in the managed storage region */
931907
ErrorIfNotInManagedStorageRegion(location);
932908

909+
910+
if (hasRestCatalogOption)
911+
{
912+
/* here we only deal with writable rest catalog iceberg tables */
913+
Assert(!HasReadOnlyOption(createStmt->options));
914+
915+
/*
916+
* For writable rest catalog iceberg tables, we register the namespace
917+
* in the rest catalog. We do that later in the command processing so
918+
* that any previous errors (e.g., table creation failures) prevents
919+
* us from registering the namespace.
920+
*
921+
* Note that registering a namespace is not a transactional operation
922+
* from pg_lake's perspective. If the subsequent table creation fails,
923+
* the namespace registration will remain. We accept that tradeoff for
924+
* simplicity as re-registering an existing namespace is a no-op. For
925+
* a writable rest catalog iceberg table, the namespace is always the
926+
* table's schema name. Similarly, the catalog name is always the
927+
* database name. We normally encode that in GetRestCatalogName()
928+
* etc., but here we need to do it early before the table is created.
929+
*/
930+
RegisterNamespaceToRestCatalog(get_database_name(MyDatabaseId),
931+
get_namespace_name(namespaceId));
932+
}
933+
933934
bool hasRowIds = GetBoolOption(createStmt->options, "row_ids", false);
934935

935936
/* when a table has row_ids, we need to create a sequence */

0 commit comments

Comments
 (0)