Skip to content
This repository has been archived by the owner on Oct 8, 2019. It is now read-only.

Adding rowid for each row

Makoto YUI edited this page May 9, 2015 · 10 revisions
CREATE TABLE xxx
AS
SELECT 
  regexp_replace(reflect('java.util.UUID','randomUUID'), '-', '') as rowid,
  *
FROM
  ..;

Another option to generate rowid is to use row_number(). However, the query execution would become too slow for large dataset because the rowid generation is executed on a single reducer.

CREATE TABLE xxx
AS
select 
  row_number() over () as rowid, 
  * 
from a9atest;

Rowid generator provided in Hivemall v0.2 or later

You can use rowid() function to generate an unique rowid in Hivemall v0.2 or later.

select
  rowid() as rowid, -- returns ${task_id}-${sequence_number}
  *
from 
  xxx
Clone this wiki locally