Skip to content

Commit a33ede2

Browse files
Utils to differentiate internal and external tables
Signed-off-by: Aykut Bozkurt <[email protected]>
1 parent cb222d4 commit a33ede2

File tree

30 files changed

+388
-365
lines changed

30 files changed

+388
-365
lines changed

pg_lake_engine/include/pg_lake/copy/copy_format.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define PG_LAKE_COPY_FORMAT_H
2020

2121
#include "commands/copy.h"
22-
#include "pg_lake/util/rel_utils.h"
22+
#include "pg_lake/util/table_type.h"
2323

2424
#define S3_URL_PREFIX "s3://"
2525
#define GCS_URL_PREFIX "gs://"

pg_lake_engine/include/pg_lake/pgduck/remote_storage.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ typedef struct RemoteFileDesc
3838

3939
extern PGDLLEXPORT int64 GetRemoteFileSize(char *path);
4040
extern PGDLLEXPORT int64 GetRemoteParquetFileRowCount(char *path);
41-
extern PGDLLEXPORT List *GetRemoteParquetColumnStats(char *path, List *leafFields);
4241
extern PGDLLEXPORT List *ListRemoteFileDescriptions(char *pattern);
4342
extern PGDLLEXPORT List *ListRemoteFileNames(char *pattern);
4443
extern PGDLLEXPORT bool RemoteFileExists(char *path);

pg_lake_engine/include/pg_lake/util/rel_utils.h

Lines changed: 16 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,57 +19,18 @@
1919

2020
#include "nodes/primnodes.h"
2121

22-
/* distinguish tables with "server pg_lake" vs "server pg_lake_iceberg" */
23-
typedef enum PgLakeTableType
24-
{
25-
PG_LAKE_INVALID_TABLE_TYPE,
26-
PG_LAKE_TABLE_TYPE,
27-
PG_LAKE_ICEBERG_TABLE_TYPE
28-
} PgLakeTableType;
22+
#include "pg_lake/copy/copy_format.h"
23+
#include "pg_lake/util/table_type.h"
2924

3025

31-
typedef enum IcebergCatalogType
32-
{
33-
NOT_ICEBERG_TABLE = 0,
34-
35-
/* catalog='postgres' */
36-
POSTGRES_CATALOG = 1,
37-
38-
/*
39-
* catalog='rest', read_only=True Always treat like external iceberg
40-
* table, read the metadata location from the external catalog and never
41-
* modify.
42-
*/
43-
REST_CATALOG_READ_ONLY = 2,
44-
45-
/*
46-
* catalog='rest', read_only=False Treat like internal iceberg table, use
47-
* all the catalog tables like lake_table.files.
48-
*/
49-
REST_CATALOG_READ_WRITE = 3,
50-
51-
/*
52-
* Similar to REST_CATALOG_READ_ONLY, but using an object store compatible
53-
* API instead of a REST catalog server.
54-
*/
55-
OBJECT_STORE_READ_ONLY = 4,
56-
57-
/*
58-
* Similar to REST_CATALOG_READ_WRITE, but using an object store
59-
* compatible API instead of a REST catalog server.
60-
*/
61-
OBJECT_STORE_READ_WRITE = 5
62-
} IcebergCatalogType;
63-
64-
struct PgLakeTableProperties;
65-
6626
#define PG_LAKE_SERVER_NAME "pg_lake"
6727
#define PG_LAKE_ICEBERG_SERVER_NAME "pg_lake_iceberg"
6828

