I'm new to hive and I'm creating a table with the following properties,
CREATE EXTERNAL TABLE EXTTBL_Transactions
(
TRANSACTION_ID varchar(70) COMMENT 'UniqueID, `Primary Key',
DEFINITION_ID varchar(70) COMMENT 'Definition, Null Allowed',
USER_ID varchar(70) COMMENT 'Contact id, Foreign Key',
PURCHASE_DATETIME Timestamp COMMENT 'Saved dattime, Null Allowed',
PURCHASE_AMOUNT FLOAT COMMENT 'Sum value of number of product purchase,Null Allowed',
INTERACTIONS_ID varchar(70) COMMENT 'Unique interaction id, Foreign Key',
PRODUCT_DETAILS array<struct<PRODUCT_NAME:varchar(70),PRODUCT_PRICE:FLOAT>> COMMENT 'Product Details'
)
COMMENT 'Transaction details'
PARTITIONED BY (LOAD_DATE DATE)
row format delimited fields terminated by ','
lines terminated by '\n'
collection items terminated by '|'
map keys terminated by ':'
LOCATION 's3a://XXX/XXX//Transactions';
In the code above I'm creating an array of struct type for the product details. And I'm separating each product details with '|' and struct element by ':', but somehow this is causing an error.
Moving to answer.
The order should be FIELDS
, COLLECTION ITEMS
, MAP KEYS
, and then LINES
row_format
: DELIMITED [FIELDS TERMINATED BY char [ESCAPED BY char]] [COLLECTION ITEMS TERMINATED BY char]
[MAP KEYS TERMINATED BY char] [LINES TERMINATED BY char]