vxquery-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From prest...@apache.org
Subject [18/50] [abbrv] vxquery git commit: Switched arithmetic from a static call to an object created at the beginning of processing.
Date Fri, 06 Mar 2015 02:00:03 GMT
Switched arithmetic from a static call to an object created at the beginning of processing.

- Helps with reusing array backed value stores.
- Added option for max data size.


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

Branch: refs/heads/site
Commit: d5101a176d7b9124db5621dee228644124ac50f6
Parents: 9ba58f8
Author: Preston Carman <prestonc@apache.org>
Authored: Fri Dec 19 09:24:06 2014 -0800
Committer: Preston Carman <prestonc@apache.org>
Committed: Fri Dec 19 09:24:06 2014 -0800

----------------------------------------------------------------------
 .../java/org/apache/vxquery/cli/VXQuery.java    |   5 +-
 .../builders/atomic/UTF8StringBuilder.java      |  54 ++
 .../builders/base/AbstractBuilder.java          |  27 +
 .../builders/nodes/UTF8StringBuilder.java       |  53 --
 .../AvgGlobalAggregateEvaluatorFactory.java     |  14 +-
 .../AvgLocalAggregateEvaluatorFactory.java      |   8 +-
 .../FnAvgAggregateEvaluatorFactory.java         |   9 +-
 .../aggregate/FnAvgScalarEvaluatorFactory.java  |  11 +-
 .../FnSumAggregateEvaluatorFactory.java         |   8 +-
 .../aggregate/FnSumScalarEvaluatorFactory.java  |   8 +-
 ...bstractArithmeticScalarEvaluatorFactory.java |  13 +-
 .../functions/util/ArithmeticHelper.java        | 511 +++++++++++++++++++
 .../vxquery/xmlparser/SAXContentHandler.java    |   2 +-
 .../xmlquery/query/XMLQueryCompiler.java        |  12 +-
 .../src/main/resources/conf/cluster.properties  |   3 +-
 15 files changed, 636 insertions(+), 102 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/vxquery/blob/d5101a17/vxquery-cli/src/main/java/org/apache/vxquery/cli/VXQuery.java
----------------------------------------------------------------------
diff --git a/vxquery-cli/src/main/java/org/apache/vxquery/cli/VXQuery.java b/vxquery-cli/src/main/java/org/apache/vxquery/cli/VXQuery.java
index 1e083df..866edd1 100644
--- a/vxquery-cli/src/main/java/org/apache/vxquery/cli/VXQuery.java
+++ b/vxquery-cli/src/main/java/org/apache/vxquery/cli/VXQuery.java
@@ -261,7 +261,7 @@ public class VXQuery {
 
             start = opts.timing ? new Date() : null;
             XMLQueryCompiler compiler = new XMLQueryCompiler(listener, getNodeList(), opts.frameSize,
-                    opts.availableProcessors, opts.joinHashSize);
+                    opts.availableProcessors, opts.joinHashSize, opts.maximumDataSize);
             resultSetId = createResultSetId();
             CompilerControlBlock ccb = new CompilerControlBlock(new StaticContextImpl(RootStaticContextImpl.INSTANCE),
                     resultSetId, null);
