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
The LPAD function returns the string with a length of len characters left-padded with pad. Example: LPAD('hive',6,'v') returns 'vvhive' LTRIM( string str ) The LTRIM function removes all the trailing spaces from the string.
Use regexp_replace to replace consecutive multiple spaces with one space character.
Trim function removes the extra space from both ends of the string value. In other words, it removes the leading and trailing space from the string. Along with this, Hive providing two more trim function as below. Ltrim – It return a string after trimming the space from the beginning (left hand side) of a string.
The || operator can be used to join the strings together. It is a concatenation operator. Similar to concat() function, we can use this operator to add the strings together in Hive.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With