VXQUERY-227 Refactor ObjectPointable.getKeys() 147/head
authorriyafa <riyafa.12@cse.mrt.ac.lk>
Thu, 18 Aug 2016 08:41:45 +0000 (14:11 +0530)
committerriyafa <riyafa.12@cse.mrt.ac.k>
Thu, 10 Nov 2016 13:57:43 +0000 (19:27 +0530)
15 files changed:
vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/ArrayBackedValueStoragePool.java [new file with mode: 0644]
vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/jsonitem/ObjectPointable.java
vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/base/AbstractTaggedValueArgumentScalarEvaluator.java
vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/AbstractLibjnAccumulateScalarEvaluator.java
vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/AbstractLibjnDescendantScalarEvaluator.java
vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/AbstractLibjnProjectScalarEvaluator.java
vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/JnKeysScalarEvaluator.java
vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/JnParseJsonScalarEvaluatorFactory.java
vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/KeysOrMembersScalarEvaluator.java
vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/LibjnValuesScalarEvaluator.java
vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/jsonitem/AbstractObjectConstructorScalarEvaluator.java
vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/jsonitem/ObjectConstructorScalarEvaluator.java
vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/jsonitem/SimpleObjectUnionScalarEvaluator.java
vxquery-core/src/main/java/org/apache/vxquery/serializer/XMLSerializer.java
vxquery-core/src/test/java/org/apache/vxquery/datamodel/ObjectByteTest.java

diff --git a/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/ArrayBackedValueStoragePool.java b/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/ArrayBackedValueStoragePool.java
new file mode 100644 (file)
index 0000000..4c432a9
--- /dev/null
@@ -0,0 +1,25 @@
+package org.apache.vxquery.datamodel.accessors;
+
+import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ArrayBackedValueStoragePool {
+    private final List<ArrayBackedValueStorage> abvsList;
+
+    public ArrayBackedValueStoragePool() {
+        abvsList = new ArrayList<>();
+    }
+
+    public ArrayBackedValueStorage takeOne() {
+        if (abvsList.isEmpty()) {
+            return new ArrayBackedValueStorage();
+        }
+        return abvsList.remove(abvsList.size() - 1);
+    }
+
+    public void giveBack(ArrayBackedValueStorage abvs) {
+        abvsList.add(abvs);
+    }
+}
index 720f438..ac96210 100644 (file)
  */
 package org.apache.vxquery.datamodel.accessors.jsonitem;
 
-import java.io.IOException;
-
 import org.apache.hyracks.api.dataflow.value.ITypeTraits;
 import org.apache.hyracks.data.std.api.AbstractPointable;
+import org.apache.hyracks.data.std.api.IMutableValueStorage;
 import org.apache.hyracks.data.std.api.IPointable;
 import org.apache.hyracks.data.std.api.IPointableFactory;
 import org.apache.hyracks.data.std.primitive.IntegerPointable;
 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;
 
+import java.io.IOException;
+
 /**
  * The datamodel of the JSON object is represented in this class:
  * Byte 1: Value tag of object (109)
@@ -54,7 +54,6 @@ public class ObjectPointable extends AbstractPointable {
     };
     private static final int ENTRY_COUNT_SIZE = IntegerPointable.TYPE_TRAITS.getFixedLength();
     private static final int SLOT_SIZE = IntegerPointable.TYPE_TRAITS.getFixedLength();
-    private final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
     private final SequenceBuilder sb = new SequenceBuilder();
     private final UTF8StringPointable key = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
 
@@ -78,7 +77,7 @@ public class ObjectPointable extends AbstractPointable {
         return getSlotArrayOffset(start) + getEntryCount(bytes, start) * SLOT_SIZE;
     }
 
-    public void getKeys(IPointable result) throws IOException {
+    public void getKeys(IMutableValueStorage abvs) throws IOException {
         abvs.reset();
         sb.reset(abvs);
         int dataAreaOffset = getDataAreaOffset(bytes, start);
@@ -90,7 +89,6 @@ public class ObjectPointable extends AbstractPointable {
             sb.addItem(ValueTag.XS_STRING_TAG, key);
         }
         sb.finish();
-        result.set(abvs);
     }
 
     //here the UTF8StringPointable of key is without the tag
index d7770b0..20f24f6 100644 (file)
@@ -16,6 +16,7 @@
  */
 package org.apache.vxquery.runtime.functions.base;
 
