Reputation: 283
In my hive, I can see the following built in function:
describe FUNCTION extended uuid
uuid() - Returns a universally unique identifier (UUID) string.
The value is returned as a canonical UUID 36-character string.
Example:
> SELECT uuid();
'0baf1f52-53df-487f-8292-99a03716b688'
> SELECT uuid();
'36718a53-84f5-45d6-8796-4f79983ad49d'
I am trying to generate a uuid for every row in a table:
from (select *, uuid() as id from table1) t
insert into table table2
select a,b,id
insert into table table3
c,id;
Every single row in each table ends up with an identical uuid value. However, if I replace uuid() function with rand() function, every row ends up with a different random id. Why is uuid() only generating one value?
I can't use reflect('java.util.UUID','randomUUID') because reflect is blocked by sentry.
Upvotes: 1
Views: 6188
Reputation: 13853
The UUID
function was added in 2.2.0, it had a bug unfortunately in that it was not tagged as non-deterministic. If you update to 2.2.3 it will work as expected, if that is not an option, you can create your own UUID generator UDF in it's place,
@UDFType(deterministic = false)
public class UUIDShim extends UDF {
private final Text result = new Text();
public Text evaluate() {
result.set(UUID.randomUUID().toString());
return result;
}
}
Upvotes: 2