Skip to content

Commit

Permalink
HIVE-2881 Remove redundant key comparing in SMBMapJoinOperator
Browse files Browse the repository at this point in the history
(Navis via namit)



git-svn-id: https://svn.apache.org/repos/asf/hive/trunk@1308241 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Namit Jain committed Apr 2, 2012
1 parent 65c86f0 commit cba99c3
Showing 1 changed file with 20 additions and 29 deletions.
49 changes: 20 additions & 29 deletions ql/src/java/org/apache/hadoop/hive/ql/exec/SMBMapJoinOperator.java
Expand Up @@ -318,10 +318,9 @@ private boolean allFetchOpDone() {
}

private List<Byte> joinOneGroup() throws HiveException {
int smallestPos = -1;
smallestPos = findSmallestKey();
int[] smallestPos = findSmallestKey();
List<Byte> listOfNeedFetchNext = null;
if(smallestPos >= 0) {
if(smallestPos != null) {
listOfNeedFetchNext = joinObject(smallestPos);
if (listOfNeedFetchNext.size() > 0) {
// listOfNeedFetchNext contains all tables that we have joined data in their
Expand All @@ -336,29 +335,23 @@ private List<Byte> joinOneGroup() throws HiveException {
return listOfNeedFetchNext;
}

private List<Byte> joinObject(int smallestPos) throws HiveException {
private List<Byte> joinObject(int[] smallestPos) throws HiveException {
List<Byte> needFetchList = new ArrayList<Byte>();
ArrayList<Object> smallKey = keyWritables[smallestPos];
needFetchList.add((byte)smallestPos);
this.storage.put((byte) smallestPos, this.candidateStorage[smallestPos]);
for (Byte i : order) {
if ((byte) smallestPos == i) {
byte index = (byte) (smallestPos.length - 1);
for (; index >= 0; index--) {
if (smallestPos[index] > 0 || keyWritables[index] == null) {
putDummyOrEmpty(index);
continue;
}
ArrayList<Object> key = keyWritables[i];
if (key == null) {
putDummyOrEmpty(i);
} else {
int cmp = compareKeys(key, smallKey);
if (cmp == 0) {
this.storage.put((byte) i, this.candidateStorage[i]);
needFetchList.add(i);
continue;
} else {
putDummyOrEmpty(i);
}
storage.put(index, candidateStorage[index]);
needFetchList.add(index);
if (smallestPos[index] < 0) {
break;
}
}
for (index--; index >= 0; index--) {
putDummyOrEmpty(index);
}
checkAndGenObject();
for (Byte pos : needFetchList) {
this.candidateStorage[pos].clear();
Expand Down Expand Up @@ -442,8 +435,8 @@ private void putDummyOrEmpty(Byte i) {
}
}

private int findSmallestKey() {
byte index = -1;
private int[] findSmallestKey() {
int[] result = new int[order.length];
ArrayList<Object> smallestOne = null;

for (byte i : order) {
Expand All @@ -453,17 +446,15 @@ private int findSmallestKey() {
}
if (smallestOne == null) {
smallestOne = key;
index = i;
result[i] = -1;
continue;
}
int cmp = compareKeys(key, smallestOne);
if (cmp < 0) {
result[i] = compareKeys(key, smallestOne);
if (result[i] < 0) {
smallestOne = key;
index = i;
continue;
}
}
return index;
return smallestOne == null ? null : result;
}

private boolean processKey(byte alias, ArrayList<Object> key)
Expand Down

0 comments on commit cba99c3

Please sign in to comment.