@@ -453,6 +453,9 @@ public class VXQuery {
         @Option(name = "-join-hash-size", usage = "Join hash size in bytes. (default 67,108,864)")
         private long joinHashSize = -1;
 
+        @Option(name = "-maximum-data-size", usage = "Maximum possible data size in bytes. (default 150,323,855,000)")
+        private long maximumDataSize = -1;
+
         @Option(name = "-buffer-size", usage = "Disk read buffer size in bytes.")
         private int bufferSize = -1;
 

http://git-wip-us.apache.org/repos/asf/vxquery/blob/d5101a17/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/atomic/UTF8StringBuilder.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/atomic/UTF8StringBuilder.java b/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/atomic/UTF8StringBuilder.java
new file mode 100644
index 0000000..f1961ff
--- /dev/null
+++ b/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/atomic/UTF8StringBuilder.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.vxquery.datamodel.builders.atomic;
+
+import java.io.DataOutput;
+import java.io.IOException;
+import java.io.UTFDataFormatException;
+
+import org.apache.vxquery.datamodel.builders.base.AbstractBuilder;
+import org.apache.vxquery.runtime.functions.util.FunctionHelper;
+
+import edu.uci.ics.hyracks.data.std.api.IMutableValueStorage;
+import edu.uci.ics.hyracks.data.std.primitive.BytePointable;
+
+public class UTF8StringBuilder extends AbstractBuilder {
+    private IMutableValueStorage mvs;
+    private DataOutput out;
+
+    @Override
+    public void reset(IMutableValueStorage mvs) throws IOException {
+        this.mvs = mvs;
+        out = mvs.getDataOutput();
+        out.write(0);
+        out.write(0);
+    }
+
+    @Override
+    public void finish() throws IOException {
+        int utflen = mvs.getLength() - 2;
+        BytePointable.setByte(mvs.getByteArray(), 0, (byte) ((utflen >>> 8) & 0xFF));
+        BytePointable.setByte(mvs.getByteArray(), 1, (byte) ((utflen >>> 0) & 0xFF));
+    }
+
+    public void appendCharArray(char[] ch, int start, int length) throws IOException {
+        FunctionHelper.writeCharArray(ch, start, length, out);
+        if (mvs.getLength() > 65535) {
+            throw new UTFDataFormatException("encoded string too long: " + mvs.getLength() + " bytes");
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/vxquery/blob/d5101a17/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/base/AbstractBuilder.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/base/AbstractBuilder.java b/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/base/AbstractBuilder.java
new file mode 100644
index 0000000..4ba9a14
--- /dev/null
+++ b/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/base/AbstractBuilder.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.vxquery.datamodel.builders.base;
+
+import java.io.IOException;
+
+import edu.uci.ics.hyracks.data.std.api.IMutableValueStorage;
+
+public abstract class AbstractBuilder {
+    public abstract void reset(IMutableValueStorage mvs) throws IOException;
+
+    public abstract void finish() throws IOException;
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/vxquery/blob/d5101a17/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/nodes/UTF8StringBuilder.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/nodes/UTF8StringBuilder.java b/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/nodes/UTF8StringBuilder.java
deleted file mode 100644
index 3b4eea0..0000000
--- a/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/nodes/UTF8StringBuilder.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.vxquery.datamodel.builders.nodes;
-
-import java.io.DataOutput;
-import java.io.IOException;
-import java.io.UTFDataFormatException;
-
-import org.apache.vxquery.runtime.functions.util.FunctionHelper;
-
-import edu.uci.ics.hyracks.data.std.api.IMutableValueStorage;
-import edu.uci.ics.hyracks.data.std.primitive.BytePointable;
-
-public class UTF8StringBuilder extends AbstractNodeBuilder {
-    private IMutableValueStorage mvs;
-    private DataOutput out;
-
-    @Override
-    public void reset(IMutableValueStorage mvs) throws IOException {
-        this.mvs = mvs;
-        out = mvs.getDataOutput();
-        out.write(0);
-        out.write(0);
-    }
-
-    @Override
-    public void finish() throws IOException {
-        int utflen = mvs.getLength() - 2;
-        BytePointable.setByte(mvs.getByteArray(), 0, (byte) ((utflen >>> 8) & 0xFF));
-        BytePointable.setByte(mvs.getByteArray(), 1, (byte) ((utflen >>> 0) & 0xFF));
-    }
-
-    public void appendCharArray(char[] ch, int start, int length) throws IOException {
-        FunctionHelper.writeCharArray(ch, start, length, out);
-        if (mvs.getLength() > 65535) {
-            throw new UTFDataFormatException("encoded string too long: " + mvs.getLength() + " bytes");
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/vxquery/blob/d5101a17/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/aggregate/AvgGlobalAggregateEvaluatorFactory.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/aggregate/AvgGlobalAggregateEvaluatorFactory.java b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/aggregate/AvgGlobalAggregateEvaluatorFactory.java
index f784a13..0f4ac08 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/aggregate/AvgGlobalAggregateEvaluatorFactory.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/aggregate/AvgGlobalAggregateEvaluatorFactory.java
@@ -29,6 +29,7 @@ import org.apache.vxquery.runtime.functions.arithmetic.AddOperation;
 import org.apache.vxquery.runtime.functions.arithmetic.DivideOperation;
 import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentAggregateEvaluator;
 import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentAggregateEvaluatorFactory;
+import org.apache.vxquery.runtime.functions.util.ArithmeticHelper;
 import org.apache.vxquery.runtime.functions.util.FunctionHelper;
 
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
@@ -53,13 +54,14 @@ public class AvgGlobalAggregateEvaluatorFactory extends AbstractTaggedValueArgum
         final ArrayBackedValueStorage abvsSum = new ArrayBackedValueStorage();
         final DataOutput dOutSum = abvsSum.getDataOutput();
         final AddOperation aOp = new AddOperation();
+        final ArithmeticHelper add1 = new ArithmeticHelper(aOp, dCtx);
+        final ArithmeticHelper add2 = new ArithmeticHelper(aOp, dCtx);
         final DivideOperation aOpDivide = new DivideOperation();
+        final ArithmeticHelper divide = new ArithmeticHelper(aOpDivide, dCtx);
         final LongPointable longp = (LongPointable) LongPointable.FACTORY.createPointable();
         final SequencePointable seq = (SequencePointable) SequencePointable.FACTORY.createPointable();
         final TaggedValuePointable tvpArg = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
-        final TypedPointables tp1 = new TypedPointables();
-        final TypedPointables tp2 = new TypedPointables();
-        
+
         return new AbstractTaggedValueArgumentAggregateEvaluator(args) {
             TaggedValuePointable tvpSum = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
             TaggedValuePointable tvpCount = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
@@ -93,7 +95,7 @@ public class AvgGlobalAggregateEvaluatorFactory extends AbstractTaggedValueArgum
                 } else {
                     // Set count as a TaggedValuePointable.
                     try {
-                        FunctionHelper.arithmeticOperation(aOpDivide, dCtx, tvpSum, tvpCount, tvpSum, tp1, tp2);
+                        divide.compute(tvpSum, tvpCount, tvpSum);
                         result.set(tvpSum);
                     } catch (Exception e) {
                         throw new AlgebricksException(e);
@@ -112,9 +114,9 @@ public class AvgGlobalAggregateEvaluatorFactory extends AbstractTaggedValueArgum
                         return;
                     } else if (seqLen == 2) {
                         seq.getEntry(0, tvpArg);
-                        FunctionHelper.arithmeticOperation(aOp, dCtx, tvpArg, tvpCount, tvpCount, tp1, tp2);
+                        add1.compute(tvpArg, tvpCount, tvpCount);
                         seq.getEntry(1, tvpArg);
-                        FunctionHelper.arithmeticOperation(aOp, dCtx, tvpArg, tvpSum, tvpSum, tp1, tp2);
+                        add2.compute(tvpArg, tvpSum, tvpSum);
                     } else {
                         throw new SystemException(ErrorCode.SYSE0001);
                     }

http://git-wip-us.apache.org/repos/asf/vxquery/blob/d5101a17/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/aggregate/AvgLocalAggregateEvaluatorFactory.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/aggregate/AvgLocalAggregateEvaluatorFactory.java b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/aggregate/AvgLocalAggregateEvaluatorFactory.java
index e325165..6eac723 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/aggregate/AvgLocalAggregateEvaluatorFactory.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/aggregate/AvgLocalAggregateEvaluatorFactory.java
@@ -19,7 +19,6 @@ package org.apache.vxquery.runtime.functions.aggregate;
 import java.io.DataOutput;
 
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
-import org.apache.vxquery.datamodel.accessors.TypedPointables;
 import org.apache.vxquery.datamodel.builders.sequence.SequenceBuilder;
 import org.apache.vxquery.datamodel.values.ValueTag;
 import org.apache.vxquery.datamodel.values.XDMConstants;
@@ -27,7 +26,7 @@ import org.apache.vxquery.exceptions.SystemException;
 import org.apache.vxquery.runtime.functions.arithmetic.AddOperation;
 import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentAggregateEvaluator;
 import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentAggregateEvaluatorFactory;
-import org.apache.vxquery.runtime.functions.util.FunctionHelper;
+import org.apache.vxquery.runtime.functions.util.ArithmeticHelper;
 
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.runtime.base.IAggregateEvaluator;
@@ -53,8 +52,7 @@ public class AvgLocalAggregateEvaluatorFactory extends AbstractTaggedValueArgume
         final ArrayBackedValueStorage abvsSeq = new ArrayBackedValueStorage();
         final SequenceBuilder sb = new SequenceBuilder();
         final AddOperation aOp = new AddOperation();
-        final TypedPointables tp1 = new TypedPointables();
-        final TypedPointables tp2 = new TypedPointables();
+        final ArithmeticHelper add = new ArithmeticHelper(aOp, dCtx);
         
         return new AbstractTaggedValueArgumentAggregateEvaluator(args) {
             long count;
@@ -106,7 +104,7 @@ public class AvgLocalAggregateEvaluatorFactory extends AbstractTaggedValueArgume
             @Override
             protected void step(TaggedValuePointable[] args) throws SystemException {
                 TaggedValuePointable tvp = args[0];
-                FunctionHelper.arithmeticOperation(aOp, dCtx, tvp, tvpSum, tvpSum, tp1, tp2);
+                add.compute(tvp, tvpSum, tvpSum);
                 count++;
             }
         };

http://git-wip-us.apache.org/repos/asf/vxquery/blob/d5101a17/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/aggregate/FnAvgAggregateEvaluatorFactory.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/aggregate/FnAvgAggregateEvaluatorFactory.java b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/aggregate/FnAvgAggregateEvaluatorFactory.java
index e1e6204..d89426b 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/aggregate/FnAvgAggregateEvaluatorFactory.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/aggregate/FnAvgAggregateEvaluatorFactory.java
@@ -29,6 +29,7 @@ import org.apache.vxquery.runtime.functions.arithmetic.AddOperation;
 import org.apache.vxquery.runtime.functions.arithmetic.DivideOperation;
 import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentAggregateEvaluator;
 import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentAggregateEvaluatorFactory;
+import org.apache.vxquery.runtime.functions.util.ArithmeticHelper;
 import org.apache.vxquery.runtime.functions.util.FunctionHelper;
 
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
@@ -53,9 +54,9 @@ public class FnAvgAggregateEvaluatorFactory extends AbstractTaggedValueArgumentA
         final ArrayBackedValueStorage abvsCount = new ArrayBackedValueStorage();
         final DataOutput dOutCount = abvsCount.getDataOutput();
         final AddOperation aOp = new AddOperation();
+        final ArithmeticHelper add = new ArithmeticHelper(aOp, dCtx);
         final DivideOperation aOpDivide = new DivideOperation();
-        final TypedPointables tp1 = new TypedPointables();
-        final TypedPointables tp2 = new TypedPointables();
+        final ArithmeticHelper divide = new ArithmeticHelper(aOpDivide, dCtx);
 
         return new AbstractTaggedValueArgumentAggregateEvaluator(args) {
             long count;
@@ -83,7 +84,7 @@ public class FnAvgAggregateEvaluatorFactory extends AbstractTaggedValueArgumentA
                         dOutCount.writeLong(count);
                         tvpCount.set(abvsCount);
 
-                        FunctionHelper.arithmeticOperation(aOpDivide, dCtx, tvpSum, tvpCount, tvpSum, tp1, tp2);
+                        divide.compute(tvpSum, tvpCount, tvpSum);
                         result.set(tvpSum);
                     } catch (Exception e) {
                         throw new AlgebricksException(e);
@@ -104,7 +105,7 @@ public class FnAvgAggregateEvaluatorFactory extends AbstractTaggedValueArgumentA
                         throw new SystemException(ErrorCode.SYSE0001, e.toString());
                     }
                 } else {
-                    FunctionHelper.arithmeticOperation(aOp, dCtx, tvp, tvpSum, tvpSum, new TypedPointables(), new TypedPointables());
+                    add.compute(tvp, tvpSum, tvpSum);
                 }
                 count++;
             }

http://git-wip-us.apache.org/repos/asf/vxquery/blob/d5101a17/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/aggregate/FnAvgScalarEvaluatorFactory.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/aggregate/FnAvgScalarEvaluatorFactory.java b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/aggregate/FnAvgScalarEvaluatorFactory.java
index e02f4e2..31fcecc 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/aggregate/FnAvgScalarEvaluatorFactory.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/aggregate/FnAvgScalarEvaluatorFactory.java
@@ -21,7 +21,6 @@ import java.io.DataOutput;
 import org.apache.vxquery.context.DynamicContext;
 import org.apache.vxquery.datamodel.accessors.SequencePointable;
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
-import org.apache.vxquery.datamodel.accessors.TypedPointables;
 import org.apache.vxquery.datamodel.values.ValueTag;
 import org.apache.vxquery.datamodel.values.XDMConstants;
 import org.apache.vxquery.exceptions.ErrorCode;
@@ -30,7 +29,7 @@ import org.apache.vxquery.runtime.functions.arithmetic.AddOperation;
 import org.apache.vxquery.runtime.functions.arithmetic.DivideOperation;
 import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluator;
 import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluatorFactory;
-import org.apache.vxquery.runtime.functions.util.FunctionHelper;
+import org.apache.vxquery.runtime.functions.util.ArithmeticHelper;
 
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluator;
@@ -57,9 +56,9 @@ public class FnAvgScalarEvaluatorFactory extends AbstractTaggedValueArgumentScal
         final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
         final DataOutput dOut = abvs.getDataOutput();
         final AddOperation aOp = new AddOperation();
+        final ArithmeticHelper add = new ArithmeticHelper(aOp, dCtx);
         final DivideOperation aOpDivide = new DivideOperation();
-        final TypedPointables tp1 = new TypedPointables();
-        final TypedPointables tp2 = new TypedPointables();
+        final ArithmeticHelper divide = new ArithmeticHelper(aOpDivide, dCtx);
 
         return new AbstractTaggedValueArgumentScalarEvaluator(args) {
             @Override
@@ -78,7 +77,7 @@ public class FnAvgScalarEvaluatorFactory extends AbstractTaggedValueArgumentScal
                                 // Init.
                                 tvpSum.set(tvpNext);
                             } else {
-                                FunctionHelper.arithmeticOperation(aOp, dCtx, tvpNext, tvpSum, tvpSum, tp1, tp2);
+                                add.compute(tvpNext, tvpSum, tvpSum);
                             }
                         }
 
@@ -92,7 +91,7 @@ public class FnAvgScalarEvaluatorFactory extends AbstractTaggedValueArgumentScal
                             throw new SystemException(ErrorCode.SYSE0001, e);
                         }
 
-                        FunctionHelper.arithmeticOperation(aOpDivide, dCtx, tvpSum, tvpCount, tvpSum, tp1, tp2);
+                        divide.compute(tvpSum, tvpCount, tvpSum);
                         result.set(tvpSum);
                     }
                 } else {

http://git-wip-us.apache.org/repos/asf/vxquery/blob/d5101a17/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/aggregate/FnSumAggregateEvaluatorFactory.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/aggregate/FnSumAggregateEvaluatorFactory.java b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/aggregate/FnSumAggregateEvaluatorFactory.java
index c9057ba..631b575 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/aggregate/FnSumAggregateEvaluatorFactory.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/aggregate/FnSumAggregateEvaluatorFactory.java
@@ -20,13 +20,12 @@ import java.io.DataOutput;
 import java.io.IOException;
 
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
-import org.apache.vxquery.datamodel.accessors.TypedPointables;
 import org.apache.vxquery.datamodel.values.ValueTag;
 import org.apache.vxquery.exceptions.SystemException;
 import org.apache.vxquery.runtime.functions.arithmetic.AddOperation;
 import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentAggregateEvaluator;
 import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentAggregateEvaluatorFactory;
-import org.apache.vxquery.runtime.functions.util.FunctionHelper;
+import org.apache.vxquery.runtime.functions.util.ArithmeticHelper;
 
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.runtime.base.IAggregateEvaluator;
@@ -47,8 +46,7 @@ public class FnSumAggregateEvaluatorFactory extends AbstractTaggedValueArgumentA
         final ArrayBackedValueStorage abvsSum = new ArrayBackedValueStorage();
         final DataOutput dOutSum = abvsSum.getDataOutput();
         final AddOperation aOp = new AddOperation();
-        final TypedPointables tp1 = new TypedPointables();
-        final TypedPointables tp2 = new TypedPointables();
+        final ArithmeticHelper add = new ArithmeticHelper(aOp, dCtx);
 
         return new AbstractTaggedValueArgumentAggregateEvaluator(args) {
             TaggedValuePointable tvpSum = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
@@ -80,7 +78,7 @@ public class FnSumAggregateEvaluatorFactory extends AbstractTaggedValueArgumentA
             @Override
             protected void step(TaggedValuePointable[] args) throws SystemException {
                 TaggedValuePointable tvp = args[0];
-                FunctionHelper.arithmeticOperation(aOp, dCtx, tvp, tvpSum, tvpSum, tp1, tp2);
+                add.compute(tvp, tvpSum, tvpSum);
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/vxquery/blob/d5101a17/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/aggregate/FnSumScalarEvaluatorFactory.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/aggregate/FnSumScalarEvaluatorFactory.java b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/aggregate/FnSumScalarEvaluatorFactory.java
index 0c82710..e70efbe 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/aggregate/FnSumScalarEvaluatorFactory.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/aggregate/FnSumScalarEvaluatorFactory.java
@@ -21,14 +21,13 @@ import java.io.DataOutput;
 import org.apache.vxquery.context.DynamicContext;
 import org.apache.vxquery.datamodel.accessors.SequencePointable;
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
-import org.apache.vxquery.datamodel.accessors.TypedPointables;
 import org.apache.vxquery.datamodel.values.ValueTag;
 import org.apache.vxquery.exceptions.ErrorCode;
 import org.apache.vxquery.exceptions.SystemException;
 import org.apache.vxquery.runtime.functions.arithmetic.AddOperation;
 import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluator;
 import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluatorFactory;
-import org.apache.vxquery.runtime.functions.util.FunctionHelper;
+import org.apache.vxquery.runtime.functions.util.ArithmeticHelper;
 
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluator;
@@ -56,8 +55,7 @@ public class FnSumScalarEvaluatorFactory extends AbstractTaggedValueArgumentScal
         final TaggedValuePointable tvpSum = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
         final VoidPointable p = (VoidPointable) VoidPointable.FACTORY.createPointable();
         final AddOperation aOp = new AddOperation();
-        final TypedPointables tp1 = new TypedPointables();
-        final TypedPointables tp2 = new TypedPointables();
+        final ArithmeticHelper add = new ArithmeticHelper(aOp, dCtx);
 
         return new AbstractTaggedValueArgumentScalarEvaluator(args) {
             @Override
@@ -91,7 +89,7 @@ public class FnSumScalarEvaluatorFactory extends AbstractTaggedValueArgumentScal
                                 // Init.
                                 tvpSum.set(tvpNext);
                             } else {
-                                FunctionHelper.arithmeticOperation(aOp, dCtx, tvpNext, tvpSum, tvpSum, tp1, tp2);
+                                add.compute(tvpNext, tvpSum, tvpSum);
                             }
                         }
                         result.set(tvpSum);

http://git-wip-us.apache.org/repos/asf/vxquery/blob/d5101a17/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/arithmetic/AbstractArithmeticScalarEvaluatorFactory.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/arithmetic/AbstractArithmeticScalarEvaluatorFactory.java b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/arithmetic/AbstractArithmeticScalarEvaluatorFactory.java
index eafb048..90e1c4e 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/arithmetic/AbstractArithmeticScalarEvaluatorFactory.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/arithmetic/AbstractArithmeticScalarEvaluatorFactory.java
@@ -16,17 +16,15 @@
 */
 package org.apache.vxquery.runtime.functions.arithmetic;
 
-
 import org.apache.vxquery.context.DynamicContext;
 import org.apache.vxquery.datamodel.accessors.SequencePointable;
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
-import org.apache.vxquery.datamodel.accessors.TypedPointables;
 import org.apache.vxquery.datamodel.values.ValueTag;
 import org.apache.vxquery.exceptions.ErrorCode;
 import org.apache.vxquery.exceptions.SystemException;
 import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluator;
 import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluatorFactory;
-import org.apache.vxquery.runtime.functions.util.FunctionHelper;
+import org.apache.vxquery.runtime.functions.util.ArithmeticHelper;
 
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluator;
@@ -45,11 +43,9 @@ public abstract class AbstractArithmeticScalarEvaluatorFactory extends
     @Override
     protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
             throws AlgebricksException {
-        final AbstractArithmeticOperation aOp = createArithmeticOperation();
-        final SequencePointable seqp = (SequencePointable) SequencePointable.FACTORY.createPointable();
         final DynamicContext dCtx = (DynamicContext) ctx.getJobletContext().getGlobalJobData();
-        final TypedPointables tp1 = new TypedPointables();
-        final TypedPointables tp2 = new TypedPointables();
+        final ArithmeticHelper aHelper = new ArithmeticHelper(createArithmeticOperation(), dCtx);
+        final SequencePointable seqp = (SequencePointable) SequencePointable.FACTORY.createPointable();
 
         return new AbstractTaggedValueArgumentScalarEvaluator(args) {
             @Override
@@ -72,11 +68,10 @@ public abstract class AbstractArithmeticScalarEvaluatorFactory extends
                     }
                     throw new SystemException(ErrorCode.XPTY0004);
                 }
-                FunctionHelper.arithmeticOperation(aOp, dCtx, tvp1, tvp2, result, tp1, tp2);
+                aHelper.compute(tvp1, tvp2, result);
             }
         };
     }
 
-
     protected abstract AbstractArithmeticOperation createArithmeticOperation();
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/vxquery/blob/d5101a17/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/util/ArithmeticHelper.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/util/ArithmeticHelper.java b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/util/ArithmeticHelper.java
new file mode 100644
index 0000000..0c2b41a
--- /dev/null
+++ b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/util/ArithmeticHelper.java
@@ -0,0 +1,511 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.vxquery.runtime.functions.util;
+
+import java.io.DataOutput;
+
+import org.apache.vxquery.context.DynamicContext;
+import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
+import org.apache.vxquery.datamodel.accessors.TypedPointables;
+import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.exceptions.ErrorCode;
+import org.apache.vxquery.exceptions.SystemException;
+import org.apache.vxquery.runtime.functions.arithmetic.AbstractArithmeticOperation;
+import org.apache.vxquery.runtime.functions.cast.CastToDoubleOperation;
+import org.apache.vxquery.types.BuiltinTypeConstants;
+import org.apache.vxquery.types.BuiltinTypeRegistry;
+
+import edu.uci.ics.hyracks.data.std.api.IPointable;
+import edu.uci.ics.hyracks.data.std.primitive.DoublePointable;
+import edu.uci.ics.hyracks.data.std.primitive.LongPointable;
+import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
+
+public class ArithmeticHelper {
+    private final AbstractArithmeticOperation aOp;
+    private final DynamicContext dCtx;
+    private final TypedPointables tp1;
+    private final TypedPointables tp2;
+    private final ArrayBackedValueStorage abvs;
+    private final DataOutput dOut;
+    private final ArrayBackedValueStorage abvsArgument1;
+    private final DataOutput dOutArgument1;
+    private final ArrayBackedValueStorage abvsArgument2;
+    private final DataOutput dOutArgument2;
+    private final CastToDoubleOperation castToDouble;
+
+    public ArithmeticHelper(AbstractArithmeticOperation aOp, DynamicContext dCtx) {
+        this.aOp = aOp;
+        this.dCtx = dCtx;
+        tp1 = new TypedPointables();
+        tp2 = new TypedPointables();
+        abvs = new ArrayBackedValueStorage();
+        dOut = abvs.getDataOutput();
+        abvsArgument1 = new ArrayBackedValueStorage();
+        dOutArgument1 = abvsArgument1.getDataOutput();
+        abvsArgument2 = new ArrayBackedValueStorage();
+        dOutArgument2 = abvsArgument2.getDataOutput();
+        castToDouble = new CastToDoubleOperation();
+    }
+
+    public void compute(TaggedValuePointable tvp1, TaggedValuePointable tvp2, IPointable result) throws SystemException {
+        abvs.reset();
+        try {
+            int tid1 = getBaseTypeForArithmetics(tvp1.getTag());
+            int tid2 = getBaseTypeForArithmetics(tvp2.getTag());
+            LongPointable longp1 = (LongPointable) LongPointable.FACTORY.createPointable();
+            DoublePointable doublep1 = (DoublePointable) DoublePointable.FACTORY.createPointable();
+            switch (tvp1.getTag()) {
+                case ValueTag.XS_INTEGER_TAG:
+                case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
+                case ValueTag.XS_NEGATIVE_INTEGER_TAG:
+                case ValueTag.XS_LONG_TAG:
+                case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
+                case ValueTag.XS_UNSIGNED_LONG_TAG:
+                case ValueTag.XS_POSITIVE_INTEGER_TAG:
+                case ValueTag.XS_INT_TAG:
+                case ValueTag.XS_UNSIGNED_INT_TAG:
+                case ValueTag.XS_SHORT_TAG:
+                case ValueTag.XS_UNSIGNED_SHORT_TAG:
+                case ValueTag.XS_BYTE_TAG:
+                case ValueTag.XS_UNSIGNED_BYTE_TAG:
+                    abvsArgument1.reset();
+                    FunctionHelper.getIntegerPointable(tvp1, dOutArgument1, tp1);
+                    longp1.set(abvsArgument1.getByteArray(), abvsArgument1.getStartOffset() + 1,
+                            LongPointable.TYPE_TRAITS.getFixedLength());
+                    break;
+                case ValueTag.XS_DOUBLE_TAG:
+                    tvp1.getValue(doublep1);
+                    break;
+                case ValueTag.XS_UNTYPED_ATOMIC_TAG:
+                    tid1 = ValueTag.XS_DOUBLE_TAG;
+                    tvp1.getValue(tp1.utf8sp);
+                    abvsArgument1.reset();
+                    castToDouble.convertUntypedAtomic(tp1.utf8sp, dOutArgument1);
+                    doublep1.set(abvsArgument1.getByteArray(), abvsArgument1.getStartOffset() + 1,
+                            DoublePointable.TYPE_TRAITS.getFixedLength());
+                    break;
+            }
+            LongPointable longp2 = (LongPointable) LongPointable.FACTORY.createPointable();
+            DoublePointable doublep2 = (DoublePointable) DoublePointable.FACTORY.createPointable();
+            switch (tvp2.getTag()) {
+                case ValueTag.XS_INTEGER_TAG:
+                case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
+                case ValueTag.XS_NEGATIVE_INTEGER_TAG:
+                case ValueTag.XS_LONG_TAG:
+                case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
+                case ValueTag.XS_UNSIGNED_LONG_TAG:
+                case ValueTag.XS_POSITIVE_INTEGER_TAG:
+                case ValueTag.XS_INT_TAG:
+                case ValueTag.XS_UNSIGNED_INT_TAG:
+                case ValueTag.XS_SHORT_TAG:
+                case ValueTag.XS_UNSIGNED_SHORT_TAG:
+                case ValueTag.XS_BYTE_TAG:
+                case ValueTag.XS_UNSIGNED_BYTE_TAG:
+                    abvsArgument2.reset();
+                    FunctionHelper.getIntegerPointable(tvp2, dOutArgument2, tp2);
+                    longp2.set(abvsArgument2.getByteArray(), abvsArgument2.getStartOffset() + 1,
+                            LongPointable.TYPE_TRAITS.getFixedLength());
+                    break;
+                case ValueTag.XS_DOUBLE_TAG:
+                    tvp2.getValue(doublep2);
+                    break;
+                case ValueTag.XS_UNTYPED_ATOMIC_TAG:
+                    tid2 = ValueTag.XS_DOUBLE_TAG;
+                    tvp2.getValue(tp2.utf8sp);
+                    abvsArgument2.reset();
+                    castToDouble.convertUntypedAtomic(tp2.utf8sp, dOutArgument2);
+                    doublep2.set(abvsArgument2.getByteArray(), abvsArgument2.getStartOffset() + 1,
+                            DoublePointable.TYPE_TRAITS.getFixedLength());
+                    break;
+            }
+            switch (tid1) {
+                case ValueTag.XS_DECIMAL_TAG:
+                    tvp1.getValue(tp1.decp);
+                    switch (tid2) {
+                        case ValueTag.XS_DECIMAL_TAG:
+                            tvp2.getValue(tp2.decp);
+                            aOp.operateDecimalDecimal(tp1.decp, tp2.decp, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_INTEGER_TAG:
+                            aOp.operateDecimalInteger(tp1.decp, longp2, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_FLOAT_TAG:
+                            tvp2.getValue(tp2.floatp);
+                            aOp.operateDecimalFloat(tp1.decp, tp2.floatp, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_DOUBLE_TAG:
+                            aOp.operateDecimalDouble(tp1.decp, doublep2, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_DAY_TIME_DURATION_TAG:
+                            tvp2.getValue(tp2.longp);
+                            aOp.operateDecimalDTDuration(tp1.decp, tp2.longp, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_YEAR_MONTH_DURATION_TAG:
+                            tvp2.getValue(tp2.intp);
+                            aOp.operateDecimalYMDuration(tp1.decp, tp2.intp, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+                    }
+                    break;
+
+                case ValueTag.XS_INTEGER_TAG:
+                    switch (tid2) {
+                        case ValueTag.XS_DECIMAL_TAG:
+                            tvp2.getValue(tp2.decp);
+                            aOp.operateIntegerDecimal(longp1, tp2.decp, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_INTEGER_TAG:
+                            aOp.operateIntegerInteger(longp1, longp2, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_FLOAT_TAG:
+                            tvp2.getValue(tp2.floatp);
+                            aOp.operateIntegerFloat(longp1, tp2.floatp, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_DOUBLE_TAG:
+                            aOp.operateIntegerDouble(longp1, doublep2, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_DAY_TIME_DURATION_TAG:
+                            tvp2.getValue(tp2.longp);
+                            aOp.operateIntegerDTDuration(longp1, tp2.longp, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_YEAR_MONTH_DURATION_TAG:
+                            tvp2.getValue(tp2.intp);
+                            aOp.operateIntegerYMDuration(longp1, tp2.intp, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+                    }
+                    break;
+
+                case ValueTag.XS_FLOAT_TAG:
+                    tvp1.getValue(tp1.floatp);
+                    switch (tid2) {
+                        case ValueTag.XS_DECIMAL_TAG:
+                            tvp2.getValue(tp2.decp);
+                            aOp.operateFloatDecimal(tp1.floatp, tp2.decp, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_INTEGER_TAG:
+                            aOp.operateFloatInteger(tp1.floatp, longp2, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_FLOAT_TAG:
+                            tvp2.getValue(tp2.floatp);
+                            aOp.operateFloatFloat(tp1.floatp, tp2.floatp, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_DOUBLE_TAG:
+                            aOp.operateFloatDouble(tp1.floatp, doublep2, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_DAY_TIME_DURATION_TAG:
+                            tvp2.getValue(tp2.longp);
+                            aOp.operateFloatDTDuration(tp1.floatp, tp2.longp, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_YEAR_MONTH_DURATION_TAG:
+                            tvp2.getValue(tp2.intp);
+                            aOp.operateFloatYMDuration(tp1.floatp, tp2.intp, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+                    }
+                    break;
+
+                case ValueTag.XS_DOUBLE_TAG:
+                    switch (tid2) {
+                        case ValueTag.XS_DECIMAL_TAG:
+                            tvp2.getValue(tp2.decp);
+                            aOp.operateDoubleDecimal(doublep1, tp2.decp, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_INTEGER_TAG:
+                            aOp.operateDoubleInteger(doublep1, longp2, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_FLOAT_TAG:
+                            tvp2.getValue(tp2.floatp);
+                            aOp.operateDoubleFloat(doublep1, tp2.floatp, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_DOUBLE_TAG:
+                            aOp.operateDoubleDouble(doublep1, doublep2, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_DAY_TIME_DURATION_TAG:
+                            tvp2.getValue(tp2.longp);
+                            aOp.operateDoubleDTDuration(doublep1, tp2.longp, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_YEAR_MONTH_DURATION_TAG:
+                            tvp2.getValue(tp2.intp);
+                            aOp.operateDoubleYMDuration(doublep1, tp2.intp, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+                    }
+                    break;
+
+                case ValueTag.XS_DATE_TAG:
+                    tvp1.getValue(tp1.datep);
+                    switch (tid2) {
+                        case ValueTag.XS_DATE_TAG:
+                            tvp2.getValue(tp2.datep);
+                            aOp.operateDateDate(tp1.datep, tp2.datep, dCtx, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_DAY_TIME_DURATION_TAG:
+                            tvp2.getValue(tp2.longp);
+                            aOp.operateDateDTDuration(tp1.datep, tp2.longp, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_YEAR_MONTH_DURATION_TAG:
+                            tvp2.getValue(tp2.intp);
+                            aOp.operateDateYMDuration(tp1.datep, tp2.intp, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+                    }
+                    break;
+
+                case ValueTag.XS_DATETIME_TAG:
+                    tvp1.getValue(tp1.datetimep);
+                    switch (tid2) {
+                        case ValueTag.XS_DATETIME_TAG:
+                            tvp2.getValue(tp2.datetimep);
+                            aOp.operateDatetimeDatetime(tp1.datetimep, tp2.datetimep, dCtx, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_DAY_TIME_DURATION_TAG:
+                            tvp2.getValue(tp2.longp);
+                            aOp.operateDatetimeDTDuration(tp1.datetimep, tp2.longp, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_YEAR_MONTH_DURATION_TAG:
+                            tvp2.getValue(tp2.intp);
+                            aOp.operateDatetimeYMDuration(tp1.datetimep, tp2.intp, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+                    }
+                    break;
+
+                case ValueTag.XS_TIME_TAG:
+                    tvp1.getValue(tp1.timep);
+                    switch (tid2) {
+                        case ValueTag.XS_TIME_TAG:
+                            tvp2.getValue(tp2.timep);
+                            aOp.operateTimeTime(tp1.timep, tp2.timep, dCtx, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_DAY_TIME_DURATION_TAG:
+                            tvp2.getValue(tp2.longp);
+                            aOp.operateTimeDTDuration(tp1.timep, tp2.longp, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                    }
+                    break;
+
+                case ValueTag.XS_DAY_TIME_DURATION_TAG:
+                    tvp1.getValue(tp1.longp);
+                    switch (tid2) {
+                        case ValueTag.XS_DECIMAL_TAG:
+                            tvp2.getValue(tp2.decp);
+                            aOp.operateDTDurationDecimal(tp1.longp, tp2.decp, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_INTEGER_TAG:
+                            aOp.operateDTDurationInteger(tp1.longp, longp2, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_FLOAT_TAG:
+                            tvp2.getValue(tp2.floatp);
+                            aOp.operateDTDurationFloat(tp1.longp, tp2.floatp, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_DOUBLE_TAG:
+                            aOp.operateDTDurationDouble(tp1.longp, doublep2, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_DATE_TAG:
+                            tvp2.getValue(tp2.datep);
+                            aOp.operateDTDurationDate(tp1.longp, tp2.datep, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_TIME_TAG:
+                            tvp2.getValue(tp2.timep);
+                            aOp.operateDTDurationTime(tp1.longp, tp2.timep, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_DATETIME_TAG:
+                            tvp2.getValue(tp2.datetimep);
+                            aOp.operateDTDurationDatetime(tp1.longp, tp2.datetimep, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_DAY_TIME_DURATION_TAG:
+                            tvp2.getValue(tp2.longp);
+                            aOp.operateDTDurationDTDuration(tp1.longp, tp2.longp, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+                    }
+                    break;
+
+                case ValueTag.XS_YEAR_MONTH_DURATION_TAG:
+                    tvp1.getValue(tp1.intp);
+                    switch (tid2) {
+                        case ValueTag.XS_DECIMAL_TAG:
+                            tvp2.getValue(tp2.decp);
+                            aOp.operateYMDurationDecimal(tp1.intp, tp2.decp, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_INTEGER_TAG:
+                            aOp.operateYMDurationInteger(tp1.intp, longp2, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_FLOAT_TAG:
+                            tvp2.getValue(tp2.floatp);
+                            aOp.operateYMDurationFloat(tp1.intp, tp2.floatp, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_DOUBLE_TAG:
+                            aOp.operateYMDurationDouble(tp1.intp, doublep2, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_DATE_TAG:
+                            tvp2.getValue(tp2.datep);
+                            aOp.operateYMDurationDate(tp1.intp, tp2.datep, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_DATETIME_TAG:
+                            tvp2.getValue(tp2.datetimep);
+                            aOp.operateYMDurationDatetime(tp1.intp, tp2.datetimep, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+
+                        case ValueTag.XS_YEAR_MONTH_DURATION_TAG:
+                            tvp2.getValue(tp2.intp);
+                            aOp.operateYMDurationYMDuration(tp1.intp, tp2.intp, dOut);
+                            result.set(abvs.getByteArray(), 0, abvs.getLength());
+                            return;
+                    }
+                    break;
+            }
+        } catch (SystemException se) {
+            throw se;
+        } catch (Exception e) {
+            throw new SystemException(ErrorCode.SYSE0001, e);
+        }
+        throw new SystemException(ErrorCode.XPTY0004);
+    }
+
+    public static int getBaseTypeForArithmetics(int tid) throws SystemException {
+        if (tid >= BuiltinTypeConstants.BUILTIN_TYPE_COUNT) {
+            throw new SystemException(ErrorCode.XPTY0004);
+        }
+        while (true) {
+            switch (tid) {
+                case ValueTag.XS_STRING_TAG:
+                case ValueTag.XS_DECIMAL_TAG:
+                case ValueTag.XS_INTEGER_TAG:
+                case ValueTag.XS_FLOAT_TAG:
+                case ValueTag.XS_DOUBLE_TAG:
+                case ValueTag.XS_ANY_URI_TAG:
+                case ValueTag.XS_BOOLEAN_TAG:
+                case ValueTag.XS_DATE_TAG:
+                case ValueTag.XS_DATETIME_TAG:
+                case ValueTag.XS_TIME_TAG:
+                case ValueTag.XS_DAY_TIME_DURATION_TAG:
+                case ValueTag.XS_YEAR_MONTH_DURATION_TAG:
+                case ValueTag.XS_BASE64_BINARY_TAG:
+                case ValueTag.XS_HEX_BINARY_TAG:
+                case ValueTag.XS_QNAME_TAG:
+                case ValueTag.XS_G_DAY_TAG:
+                case ValueTag.XS_G_MONTH_DAY_TAG:
+                case ValueTag.XS_G_MONTH_TAG:
+                case ValueTag.XS_G_YEAR_MONTH_TAG:
+                case ValueTag.XS_G_YEAR_TAG:
+                case ValueTag.XS_UNTYPED_ATOMIC_TAG:
+                    return tid;
+
+                case ValueTag.XS_LONG_TAG:
+                case ValueTag.XS_NEGATIVE_INTEGER_TAG:
+                case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
+                case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
+                case ValueTag.XS_POSITIVE_INTEGER_TAG:
+                case ValueTag.XS_UNSIGNED_INT_TAG:
+                case ValueTag.XS_UNSIGNED_LONG_TAG:
+                case ValueTag.XS_INT_TAG:
+                case ValueTag.XS_UNSIGNED_SHORT_TAG:
+                case ValueTag.XS_SHORT_TAG:
+                case ValueTag.XS_UNSIGNED_BYTE_TAG:
+                case ValueTag.XS_BYTE_TAG:
+                    return ValueTag.XS_INTEGER_TAG;
+
+                case ValueTag.XS_ANY_ATOMIC_TAG:
+                    throw new SystemException(ErrorCode.XPTY0004);
+
+                default:
+                    tid = BuiltinTypeRegistry.INSTANCE.getSchemaTypeById(tid).getBaseType().getTypeId();
+                    return tid;
+            }
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/vxquery/blob/d5101a17/vxquery-core/src/main/java/org/apache/vxquery/xmlparser/SAXContentHandler.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/xmlparser/SAXContentHandler.java b/vxquery-core/src/main/java/org/apache/vxquery/xmlparser/SAXContentHandler.java
index e40147e..296d062 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/xmlparser/SAXContentHandler.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/xmlparser/SAXContentHandler.java
@@ -22,6 +22,7 @@ import java.util.List;
 
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
 import org.apache.vxquery.datamodel.accessors.nodes.NodeTreePointable;
+import org.apache.vxquery.datamodel.builders.atomic.UTF8StringBuilder;
 import org.apache.vxquery.datamodel.builders.nodes.AbstractNodeBuilder;
 import org.apache.vxquery.datamodel.builders.nodes.AttributeNodeBuilder;
 import org.apache.vxquery.datamodel.builders.nodes.CommentNodeBuilder;
@@ -30,7 +31,6 @@ import org.apache.vxquery.datamodel.builders.nodes.DocumentNodeBuilder;
 import org.apache.vxquery.datamodel.builders.nodes.ElementNodeBuilder;
 import org.apache.vxquery.datamodel.builders.nodes.PINodeBuilder;
 import org.apache.vxquery.datamodel.builders.nodes.TextNodeBuilder;
-import org.apache.vxquery.datamodel.builders.nodes.UTF8StringBuilder;
 import org.apache.vxquery.datamodel.values.ValueTag;
 import org.apache.vxquery.types.BuiltinTypeQNames;
 import org.apache.vxquery.types.ElementType;

http://git-wip-us.apache.org/repos/asf/vxquery/blob/d5101a17/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/query/XMLQueryCompiler.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/query/XMLQueryCompiler.java b/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/query/XMLQueryCompiler.java
index 0e18328..263a93d 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/query/XMLQueryCompiler.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/query/XMLQueryCompiler.java
@@ -90,11 +90,11 @@ public class XMLQueryCompiler {
     private String[] nodeList;
 
     public XMLQueryCompiler(XQueryCompilationListener listener, String[] nodeList, int frameSize) {
-        this(listener, nodeList, frameSize, -1, -1);
+        this(listener, nodeList, frameSize, -1, -1, -1);
     }
 
     public XMLQueryCompiler(XQueryCompilationListener listener, String[] nodeList, int frameSize,
-            int availableProcessors, long joinHashSize) {
+            int availableProcessors, long joinHashSize, long maximumDataSize) {
         this.listener = listener == null ? NoopXQueryCompilationListener.INSTANCE : listener;
         this.frameSize = frameSize;
         this.nodeList = nodeList;
@@ -115,10 +115,10 @@ public class XMLQueryCompiler {
         if (joinHashSize > 0) {
             builder.getPhysicalOptimizationConfig().setMaxFramesHybridHash((int) (joinHashSize / this.frameSize));
         }
-
-        builder.getPhysicalOptimizationConfig().setMaxFramesLeftInputHybridHash(
-                (int) (60L * 1024 * 1048576 / this.frameSize));
-
+        if (maximumDataSize > 0) {
+            builder.getPhysicalOptimizationConfig().setMaxFramesLeftInputHybridHash(
+                    (int) (maximumDataSize / this.frameSize));
+        }
         builder.setLogicalRewrites(buildDefaultLogicalRewrites());
         builder.setPhysicalRewrites(buildDefaultPhysicalRewrites());
         builder.setSerializerDeserializerProvider(new ISerializerDeserializerProvider() {

http://git-wip-us.apache.org/repos/asf/vxquery/blob/d5101a17/vxquery-server/src/main/resources/conf/cluster.properties
----------------------------------------------------------------------
diff --git a/vxquery-server/src/main/resources/conf/cluster.properties b/vxquery-server/src/main/resources/conf/cluster.properties
index 4614898..9f7d950 100644
--- a/vxquery-server/src/main/resources/conf/cluster.properties
+++ b/vxquery-server/src/main/resources/conf/cluster.properties
@@ -35,7 +35,8 @@ NCLOGS_DIR=$VXTMP_DIR/logs
 JAVA_HOME=$JAVA_HOME
 
 #The directory to put cc logs
-CCOPTS=" -cc-root ${CCTMP_DIR} "
+CCOPTS=" -cc-root ${CCTMP_DIR} -heartbeat-period 60000 -max-heartbeat-lapse-periods 10 "
+
 
 #The directory to put nc logs
 NCOPTS=" -iodevices /home/ecarman/disk1/tmp/,/home/ecarman/disk2/tmp/ "


Mime
View raw message