Github user sureshsubbiah commented on a diff in the pull request:
https://github.com/apache/incubator-trafodion/pull/229#discussion_r47986827
--- Diff: core/sql/src/main/java/org/trafodion/sql/HBaseClient.java ---
@@ -1032,11 +1032,58 @@ public float getBlockCacheFraction()
float defCacheFraction = 0.4f;
return config.getFloat("hfile.block.cache.size",defCacheFraction);
}
+
+ // if we make the method below public later, should think about
whether this is the
+ // right class to host this method
+
+ // compares two qualifiers as unsigned, lexicographically ordered byte
strings
+ static private boolean isQualifierLessThanOrEqual(KeyValue nextKv,
+ KeyValue currKv)
+ {
+ int currLength = currKv.getQualifierLength();
+ int currOffset = currKv.getQualifierOffset();
+ byte [] currQual = currKv.getQualifierArray();
+ int nextLength = nextKv.getQualifierLength();
+ int nextOffset = nextKv.getQualifierOffset();
+ byte [] nextQual = nextKv.getQualifierArray();
+
+ // If we later decide we need a performance-critical version of
this method,
+ // we should just use a native method that calls C memcmp.
+
+ int minLength = nextLength;
+ if (currLength < nextLength)
+ minLength = currLength;
+
+ for (int i = 0; i < minLength; i++) {
+ // ugh... have to do some gymnastics to make this an
+ // unsigned comparison
+ int nextQualI = nextQual[i+nextOffset];
+ if (nextQualI < 0)
+ nextQualI = nextQualI + 256;
+ int currQualI = currQual[i+currOffset];
+ if (currQualI < 0)
+ currQualI = currQualI + 256;
+
+ if (nextQualI < currQualI)
+ return true;
+ else if (nextQualI > currQualI)
+ return false;
+ // else equal, move on to next byte
+ }
+
+ // the first minLength bytes are the same; the shorter array
+ // is regarded as less
+
+ boolean rc = (nextLength <= currLength);
+
+ return rc;
+ }
+
--- End diff --
This method looks good me. An alternative may be to use the compareTo
method in ByteBuffer
http://docs.oracle.com/javase/1.5.0/docs/api/java/nio/ByteBuffer.html#compareTo(java.nio.ByteBuffer)
We use ByteBuffer in a few places in
$MY_SQROOT/../sql/src/main/java/org/trafodion/sql and
$MY_SQROOT/../sql/src/main/java/org/trafodion/sql/udr.
In this case we may have to use the wrap method to get a ByteBuffer of just
the relevant parts and then call compareTo on that?
http://docs.oracle.com/javase/1.5.0/docs/api/java/nio/ByteBuffer.html#wrap(byte[],
int, int)
I have been fascinated by the ByteBuffer class and could not pass up an
opportunity to mention them here. Current code is good too.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---