+import org.apache.vxquery.datamodel.accessors.ArrayBackedValueStoragePool;
 import org.apache.vxquery.datamodel.accessors.PointablePool;
 import org.apache.vxquery.datamodel.accessors.PointablePoolFactory;
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
@@ -32,6 +33,7 @@ public abstract class AbstractTaggedValueArgumentScalarEvaluator implements ISca
     private final TaggedValuePointable[] tvps;
 
     protected final PointablePool ppool = PointablePoolFactory.INSTANCE.createPointablePool();
+    protected final ArrayBackedValueStoragePool abvsPool = new ArrayBackedValueStoragePool();
 
     public AbstractTaggedValueArgumentScalarEvaluator(IScalarEvaluator[] args) {
         this.args = args;
index 90dc034..3d5a842 100644 (file)
@@ -46,9 +46,10 @@ public abstract class AbstractLibjnAccumulateScalarEvaluator extends AbstractTag
     private final ArrayBuilder ab;
     protected TaggedValuePointable key, value;
     private final UTF8StringPointable stringKey;
-    private final ArrayBackedValueStorage abvs, abvs1;
+    private final List<ArrayBackedValueStorage> abvsList;
     private final Map<TaggedValuePointable, List<TaggedValuePointable>> tvps;
     protected List<TaggedValuePointable> values;
+    protected final ObjectPointable op;
 
     public AbstractLibjnAccumulateScalarEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args) {
         super(args);
@@ -56,12 +57,11 @@ public abstract class AbstractLibjnAccumulateScalarEvaluator extends AbstractTag
         sp = (SequencePointable) SequencePointable.FACTORY.createPointable();
         sp1 = (SequencePointable) SequencePointable.FACTORY.createPointable();
         stringKey = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
-        abvs = new ArrayBackedValueStorage();
-        abvs1 = new ArrayBackedValueStorage();
         ob = new ObjectBuilder();
         ab = new ArrayBuilder();
         tvps = new LinkedHashMap<>();
-
+        op = (ObjectPointable) ObjectPointable.FACTORY.createPointable();
+        abvsList = new ArrayList<>();
     }
 
     @Override
@@ -71,9 +71,13 @@ public abstract class AbstractLibjnAccumulateScalarEvaluator extends AbstractTag
             throw new SystemException(ErrorCode.FORG0006);
         }
         TaggedValuePointable tempTvp = ppool.takeOne(TaggedValuePointable.class);
+        ArrayBackedValueStorage abvsResult = abvsPool.takeOne();
+        abvsList.add(abvsResult);
+        ArrayBackedValueStorage abvsItem = abvsPool.takeOne();
+        abvsList.add(abvsItem);
         try {
-            abvs.reset();
-            ob.reset(abvs);
+            abvsResult.reset();
+            ob.reset(abvsResult);
             tvps.clear();
             if (arg.getTag() == ValueTag.SEQUENCE_TAG) {
                 arg.getValue(sp);
@@ -92,13 +96,13 @@ public abstract class AbstractLibjnAccumulateScalarEvaluator extends AbstractTag
                 if (values.size() > 1) {
                     FunctionHelper.removeDuplicates(values);
                     if (values.size() > 1) {
-                        abvs1.reset();
-                        ab.reset(abvs1);
+                        abvsItem.reset();
+                        ab.reset(abvsItem);
                         for (TaggedValuePointable pointable : values) {
                             ab.addItem(pointable);
                         }
                         ab.finish();
-                        ob.addItem(stringKey, abvs1);
+                        ob.addItem(stringKey, abvsItem);
                     } else {
                         ob.addItem(stringKey, values.get(0));
                     }
@@ -107,7 +111,7 @@ public abstract class AbstractLibjnAccumulateScalarEvaluator extends AbstractTag
                 }
             }
             ob.finish();
-            result.set(abvs);
+            result.set(abvsResult);
         } catch (IOException e) {
             throw new SystemException(ErrorCode.SYSE0001, e);
         } finally {
@@ -118,6 +122,9 @@ public abstract class AbstractLibjnAccumulateScalarEvaluator extends AbstractTag
                 }
                 ppool.giveBack(key1);
             }
+            for (ArrayBackedValueStorage arrayBackedValueStorage : abvsList) {
+                abvsPool.giveBack(arrayBackedValueStorage);
+            }
         }
     }
 
