Skip to content

Commit 20add92

Browse files
zhangwenchao-123my-ship-it
authored andcommitted
Implement Directory Table.
Implement directory table feature in this commit. Directory table is a new relation which used to organize the unstructured data files in the specified tablespace. The date files are stored in the specified tablespace while the tuples recorded the metadata of the data files such as relative_path, md5 size etc. are stored in normal table. We support local directory table and remote directory table meanwhile. The local directory table uses the local tablespace while the remote directory table uses the DFS tablespace which implemented in our enterprise extension. We support copy binary from to upload file to directory table, directory_table UDF to get file content, remove_file UDF to remove file from directory table. What's more, we implement a tool called cbload used to upload file to direcotry table. Meanwhile, to support DFS directory table, we also import some catalog tables such as gp_storage_server, gp_storage_user_mapping which are shared in all databases. We will illustrage some examples for your convinence of usage as follow. -- Create an oss_server that points to endpoint: CREATE STORAGE SERVER oss_server OPTIONS (protocol 'qingstor', endpoint 'pek3b.qingstor.com', https 'true', virtual_host 'false'); -- Create a user mapping to access oss_server CREATE STORAGE USER MAPPING FOR CURRENT_USER STORAGE SERVER oss_server OPTIONS (accesskey 'KGCPPHVCHRDSYFEAWLLC', secretkey '0SJIWiIATh6jOlmAas23q6hOAGBI1BnsnvgJmTs'); -- Create a local tablespace CREATE TABLESPACE dirtable_spc location '/data/dirtable_spc'; -- Create a local directory table CREATE DIRECTORY TABLE dirtable TABLESPACE dirtable_spc; -- Copy binary from directory table COPY BINARY dirtable FROM '/data/file1.csv' 'file1'; -- Select directory table SELECT * FROM dirtable; SELECT * FROM directory_table('dirtable'); -- Remove file from directory table SELECT remove_file('dirtable', 'file1'); Co-authored-by: Mu Guoqing muguoqing@hashdata.cn Reviewd-by: Yang Yu yangyu@hashdata.cn Yang Jianghua yjhjstz@gmail.com
1 parent 09ed012 commit 20add92

142 files changed

Lines changed: 11686 additions & 146 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

