@@ -488,55 +488,75 @@ GetIcebergCatalogType(Oid relationId)
488488
489489
490490/*
491- * Users can provide different names for the table and the catalog names.
492- * This function first checks if users provided a custom catalog table name.
493- * If so, returns that, otherwise returns Postgres table name.
491+ * Readable rest catalog tables always use the catalog_table_name option
492+ * as the table name in the external catalog. Writable rest catalog tables
493+ * use the Postgres table name as the catalog table name.
494494*/
495495char *
496496GetRestCatalogTableName (Oid relationId )
497497{
498- Assert (GetIcebergCatalogType (relationId ) == REST_CATALOG_READ_ONLY ||
499- GetIcebergCatalogType (relationId ) == REST_CATALOG_READ_WRITE );
498+ IcebergCatalogType catalogType = GetIcebergCatalogType (relationId );
500499
501- ForeignTable * foreignTable = GetForeignTable ( relationId );
502- List * options = foreignTable -> options ;
500+ Assert ( catalogType == REST_CATALOG_READ_ONLY ||
501+ catalogType == REST_CATALOG_READ_WRITE ) ;
503502
504- char * catalogTableName = GetStringOption (options , "catalog_table_name" , false);
503+ if (catalogType == REST_CATALOG_READ_ONLY )
504+ {
505+ ForeignTable * foreignTable = GetForeignTable (relationId );
506+ List * options = foreignTable -> options ;
505507
506- /* user provided the custom catalog table name */
507- if (!catalogTableName )
508- ereport (ERROR ,
509- (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
510- errmsg ("catalog_table_name option is required for rest catalog iceberg tables" )));
508+ char * catalogTableName = GetStringOption (options , "catalog_table_name" , false);
511509
512- return catalogTableName ;
510+ /* user provided the custom catalog table name */
511+ if (!catalogTableName )
512+ ereport (ERROR ,
513+ (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
514+ errmsg ("catalog_table_name option is required for rest catalog iceberg tables" )));
513515
516+ return catalogTableName ;
517+ }
518+ else
519+ {
520+ /* for writable rest catalog tables, we use the Postgres table name */
521+ return get_rel_name (relationId );
522+ }
514523}
515524
516525
517526/*
518- * Users can provide different names for the table and the catalog names.
519- * This function first checks if users provided a custom catalog namespace.
520- * If so, returns that, otherwise returns Postgres schema name.
527+ * Readable rest catalog tables always use the catalog_namespace option
528+ * as the namespace in the external catalog. Writable rest catalog tables
529+ * use the Postgres schema name as the namespace .
521530*/
522531char *
523532GetRestCatalogNamespace (Oid relationId )
524533{
525- Assert (GetIcebergCatalogType (relationId ) == REST_CATALOG_READ_ONLY ||
526- GetIcebergCatalogType (relationId ) == REST_CATALOG_READ_WRITE );
534+ IcebergCatalogType catalogType = GetIcebergCatalogType (relationId );
527535
528- ForeignTable * foreignTable = GetForeignTable (relationId );
529- List * options = foreignTable -> options ;
536+ Assert (catalogType == REST_CATALOG_READ_ONLY ||
537+ catalogType == REST_CATALOG_READ_WRITE );
538+
539+ if (catalogType == REST_CATALOG_READ_ONLY )
540+ {
530541
531- char * catalogNamespace = GetStringOption (options , "catalog_namespace" , false);
542+ ForeignTable * foreignTable = GetForeignTable (relationId );
543+ List * options = foreignTable -> options ;
532544
533- /* user provided the custom catalog namespace */
534- if (!catalogNamespace )
535- ereport (ERROR ,
536- (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
537- errmsg ("catalog_namespace option is required for rest catalog iceberg tables" )));
545+ char * catalogNamespace = GetStringOption (options , "catalog_namespace" , false);
538546
539- return catalogNamespace ;
547+ /* user provided the custom catalog namespace */
548+ if (!catalogNamespace )
549+ ereport (ERROR ,
550+ (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
551+ errmsg ("catalog_namespace option is required for rest catalog iceberg tables" )));
552+
553+ return catalogNamespace ;
554+ }
555+ else
556+ {
557+ /* for writable rest catalog tables, we use the Postgres schema name */
558+ return get_namespace_name (get_rel_namespace (relationId ));
559+ }
540560}
541561
542562bool
@@ -558,14 +578,21 @@ HasReadOnlyOption(List *options)
558578
559579
560580/*
561- * Users can provide different names for the catalog. If not provided,
562- * we use the database name as the catalog name.
581+ * Readable rest catalog tables always use the catalog_name option
582+ * as the catalog name in the external catalog. Writable rest catalog tables
583+ * use the current database name as the catalog name.
563584*/
564585static char *
565586GetRestCatalogName (Oid relationId )
566587{
567- if (relationId != InvalidOid )
588+ IcebergCatalogType catalogType = GetIcebergCatalogType (relationId );
589+
590+ Assert (catalogType == REST_CATALOG_READ_ONLY ||
591+ catalogType == REST_CATALOG_READ_WRITE );
592+
593+ if (catalogType == REST_CATALOG_READ_ONLY )
568594 {
595+
569596 Assert (GetIcebergCatalogType (relationId ) == REST_CATALOG_READ_ONLY ||
570597 GetIcebergCatalogType (relationId ) == REST_CATALOG_READ_WRITE );
571598
@@ -575,8 +602,12 @@ GetRestCatalogName(Oid relationId)
575602 char * catalogName = GetStringOption (options , "catalog_name" , false);
576603
577604 /* user provided the custom catalog name */
578- if (catalogName )
579- return catalogName ;
605+ if (!catalogName )
606+ ereport (ERROR ,
607+ (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
608+ errmsg ("catalog_name option is required for rest catalog iceberg tables" )));
609+
610+ return catalogName ;
580611 }
581612
582613 return get_database_name (MyDatabaseId );
0 commit comments