@@ -141,9 +148,11 @@ public abstract class AbstractLibjnAccumulateScalarEvaluator extends AbstractTag
     }
 
     private void addPairs(TaggedValuePointable tvp1) throws IOException, SystemException {
-        ObjectPointable op = (ObjectPointable) ObjectPointable.FACTORY.createPointable();
+        ArrayBackedValueStorage mvs = abvsPool.takeOne();
+        abvsList.add(mvs);
         tvp1.getValue(op);
-        op.getKeys(tvp1);
+        op.getKeys(mvs);
+        tvp1.set(mvs);
         if (tvp1.getTag() == ValueTag.XS_STRING_TAG) {
             addPair(tvp1, op);
         } else if (tvp1.getTag() == ValueTag.SEQUENCE_TAG) {
index 7083291..a600865 100644 (file)
@@ -38,7 +38,6 @@ public abstract class AbstractLibjnDescendantScalarEvaluator extends AbstractTag
     protected final UTF8StringPointable stringp;
     protected final SequencePointable sp, sp1;
     protected final SequenceBuilder sb;
-    protected final ArrayBackedValueStorage abvs;
 
     public AbstractLibjnDescendantScalarEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args) {
         super(args);
@@ -47,11 +46,12 @@ public abstract class AbstractLibjnDescendantScalarEvaluator extends AbstractTag
         sp = (SequencePointable) SequencePointable.FACTORY.createPointable();
         sp1 = (SequencePointable) SequencePointable.FACTORY.createPointable();
         sb = new SequenceBuilder();
-        abvs = new ArrayBackedValueStorage();
     }
 
     @Override
     protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
+
+        ArrayBackedValueStorage abvs = abvsPool.takeOne();
         try {
             abvs.reset();
             sb.reset(abvs);
@@ -72,14 +72,18 @@ public abstract class AbstractLibjnDescendantScalarEvaluator extends AbstractTag
             result.set(abvs);
         } catch (IOException e) {
             throw new SystemException(ErrorCode.SYSE0001, e);
+        } finally {
+            abvsPool.giveBack(abvs);
         }
     }
 
     protected void processObject(TaggedValuePointable tvp) throws IOException {
         TaggedValuePointable tempTvp = ppool.takeOne(TaggedValuePointable.class);
         ObjectPointable tempOp = ppool.takeOne(ObjectPointable.class);
+        ArrayBackedValueStorage abvs = abvsPool.takeOne();
         tvp.getValue(tempOp);
-        tempOp.getKeys(tempTvp);
+        tempOp.getKeys(abvs);
+        tempTvp.set(abvs);
         if (tempTvp.getTag() == ValueTag.XS_STRING_TAG) {
             processPair(tempTvp, tempOp);
             process(tempTvp);
@@ -94,6 +98,7 @@ public abstract class AbstractLibjnDescendantScalarEvaluator extends AbstractTag
         }
         ppool.giveBack(tempOp);
         ppool.giveBack(tempTvp);
+        abvsPool.giveBack(abvs);
     }
 
     protected abstract void processPair(TaggedValuePointable tempTvp, ObjectPointable tempOp) throws IOException;
index d81cc7d..a0b34a8 100644 (file)
@@ -39,7 +39,6 @@ public abstract class AbstractLibjnProjectScalarEvaluator extends AbstractTagged
     protected final ObjectPointable op;
     protected final UTF8StringPointable stringKey;
     protected final ObjectBuilder ob;
-    protected final ArrayBackedValueStorage abvs, abvs1;
     protected final SequenceBuilder sb;
     protected final SequencePointable sp1;
     protected final TaggedValuePointable tvp1;
@@ -49,8 +48,6 @@ public abstract class AbstractLibjnProjectScalarEvaluator extends AbstractTagged
         this.ctx = ctx;
         stringKey = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
         ob = new ObjectBuilder();
-        abvs = new ArrayBackedValueStorage();
-        abvs1 = new ArrayBackedValueStorage();
         sb = new SequenceBuilder();
         op = (ObjectPointable) ObjectPointable.FACTORY.createPointable();
         sp1 = (SequencePointable) SequencePointable.FACTORY.createPointable();
@@ -66,16 +63,19 @@ public abstract class AbstractLibjnProjectScalarEvaluator extends AbstractTagged
         }
         TaggedValuePointable tempTvp = ppool.takeOne(TaggedValuePointable.class);
         SequencePointable sp = ppool.takeOne(SequencePointable.class);
