DEV Community

Michael
Michael

Posted on Edited on Originally published at gbase8.cn

How GBase 8a Ensures Exported Table Data Always Imports Back Correctly

GBase 8a is a columnar analytical database from GBASE, one of China's domestically developed database vendors. A routine task when you operate a gbase cluster sounds simple: export every row of a table into a file, then make sure all of it loads back correctly — into the same table after a rebuild, into another table in the same cluster, or into a table on an entirely different cluster. This post walks through a practical way to guarantee exactly that.

Why Export-then-Import Is Hard

Table data can contain any character — visible, invisible, or raw binary. If you export to a plain text file and rely on the traditional model of column separators, enclosing characters, and line terminators, it is nearly impossible to find one universal set of rules that works for every table.

That is why the answer is a dedicated non-text format: one that does not depend on separators or enclosing characters at all.

The GBase 8a Approach

Starting with V95, GBase 8a supports exporting and importing data in ORC (Optimized Row Columnar) format — a columnar storage format from the Hadoop ecosystem. Newer versions also support Parquet: export with a .parquet file extension and specify it at load time, in the same way as ORC.

Exporting to ORC

The simplest export statement:

select * from torc into outfile '/home/gbase/torc.orc';
Enter fullscreen mode Exit fullscreen mode

Exporting over sftp, ftp, or hdfs works too:

select * from torc into outfile 'sftp://gbase:gbase@192.168.2.101/home/gbase/torc.orc';
Enter fullscreen mode Exit fullscreen mode

Other supported parameters include outfilemode by, writemode by, filecount, filesize, and character set — see the standard LOAD syntax in gbase for details.

The following parameters are no longer needed and are silently ignored for ORC exports:

  • having lines separator — data containing embedded newlines
  • fields terminated by — field separator
  • fields enclosed by — field enclosure character
  • lines terminated by — line terminator
  • length — field length for fixed-width loading
  • min_chunk_size — minimum chunk size for the load task, 64 MB by default

Importing from ORC

The simplest import statement:

load data infile 'file:///home/gbase/torc.orc/torc.orc' into table torc_new data_format orc
Enter fullscreen mode Exit fullscreen mode

The data_format orc keyword tells gbase the file is in ORC format.

A common companion parameter is the datetime format, for example when values include microseconds:

load data infile 'file:///home/gbase/torc.orc/torc.orc' into table torc_new data_format orc datetime format '%Y-%m-%d %H:%i:%s.%f'
Enter fullscreen mode Exit fullscreen mode

All other parameters work the same as a regular LOAD.

Going forward, using a standard columnar format such as ORC or Parquet as the interchange medium removes the separator-hunting step entirely — no more rows failing to land in the database because of one unlucky delimiter choice.

Top comments (0)