6929
extern PGDLLEXPORT bool IsAnyLakeForeignTableById(Oid foreignTableId);
7030
extern PGDLLEXPORT char *GetQualifiedRelationName(Oid relationId);
7131
extern PGDLLEXPORT const char *PgLakeTableTypeToName(PgLakeTableType tableType);
7232
extern PGDLLEXPORT PgLakeTableType GetPgLakeTableType(Oid foreignTableId);
33+
extern PGDLLEXPORT IcebergCatalogType GetIcebergCatalogType(Oid relationId);
7334
extern PGDLLEXPORT char *GetPgLakeForeignServerName(Oid foreignTableId);
7435
extern PGDLLEXPORT PgLakeTableType GetPgLakeTableTypeViaServerName(char *serverName);
7536
extern PGDLLEXPORT bool IsPgLakeForeignTableById(Oid foreignTableId);
@@ -79,8 +40,19 @@ extern PGDLLEXPORT bool IsAnyWritableLakeTable(Oid foreignTableId);
7940
extern PGDLLEXPORT bool IsPgLakeIcebergServerName(const char *serverName);
8041
extern PGDLLEXPORT char *GetWritableTableLocation(Oid relationId, char **queryArguments);
8142
extern PGDLLEXPORT void EnsureTableOwner(Oid relationId);
82-
extern PGDLLEXPORT struct PgLakeTableProperties GetPgLakeTableProperties(Oid relationId);
83-
extern PGDLLEXPORT bool IsInternalOrExternalIcebergTable(struct PgLakeTableProperties properties);
43+
extern PGDLLEXPORT PgLakeTableProperties GetPgLakeTableProperties(Oid relationId);
44+
extern PGDLLEXPORT bool IsAnyLakeForeignTable(RangeTblEntry *rte);
45+
extern PGDLLEXPORT CopyDataFormat GetForeignTableFormat(Oid foreignTableId);
46+
extern PGDLLEXPORT char *GetForeignTablePath(Oid foreignTableId);
47+
extern PGDLLEXPORT bool IsAnyIcebergTable(Oid relationId);
48+
extern PGDLLEXPORT bool IsAnyInternalIcebergTable(Oid relationId);
49+
extern PGDLLEXPORT bool IsAnyExternalIcebergTable(Oid relationId);
50+
extern PGDLLEXPORT bool IsWritablePgLakeTable(Oid relationId);
51+
extern PGDLLEXPORT void ErrorIfTypeUnsupportedForIcebergTables(Oid typeOid, int32 typmod, char *columnName);
52+
extern PGDLLEXPORT void ErrorIfTypeUnsupportedNumericForIcebergTables(int32 typmod, char *columnName);
53+
extern PGDLLEXPORT bool HasRestCatalogTableOption(List *options);
54+
extern PGDLLEXPORT bool HasObjectStoreCatalogTableOption(List *options);
55+
extern PGDLLEXPORT bool HasReadOnlyOption(List *options);
8456

8557
/* range var help */
8658
extern PGDLLEXPORT List *MakeNameListFromRangeVar(const RangeVar *rel);
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2025 Snowflake Inc.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#pragma once
19+
20+
21+
/* distinguish tables with "server pg_lake" vs "server pg_lake_iceberg" */
22+
typedef enum PgLakeTableType
23+
{
24+
PG_LAKE_INVALID_TABLE_TYPE,
25+
PG_LAKE_TABLE_TYPE,
26+
PG_LAKE_ICEBERG_TABLE_TYPE
27+
} PgLakeTableType;
28+
29+
30+
typedef enum IcebergCatalogType
31+
{
32+
NONE_CATALOG = 0,
33+
34+
/* catalog='postgres' */
35+
POSTGRES_CATALOG = 1,
36+
37+
/*
38+
* catalog='rest', read_only=True Always treat like external iceberg
39+
* table, read the metadata location from the external catalog and never
40+
* modify.
41+
*/
42+
REST_CATALOG_READ_ONLY = 2,
43+
44+
/*
45+
* catalog='rest', read_only=False Treat like internal iceberg table, use
46+
* all the catalog tables like lake_table.files.
47+
*/
48+
REST_CATALOG_READ_WRITE = 3,
49+
50+
/*
51+
* Similar to REST_CATALOG_READ_ONLY, but using an object store compatible
52+
* API instead of a REST catalog server.
53+
*/
54+
OBJECT_STORE_READ_ONLY = 4,
55+
56+
/*
57+
* Similar to REST_CATALOG_READ_WRITE, but using an object store
58+
* compatible API instead of a REST catalog server.
59+
*/
60+
OBJECT_STORE_READ_WRITE = 5
61+
} IcebergCatalogType;

0 commit comments

Comments
 (0)