+        ArrayBackedValueStorage abvsKeys = abvsPool.takeOne();
+        ArrayBackedValueStorage abvsResult = abvsPool.takeOne();
         try {
-            abvs1.reset();
-            sb.reset(abvs1);
+            abvsResult.reset();
+            sb.reset(abvsResult);
             if (sequence.getTag() == ValueTag.SEQUENCE_TAG) {
                 sequence.getValue(sp);
                 for (int i = 0; i < sp.getEntryCount(); ++i) {
                     sp.getEntry(i, tempTvp);
                     if (tempTvp.getTag() == ValueTag.OBJECT_TAG) {
                         tempTvp.getValue(op);
-                        op.getKeys(tempTvp);
+                        op.getKeys(abvsKeys);
+                        tempTvp.set(abvsKeys);
                         addPairs(tempTvp, keys);
                     } else {
                         sb.addItem(tempTvp);
@@ -88,12 +88,14 @@ public abstract class AbstractLibjnProjectScalarEvaluator extends AbstractTagged
                 sb.addItem(sequence);
             }
             sb.finish();
-            result.set(abvs1);
+            result.set(abvsResult);
         } catch (IOException e) {
             throw new SystemException(ErrorCode.SYSE0001, e);
         } finally {
             ppool.giveBack(tempTvp);
             ppool.giveBack(sp);
+            abvsPool.giveBack(abvsResult);
+            abvsPool.giveBack(abvsKeys);
         }
     }
 
@@ -105,33 +107,39 @@ public abstract class AbstractLibjnProjectScalarEvaluator extends AbstractTagged
     }
 
     private void addPairs(TaggedValuePointable tvp2, TaggedValuePointable keys) throws IOException, SystemException {
-        op.getKeys(tvp2);
-        if (tvp2.getTag() == ValueTag.XS_STRING_TAG) {
-            if (keyCheck(tvp2, keys)) {
-                abvs.reset();
-                ob.reset(abvs);
-                addPair(tvp2, tvp1);
-                ob.finish();
-                sb.addItem(abvs);
-            }
-        } else if (tvp2.getTag() == ValueTag.SEQUENCE_TAG) {
-            tvp2.getValue(sp1);
-            boolean found = false;
-            for (int j = 0; j < sp1.getEntryCount(); ++j) {
-                sp1.getEntry(j, tvp2);
+        ArrayBackedValueStorage abvs = abvsPool.takeOne();
+        try {
+            op.getKeys(abvs);
+            tvp2.set(abvs);
+            if (tvp2.getTag() == ValueTag.XS_STRING_TAG) {
                 if (keyCheck(tvp2, keys)) {
-                    if (!found) {
-                        abvs.reset();
-                        ob.reset(abvs);
-                        found = true;
-                    }
+                    abvs.reset();
+                    ob.reset(abvs);
                     addPair(tvp2, tvp1);
+                    ob.finish();
+                    sb.addItem(abvs);
+                }
+            } else if (tvp2.getTag() == ValueTag.SEQUENCE_TAG) {
+                tvp2.getValue(sp1);
+                boolean found = false;
+                for (int j = 0; j < sp1.getEntryCount(); ++j) {
+                    sp1.getEntry(j, tvp2);
+                    if (keyCheck(tvp2, keys)) {
+                        if (!found) {
+                            abvs.reset();
+                            ob.reset(abvs);
+                            found = true;
+                        }
+                        addPair(tvp2, tvp1);
+                    }
+                }
+                if (found) {
+                    ob.finish();
+                    sb.addItem(abvs);
                 }
             }
-            if (found) {
-                ob.finish();
-                sb.addItem(abvs);
-            }
+        } finally {
+            abvsPool.giveBack(abvs);
         }
 
     }
index c90472e..07283e6 100644 (file)
@@ -39,8 +39,8 @@ public class JnKeysScalarEvaluator extends AbstractTaggedValueArgumentScalarEval
     protected final IHyracksTaskContext ctx;
     private final SequencePointable sp1, sp2;
     private final SequenceBuilder sb;
-    private final ArrayBackedValueStorage abvs;
     private List<TaggedValuePointable> pointables;
+    private final ObjectPointable op;
 
     public JnKeysScalarEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args) {
         super(args);
@@ -48,17 +48,19 @@ public class JnKeysScalarEvaluator extends AbstractTaggedValueArgumentScalarEval
         sp1 = (SequencePointable) SequencePointable.FACTORY.createPointable();
         sp2 = (SequencePointable) SequencePointable.FACTORY.createPointable();
         sb = new SequenceBuilder();
-        abvs = new ArrayBackedValueStorage();
         pointables = new ArrayList<>();
+        op = (ObjectPointable) ObjectPointable.FACTORY.createPointable();
     }
 
     @Override
     protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
         TaggedValuePointable tvp1 = args[0];
-        ObjectPointable op;
         pointables.clear();
         if (tvp1.getTag() == ValueTag.SEQUENCE_TAG) {
+            List<ArrayBackedValueStorage> abvsList = new ArrayList<>();
             TaggedValuePointable temptvp = ppool.takeOne(TaggedValuePointable.class);
+            ArrayBackedValueStorage abvsResult = abvsPool.takeOne();
+            abvsList.add(abvsResult);
             try {
                 tvp1.getValue(sp1);
                 int size1 = sp1.getEntryCount();
@@ -66,9 +68,11 @@ public class JnKeysScalarEvaluator extends AbstractTaggedValueArgumentScalarEval
                 for (int i = 0; i < size1; i++) {
                     sp1.getEntry(i, temptvp);
                     if (temptvp.getTag() == ValueTag.OBJECT_TAG) {
-                        op = (ObjectPointable) ObjectPointable.FACTORY.createPointable();
                         temptvp.getValue(op);
-                        op.getKeys(temptvp);
+                        ArrayBackedValueStorage abvsKeys = new ArrayBackedValueStorage();
+                        abvsList.add(abvsKeys);
+                        op.getKeys(abvsKeys);
+                        temptvp.set(abvsKeys);
                         temptvp.getValue(sp2);
                         size2 = sp2.getEntryCount();
                         for (int j = 0; j < size2; j++) {
@@ -80,25 +84,31 @@ public class JnKeysScalarEvaluator extends AbstractTaggedValueArgumentScalarEval
                     }
                 }
                 FunctionHelper.removeDuplicates(pointables);
-                abvs.reset();
-                sb.reset(abvs);
+                abvsResult.reset();
+                sb.reset(abvsResult);
                 for (TaggedValuePointable tvp : pointables) {
                     sb.addItem(tvp);
                 }
                 sb.finish();
-                result.set(abvs);
+                result.set(abvsResult);
             } catch (IOException e) {
                 throw new SystemException(ErrorCode.SYSE0001, e);
             } finally {
+                for (ArrayBackedValueStorage arrayBackedValueStorage : abvsList) {
+                    abvsPool.giveBack(arrayBackedValueStorage);
+                }
                 ppool.giveBack(temptvp);
             }
         } else if (tvp1.getTag() == ValueTag.OBJECT_TAG) {
+            ArrayBackedValueStorage abvsResult = abvsPool.takeOne();
             try {
-                op = (ObjectPointable) ObjectPointable.FACTORY.createPointable();
                 tvp1.getValue(op);
-                op.getKeys(result);
+                op.getKeys(abvsResult);
+                result.set(abvsResult);
             } catch (IOException e) {
                 throw new SystemException(ErrorCode.SYSE0001, e);
+            } finally {
+                abvsPool.giveBack(abvsResult);
             }
         } else {
             XDMConstants.setEmptySequence(result);
index 8c7951c..772118e 100644 (file)
  */
 package org.apache.vxquery.runtime.functions.json;
 
-import java.io.BufferedReader;
-import java.io.DataInputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-
 import org.apache.commons.io.IOUtils;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
@@ -42,6 +37,11 @@ import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScal
 import org.apache.vxquery.runtime.functions.util.FunctionHelper;
 import org.apache.vxquery.xmlparser.IParser;
 
+import java.io.BufferedReader;
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
 public class JnParseJsonScalarEvaluatorFactory extends AbstractTaggedValueArgumentScalarEvaluatorFactory {
 
     private static final long serialVersionUID = 1L;
@@ -60,6 +60,7 @@ public class JnParseJsonScalarEvaluatorFactory extends AbstractTaggedValueArgume
         final ByteBufferInputStream bbis = new ByteBufferInputStream();
         final DataInputStream di = new DataInputStream(bbis);
         final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
+        final ArrayBackedValueStorage abvs1 = new ArrayBackedValueStorage();
 
         return new AbstractTaggedValueArgumentScalarEvaluator(args) {
 
@@ -82,7 +83,8 @@ public class JnParseJsonScalarEvaluatorFactory extends AbstractTaggedValueArgume
                     tvp1.getValue(op);
                     TaggedValuePointable tempTvp = ppool.takeOne(TaggedValuePointable.class);
                     try {
-                        op.getKeys(tvp1);
+                        op.getKeys(abvs1);
+                        tvp1.set(abvs1);
                         tvp1.getValue(stringp2);
                         op.getValue(stringp2, tempTvp);
                     } catch (IOException e1) {
index b19985a..d255345 100644 (file)
@@ -16,8 +16,6 @@
 */
 package org.apache.vxquery.runtime.functions.json;
 
-import java.io.IOException;
-
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import org.apache.hyracks.api.context.IHyracksTaskContext;
 import org.apache.hyracks.data.std.api.IPointable;
@@ -31,11 +29,12 @@ import org.apache.vxquery.exceptions.ErrorCode;
 import org.apache.vxquery.exceptions.SystemException;
 import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluator;
 
+import java.io.IOException;
+
 public class KeysOrMembersScalarEvaluator extends AbstractTaggedValueArgumentScalarEvaluator {
     protected final IHyracksTaskContext ctx;
     private final ObjectPointable op;
     private final ArrayPointable ap;
-    private final ArrayBackedValueStorage abvs;
     private final SequenceBuilder sb;
     private final TaggedValuePointable tempTvp;
 
@@ -44,7 +43,6 @@ public class KeysOrMembersScalarEvaluator extends AbstractTaggedValueArgumentSca
         this.ctx = ctx;
         op = (ObjectPointable) ObjectPointable.FACTORY.createPointable();
         ap = (ArrayPointable) ArrayPointable.FACTORY.createPointable();
-        abvs = new ArrayBackedValueStorage();
         sb = new SequenceBuilder();
         tempTvp = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
     }
@@ -52,11 +50,13 @@ public class KeysOrMembersScalarEvaluator extends AbstractTaggedValueArgumentSca
     @Override
     protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
         final TaggedValuePointable tvp = args[0];
+        ArrayBackedValueStorage abvs = abvsPool.takeOne();
         try {
             switch (tvp.getTag()) {
                 case ValueTag.OBJECT_TAG:
                     tvp.getValue(op);
-                    op.getKeys(result);
+                    op.getKeys(abvs);
+                    result.set(abvs);
                     break;
                 case ValueTag.ARRAY_TAG:
                     abvs.reset();
@@ -71,6 +71,8 @@ public class KeysOrMembersScalarEvaluator extends AbstractTaggedValueArgumentSca
             }
         } catch (IOException e) {
             throw new SystemException(ErrorCode.SYSE0001, e);
+        } finally {
+            abvsPool.giveBack(abvs);
         }
     }
 }
index 70ffcd8..6809562 100644 (file)
@@ -36,14 +36,12 @@ public class LibjnValuesScalarEvaluator extends AbstractTaggedValueArgumentScala
     protected final IHyracksTaskContext ctx;
     private final ObjectPointable op;
     private final UTF8StringPointable stringKey;
-    private final ArrayBackedValueStorage abvs1;
     private final SequenceBuilder sb;
 
     public LibjnValuesScalarEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args) {
         super(args);
         this.ctx = ctx;
         stringKey = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
-        abvs1 = new ArrayBackedValueStorage();
         sb = new SequenceBuilder();
         op = (ObjectPointable) ObjectPointable.FACTORY.createPointable();
     }
@@ -54,9 +52,10 @@ public class LibjnValuesScalarEvaluator extends AbstractTaggedValueArgumentScala
 
         TaggedValuePointable tempTvp = ppool.takeOne(TaggedValuePointable.class);
         SequencePointable sp = ppool.takeOne(SequencePointable.class);
+        ArrayBackedValueStorage abvs = abvsPool.takeOne();
         try {
-            abvs1.reset();
-            sb.reset(abvs1);
+            abvs.reset();
+            sb.reset(abvs);
             if (sequence.getTag() == ValueTag.SEQUENCE_TAG) {
                 sequence.getValue(sp);
                 for (int i = 0; i < sp.getEntryCount(); ++i) {
@@ -71,20 +70,23 @@ public class LibjnValuesScalarEvaluator extends AbstractTaggedValueArgumentScala
                 addValues(tempTvp);
             }
             sb.finish();
-            result.set(abvs1);
+            result.set(abvs);
         } catch (IOException e) {
             throw new SystemException(ErrorCode.SYSE0001, e);
         } finally {
             ppool.giveBack(tempTvp);
             ppool.giveBack(sp);
+            abvsPool.giveBack(abvs);
         }
     }
 
     private void addValues(TaggedValuePointable tempTvp) throws IOException, SystemException {
         TaggedValuePointable tempValue = ppool.takeOne(TaggedValuePointable.class);
         SequencePointable sp1 = ppool.takeOne(SequencePointable.class);
+        ArrayBackedValueStorage abvsKeys = abvsPool.takeOne();
         try {
-            op.getKeys(tempTvp);
+            op.getKeys(abvsKeys);
+            tempTvp.set(abvsKeys);
             if (tempTvp.getTag() == ValueTag.XS_STRING_TAG) {
                 tempTvp.getValue(stringKey);
                 op.getValue(stringKey, tempValue);
@@ -101,6 +103,7 @@ public class LibjnValuesScalarEvaluator extends AbstractTaggedValueArgumentScala
         } finally {
             ppool.giveBack(tempValue);
             ppool.giveBack(sp1);
+            abvsPool.giveBack(abvsKeys);
         }
     }
 
index 810de40..77ffc7d 100644 (file)
@@ -31,14 +31,12 @@ import java.util.List;
 public abstract class AbstractObjectConstructorScalarEvaluator extends AbstractTaggedValueArgumentScalarEvaluator {
     protected final IHyracksTaskContext ctx;
     protected final ObjectBuilder ob;
-    protected final ArrayBackedValueStorage abvs;
     protected final List<TaggedValuePointable> tvps;
 
     public AbstractObjectConstructorScalarEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args) {
         super(args);
         this.ctx = ctx;
         ob = new ObjectBuilder();
-        abvs = new ArrayBackedValueStorage();
         tvps = new ArrayList<>();
     }
 
index 0d718a4..6cde2c7 100644 (file)
@@ -37,13 +37,11 @@ public class ObjectConstructorScalarEvaluator extends AbstractObjectConstructorS
     private IPointable vp;
     private UTF8StringPointable sp;
     private SequencePointable seqp;
-    private final ArrayBackedValueStorage abvs1;
     private final BooleanPointable bp;
     private final ArrayBuilder ab;
 
     public ObjectConstructorScalarEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args) {
         super(ctx, args);
-        abvs1 = new ArrayBackedValueStorage();
         vp = VoidPointable.FACTORY.createPointable();
         sp = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
         seqp = (SequencePointable) SequencePointable.FACTORY.createPointable();
@@ -54,9 +52,11 @@ public class ObjectConstructorScalarEvaluator extends AbstractObjectConstructorS
     @Override
     protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
         TaggedValuePointable key, value, qmc, tvp;
+        ArrayBackedValueStorage abvsResult = abvsPool.takeOne();
+        ArrayBackedValueStorage abvsItem = abvsPool.takeOne();
         try {
-            abvs.reset();
-            ob.reset(abvs);
+            abvsResult.reset();
+            ob.reset(abvsResult);
             tvps.clear();
             int len = args.length;
             for (int i = 0; i < len; i += 3) {
@@ -76,15 +76,15 @@ public class ObjectConstructorScalarEvaluator extends AbstractObjectConstructorS
                             XDMConstants.setJsNull(value);
                             ob.addItem(sp, value);
                         } else {
-                            abvs1.reset();
-                            ab.reset(abvs1);
+                            abvsItem.reset();
+                            ab.reset(abvsItem);
                             int l = seqp.getEntryCount();
                             for (int j = 0; j < l; j++) {
                                 seqp.getEntry(j, value);
                                 ab.addItem(value);
                             }
                             ab.finish();
-                            vp.set(abvs1);
+                            vp.set(abvsItem);
                             ob.addItem(sp, vp);
                         }
                     } else {
@@ -96,9 +96,12 @@ public class ObjectConstructorScalarEvaluator extends AbstractObjectConstructorS
             }
 
             ob.finish();
-            result.set(abvs);
+            result.set(abvsResult);
         } catch (IOException e) {
             throw new SystemException(ErrorCode.SYSE0001, e);
+        } finally {
+            abvsPool.giveBack(abvsResult);
+            abvsPool.giveBack(abvsItem);
         }
     }
 }
index 2b13a9f..a66fad1 100644 (file)
@@ -20,6 +20,7 @@ import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import org.apache.hyracks.api.context.IHyracksTaskContext;
 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;
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
 import org.apache.vxquery.datamodel.accessors.jsonitem.ObjectPointable;
@@ -28,19 +29,24 @@ import org.apache.vxquery.exceptions.ErrorCode;
 import org.apache.vxquery.exceptions.SystemException;
 
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 
 public class SimpleObjectUnionScalarEvaluator extends AbstractObjectConstructorScalarEvaluator {
 
     private final SequencePointable sp, sp1;
-    private ObjectPointable op;
+    private final ObjectPointable op;
     private TaggedValuePointable key;
     private final UTF8StringPointable stringKey;
+    private final List<ArrayBackedValueStorage> abvsList;
 
     public SimpleObjectUnionScalarEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args) {
         super(ctx, args);
         sp = (SequencePointable) SequencePointable.FACTORY.createPointable();
         sp1 = (SequencePointable) SequencePointable.FACTORY.createPointable();
         stringKey = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
+        op = (ObjectPointable) ObjectPointable.FACTORY.createPointable();
+        abvsList = new ArrayList<>();
     }
 
     @Override
@@ -51,6 +57,9 @@ public class SimpleObjectUnionScalarEvaluator extends AbstractObjectConstructorS
         }
         TaggedValuePointable tempTvp = ppool.takeOne(TaggedValuePointable.class);
         TaggedValuePointable tempValue = ppool.takeOne(TaggedValuePointable.class);
