Greenplum Database provides protocols such as gpfdist, http, and file for accessing data over a network, or you can author a custom protocol. You can use the standard data formats, TEXT and CSV, or a custom data format with custom protocols.

    You can create a custom protocol whenever the available built-in protocols do not suffice for a particular need. For example, you could connect Greenplum Database in parallel to another system directly, and stream data from one to the other without the need to materialize the data on disk or use an intermediate process such as gpfdist. You must be a superuser to create and register a custom protocol.

    1. Author the send, receive, and (optionally) validator functions in C, with a predefined API. These functions are compiled and registered with the Greenplum Database. For an example custom protocol, see Example Custom Data Access Protocol.
    2. After writing and compiling the read and write functions into a shared object (.so), declare a database function that points to the .so file and function names.

      The following examples use the compiled import and export code.

      1. CREATE FUNCTION myread() RETURNS integer
      2. as '$libdir/gpextprotocol.so', 'myprot_import'
      3. LANGUAGE C STABLE;
      4. CREATE FUNCTION mywrite() RETURNS integer
      5. as '$libdir/gpextprotocol.so', 'myprot_export'
      6. LANGUAGE C STABLE;

      The format of the optional validator function is:

      1. CREATE OR REPLACE FUNCTION myvalidate() RETURNS void
      2. AS '$libdir/gpextprotocol.so', 'myprot_validate'
      3. LANGUAGE C STABLE;
    3. Create a protocol that accesses these functions. Validatorfunc is optional.

      1. CREATE TRUSTED PROTOCOL myprot(
      2. writefunc='mywrite',
      3. readfunc='myread',
      4. validatorfunc='myvalidate');
    4. Grant access to any other users, as necessary.

      1. GRANT ALL ON PROTOCOL myprot TO otheruser;
    5. Use the protocol in readable or writable external tables.

      1. CREATE WRITABLE EXTERNAL TABLE ext_sales(LIKE sales)
      2. LOCATION ('myprot://<meta>/<meta>/…')
      3. FORMAT 'TEXT';
      4. CREATE READABLE EXTERNAL TABLE ext_sales(LIKE sales)
      5. LOCATION('myprot://<meta>/<meta>/…')
      6. FORMAT 'TEXT';

    Declare custom protocols with the SQL command CREATE TRUSTED PROTOCOL, then use the GRANT command to grant access to your users. For example:

    • Allow a user to create a readable external table with a trusted protocol

      1. GRANT SELECT ON PROTOCOL <protocol name> TO <user name>;
    • Allow a user to create a writable external table with a trusted protocol

      1. GRANT INSERT ON PROTOCOL <protocol name> TO <user name>;
    • Allow a user to create readable and writable external tables with a trusted protocol

      1. GRANT ALL ON PROTOCOL <protocol name> TO <user name>;

    Parent topic: Loading and Writing Non-HDFS Custom Data