Changes to sequence Pointable and retaining old ObjectByteTest
Project: http://git-wip-us.apache.org/repos/asf/vxquery/repo Commit: http://git-wip-us.apache.org/repos/asf/vxquery/commit/b28fc195 Tree: http://git-wip-us.apache.org/repos/asf/vxquery/tree/b28fc195 Diff: http://git-wip-us.apache.org/repos/asf/vxquery/diff/b28fc195 Branch: refs/heads/master Commit: b28fc195a0d49f37c3618e57752764daca2f0c44 Parents: e8afa64 Author: riyafa <[email protected]> Authored: Thu May 19 09:02:40 2016 +0530 Committer: riyafa <[email protected]> Committed: Thu May 19 09:02:40 2016 +0530 ---------------------------------------------------------------------- .../datamodel/accessors/SequencePointable.java | 38 ++++++++++---------- .../vxquery/datamodel/ObjectByteTest.java | 15 +++++--- 2 files changed, 30 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/vxquery/blob/b28fc195/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/SequencePointable.java ---------------------------------------------------------------------- diff --git a/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/SequencePointable.java b/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/SequencePointable.java index d1b7dd8..9ccac0b 100644 --- a/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/SequencePointable.java +++ b/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/SequencePointable.java @@ -24,6 +24,8 @@ import org.apache.hyracks.data.std.primitive.IntegerPointable; import org.apache.hyracks.data.std.primitive.VoidPointable; public class SequencePointable extends AbstractPointable { + private static final int ENTRY_COUNT_SIZE = IntegerPointable.TYPE_TRAITS.getFixedLength(); + private static final int SLOT_SIZE = IntegerPointable.TYPE_TRAITS.getFixedLength(); public static final IPointableFactory FACTORY = new IPointableFactory() { private static final long serialVersionUID = 1L; @@ -37,39 +39,29 @@ public class SequencePointable extends AbstractPointable { return new SequencePointable(); } }; - private static final int ENTRY_COUNT_SIZE = IntegerPointable.TYPE_TRAITS.getFixedLength(); - private static final int SLOT_SIZE = IntegerPointable.TYPE_TRAITS.getFixedLength(); public static int getSequenceLength(byte[] bytes, int start) { int entryCount = getEntryCount(bytes, start); return getSlotValue(bytes, start, entryCount - 1) + (getDataAreaOffset(bytes, start) - start); } - private static int getEntryCount(byte[] bytes, int start) { - return IntegerPointable.getInteger(bytes, start); - } - - private static int getSlotValue(byte[] bytes, int start, int idx) { - return IntegerPointable.getInteger(bytes, getSlotArrayOffset(start) + idx * SLOT_SIZE); - } - - private static int getSlotArrayOffset(int start) { - return start + ENTRY_COUNT_SIZE; - } - - private static int getDataAreaOffset(byte[] bytes, int start) { - return getSlotArrayOffset(start) + getEntryCount(bytes, start) * SLOT_SIZE; - } - public int getEntryCount() { return getEntryCount(bytes, start); } + private static int getEntryCount(byte[] bytes, int start) { + return IntegerPointable.getInteger(bytes, start); + } + public void getEntry(int idx, IPointable pointer) { int dataAreaOffset = getDataAreaOffset(bytes, start); pointer.set(bytes, dataAreaOffset + getRelativeEntryStartOffset(idx), getEntryLength(idx)); } + private static int getSlotValue(byte[] bytes, int start, int idx) { + return IntegerPointable.getInteger(bytes, getSlotArrayOffset(start) + idx * SLOT_SIZE); + } + private int getRelativeEntryStartOffset(int idx) { return idx == 0 ? 0 : getSlotValue(bytes, start, idx - 1); } @@ -77,4 +69,12 @@ public class SequencePointable extends AbstractPointable { private int getEntryLength(int idx) { return getSlotValue(bytes, start, idx) - getRelativeEntryStartOffset(idx); } -} + + private static int getSlotArrayOffset(int start) { + return start + ENTRY_COUNT_SIZE; + } + + private static int getDataAreaOffset(byte[] bytes, int start) { + return getSlotArrayOffset(start) + getEntryCount(bytes, start) * SLOT_SIZE; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/vxquery/blob/b28fc195/vxquery-core/src/test/java/org/apache/vxquery/datamodel/ObjectByteTest.java ---------------------------------------------------------------------- diff --git a/vxquery-core/src/test/java/org/apache/vxquery/datamodel/ObjectByteTest.java b/vxquery-core/src/test/java/org/apache/vxquery/datamodel/ObjectByteTest.java index e55706e..2bf95c1 100644 --- a/vxquery-core/src/test/java/org/apache/vxquery/datamodel/ObjectByteTest.java +++ b/vxquery-core/src/test/java/org/apache/vxquery/datamodel/ObjectByteTest.java @@ -16,6 +16,7 @@ package org.apache.vxquery.datamodel; import java.io.IOException; +import org.apache.hyracks.data.std.api.IPointable; import org.apache.hyracks.data.std.primitive.UTF8StringPointable; import org.apache.hyracks.data.std.util.ArrayBackedValueStorage; import org.apache.vxquery.datamodel.accessors.SequencePointable; @@ -95,7 +96,7 @@ public class ObjectByteTest extends AbstractPointableTest { if (tvp.getTag() != ValueTag.XS_STRING_TAG) { Assert.fail("Type tag is incorrect. Expected: " + ValueTag.XS_STRING_TAG + " Got: " + tvp.getTag()); } - if (tvpKey1.compareTo(tvp) < 0) { + if (!compareKeys(tvp, tvpKey1)) { Assert.fail("Key is incorrect. Expected: id"); } @@ -156,21 +157,21 @@ public class ObjectByteTest extends AbstractPointableTest { if (tvp.getTag() != ValueTag.XS_STRING_TAG) { Assert.fail("Type tag is incorrect. Expected: " + ValueTag.XS_STRING_TAG + " Got: " + tvp.getTag()); } - if (tvpKey1.compareTo(tvp) < 0) { + if (!compareKeys(tvp, tvpKey1)) { Assert.fail("Object key one is incorrect. Expected: name"); } sp.getEntry(1, tvp); if (tvp.getTag() != ValueTag.XS_STRING_TAG) { Assert.fail("Type tag is incorrect. Expected: " + ValueTag.XS_STRING_TAG + " Got: " + tvp.getTag()); } - if (tvpKey2.compareTo(tvp) < 0) { + if (!compareKeys(tvp, tvpKey2)) { Assert.fail("Object key two is incorrect. Expected: price"); } sp.getEntry(2, tvp); if (tvp.getTag() != ValueTag.XS_STRING_TAG) { Assert.fail("Type tag is incorrect. Expected: " + ValueTag.XS_STRING_TAG + " Got: " + tvp.getTag()); } - if (tvpKey3.compareTo(tvp) < 0) { + if (!compareKeys(tvp, tvpKey3)) { Assert.fail("Object key three is incorrect. Expected: properties"); } @@ -252,4 +253,10 @@ public class ObjectByteTest extends AbstractPointableTest { Assert.fail("Test failed to write the object pointable."); } } + + private boolean compareKeys(IPointable tvp1, IPointable tvp2) { + + return FunctionHelper.arraysEqual(tvp1.getByteArray(), tvp1.getStartOffset() + 1, tvp1.getLength() - 1, + tvp2.getByteArray(), tvp2.getStartOffset(), tvp2.getLength()); + } }