+        ArrayBackedValueStorage abvs = abvsPool.takeOne();
+        abvsList.add(abvs);
+
         try {
             abvs.reset();
             ob.reset(abvs);
@@ -58,13 +67,13 @@ public class SimpleObjectUnionScalarEvaluator extends AbstractObjectConstructorS
             if (arg.getTag() == ValueTag.SEQUENCE_TAG) {
                 arg.getValue(sp);
                 for (int i = 0; i < sp.getEntryCount(); ++i) {
-                    op = (ObjectPointable) ObjectPointable.FACTORY.createPointable();
+
                     sp.getEntry(i, tempTvp);
                     tempTvp.getValue(op);
                     addPairs(tempTvp, tempValue);
                 }
             } else if (arg.getTag() == ValueTag.OBJECT_TAG) {
-                op = (ObjectPointable) ObjectPointable.FACTORY.createPointable();
+
                 arg.getValue(op);
                 addPairs(tempTvp, tempValue);
             }
@@ -77,6 +86,9 @@ public class SimpleObjectUnionScalarEvaluator extends AbstractObjectConstructorS
             for (TaggedValuePointable pointable : tvps) {
                 ppool.giveBack(pointable);
             }
+            for (ArrayBackedValueStorage arrayBackedValueStorage : abvsList) {
+                abvsPool.giveBack(arrayBackedValueStorage);
+            }
         }
     }
 
