You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ha...@apache.org on 2020/07/23 04:05:56 UTC
[hive] 02/02: HIVE-23870: Optimise multiple text conversions in
WritableHiveCharObjectInspector.getPrimitiveJavaObject / HiveCharWritable
(Rajesh Balamohan via Ashutosh Chauhan, David Mollitor)
This is an automated email from the ASF dual-hosted git repository.
hashutosh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git
commit 51346a0935acfca410c4858c7d4367e27a075392
Author: Rajesh Balamohan <rb...@apache.org>
AuthorDate: Mon Jul 20 15:19:41 2020 +0530
HIVE-23870: Optimise multiple text conversions in WritableHiveCharObjectInspector.getPrimitiveJavaObject / HiveCharWritable (Rajesh Balamohan via Ashutosh Chauhan, David Mollitor)
Signed-off-by: Ashutosh Chauhan <ha...@apache.org>
---
.../org/apache/hadoop/hive/serde2/io/HiveBaseCharWritable.java | 8 +++++++-
.../org/apache/hadoop/hive/serde2/io/HiveCharWritable.java | 10 +++++++++-
.../org/apache/hadoop/hive/serde2/io/HiveVarcharWritable.java | 2 ++
3 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/serde/src/java/org/apache/hadoop/hive/serde2/io/HiveBaseCharWritable.java b/serde/src/java/org/apache/hadoop/hive/serde2/io/HiveBaseCharWritable.java
index 5b7b3b4..c4bd6ff 100644
--- a/serde/src/java/org/apache/hadoop/hive/serde2/io/HiveBaseCharWritable.java
+++ b/serde/src/java/org/apache/hadoop/hive/serde2/io/HiveBaseCharWritable.java
@@ -27,12 +27,17 @@ import org.apache.hive.common.util.HiveStringUtils;
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;
}
/**
@@ -45,6 +50,7 @@ public abstract class HiveBaseCharWritable {
public void readFields(DataInput in) throws IOException {
value.readFields(in);
+ charLength = -1;
}
public void write(DataOutput out) throws IOException {
diff --git a/serde/src/java/org/apache/hadoop/hive/serde2/io/HiveCharWritable.java b/serde/src/java/org/apache/hadoop/hive/serde2/io/HiveCharWritable.java
index 5cc10a8..ea3b8e5 100644
--- a/serde/src/java/org/apache/hadoop/hive/serde2/io/HiveCharWritable.java
+++ b/serde/src/java/org/apache/hadoop/hive/serde2/io/HiveCharWritable.java
@@ -53,6 +53,7 @@ public class HiveCharWritable extends HiveBaseCharWritable
public void set(HiveCharWritable val) {
value.set(val.value);
+ charLength = -1;
}
public void set(HiveCharWritable val, int maxLength) {
@@ -78,6 +79,9 @@ public class HiveCharWritable extends HiveBaseCharWritable
}
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());
@@ -88,7 +92,11 @@ public class HiveCharWritable extends HiveBaseCharWritable
}
public int getCharacterLength() {
- return HiveStringUtils.getTextUtfLength(getStrippedValue());
+ if (charLength != -1) {
+ return charLength;
+ }
+ charLength = HiveStringUtils.getTextUtfLength(getStrippedValue());
+ return charLength;
}
public int compareTo(HiveCharWritable rhs) {
diff --git a/serde/src/java/org/apache/hadoop/hive/serde2/io/HiveVarcharWritable.java b/serde/src/java/org/apache/hadoop/hive/serde2/io/HiveVarcharWritable.java
index 796c533..c3812d6 100644
--- a/serde/src/java/org/apache/hadoop/hive/serde2/io/HiveVarcharWritable.java
+++ b/serde/src/java/org/apache/hadoop/hive/serde2/io/HiveVarcharWritable.java
@@ -45,6 +45,7 @@ public class HiveVarcharWritable extends HiveBaseCharWritable
public void set(HiveVarcharWritable val) {
value.set(val.value);
+ charLength = val.charLength;
}
public void set(HiveVarcharWritable val, int maxLength) {
@@ -57,6 +58,7 @@ public class HiveVarcharWritable extends HiveBaseCharWritable
public void set(String val, int maxLength) {
value.set(HiveBaseChar.enforceMaxLength(val, maxLength));
+ charLength = maxLength;
}
public HiveVarchar getHiveVarchar() {