5050#include "pg_lake/extensions/postgis.h"
5151#include "pg_lake/fdw/schema_operations/field_id_mapping_catalog.h"
5252#include "pg_lake/fdw/schema_operations/register_field_ids.h"
53+ #include "pg_lake/fdw/utils.h"
5354#include "pg_lake/fdw/data_file_pruning.h"
5455#include "pg_lake/fdw/partition_transform.h"
5556#include "pg_lake/fdw/writable_table.h"
5657#include "pg_lake/iceberg/api/table_schema.h"
58+ #include "pg_lake/iceberg/catalog.h"
5759#include "pg_lake/iceberg/data_file_stats.h"
5860#include "pg_lake/iceberg/partitioning/partition.h"
5961#include "pg_lake/iceberg/temporal_utils.h"
@@ -183,11 +185,9 @@ PruneDataFiles(Oid relationId, List *dataFiles, List *baseRestrictInfoList, Prun
183185 List * columnsUsedInFilters = ColumnsUsedInRestrictions (relationId , baseRestrictInfoList );
184186 List * partitionTransforms = AllPartitionTransformList (relationId );
185187 PgLakeTableProperties tableProperties = GetPgLakeTableProperties (relationId );
186- PgLakeTableType tableType = tableProperties .tableType ;
187- IcebergCatalogType icebergCatalogType = GetIcebergCatalogType (relationId );
188188
189189 if ((!EnableDataFilePruning && !EnablePartitionPruning ) ||
190- !IsInternalOrExternalIcebergTable ( tableProperties ))
190+ !IsAnyIcebergTable ( relationId ))
191191 {
192192 /*
193193 * User disabled or no columns used in filters, so we cannot prune any
@@ -239,20 +239,15 @@ PruneDataFiles(Oid relationId, List *dataFiles, List *baseRestrictInfoList, Prun
239239 List * columnStats = NIL ;
240240 Partition * partition = NULL ;
241241
242- if (tableType == PG_LAKE_ICEBERG_TABLE_TYPE &&
243- (icebergCatalogType == POSTGRES_CATALOG || icebergCatalogType == REST_CATALOG_READ_WRITE ||
244- icebergCatalogType == OBJECT_STORE_READ_WRITE ))
242+ if (IsAnyInternalIcebergTable (relationId ))
245243 {
246244 TableDataFile * tableDataFile = (TableDataFile * ) list_nth (dataFiles , dataFileIndex );
247245
248246 Assert (tableDataFile -> content == CONTENT_DATA );
249247 columnStats = tableDataFile -> stats .columnStats ;
250248 partition = tableDataFile -> partition ;
251249 }
252- else if ((tableType == PG_LAKE_TABLE_TYPE && tableProperties .format == DATA_FORMAT_ICEBERG ) ||
253- (tableType == PG_LAKE_ICEBERG_TABLE_TYPE &&
254- (icebergCatalogType == REST_CATALOG_READ_ONLY ||
255- icebergCatalogType == OBJECT_STORE_READ_ONLY )))
250+ else if (IsAnyExternalIcebergTable (relationId ))
256251 {
257252 DataFile * dataFile = (DataFile * ) list_nth (dataFiles , dataFileIndex );
258253
@@ -334,7 +329,6 @@ AddFieldIdsUsedInQuery(HTAB *fieldIdsUsedInQuery, Oid relationId, PgLakeTablePro
334329 List * columnsUsedInFilters )
335330{
336331 PgLakeTableType tableType = tableProperties .tableType ;
337- IcebergCatalogType icebergCatalogType = GetIcebergCatalogType (relationId );
338332
339333 List * attrNos = NIL ;
340334 ListCell * columnCell = NULL ;
@@ -350,9 +344,7 @@ AddFieldIdsUsedInQuery(HTAB *fieldIdsUsedInQuery, Oid relationId, PgLakeTablePro
350344 /* fetch the field mappings for all columns in a single catalog lookup */
351345 List * fields = NIL ;
352346
353- if (tableType == PG_LAKE_ICEBERG_TABLE_TYPE &&
354- (icebergCatalogType == POSTGRES_CATALOG || icebergCatalogType == REST_CATALOG_READ_WRITE ||
355- icebergCatalogType == OBJECT_STORE_READ_WRITE ))
347+ if (IsAnyInternalIcebergTable (relationId ))
356348 {
357349 fields = GetRegisteredFieldForAttributes (relationId , attrNos );
358350
@@ -362,9 +354,7 @@ AddFieldIdsUsedInQuery(HTAB *fieldIdsUsedInQuery, Oid relationId, PgLakeTablePro
362354 */
363355 Assert (list_length (fields ) == list_length (columnsUsedInFilters ));
364356 }
365- else if ((tableType == PG_LAKE_TABLE_TYPE && tableProperties .format == DATA_FORMAT_ICEBERG ) ||
366- (tableType == PG_LAKE_ICEBERG_TABLE_TYPE && (icebergCatalogType == REST_CATALOG_READ_ONLY ||
367- icebergCatalogType == OBJECT_STORE_READ_ONLY )))
357+ else if (IsAnyExternalIcebergTable (relationId ))
368358 {
369359 fields = GetExternalIcebergFieldsForAttributes (relationId , columnsUsedInFilters );
370360
0 commit comments