@@ -96,7 +108,10 @@ public class SimpleObjectUnionScalarEvaluator extends AbstractObjectConstructorS
 
     private void addPairs(TaggedValuePointable tempTvp, TaggedValuePointable tempValue)
             throws IOException, SystemException {
-        op.getKeys(tempTvp);
+        ArrayBackedValueStorage abvs = abvsPool.takeOne();
+        abvsList.add(abvs);
+        op.getKeys(abvs);
+        tempTvp.set(abvs);
         if (tempTvp.getTag() == ValueTag.XS_STRING_TAG) {
             addPair(tempTvp, tempValue);
         } else if (tempTvp.getTag() == ValueTag.SEQUENCE_TAG) {
index ee08891..984ab81 100644 (file)
@@ -361,9 +361,12 @@ public class XMLSerializer implements IPrinter {
     private void printObject(PrintStream ps, TaggedValuePointable tvp) {
         ObjectPointable op = pp.takeOne(ObjectPointable.class);
         TaggedValuePointable keys = pp.takeOne(TaggedValuePointable.class);
+        ArrayBackedValueStorage mvs = new ArrayBackedValueStorage();
+
         tvp.getValue(op);
         try {
-            op.getKeys(keys);
+            op.getKeys(mvs);
+            keys.set(mvs);
             ps.append('{');
             if (keys.getTag() == ValueTag.SEQUENCE_TAG) {
                 printObjectPairs(ps, keys, op);
index 265f316..56d689f 100644 (file)
@@ -14,8 +14,6 @@
  */
 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.primitive.VoidPointable;
@@ -29,8 +27,11 @@ import org.apache.vxquery.runtime.functions.util.FunctionHelper;
 import org.junit.Assert;
 import org.junit.Test;
 
+import java.io.IOException;
+
 public class ObjectByteTest extends AbstractPointableTest {
     private ArrayBackedValueStorage abvsResult = new ArrayBackedValueStorage();
+    private ArrayBackedValueStorage abvsKeys = new ArrayBackedValueStorage();
     private ObjectBuilder ob = new ObjectBuilder();
     private TaggedValuePointable tvp = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
     private UTF8StringPointable tvpKey1 = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
@@ -90,7 +91,8 @@ public class ObjectByteTest extends AbstractPointableTest {
             Assert.fail("Object size is incorrect. Expected: 1 Got: " + op.getEntryCount());
         }
         try {
-            op.getKeys(tvp);
+            op.getKeys(abvsKeys);
+            tvp.set(abvsKeys);
         } catch (IOException e) {
             Assert.fail("Test failed to write the object pointable.");
         }
@@ -142,7 +144,8 @@ public class ObjectByteTest extends AbstractPointableTest {
 
         //Test keys
         try {
-            op.getKeys(tvp);
+            op.getKeys(abvsKeys);
+            tvp.set(abvsKeys);
         } catch (IOException e) {
             Assert.fail("Test failed to write the object pointable.");
         }