Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: minor edits

...

Note
titleEarliest version CSVSerde is available

The CSVSerde is available in Hive 0.14 and greater.

Background

The CSV Serde SerDe is based from on https://github.com/ogrodnek/csv-serde, and was added to the Hive distribution in HIVE-7777.

 

Note
titleLimitation

This SerDe treats all columns to be of type String. Even if you create a table with non-string column types using this SerDe, the DESCRIBE TABLE output would show string column type. The type information is retrieved from the SerDe. To convert columns to the desired type in a table, you can create a view over the table that does the CAST to the desired type.

Usage

This Serde SerDe works for most CSV data, but does not handled handle embedded newlines. To use the SerdeSerDe, specify the fully qualified class name org.apache.hadoop.hive.serde2.OpenCSVSerde.  

Documentation is based on original documentation at https://github.com/ogrodnek/csv-serde.

Code Block
languagesql
titleCreate table, specify CSV properties
createCREATE tableTABLE my_table(a string, b string, ...)
ROW rowFORMAT formatSERDE serde 'org.apache.hadoop.hive.serde2.OpenCSVSerde'
WITH withSERDEPROPERTIES serdeproperties (
   "separatorChar" = "\t",
   "quoteChar"     = "'",
   "escapeChar"    = "\\"
  )   
STORED stored as textfile
AS TEXTFILE;
Code Block
titleDefault separator, quote, and escape characters if unspecified.
DEFAULT_ESCAPE_CHARACTER \
DEFAULT_QUOTE_CHARACTER  "
DEFAULT_SEPARATOR        ,

 

For general information about SerDes, see Hive SerDe in the Developer Guide. Also see SerDe for details about input and output processing.

...

Versions

The CSVSerde has been built and tested against Hive 0.14 and later, and uses Super Open-CSV 2.2.03 which is bundled with the Hive distribution.

Hive VersionsSuperCSV Open-CSV Version
Hive 0.14 and later2.2.03