Configure a server for your network file system, then read and write its data through external tables.
Configuring the server
Create a server that points PXF at a directory mounted at the same path on every WarehousePG (WHPG) host.
Create a server directory under
$PXF_BASE/servers, and copy thepxf-site.xmltemplate from$PXF_HOME/templatesinto it. For example, to configure a server namednfssrvcfg:bashmkdir -p $PXF_BASE/servers/nfssrvcfg cp $PXF_HOME/templates/pxf-site.xml $PXF_BASE/servers/nfssrvcfgUncomment
pxf.fs.basePathand set it to the mount point, and setpxf.service.user.impersonationtofalse, since this connector always accesses files as the OS user running PXF rather than the connecting WHPG user:xml<property> <name>pxf.fs.basePath</name> <value>/mnt/extdata/pxffs</value> </property> <property> <name>pxf.service.user.impersonation</name> <value>false</value> </property>The path in
LOCATIONis relative topxf.fs.basePath. See Configuration templates for the full list ofpxf-site.xmlproperties.Sync the change to every segment host, then restart PXF to apply it:
bashpxf cluster sync pxf cluster restart
Reading data
Read a file from the mounted directory by creating a readable external table with the profile for its format and the server you configured. For example, to read a CSV file using the nfssrvcfg server:
CREATE EXTERNAL TABLE pxf_read_example (id int, name text, age int)
LOCATION ('pxf://data.csv?PROFILE=file:text&SERVER=nfssrvcfg')
FORMAT 'CSV' (delimiter=',');
SELECT * FROM pxf_read_example;PXF also supports structured formats like Parquet, through the same profile-based syntax:
CREATE EXTERNAL TABLE pxf_parquet_example (
id bigint,
created timestamp without time zone,
status integer
)
LOCATION ('pxf://parquet_data/?PROFILE=file:parquet&SERVER=nfssrvcfg')
FORMAT 'CUSTOM' (FORMATTER = 'pxfwritable_import')
ENCODING 'UTF8';The path in LOCATION can't be relative, and can't include the $ character. See PXF profiles for the full list of supported formats, including worked examples of Avro, JSON, and multi-byte delimiters.
Writing data
Create a writable external table with the pxfwritable_export formatter to write WHPG data out to the mounted directory:
CREATE WRITABLE EXTERNAL TABLE pxf_write_example (
id bigint,
created timestamp without time zone,
status integer
)
LOCATION ('pxf://parquet_data/?PROFILE=file:parquet&SERVER=nfssrvcfg')
FORMAT 'CUSTOM' (FORMATTER = 'pxfwritable_export')
ENCODING 'UTF8';
INSERT INTO pxf_write_example SELECT id, created, status FROM some_local_table;To query the data, create a separate readable external table at the same location:
CREATE EXTERNAL TABLE pxf_read_back (
id bigint,
created timestamp without time zone,
status integer
)
LOCATION ('pxf://parquet_data/?PROFILE=file:parquet&SERVER=nfssrvcfg')
FORMAT 'CUSTOM' (FORMATTER = 'pxfwritable_import')
ENCODING 'UTF8';
SELECT * FROM pxf_read_back;