Added comments on the object datamodel and further improvements

Project: http://git-wip-us.apache.org/repos/asf/vxquery/repo
Commit: http://git-wip-us.apache.org/repos/asf/vxquery/commit/131295d1
Tree: http://git-wip-us.apache.org/repos/asf/vxquery/tree/131295d1
Diff: http://git-wip-us.apache.org/repos/asf/vxquery/diff/131295d1

Branch: refs/heads/master
Commit: 131295d1c87c1cc392683b20d8fa6a89ed6a8b2a
Parents: 18a301e
Author: riyafa <[email protected]>
Authored: Tue May 17 14:48:20 2016 +0530
Committer: riyafa <[email protected]>
Committed: Tue May 17 14:48:20 2016 +0530

----------------------------------------------------------------------
 .../accessors/jsonItem/ObjectPointable.java     | 21 ++++++++++++++------
 .../datamodel/AbstractPointableTest.java        |  4 ++--
 .../vxquery/datamodel/ObjectByteTest.java       | 13 +++++++-----
 3 files changed, 25 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/vxquery/blob/131295d1/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/jsonItem/ObjectPointable.java
----------------------------------------------------------------------
diff --git 
a/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/jsonItem/ObjectPointable.java
 
b/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/jsonItem/ObjectPointable.java
index b8cf83b..039d8cd 100644
--- 
a/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/jsonItem/ObjectPointable.java
+++ 
b/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/jsonItem/ObjectPointable.java
@@ -32,6 +32,14 @@ import org.apache.vxquery.exceptions.ErrorCode;
 import org.apache.vxquery.exceptions.SystemException;
 import org.apache.vxquery.runtime.functions.util.FunctionHelper;
 
+/**
+ * The datamodel of the JSON object is represented in this class:
+ * Byte 1: Value tag of object (109)
+ * Byte 2 to 5: number of key-value pairs in the object
+ * Next few bytes: Offsets for each key-value pair in the object in the order 
appearing in the json data
+ * Next bytes: The keys in the object each followed by the value of the key. 
Each key is a StringPointable and the value
+ * of the key will be the respective pointable starting with its valuetag.
+ */
 public class ObjectPointable extends AbstractPointable {
     public static final IPointableFactory FACTORY = new IPointableFactory() {
         private static final long serialVersionUID = 1L;
@@ -72,10 +80,6 @@ public class ObjectPointable extends AbstractPointable {
         return getSlotArrayOffset(start) + getEntryCount(bytes, start) * 
SLOT_SIZE;
     }
 
-    public int getEntryCount() {
-        return getEntryCount(bytes, start);
-    }
-
     public void getKeys(IPointable result) throws SystemException {
         try {
             abvs.reset();
@@ -95,7 +99,7 @@ public class ObjectPointable extends AbstractPointable {
         }
     }
 
-    public void getValue(TaggedValuePointable key, TaggedValuePointable 
pointer) {
+    public void getValue(TaggedValuePointable key, TaggedValuePointable 
result) {
         int dataAreaOffset = getDataAreaOffset(bytes, start);
         int entryCount = getEntryCount();
         int s, l;
@@ -104,9 +108,10 @@ public class ObjectPointable extends AbstractPointable {
             l = getKeyLength(bytes, s);
             key1.set(bytes, s, l);
             if (FunctionHelper.arraysEqual(key1, key)) {
-                pointer.set(bytes, s + l, getEntryLength(i) - l);
+                result.set(bytes, s + l, getEntryLength(i) - l);
                 break;
             }
+            //Todo: if no key found return null
         }
     }
 
@@ -118,4 +123,8 @@ public class ObjectPointable extends AbstractPointable {
         return getSlotValue(bytes, start, idx) - 
getRelativeEntryStartOffset(idx);
     }
 
+    public int getEntryCount() {
+        return getEntryCount(bytes, start);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/vxquery/blob/131295d1/vxquery-core/src/test/java/org/apache/vxquery/datamodel/AbstractPointableTest.java
----------------------------------------------------------------------
diff --git 
a/vxquery-core/src/test/java/org/apache/vxquery/datamodel/AbstractPointableTest.java
 
b/vxquery-core/src/test/java/org/apache/vxquery/datamodel/AbstractPointableTest.java
index d186c10..28ef372 100644
--- 
a/vxquery-core/src/test/java/org/apache/vxquery/datamodel/AbstractPointableTest.java
+++ 
b/vxquery-core/src/test/java/org/apache/vxquery/datamodel/AbstractPointableTest.java
@@ -41,8 +41,8 @@ public class AbstractPointableTest {
     }
 
     protected void writeInteger(Integer value, DataOutput dOut) throws 
IOException {
-        dOut.write(ValueTag.XS_LONG_TAG);
-        dOut.writeLong(value);
+        dOut.write(ValueTag.XS_INT_TAG);
+        dOut.writeInt(value);
     }
 
     protected void writeLong(Long value, DataOutput dOut) throws IOException {

http://git-wip-us.apache.org/repos/asf/vxquery/blob/131295d1/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 2b2e676..eb29134 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
@@ -129,7 +129,7 @@ public class ObjectByteTest extends AbstractPointableTest {
 
         // Check results.
         if (tvp.getTag() != ValueTag.OBJECT_TAG) {
-            Assert.fail("Type tag is incorrect. Expected: " + 
ValueTag.SEQUENCE_TAG + " Got: " + tvp.getTag());
+            Assert.fail("Type tag is incorrect. Expected: " + 
ValueTag.OBJECT_TAG + " Got: " + tvp.getTag());
         }
         tvp.getValue(op);
         if (op.getEntryCount() != 3) {
@@ -144,7 +144,7 @@ public class ObjectByteTest extends AbstractPointableTest {
         }
 
         if (tvp.getTag() != ValueTag.SEQUENCE_TAG) {
-            Assert.fail("Object tag is incorrect. Expected: " + 
ValueTag.SEQUENCE_TAG + " Got: " + tvp.getTag());
+            Assert.fail("Tag type is incorrect. Expected: " + 
ValueTag.SEQUENCE_TAG + " Got: " + tvp.getTag());
         }
         tvp.getValue(sp);
         if (sp.getEntryCount() != 3) {
@@ -166,15 +166,18 @@ public class ObjectByteTest extends AbstractPointableTest 
{
         //Test values
         op.getValue(tvp1, tvp);
         if (!FunctionHelper.arraysEqual(tvp, tvp2)) {
-            Assert.fail("Value is incorrect for the given key. Expected: A 
green door");
+            Assert.fail("Value is incorrect for the given key. Expected: A 
green door with valuetag: "
+                    + ValueTag.XS_STRING_TAG + " Got valuetag: " + 
tvp.getTag());
         }
         op.getValue(tvp3, tvp);
         if (!FunctionHelper.arraysEqual(tvp, tvp4)) {
-            Assert.fail("Value is incorrect for the given key. Expected: 
12.5");
+            Assert.fail("Value is incorrect for the given key. Expected: 12.5 
with valuetag: " + ValueTag.XS_DOUBLE_TAG
+                    + " Got valuetag: " + tvp.getTag());
         }
         op.getValue(tvp5, tvp);
         if (!FunctionHelper.arraysEqual(tvp, tvp6)) {
-            Assert.fail("Value is incorrect for the given key. Expected: 100");
+            Assert.fail("Value is incorrect for the given key. Expected: 100 
with valuetag: " + ValueTag.XS_LONG_TAG
+                    + " Got valuetag: " + tvp.getTag());
         }
     }
 

Reply via email to