Muthu Palaniappan
Muthu Palaniappan

Reputation: 231

Hive padding leading zeroes

I need the output of a string column in my table as 13 length char, irrespective of whatever length it is, i need to stuff the remaining chars with 0...

I tried to use the following code in my hive query, but failed to get the desired output

right('0000000000000' + ProductID, 13)

Any help? Thanks

Upvotes: 21

Views: 53117

Answers (1)

Jason Rosendale
Jason Rosendale

Reputation: 593

Hive has built-in lpad and rpad functions. In your case you could use:

lpad(ProductId, 13, "0")

Or, if you might need to truncate to 13 characters, you could wrap this in the "right" function.

Upvotes: 53

Related Questions