Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@

public abstract class HiveBaseCharWritable {
protected Text value = new Text();
protected int charLength = -1;

public HiveBaseCharWritable() {
}

public int getCharacterLength() {
return HiveStringUtils.getTextUtfLength(value);
if (charLength != -1) {
return charLength;
}
charLength = HiveStringUtils.getTextUtfLength(value);
return charLength;
}

/**
Expand All @@ -45,6 +50,7 @@ public Text getTextValue() {

public void readFields(DataInput in) throws IOException {
value.readFields(in);
charLength = -1;
}

public void write(DataOutput out) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public void set(String val) {

public void set(HiveCharWritable val) {
value.set(val.value);
charLength = -1;
}

public void set(HiveCharWritable val, int maxLength) {
Expand All @@ -78,6 +79,9 @@ public void enforceMaxLength(int maxLength) {
}

public Text getStrippedValue() {
if (value.charAt(value.getLength() - 1) != ' ') {
return value;
}
// A lot of these methods could be done more efficiently by operating on the Text value
// directly, rather than converting to HiveChar.
return new Text(getHiveChar().getStrippedValue());
Expand All @@ -88,7 +92,11 @@ public Text getPaddedValue() {
}

public int getCharacterLength() {
return HiveStringUtils.getTextUtfLength(getStrippedValue());
if (charLength != -1) {
return charLength;
}
charLength = HiveStringUtils.getTextUtfLength(getStrippedValue());
return charLength;
}

public int compareTo(HiveCharWritable rhs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public void set(String val) {

public void set(HiveVarcharWritable val) {
value.set(val.value);
charLength = val.charLength;
}

public void set(HiveVarcharWritable val, int maxLength) {
Expand All @@ -57,6 +58,7 @@ public void set(HiveVarchar val, int len) {

public void set(String val, int maxLength) {
value.set(HiveBaseChar.enforceMaxLength(val, maxLength));
charLength = maxLength;
}

public HiveVarchar getHiveVarchar() {
Expand Down