Skip to content

Commit e991beb

Browse files
feat: Re-adapt cloudberry/pxf_fdw to Cloudberry (#31)
Co-authored-by: Nikolay Antonov <ostinru@gmail.com>
1 parent dac417b commit e991beb

15 files changed

Lines changed: 117 additions & 223 deletions

File tree

.github/workflows/pxf-ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ jobs:
103103
test_group:
104104
- cli
105105
- external-table
106+
- fdw
106107
- server
107108
- sanity
108109
- smoke
@@ -118,6 +119,7 @@ jobs:
118119
- s3
119120
- features
120121
- gpdb
122+
- gpdb_fdw
121123
- load
122124
- pxf_extension
123125
steps:

Makefile

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ export PXF_MODULES
66
PXF_VERSION ?= $(shell cat version)
77
export PXF_VERSION
88

9-
FDW_SUPPORT = $(shell $(PG_CONFIG) --version | egrep "PostgreSQL 1[2-5]")
10-
FDW_SUPPORT =
9+
export SKIP_EXTERNAL_TABLE_BUILD_REASON
10+
export SKIP_FDW_BUILD_REASON
1111

1212
SOURCE_EXTENSION_DIR = external-table
1313
TARGET_EXTENSION_DIR = gpextable
@@ -24,29 +24,31 @@ all: extensions cli server
2424

2525
extensions: external-table fdw
2626

27-
external-table cli server:
27+
external-table:
28+
ifeq ($(SKIP_EXTERNAL_TABLE_BUILD_REASON),)
2829
@echo "===> Compiling [$@] module <==="
2930
make -C $@
31+
else
32+
@echo "Skipping building external-table extension because $(SKIP_EXTERNAL_TABLE_BUILD_REASON)"
33+
endif
3034

31-
fdw:
32-
ifneq ($(FDW_SUPPORT),)
35+
ifeq ($(SKIP_FDW_BUILD_REASON),)
36+
@echo "===> Compiling [$@] module <==="
3337
make -C fdw
38+
else
39+
@echo "Skipping building FDW extension because $(SKIP_FDW_BUILD_REASON)"
3440
endif
3541

36-
cli:
37-
make -C cli
38-
39-
server:
40-
make -C server
42+
cli server:
43+
@echo "===> Compiling [$@] module <==="
44+
make -C $@
4145

4246
clean:
4347
rm -rf build
4448
make -C $(SOURCE_EXTENSION_DIR) clean-all
4549
make -C cli clean
4650
make -C server clean
47-
ifneq ($(FDW_SUPPORT),)
4851
make -C fdw clean
49-
endif
5052

5153
test:
5254
ifeq ($(SKIP_FDW_BUILD_REASON),)
@@ -61,18 +63,30 @@ it:
6163
make -C automation TEST=$(TEST)
6264

6365
install:
64-
make -C $(SOURCE_EXTENSION_DIR) install
65-
make -C cli install
66-
make -C server install
67-
ifneq ($(FDW_SUPPORT),)
68-
make -C fdw install
66+
ifneq ($(SKIP_EXTERNAL_TABLE_BUILD_REASON),)
67+
@echo "Skipping installing FDW extension because $(SKIP_EXTERNAL_TABLE_BUILD_REASON)"
68+
$(eval PXF_MODULES := $(filter-out external-table,$(PXF_MODULES)))
69+
endif
70+
ifneq ($(SKIP_FDW_BUILD_REASON),)
71+
@echo "Skipping installing FDW extension because $(SKIP_FDW_BUILD_REASON)"
72+
$(eval PXF_MODULES := $(filter-out fdw,$(PXF_MODULES)))
6973
endif
74+
set -e ;\
75+
for module in $${PXF_MODULES[@]}; do \
76+
echo "===> Installing [$${module}] module <===" ;\
77+
make -C $${module} install ;\
78+
done ;\
79+
echo "===> PXF installation is complete <==="
7080

7181
install-server:
7282
make -C server install-server
7383

7484
stage:
7585
rm -rf build/stage
86+
ifneq ($(SKIP_EXTERNAL_TABLE_PACKAGE_REASON),)
87+
@echo "Skipping staging FDW extension because $(SKIP_EXTERNAL_TABLE_PACKAGE_REASON)"
88+
$(eval PXF_MODULES := $(filter-out external-table,$(PXF_MODULES)))
89+
endif
7690
ifneq ($(SKIP_FDW_PACKAGE_REASON),)
7791
@echo "Skipping staging FDW extension because $(SKIP_FDW_PACKAGE_REASON)"
7892
$(eval PXF_MODULES := $(filter-out fdw,$(PXF_MODULES)))

automation/src/test/java/org/greenplum/pxf/automation/features/writable/HdfsWritableTextTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.greenplum.pxf.automation.features.writable;
22

3+
import annotations.FailsWithFDW;
34
import annotations.SkipForFDW;
45
import annotations.WorksWithFDW;
56
import org.apache.commons.lang.StringUtils;
@@ -75,6 +76,7 @@ protected void beforeClass() throws Exception {
7576
*
7677
* @throws Exception if test fails to run
7778
*/
79+
@FailsWithFDW
7880
@Test(groups = {"features", "gpdb", "security"})
7981
public void textFormatInsertNoProfile() throws Exception {
8082

ci/docker/pxf-cbdb-dev/ubuntu/script/build_cloudberrry.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ cd ~/workspace/cloudberry
100100
--enable-orafce \
101101
--enable-orca \
102102
--disable-pax \
103-
--enable-pxf \
103+
--disable-pxf \
104104
--enable-tap-tests \
105105
--with-gssapi \
106106
--with-ldap \

ci/docker/pxf-cbdb-dev/ubuntu/script/build_cloudberry_deb.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ cd "${CLOUDBERRY_SRC}"
2828
--enable-orafce \
2929
--enable-orca \
3030
--disable-pax \
31-
--enable-pxf \
31+
--disable-pxf \
3232
--enable-tap-tests \
3333
--with-gssapi \
3434
--with-ldap \

ci/docker/pxf-cbdb-dev/ubuntu/script/run_tests.sh

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ feature_test(){
549549
}
550550

551551
gpdb_test() {
552+
local use_fdw="$1"
552553
export PROTOCOL=HDFS
553554
export PXF_HOME=${PXF_HOME:-/usr/local/pxf}
554555
export PATH="${PXF_HOME}/bin:${PATH}"
@@ -570,10 +571,20 @@ gpdb_test() {
570571
# Ensure PXF points to local HDFS/Hive/HBase configs
571572
configure_pxf_default_hdfs_server
572573

573-
echo "[run_tests] Starting GROUP=gpdb"
574-
make GROUP="gpdb" || true
575-
save_test_reports "gpdb"
576-
echo "[run_tests] GROUP=gpdb finished"
574+
local extra_args=""
575+
if [[ "$use_fdw" == "true" ]]; then
576+
extra_args="USE_FDW=true"
577+
else
578+
extra_args="USE_FDW=false"
579+
fi
580+
echo "[run_tests] Starting GROUP=gpdb $extra_args"
581+
make GROUP="gpdb" $extra_args || true
582+
if [[ "$use_fdw" == "true" ]]; then
583+
save_test_reports "gpdb_fdw"
584+
else
585+
save_test_reports "gpdb"
586+
fi
587+
echo "[run_tests] GROUP=gpdb $extra_args finished"
577588
}
578589

579590
pxf_extension_test(){
@@ -709,7 +720,7 @@ generate_test_summary() {
709720

710721
local group=$(basename "$group_dir")
711722
# Skip if it's not a test group directory
712-
[[ "$group" =~ ^(smoke|hcatalog|hcfs|hdfs|hive|gpdb|sanity|hbase|profile|jdbc|proxy|unused|s3|features|load|performance|pxfExtensionVersion2|pxfExtensionVersion2_1|pxfFdwExtensionVersion1|pxfFdwExtensionVersion2)$ ]] || continue
723+
[[ "$group" =~ ^(smoke|hcatalog|hcfs|hdfs|hive|gpdb|sanity|hbase|profile|jdbc|proxy|unused|s3|features|load|performance|pxfExtensionVersion2|pxfExtensionVersion2_1|pxfFdwExtensionVersion1|pxfFdwExtensionVersion2|fdw|gpdb_fdw)$ ]] || continue
713724

714725
echo "Processing $group test reports from $group_dir"
715726

@@ -841,6 +852,13 @@ run_single_group() {
841852
cd "${REPO_ROOT}/external-table"
842853
make installcheck
843854
;;
855+
fdw)
856+
cd "${REPO_ROOT}/fdw"
857+
make test
858+
;;
859+
gpdb_fdw)
860+
gpdb_test "true"
861+
;;
844862
server)
845863
cd "${REPO_ROOT}/server"
846864
./gradlew test
@@ -873,7 +891,7 @@ run_single_group() {
873891
feature_test
874892
;;
875893
gpdb)
876-
gpdb_test
894+
gpdb_test "false"
877895
;;
878896
pxf_extension)
879897
pxf_extension_test
@@ -898,7 +916,7 @@ run_single_group() {
898916
;;
899917
*)
900918
echo "Unknown test group: $group"
901-
echo "Available groups: cli, external-table, server, sanity, smoke, hdfs, hcatalog, hcfs, hive, hbase, profile, jdbc, proxy, unused, s3, features, gpdb, load, performance, bench, pxf_extension"
919+
echo "Available groups: cli, external-table, fdw, server, sanity, smoke, hdfs, hcatalog, hcfs, hive, hbase, profile, jdbc, proxy, unused, s3, features, gpdb, gpdb_fdw, load, performance, bench, pxf_extension"
902920
exit 1
903921
;;
904922
esac

fdw/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# PXF Foreign Data Wrapper for Greenplum and PostgreSQL
1+
# PXF Foreign Data Wrapper for Cloudberry
22

3-
This Greenplum extension implements a Foreign Data Wrapper (FDW) for PXF.
3+
This Cloudberry extension implements a Foreign Data Wrapper (FDW) for PXF.
44

55
PXF is a query federation engine that accesses data residing in external systems
66
such as Hadoop, Hive, HBase, relational databases, S3, Google Cloud Storage,
@@ -10,9 +10,9 @@ among other external systems.
1010

1111
## Compile
1212

13-
To compile the PXF foreign data wrapper, we need a Greenplum 6+ installation and libcurl.
13+
To compile the PXF foreign data wrapper, we need a Cloudberry installation and libcurl.
1414

15-
export PATH=/usr/local/greenplum-db/bin/:$PATH
15+
export PATH=/usr/local/cloudberry-db/bin/:$PATH
1616

1717
make
1818

fdw/libchurl.c

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,15 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
#if PG_VERSION_NUM >= 90600
2019
#include "postgres.h"
21-
#endif
22-
2320
#include "libchurl.h"
24-
#if PG_VERSION_NUM >= 90600
2521
#include "lib/stringinfo.h"
26-
#endif
2722
#include "miscadmin.h"
2823
#include "utils/builtins.h"
2924
#include "utils/fmgroids.h"
3025
#include "utils/guc.h"
31-
#include "utils/jsonapi.h"
26+
#include "common/jsonapi.h"
27+
#include "mb/pg_wchar.h"
3228

3329
/* include libcurl without typecheck.
3430
* This allows wrapping curl_easy_setopt to be wrapped
@@ -98,13 +94,6 @@ typedef struct churl_settings
9894
struct curl_slist *headers;
9995
} churl_settings;
10096

101-
/* the null action object used for pure validation */
102-
static JsonSemAction nullSemAction =
103-
{
104-
NULL, NULL, NULL, NULL, NULL,
105-
NULL, NULL, NULL, NULL, NULL
106-
};
107-
10897
churl_context *churl_new_context(void);
10998
static void create_curl_handle(churl_context *context);
11099
static void set_curl_option(churl_context *context, CURLoption option, const void *data);
@@ -864,13 +853,8 @@ fill_internal_buffer(churl_context *context, int want)
864853

865854
if (errno == EINTR || errno == EAGAIN)
866855
continue;
867-
#if PG_VERSION_NUM >= 90600
868856
elog(ERROR, "internal error: select failed on curl_multi_fdset (maxfd %d) (%d - %m)",
869857
maxfd, save_errno);
870-
#else
871-
elog(ERROR, "internal error: select failed on curl_multi_fdset (maxfd %d) (%d - %s)",
872-
maxfd, save_errno, strerror(errno));
873-
#endif
874858
}
875859
multi_perform(context);
876860
}
@@ -1056,7 +1040,7 @@ IsValidJson(text *json)
10561040
PG_TRY();
10571041
{
10581042
/* validate it */
1059-
lex = makeJsonLexContext(json, false);
1043+
lex = makeJsonLexContextCstringLen(text_to_cstring(json), VARSIZE_ANY_EXHDR(json), GetDatabaseEncoding(), false);
10601044
pg_parse_json(lex, &nullSemAction);
10611045
}
10621046
PG_CATCH();

fdw/pxf_bridge.c

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@
2727
/* helper function declarations */
2828
static void BuildUriForRead(PxfFdwScanState *pxfsstate);
2929
static void BuildUriForWrite(PxfFdwModifyState *pxfmstate);
30-
#if PG_VERSION_NUM >= 90600
3130
static size_t FillBuffer(PxfFdwScanState *pxfsstate, char *start, int minlen, int maxlen);
32-
#else
33-
static size_t FillBuffer(PxfFdwScanState *pxfsstate, char *start, size_t size);
34-
#endif
3531

3632
/*
3733
* Clean up churl related data structures from the PXF FDW modify state.
@@ -102,20 +98,12 @@ PxfBridgeExportStart(PxfFdwModifyState *pxfmstate)
10298
* Reads data from the PXF server into the given buffer of a given size
10399
*/
104100
int
105-
#if PG_VERSION_NUM >= 90600
106101
PxfBridgeRead(void *outbuf, int minlen, int maxlen, void *extra)
107-
#else
108-
PxfBridgeRead(void *outbuf, int datasize, void *extra)
109-
#endif
110102
{
111103
size_t n = 0;
112104
PxfFdwScanState *pxfsstate = (PxfFdwScanState *) extra;
113105

114-
#if PG_VERSION_NUM >= 90600
115106
n = FillBuffer(pxfsstate, outbuf, minlen, maxlen);
116-
#else
117-
n = FillBuffer(pxfsstate, outbuf, datasize);
118-
#endif
119107

120108
if (n == 0)
121109
{
@@ -176,28 +164,16 @@ BuildUriForWrite(PxfFdwModifyState *pxfmstate)
176164
* Read data from churl until the buffer is full or there is no more data to be read
177165
*/
178166
static size_t
179-
#if PG_VERSION_NUM >= 90600
180167
FillBuffer(PxfFdwScanState *pxfsstate, char *start, int minlen, int maxlen)
181-
#else
182-
FillBuffer(PxfFdwScanState *pxfsstate, char *start, size_t size)
183-
#endif
184168
{
185169
size_t n = 0;
186170
char *ptr = start;
187-
#if PG_VERSION_NUM >= 90600
188171
char *minend = ptr + minlen;
189172
char *maxend = ptr + maxlen;
190173

191174
while (ptr < minend)
192175
{
193176
n = churl_read(pxfsstate->churl_handle, ptr, maxend - ptr);
194-
#else
195-
char *end = ptr + size;
196-
197-
while (ptr < end)
198-
{
199-
n = churl_read(pxfsstate->churl_handle, ptr, end - ptr);
200-
#endif
201177
if (n == 0)
202178
break;
203179

0 commit comments

Comments
 (0)