hawq register

Loads and registers AO or Parquet-formatted tables in HDFS into a corresponding table in HAWQ.

Synopsis

  1. Usage 1:
  2. hawq register [<connection_options>] [-f <hdfsfilepath>] [-e <Eof>] <tablename>
  3. Usage 2:
  4. hawq register [<connection_options>] [-c <configfilepath>][-F] <tablename>
  5. Connection Options:
  6. [-h | --host <hostname>]
  7. [-p | --port <port>]
  8. [-U | --user <username>]
  9. [-d | --database <database>]
  10. Misc. Options:
  11. [-f | --filepath <filepath>]
  12. [-e | --eof<eof>]
  13. [-F | --force ]
  14. [-c | --config <yml_config>]
  15. hawq register help | -?
  16. hawq register --version

Prerequisites

The client machine where hawq register is executed must meet the following conditions:

  • All hosts in your HAWQ cluster (master and segments) must have network access between them and the hosts containing the data to be loaded.
  • The Hadoop client must be configured and the hdfs filepath specified.
  • The files to be registered and the HAWQ table must be located in the same HDFS cluster.
  • The target table DDL is configured with the correct data type mapping.

Description

hawq register is a utility that loads and registers existing data files or folders in HDFS into HAWQ internal tables, allowing HAWQ to directly read the data and use internal table processing for operations such as transactions and high performance, without needing to load or copy it. Data from the file or directory specified by <hdfsfilepath> is loaded into the appropriate HAWQ table directory in HDFS and the utility updates the corresponding HAWQ metadata for the files.

You can use hawq register to:

  • Load and register external Parquet-formatted file data generated by an external system such as Hive or Spark.
  • Recover cluster data from a backup cluster.

Two usage models are available.

Usage Model 1: Register file data to an existing table.

hawq register [-h hostname] [-p port] [-U username] [-d databasename] [-f filepath] [-e eof]<tablename>

Metadata for the Parquet file(s) and the destination table must be consistent. Different data types are used by HAWQ tables and Parquet files, so the data is mapped. Refer to the section Data Type Mapping below. You must verify that the structure of the Parquet files and the HAWQ table are compatible before running hawq register.

Limitations

Only HAWQ or Hive-generated Parquet tables are supported. Hash tables and partitioned tables are not supported in this use model.

Usage Model 2: Use information from a YAML configuration file to register data

hawq register [-h hostname] [-p port] [-U username] [-d databasename] [-c configfile] [--force] <tablename>

Files generated by the hawq extract command are registered through use of metadata in a YAML configuration file. Both AO and Parquet tables can be registered. Tables need not exist in HAWQ before being registered.

The register process behaves differently, according to different conditions.

  • Existing tables have files appended to the existing HAWQ table.
  • If a table does not exist, it is created and registered into HAWQ.
  • If the —force option is used, the data in existing catalog tables is erased and re-registered.

Limitations for Registering Hive Tables to HAWQ

The currently-supported data types for generating Hive tables into HAWQ tables are: boolean, int, smallint, tinyint, bigint, float, double, string, binary, char, and varchar.

The following HIVE data types cannot be converted to HAWQ equivalents: timestamp, decimal, array, struct, map, and union.

Only single-level partitioned tables are supported.

Data Type Mapping

HAWQ and Parquet tables and HIVE and HAWQ tables use different data types. Mapping must be used for compatibility. You are responsible for making sure your implementation is mapped to the appropriate data type before running hawq register. The tables below show equivalent data types, if available.

Table 1. HAWQ to Parquet Mapping

HAWQ Data TypeParquet Data Type
boolboolean
int2/int4/dateint32
int8/moneyint64
time/timestamptz/timestampint64
float4float
float8double
bit/varbit/bytea/numericByte array
char/bpchar/varchar/nameByte array
text/xml/interval/timetzByte array
macaddr/inet/cidrByte array

Additional HAWQ-to-Parquet Mapping

point:

  1. group {
  2. required int x;
  3. required int y;
  4. }

circle:

  1. group {
  2. required int x;
  3. required int y;
  4. required int r;
  5. }

box:

  1. group {
  2. required int x1;
  3. required int y1;
  4. required int x2;
  5. required int y2;
  6. }

iseg:

  1. group {
  2. required int x1;
  3. required int y1;
  4. required int x2;
  5. required int y2;
  6. }

path:

  1. group {
  2. repeated group {
  3. required int x;
  4. required int y;
  5. }
  6. }

Table 2. HIVE to HAWQ Mapping

HIVE Data TypeHAWQ Data Type
booleanbool
tinyintint2
smallintint2/smallint
intint4 / int
bigintint8 / bigint
floatfloat4
doublefloat8
stringvarchar
binarybytea
charchar
varcharvarchar

Options

General Options

-? (show help)

Show help, then exit.

--version

Show the version of this utility, then exit.

Connection Options

-h , —host <hostname>

Specifies the host name of the machine on which the HAWQ master database server is running. If not specified, reads from the environment variable $PGHOST or defaults to localhost.

-p , —port <port>

Specifies the TCP port on which the HAWQ master database server is listening for connections. If not specified, reads from the environment variable $PGPORT or defaults to 5432.

-U , —user <username>

The database role name to connect as. If not specified, reads from the environment variable $PGUSER or defaults to the current system user name.

-d , —database <databasename>

The database to register the Parquet HDFS data into. The default is postgres

-f , —filepath <hdfspath>

The path of the file or directory in HDFS containing the files to be registered.

<tablename>

The HAWQ table that will store the data to be registered. If the –config option is not supplied, the table cannot use hash distribution. Random table distribution is strongly preferred. If hash distribution must be used, make sure that the distribution policy for the data files described in the YAML file is consistent with the table being registered into.

Miscellaneous Options

The following options are used with specific use models.

-e , —eof <eof>

Specify the end of the file to be registered. <eof> represents the valid content length of the file, in bytes to be used, a value between 0 the actual size of the file. If this option is not included, the actual file size, or size of files within a folder, is used. Used with Use Model 1.

-F , —force

Used for disaster recovery of a cluster. Clears all HDFS-related catalog contents in pg_aoseg.pg_paqseg_$relidand re-registers files to a specified table. The HDFS files are not removed or modified. To use this option for recovery, data is assumed to be periodically imported to the cluster to be recovered. Used with Usage Model 2.

-c , —config <yml_config>

Registers files specified by YAML-format configuration files into HAWQ. Used with Usage Model 2.

Example: Usage Model 2

This example shows how to register files using a YAML configuration file. This file is usually generated by the hawq extract command.

Create a table and insert data into the table:

  1. => CREATE TABLE paq1(a int, b varchar(10))with(appendonly=true, orientation=parquet);`
  2. => INSERT INTO paq1 values(generate_series(1,1000), 'abcde');

Extract the table’s metadata.

  1. hawq extract -o paq1.yml paq1

Use the YAML file to register the new table paq2:

  1. hawq register --config paq1.yml paq2

Select the new table to determine if the content has already been registered:

  1. => SELECT count(*) FROM paq2;

The result should return 1000.

See Also

hawq extract