Details
Description
The Hadoop Text class contains an array of byte which contain a UTF-8 encoded string. However, there is no way to quickly get the length of that string. One can get the number of bytes in the byte array, but to figure out the length of the String, it needs to be decoded first. In this simple example, sorting the Text objects by String length, the String needs to be decoded from the byte array repeatedly. This was brought to my attention based on HIVE-23870.
public static void main(String[] args) { List<Text> list = Arrays.asList(new Text("1"), new Text("22"), new Text("333")); list.sort((Text t1, Text t2) -> t1.toString().length() - t2.toString().length()); }
Also helpful if I want to check the last letter in the Text object repeatedly:
Text t = new Text("4444"); System.out.println(t.charAt(t.toString().length() - 1));
Attachments
Issue Links
- is related to
-
HIVE-23870 Optimise multiple text conversions in WritableHiveCharObjectInspector.getPrimitiveJavaObject / HiveCharWritable
- Closed
- links to