contrib/amcheck/verify_heapam.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,10 +549,11 @@ sanity_check_relation(Relation rel)
549549
{
550550
if (rel->rd_rel->relkind != RELKIND_RELATION &&
551551
rel->rd_rel->relkind != RELKIND_MATVIEW &&
552-
rel->rd_rel->relkind != RELKIND_TOASTVALUE)
552+
rel->rd_rel->relkind != RELKIND_TOASTVALUE &&
553+
rel->rd_rel->relkind != RELKIND_DIRECTORY_TABLE)
553554
ereport(ERROR,
554555
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
555-
errmsg("\"%s\" is not a table, materialized view, or TOAST table",
556+
errmsg("\"%s\" is not a table, directory table, materialized view, or TOAST table",
556557
RelationGetRelationName(rel))));
557558
if (rel->rd_rel->relam != HEAP_TABLE_AM_OID)
558559
ereport(ERROR,

contrib/oid2name/oid2name.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ sql_exec_dumpalltables(PGconn *conn, struct options *opts)
479479
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace "
480480
" LEFT JOIN pg_catalog.pg_database d ON d.datname = pg_catalog.current_database(),"
481481
" pg_catalog.pg_tablespace t "
482-
"WHERE relkind IN (" CppAsString2(RELKIND_RELATION) ","
482+
"WHERE relkind IN (" CppAsString2(RELKIND_RELATION) "," CppAsString2(RELKIND_DIRECTORY_TABLE) ","
483483
CppAsString2(RELKIND_MATVIEW) "%s%s) AND "
484484
" %s"
485485
" t.oid = CASE"
@@ -553,6 +553,7 @@ sql_exec_searchtables(PGconn *conn, struct options *opts)
553553
CppAsString2(RELKIND_MATVIEW) ","
554554
CppAsString2(RELKIND_INDEX) ","
555555
CppAsString2(RELKIND_SEQUENCE) ","
556+
CppAsString2(RELKIND_DIRECTORY_TABLE) ","
556557
CppAsString2(RELKIND_TOASTVALUE) ") AND\n"
557558
" t.oid = CASE\n"
558559
" WHEN reltablespace <> 0 THEN reltablespace\n"

contrib/pg_surgery/heap_surgery.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,8 @@ sanity_check_relation(Relation rel)
374374
{
375375
if (rel->rd_rel->relkind != RELKIND_RELATION &&
376376
rel->rd_rel->relkind != RELKIND_MATVIEW &&
377-
rel->rd_rel->relkind != RELKIND_TOASTVALUE)
377+
rel->rd_rel->relkind != RELKIND_TOASTVALUE &&
378+
rel->rd_rel->relkind != RELKIND_DIRECTORY_TABLE)
378379
ereport(ERROR,
379380
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
380381
errmsg("\"%s\" is not a table, materialized view, or TOAST table",

contrib/pg_visibility/pg_visibility.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,8 @@ check_relation_relkind(Relation rel)
778778
{
779779
if (rel->rd_rel->relkind != RELKIND_RELATION &&
780780
rel->rd_rel->relkind != RELKIND_MATVIEW &&
781-
rel->rd_rel->relkind != RELKIND_TOASTVALUE)
781+
rel->rd_rel->relkind != RELKIND_TOASTVALUE &&
782+
rel->rd_rel->relkind != RELKIND_DIRECTORY_TABLE)
782783
ereport(ERROR,
783784
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
784785
errmsg("\"%s\" is not a table, materialized view, or TOAST table",

contrib/pgstattuple/pgstatapprox.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,11 @@ pgstattuple_approx_internal(Oid relid, FunctionCallInfo fcinfo)
289289
rel->rd_rel->relkind == RELKIND_AOBLOCKDIR ||
290290
rel->rd_rel->relkind == RELKIND_AOVISIMAP ||
291291
rel->rd_rel->relkind == RELKIND_MATVIEW ||
292-
rel->rd_rel->relkind == RELKIND_TOASTVALUE))
292+
rel->rd_rel->relkind == RELKIND_TOASTVALUE ||
293+
rel->rd_rel->relkind == RELKIND_DIRECTORY_TABLE))
293294
ereport(ERROR,
294295
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
295-
errmsg("\"%s\" is not a table, materialized view, or TOAST table",
296+
errmsg("\"%s\" is not a table, directory table, materialized view, or TOAST table",
296297
RelationGetRelationName(rel))));
297298

298299
if (rel->rd_rel->relam != HEAP_TABLE_AM_OID)

contrib/pgstattuple/pgstatindex.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,9 +766,10 @@ check_relation_relkind(Relation rel)
766766
rel->rd_rel->relkind != RELKIND_INDEX &&
767767
rel->rd_rel->relkind != RELKIND_MATVIEW &&
768768
rel->rd_rel->relkind != RELKIND_SEQUENCE &&
769-
rel->rd_rel->relkind != RELKIND_TOASTVALUE)
769+
rel->rd_rel->relkind != RELKIND_TOASTVALUE &&
770+
rel->rd_rel->relkind != RELKIND_DIRECTORY_TABLE)
770771
ereport(ERROR,
771772
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
772-
errmsg("\"%s\" is not a table, index, materialized view, sequence, or TOAST table",
773+
errmsg("\"%s\" is not a table, directory table, index, materialized view, sequence, or TOAST table",
773774
RelationGetRelationName(rel))));
774775
}

contrib/pgstattuple/pgstattuple.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ pgstat_relation(Relation rel, FunctionCallInfo fcinfo)
261261
case RELKIND_AOSEGMENTS:
262262
case RELKIND_AOBLOCKDIR:
263263
case RELKIND_AOVISIMAP:
264+
case RELKIND_DIRECTORY_TABLE:
264265
return pgstat_heap(rel, fcinfo);
265266
case RELKIND_INDEX:
266267
switch (rel->rd_rel->relam)

contrib/postgres_fdw/postgres_fdw.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5368,6 +5368,7 @@ postgresImportForeignSchema(ImportForeignSchemaStmt *stmt, Oid serverOid)
53685368
CppAsString2(RELKIND_VIEW) ","
53695369
CppAsString2(RELKIND_FOREIGN_TABLE) ","
53705370
CppAsString2(RELKIND_MATVIEW) ","
5371+
CppAsString2(RELKIND_DIRECTORY_TABLE) ","
53715372
CppAsString2(RELKIND_PARTITIONED_TABLE) ") "
53725373
" AND n.nspname = ");
53735374
deparseStringLiteral(&buf, stmt->remote_schema);

gpMgmt/bin/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ endif
99

1010
SUBDIRS = stream gpcheckcat_modules gpconfig_modules gpssh_modules gppylib lib
1111
SUBDIRS += ifaddrs
12+
SUBDIRS += cbload
1213

1314
$(recurse)
1415

gpMgmt/bin/cbload/Makefile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
subdir = gpMgmt/bin/cbload
2+
top_builddir = ../../..
3+
include $(top_builddir)/src/Makefile.global
4+
5+
.DEFAULT_GOAL := all
6+
7+
export GOPROXY ?= https://proxy.golang.org
8+
9+
all: build
10+
11+
build :
12+
go mod download
13+
go build -o cbload github.com/cloudberrydb/cbload
14+
15+
clean :
16+
rm -f cbload
17+
18+
install: all
19+
$(INSTALL_PROGRAM) 'cbload' $(bindir)
20+
21+
uninstall:
22+
rm -f $(bindir)/cbload
23+
24+
distclean:
25+
rm -f cbload

0 commit comments

Comments
 (0)