vxquery-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From prest...@apache.org
Subject [06/11] vxquery git commit: Include the string pointable tags when returning the sequence pointable in getKeys method
Date Wed, 25 May 2016 01:03:22 GMT
Include the string pointable tags when returning the sequence pointable in getKeys method


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

Branch: refs/heads/master
Commit: 98cc0f89d52358d24fa015903ca53c6818567755
Parents: 5ec28cb
Author: riyafa <riyafa0@gmail.com>
Authored: Thu May 19 06:38:02 2016 +0530
Committer: riyafa <riyafa0@gmail.com>
Committed: Thu May 19 06:38:02 2016 +0530

----------------------------------------------------------------------
 .../accessors/jsonItem/ObjectPointable.java     | 14 +++++-----
 .../builders/sequence/SequenceBuilder.java      |  6 +++++
 .../vxquery/datamodel/ObjectByteTest.java       | 27 ++++++++++++++++----
 3 files changed, 36 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/vxquery/blob/98cc0f89/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 3aadee3..953a8fa 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
@@ -27,6 +27,7 @@ import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.primitive.VoidPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.vxquery.datamodel.builders.sequence.SequenceBuilder;
+import org.apache.vxquery.datamodel.values.ValueTag;
 import org.apache.vxquery.runtime.functions.util.FunctionHelper;
 
 /**
@@ -86,7 +87,7 @@ public class ObjectPointable extends AbstractPointable {
         for (int i = 0; i < entryCount; i++) {
             s = dataAreaOffset + getRelativeEntryStartOffset(i);
             key1.set(bytes, s, getKeyLength(bytes, s));
-            sb.addItem(key1);
+            sb.addItem(ValueTag.XS_STRING_TAG, key1);
         }
         sb.finish();
         result.set(abvs);
@@ -95,12 +96,13 @@ public class ObjectPointable extends AbstractPointable {
     public boolean getValue(UTF8StringPointable key, IPointable result) {
         int dataAreaOffset = getDataAreaOffset(bytes, start);
         int entryCount = getEntryCount();
-        int s, l, i;
+        int start, length, i;
         for (i = 0; i < entryCount; i++) {
-            s = dataAreaOffset + getRelativeEntryStartOffset(i);
-            l = getKeyLength(bytes, s);
-            if (FunctionHelper.arraysEqual(bytes, s, l, key.getByteArray(), key.getStartOffset(),
key.getLength())) {
-                result.set(bytes, s + l, getEntryLength(i) - l);
+            start = dataAreaOffset + getRelativeEntryStartOffset(i);
+            length = getKeyLength(bytes, start);
+            if (FunctionHelper.arraysEqual(bytes, start, length, key.getByteArray(), key.getStartOffset(),
+                    key.getLength())) {
+                result.set(bytes, start + length, getEntryLength(i) - length);
                 return true;
             }
         }

http://git-wip-us.apache.org/repos/asf/vxquery/blob/98cc0f89/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/sequence/SequenceBuilder.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/sequence/SequenceBuilder.java
b/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/sequence/SequenceBuilder.java
index fbea148..a5ca065 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/sequence/SequenceBuilder.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/sequence/SequenceBuilder.java
@@ -42,6 +42,12 @@ public class SequenceBuilder implements IBuilder {
         slots.append(dataArea.getLength());
     }
 
+    public void addItem(int tagValue, IValueReference p) throws IOException {
+        dataArea.getDataOutput().write(tagValue);
+        dataArea.getDataOutput().write(p.getByteArray(), p.getStartOffset(), p.getLength());
+        slots.append(dataArea.getLength());
+    }
+
     public void finish() throws IOException {
         DataOutput out = mvs.getDataOutput();
         if (slots.getSize() != 1) {

http://git-wip-us.apache.org/repos/asf/vxquery/blob/98cc0f89/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 ff05c24..41694e8 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;
@@ -92,8 +93,10 @@ public class ObjectByteTest extends AbstractPointableTest {
         } catch (IOException e) {
             Assert.fail("Test failed to write the object pointable.");
         }
-
-        if (!FunctionHelper.arraysEqual(tvp, tvpKey1)) {
+        if (tvp.getTag() != ValueTag.XS_STRING_TAG) {
+            Assert.fail("Type tag is incorrect. Expected: " + ValueTag.XS_STRING_TAG + "
Got: " + tvp.getTag());
+        }
+        if (!compareKeys(tvp, tvpKey1)) {
             Assert.fail("Key is incorrect. Expected: id");
         }
 
@@ -151,15 +154,24 @@ public class ObjectByteTest extends AbstractPointableTest {
             Assert.fail("Object size is incorrect. Expected: 3 Got: " + sp.getEntryCount());
         }
         sp.getEntry(0, tvp);
-        if (!FunctionHelper.arraysEqual(tvp, tvpKey1)) {
+        if (tvp.getTag() != ValueTag.XS_STRING_TAG) {
+            Assert.fail("Type tag is incorrect. Expected: " + ValueTag.XS_STRING_TAG + "
Got: " + tvp.getTag());
+        }
+        if (!compareKeys(tvp, tvpKey1)) {
             Assert.fail("Object key one is incorrect. Expected: name");
         }
         sp.getEntry(1, tvp);
-        if (!FunctionHelper.arraysEqual(tvp, tvpKey2)) {
+        if (tvp.getTag() != ValueTag.XS_STRING_TAG) {
+            Assert.fail("Type tag is incorrect. Expected: " + ValueTag.XS_STRING_TAG + "
Got: " + tvp.getTag());
+        }
+        if (!compareKeys(tvp, tvpKey2)) {
             Assert.fail("Object key two is incorrect. Expected: price");
         }
         sp.getEntry(2, tvp);
-        if (!FunctionHelper.arraysEqual(tvp, tvpKey3)) {
+        if (tvp.getTag() != ValueTag.XS_STRING_TAG) {
+            Assert.fail("Type tag is incorrect. Expected: " + ValueTag.XS_STRING_TAG + "
Got: " + tvp.getTag());
+        }
+        if (!compareKeys(tvp, tvpKey3)) {
             Assert.fail("Object key three is incorrect. Expected: properties");
         }
 
@@ -241,4 +253,9 @@ public class ObjectByteTest extends AbstractPointableTest {
             Assert.fail("Test failed to write the object pointable.");
         }
     }
+
+    public boolean compareKeys(IPointable tvp1, IPointable tvp2) {
+        return FunctionHelper.arraysEqual(tvp1.getByteArray(), tvp1.getStartOffset() + 1,
tvp1.getLength() - 1,
+                tvp2.getByteArray(), tvp2.getStartOffset(), tvp2.getLength());
+    }
 }


Mime
View raw message