Skip to content

Commit 7f200e8

Browse files
drop table in rest catalog
1 parent 7cc8b6b commit 7f200e8

File tree

4 files changed

+39
-28
lines changed

4 files changed

+39
-28
lines changed

pg_lake_table/src/ddl/create_table.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
#include "pg_lake/planner/dbt.h"
7777
#include "pg_lake/query/execute.h"
7878
#include "pg_lake/object_store_catalog/object_store_catalog.h"
79+
#include "pg_lake/transaction/track_iceberg_metadata_changes.h"
7980
#include "pg_lake/rest_catalog/rest_catalog.h"
8081

8182

@@ -965,6 +966,16 @@ ProcessCreateIcebergTableFromForeignTableStmt(ProcessUtilityParams * params)
965966
* is successful in post-commit.
966967
*/
967968
StartStageRestCatalogIcebergTableCreate(relationId);
969+
970+
/*
971+
* Record the create table operation in the rest catalog. Note that
972+
* this is not the final registration of the table in the tx, we'll
973+
* update this record in
974+
* FinalizeStagingCreateRestCatalogIcebergTableCreate. We prefer to
975+
* record it here such if table is dropped before commit, we can track
976+
* the creation of the table properly.
977+
*/
978+
RecordRestCatalogRequestInTx(relationId, REST_CATALOG_CREATE_TABLE, "");
968979
}
969980

970981

pg_lake_table/src/ddl/ddl_changes.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,6 @@ ApplyDDLCatalogChanges(Oid relationId, List *ddlOperations,
128128
}
129129
else if (ddlOperation->type == DDL_TABLE_DROP)
130130
{
131-
IcebergCatalogType catalogType = GetIcebergCatalogType(relationId);
132-
133-
if (catalogType == REST_CATALOG_READ_WRITE)
134-
{
135-
/*
136-
* TODO: Handle dropping of writable rest catalog iceberg
137-
* tables here.
138-
*/
139-
return;
140-
}
141-
142131
/*
143132
* This is not an expected case, either user manually messed with
144133
* the catalog or we have a bug. Still, we should not fail the

pg_lake_table/src/ddl/drop_table.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include "pg_lake/iceberg/operations/find_referenced_files.h"
5353
#include "pg_lake/util/spi_helpers.h"
5454
#include "pg_lake/object_store_catalog/object_store_catalog.h"
55+
#include "pg_lake/transaction/track_iceberg_metadata_changes.h"
5556
#include "pg_lake/rest_catalog/rest_catalog.h"
5657
#include "pg_lake/parsetree/options.h"
5758
#include "utils/lsyscache.h"
@@ -293,6 +294,11 @@ DropTableAccessHook(ObjectAccessType access, Oid classId, Oid objectId,
293294
ApplyDDLChanges(objectId, list_make1(ddlOperation));
294295

295296
TriggerCatalogExportIfObjectStoreTable(objectId);
297+
298+
IcebergCatalogType catalogType = GetIcebergCatalogType(objectId);
299+
300+
if (catalogType == REST_CATALOG_READ_WRITE)
301+
RecordRestCatalogRequestInTx(objectId, REST_CATALOG_DROP_TABLE, NULL);
296302
}
297303
}
298304
else if (get_rel_type_id(objectId) != InvalidOid && subId != 0)
@@ -455,7 +461,10 @@ static bool
455461
MarkAllReferencedFilesForDeletion(Oid relationId)
456462
{
457463
TimestampTz orphanedAt = GetCurrentTransactionStartTimestamp();
458-
char *metadataLocation = GetIcebergCatalogMetadataLocation(relationId, true);
464+
IcebergCatalogType catalogType = GetIcebergCatalogType(relationId);
465+
char *metadataLocation =
466+
(catalogType == REST_CATALOG_READ_WRITE) ? GetMetadataLocationForRestCatalogForIcebergTable(relationId) :
467+
GetIcebergCatalogMetadataLocation(relationId, true);
459468
MemoryContext savedContext = CurrentMemoryContext;
460469
List *allFiles = NIL;
461470
volatile bool success = true;

pg_lake_table/src/transaction/track_iceberg_metadata_changes.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,16 @@ PostAllRestCatalogRequests(void)
210210
RestCatalogRequest *createTableRequest = requestPerTable->createTableRequest;
211211
RestCatalogRequest *dropTableRequest = requestPerTable->dropTableRequest;
212212

213-
if (createTableRequest != NULL || dropTableRequest != NULL)
213+
if (createTableRequest != NULL && dropTableRequest != NULL)
214214
{
215215
/*
216-
* We can only have one create or one drop table request per
217-
* table. If a table is created and dropped in the same
218-
* transaction, we skip both requests.
216+
* table is created and dropped in the same transaction, skip both
217+
* requests, essentially a no-op.
219218
*/
220-
Assert(createTableRequest == NULL || dropTableRequest == NULL);
221-
219+
continue;
220+
}
221+
else if (createTableRequest != NULL || dropTableRequest != NULL)
222+
{
222223
const char *url =
223224
psprintf(REST_CATALOG_TABLE,
224225
RestCatalogHost,
@@ -280,7 +281,17 @@ PostAllRestCatalogRequests(void)
280281
{
281282
/* TODO: can we ever have multiple catalogs? */
282283
catalogName = requestPerTable->catalogName;
283-
if (requestPerTable->tableModifyRequests == NIL)
284+
285+
if (requestPerTable->createTableRequest != NULL &&
286+
requestPerTable->dropTableRequest != NULL)
287+
{
288+
/*
289+
* table is created and dropped in the same transaction, nothing
290+
* post to do for this table to the REST catalog.
291+
*/
292+
continue;
293+
}
294+
else if (requestPerTable->tableModifyRequests == NIL)
284295
{
285296
/*
286297
* no modifications to send for this table
@@ -567,16 +578,7 @@ ApplyTrackedIcebergMetadataChanges(void)
567578

568579
/* relation is dropped */
569580
if (!RelationExistsInTheIcebergCatalog(relationId))
570-
{
571-
/*
572-
* if created and dropped in the same tx, treat as no-op and skip
573-
* all
574-
*/
575-
if (!opTracker->relationCreated)
576-
RecordRestCatalogRequestInTx(relationId, REST_CATALOG_DROP_TABLE, NULL);
577-
578581
continue;
579-
}
580582

581583
List *allTransforms = AllPartitionTransformList(relationId);
582584

0 commit comments

Comments
 (0)