asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jianf...@apache.org
Subject [02/15] incubator-asterixdb git commit: ASTERIXDB-1102: VarSize Encoding to store length of String and ByteArray
Date Thu, 29 Oct 2015 04:44:53 GMT
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringReplaceWithFlagsDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringReplaceWithFlagsDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringReplaceWithFlagsDescriptor.java
index 597e9c0..1511d0d 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringReplaceWithFlagsDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringReplaceWithFlagsDescriptor.java
@@ -18,31 +18,22 @@
  */
 package org.apache.asterix.runtime.evaluators.functions;
 
-import java.io.ByteArrayInputStream;
-import java.io.DataInputStream;
 import java.io.DataOutput;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.apache.asterix.common.utils.UTF8CharSequence;
-import org.apache.asterix.formats.nontagged.AqlBinaryComparatorFactoryProvider;
-import org.apache.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
-import org.apache.asterix.om.base.AString;
 import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
-import org.apache.asterix.om.types.BuiltinType;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
-import org.apache.hyracks.api.dataflow.value.IBinaryComparator;
-import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
-import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.data.std.api.IDataOutputProvider;
-import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
+import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.util.ByteArrayAccessibleOutputStream;
+import org.apache.hyracks.data.std.util.UTF8CharSequence;
 
 public class StringReplaceWithFlagsDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
@@ -67,105 +58,58 @@ public class StringReplaceWithFlagsDescriptor extends AbstractScalarFunctionDyna
 
                 return new AbstractQuadStringStringEval(dout, args[0], args[1], args[2], args[3],
                         AsterixBuiltinFunctions.STRING_REPLACE_WITH_FLAG) {
-
                     private Pattern pattern = null;
                     private Matcher matcher = null;
-                    private String strPattern = "";
-                    private String replace = "";
-                    private int flags = 0;
+                    private String replaceStr;
+                    private String flagStr;
                     private StringBuffer resultBuf = new StringBuffer();
-                    private ByteArrayAccessibleOutputStream lastPattern = new ByteArrayAccessibleOutputStream();
-                    private ByteArrayAccessibleOutputStream lastFlags = new ByteArrayAccessibleOutputStream();
-                    private ByteArrayAccessibleOutputStream lastReplace = new ByteArrayAccessibleOutputStream();
-                    private IBinaryComparator strComp = AqlBinaryComparatorFactoryProvider.INSTANCE
-                            .getBinaryComparatorFactory(BuiltinType.ASTRING, true).createBinaryComparator();
+                    private ByteArrayAccessibleOutputStream lastPatternStorage = new ByteArrayAccessibleOutputStream();
+                    private ByteArrayAccessibleOutputStream lastReplaceStorage = new ByteArrayAccessibleOutputStream();
+                    private ByteArrayAccessibleOutputStream lastFlagStorage = new ByteArrayAccessibleOutputStream();
+                    private UTF8StringPointable lastPatternPtr = new UTF8StringPointable();
+                    private UTF8StringPointable lastReplacePtr = new UTF8StringPointable();
+                    private UTF8StringPointable lastFlagPtr = new UTF8StringPointable();
                     private UTF8CharSequence carSeq = new UTF8CharSequence();
-                    @SuppressWarnings("unchecked")
-                    private ISerializerDeserializer<AString> stringSerde = AqlSerializerDeserializerProvider.INSTANCE
-                            .getSerializerDeserializer(BuiltinType.ASTRING);
 
                     @Override
-                    protected String compute(byte[] b0, int l0, int s0, byte[] b1, int l1, int s1, byte[] b2, int l2,
-                            int s2, byte[] b3, int l3, int s3, ArrayBackedValueStorage array0,
-                            ArrayBackedValueStorage array1) throws AlgebricksException {
-                        try {
-                            boolean newPattern = false;
-                            boolean newFlags = false;
-                            boolean newReplace = false;
-
-                            AString astrPattern;
-                            AString astrFlags;
-
-                            if (pattern == null) {
-                                newPattern = true;
-                                newFlags = true;
-                            } else {
-                                int c = strComp.compare(b1, s1, l1, lastPattern.getByteArray(), 0, lastPattern.size());
-                                if (c != 0) {
-                                    newPattern = true;
-                                }
-
-                                c = strComp.compare(b3, s3, l3, lastFlags.getByteArray(), 0, lastFlags.size());
-                                if (c != 0) {
-                                    newFlags = true;
-                                }
-                            }
-
-                            if (replace == null) {
-                                newReplace = true;
-                            } else {
-                                int c = strComp.compare(b2, s2, l2, lastReplace.getByteArray(), 0, lastReplace.size());
-                                if (c != 0) {
-                                    newReplace = true;
-                                }
-                            }
-
-                            if (newPattern) {
-                                lastPattern.reset();
-                                lastPattern.write(b1, s1, l1);
-                                // ! object creation !
-                                DataInputStream di = new DataInputStream(new ByteArrayInputStream(
-                                        lastPattern.getByteArray()));
-                                astrPattern = (AString) stringSerde.deserialize(di);
-                                // strPattern = toRegex(astrPattern);
-                                strPattern = astrPattern.getStringValue();
-                            }
-                            if (newReplace) {
-                                lastReplace.reset();
-                                lastReplace.write(b2, s2, l2);
-                                // ! object creation !
-                                DataInputStream di = new DataInputStream(new ByteArrayInputStream(
-                                        lastReplace.getByteArray()));
-                                replace = ((AString) stringSerde.deserialize(di)).getStringValue();
-                            }
-                            if (newFlags) {
-                                lastFlags.reset();
-                                lastFlags.write(b3, s3, l3);
-                                // ! object creation !
-                                DataInputStream di = new DataInputStream(new ByteArrayInputStream(
-                                        lastFlags.getByteArray()));
-                                astrFlags = (AString) stringSerde.deserialize(di);
-                                flags = StringEvaluatorUtils.toFlag(astrFlags);
-                            }
-
-                            if (newPattern || newFlags)
-                                pattern = Pattern.compile(strPattern, flags);
-                            resultBuf.setLength(0);
-                            carSeq.reset(array0, 1);
-                            if (newPattern) {
-                                matcher = pattern.matcher(carSeq);
-                            } else {
-                                matcher.reset(carSeq);
-                            }
-                            while (matcher.find()) {
-                                matcher.appendReplacement(resultBuf, replace);
-                            }
-                            matcher.appendTail(resultBuf);
-                            return resultBuf.toString();
-                        } catch (HyracksDataException e) {
-                            throw new AlgebricksException(e);
+                    protected String compute(UTF8StringPointable srcPtr, UTF8StringPointable patternPtr,
+                            UTF8StringPointable replacePtr, UTF8StringPointable flagPtr) throws AlgebricksException {
+                        resultBuf.setLength(0);
+                        final boolean newPattern = (pattern == null || lastPatternPtr.compareTo(patternPtr) != 0);
+                        final boolean newReplace = (pattern == null || lastReplacePtr.compareTo(replacePtr) != 0);
+                        final boolean newFlag = (pattern == null || lastFlagPtr.compareTo(flagPtr) != 0);
+
+                        if (newFlag) {
+                            StringEvaluatorUtils.copyResetUTF8Pointable(flagPtr, lastFlagStorage, lastFlagPtr);
+                            flagStr = lastFlagPtr.toString();
+                        }
+                        if (newPattern) {
+                            StringEvaluatorUtils.copyResetUTF8Pointable(patternPtr, lastPatternStorage, lastPatternPtr);
+                        }
+
+                        if (newPattern || newFlag) {
+                            pattern = Pattern.compile(lastPatternPtr.toString(), StringEvaluatorUtils.toFlag(flagStr));
+                        }
+
+                        if (newReplace) {
+                            StringEvaluatorUtils.copyResetUTF8Pointable(replacePtr, lastReplaceStorage, lastReplacePtr);
+                            replaceStr = replacePtr.toString();
                         }
+
+                        carSeq.reset(srcPtr);
+                        if (newPattern || newFlag) {
+                            matcher = pattern.matcher(carSeq);
+                        } else {
+                            matcher.reset(carSeq);
+                        }
+
+                        while (matcher.find()) {
+                            matcher.appendReplacement(resultBuf, replaceStr);
+                        }
+                        matcher.appendTail(resultBuf);
+                        return resultBuf.toString();
                     }
+
                 };
             }
         };

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringStartWithDescrtiptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringStartWithDescrtiptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringStartWithDescrtiptor.java
deleted file mode 100644
index 4920443..0000000
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringStartWithDescrtiptor.java
+++ /dev/null
@@ -1,87 +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.asterix.runtime.evaluators.functions;
-
-import java.io.DataOutput;
-
-import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
-import org.apache.asterix.om.functions.IFunctionDescriptor;
-import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
-import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
-import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
-import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
-import org.apache.hyracks.data.std.api.IDataOutputProvider;
-import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
-import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
-
-public class StringStartWithDescrtiptor extends AbstractScalarFunctionDynamicDescriptor {
-    private static final long serialVersionUID = 1L;
-
-    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
-        public IFunctionDescriptor createFunctionDescriptor() {
-            return new StringStartWithDescrtiptor();
-        }
-    };
-
-    @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
-
-        return new ICopyEvaluatorFactory() {
-            private static final long serialVersionUID = 1L;
-
-            @Override
-            public ICopyEvaluator createEvaluator(IDataOutputProvider output) throws AlgebricksException {
-
-                DataOutput dout = output.getDataOutput();
-
-                return new AbstractBinaryStringBoolEval(dout, args[0], args[1],
-                        AsterixBuiltinFunctions.STRING_START_WITH) {
-
-                    @Override
-                    protected boolean compute(byte[] lBytes, int lLen, int lStart, byte[] rBytes, int rLen, int rStart,
-                            ArrayBackedValueStorage array0, ArrayBackedValueStorage array1) {
-                        int patternLength = UTF8StringPointable.getUTFLength(rBytes, 1);
-                        if (patternLength > UTF8StringPointable.getUTFLength(lBytes, 1))
-                            return false;
-
-                        int pos = 3;
-                        while (pos < patternLength + 3) {
-                            char c1 = UTF8StringPointable.charAt(lBytes, pos);
-                            char c2 = UTF8StringPointable.charAt(rBytes, pos);
-                            if (c1 != c2)
-                                return false;
-
-                            pos += UTF8StringPointable.charSize(lBytes, pos);
-                        }
-
-                        return true;
-                    }
-
-                };
-            }
-        };
-    }
-
-    @Override
-    public FunctionIdentifier getIdentifier() {
-        return AsterixBuiltinFunctions.STRING_START_WITH;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringStartsWithDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringStartsWithDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringStartsWithDescriptor.java
new file mode 100644
index 0000000..8fcca3c
--- /dev/null
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringStartsWithDescriptor.java
@@ -0,0 +1,72 @@
+/*
+ * 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.asterix.runtime.evaluators.functions;
+
+import java.io.DataOutput;
+
+import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
+import org.apache.asterix.om.functions.IFunctionDescriptor;
+import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
+import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
+
+public class StringStartsWithDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+    private static final long serialVersionUID = 1L;
+
+    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        public IFunctionDescriptor createFunctionDescriptor() {
+            return new StringStartsWithDescriptor();
+        }
+    };
+
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
+
+        return new ICopyEvaluatorFactory() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public ICopyEvaluator createEvaluator(IDataOutputProvider output) throws AlgebricksException {
+
+                DataOutput dout = output.getDataOutput();
+
+                return new AbstractBinaryStringBoolEval(dout, args[0], args[1],
+                        AsterixBuiltinFunctions.STRING_STARTS_WITH) {
+
+                    @Override
+                    protected boolean compute(UTF8StringPointable left, UTF8StringPointable right)
+                            throws AlgebricksException {
+                        return UTF8StringPointable.startsWith(left, right, false);
+                    }
+                };
+            }
+        };
+    }
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return AsterixBuiltinFunctions.STRING_STARTS_WITH;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringToCodePointDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringToCodePointDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringToCodePointDescriptor.java
index 3bf0dc5..654e0b6 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringToCodePointDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringToCodePointDescriptor.java
@@ -39,9 +39,9 @@ import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
 import org.apache.hyracks.data.std.api.IDataOutputProvider;
-import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+import org.apache.hyracks.util.string.UTF8StringUtil;
 
 public class StringToCodePointDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
@@ -62,7 +62,8 @@ public class StringToCodePointDescriptor extends AbstractScalarFunctionDynamicDe
             @Override
             public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
                 return new ICopyEvaluator() {
-                    protected final DataOutput out = output.getDataOutput();;
+                    protected final DataOutput out = output.getDataOutput();
+                    ;
                     protected final ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
                     protected final ICopyEvaluator stringEval = args[0].createEvaluator(argOut);
                     protected final AOrderedListType intListType = new AOrderedListType(BuiltinType.AINT64, null);
@@ -75,36 +76,6 @@ public class StringToCodePointDescriptor extends AbstractScalarFunctionDynamicDe
                             .getSerializerDeserializer(BuiltinType.AINT64);
                     private final AMutableInt64 aInt64 = new AMutableInt64(0);
 
-                    int UTF8ToCodePoint(byte[] b, int s) {
-                        if (b[s] >> 7 == 0) {
-                            // 1 byte
-                            return b[s];
-                        } else if ((b[s] & 0xe0) == 0xc0) { /*0xe0 = 0b1110000*/
-                            // 2 bytes
-                            return ((int) (b[s] & 0x1f)) << 6 | /*0x3f = 0b00111111*/
-                            ((int) (b[s + 1] & 0x3f));
-                        } else if ((b[s] & 0xf0) == 0xe0) {
-                            // 3bytes
-                            return ((int) (b[s] & 0xf)) << 12 | ((int) (b[s + 1] & 0x3f)) << 6
-                                    | ((int) (b[s + 2] & 0x3f));
-                        } else if ((b[s] & 0xf8) == 0xf0) {
-                            // 4bytes
-                            return ((int) (b[s] & 0x7)) << 18 | ((int) (b[s + 1] & 0x3f)) << 12
-                                    | ((int) (b[s + 2] & 0x3f)) << 6 | ((int) (b[s + 3] & 0x3f));
-                        } else if ((b[s] & 0xfc) == 0xf8) {
-                            // 5bytes
-                            return ((int) (b[s] & 0x3)) << 24 | ((int) (b[s + 1] & 0x3f)) << 18
-                                    | ((int) (b[s + 2] & 0x3f)) << 12 | ((int) (b[s + 3] & 0x3f)) << 6
-                                    | ((int) (b[s + 4] & 0x3f));
-                        } else if ((b[s] & 0xfe) == 0xfc) {
-                            // 6bytes
-                            return ((int) (b[s] & 0x1)) << 30 | ((int) (b[s + 1] & 0x3f)) << 24
-                                    | ((int) (b[s + 2] & 0x3f)) << 18 | ((int) (b[s + 3] & 0x3f)) << 12
-                                    | ((int) (b[s + 4] & 0x3f)) << 6 | ((int) (b[s + 5] & 0x3f));
-                        }
-                        return 0;
-                    }
-
                     @Override
                     public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
                         try {
@@ -114,13 +85,14 @@ public class StringToCodePointDescriptor extends AbstractScalarFunctionDynamicDe
 
                             if (serString[0] == SER_STRING_TYPE_TAG) {
                                 byte[] bytes = argOut.getByteArray();
-                                int len = UTF8StringPointable.getUTFLength(bytes, 1);
+                                int len = UTF8StringUtil.getUTFLength(bytes, 1);
 
-                                int pos = 3;
+                                int start = 1 + UTF8StringUtil.getNumBytesToStoreLength(len);
+                                int pos = 0;
                                 listBuilder.reset(intListType);
-                                while (pos < len + 3) {
-                                    int codePoint = UTF8ToCodePoint(bytes, pos);
-                                    pos += UTF8StringPointable.charSize(bytes, pos);
+                                while (pos < len) {
+                                    int codePoint = UTF8StringUtil.UTF8ToCodePoint(bytes, start + pos);
+                                    pos += UTF8StringUtil.charSize(bytes, start + pos);
 
                                     inputVal.reset();
                                     aInt64.setValue(codePoint);

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringUpperCaseDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringUpperCaseDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringUpperCaseDescriptor.java
index 3a13670..fc32dfd 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringUpperCaseDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringUpperCaseDescriptor.java
@@ -38,8 +38,9 @@ import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
 import org.apache.hyracks.data.std.api.IDataOutputProvider;
 import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
+import org.apache.hyracks.data.std.util.GrowableArray;
+import org.apache.hyracks.data.std.util.UTF8StringBuilder;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
-import org.apache.hyracks.dataflow.common.data.util.StringUtils;
 
 public class StringUpperCaseDescriptor extends AbstractScalarFunctionDynamicDescriptor {
     private static final long serialVersionUID = 1L;
@@ -67,6 +68,10 @@ public class StringUpperCaseDescriptor extends AbstractScalarFunctionDynamicDesc
 
                     private final byte stt = ATypeTag.STRING.serialize();
 
+                    private final GrowableArray array = new GrowableArray();
+                    private final UTF8StringBuilder builder = new UTF8StringBuilder();
+                    private final UTF8StringPointable string = new UTF8StringPointable();
+
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
@@ -80,19 +85,12 @@ public class StringUpperCaseDescriptor extends AbstractScalarFunctionDynamicDesc
                             byte[] serString = outInput.getByteArray();
 
                             if (serString[0] == SER_STRING_TYPE_TAG) {
-                                byte[] bytes = outInput.getByteArray();
-                                int len = UTF8StringPointable.getUTFLength(bytes, 1);
+                                string.set(serString, 1, serString.length);
+                                array.reset();
+                                UTF8StringPointable.uppercase(string, builder, array);
 
                                 out.writeByte(stt);
-                                StringUtils.writeUTF8Len(len, out);
-
-                                int pos = 3;
-                                while (pos < len + 3) {
-                                    char c1 = UTF8StringPointable.charAt(bytes, pos);
-                                    c1 = Character.toUpperCase(c1);
-                                    pos += UTF8StringPointable.charSize(bytes, pos);
-                                    StringUtils.writeCharAsModifiedUTF8(c1, out);
-                                }
+                                out.write(array.getByteArray(), 0, array.getLength());
                             } else if (serString[0] == SER_NULL_TYPE_TAG)
                                 nullSerde.serialize(ANull.NULL, out);
                             else

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/Substring2Descriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/Substring2Descriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/Substring2Descriptor.java
index 0a4d270..f843051 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/Substring2Descriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/Substring2Descriptor.java
@@ -36,6 +36,8 @@ import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.data.std.api.IDataOutputProvider;
 import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
+import org.apache.hyracks.data.std.util.GrowableArray;
+import org.apache.hyracks.data.std.util.UTF8StringBuilder;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
 public class Substring2Descriptor extends AbstractScalarFunctionDynamicDescriptor {
@@ -66,6 +68,10 @@ public class Substring2Descriptor extends AbstractScalarFunctionDynamicDescripto
                     private ICopyEvaluator evalStart = args[1].createEvaluator(argOut);
                     private final byte stt = ATypeTag.STRING.serialize();
 
+                    private final GrowableArray array = new GrowableArray();
+                    private final UTF8StringBuilder builder = new UTF8StringBuilder();
+                    private final UTF8StringPointable string = new UTF8StringPointable();
+
                     @Override
                     public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
                         argOut.reset();
@@ -86,29 +92,20 @@ public class Substring2Descriptor extends AbstractScalarFunctionDynamicDescripto
                                     + ": expects type STRING for the first argument but got "
                                     + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut.getByteArray()[0]));
                         }
-                        int utflen = UTF8StringPointable.getUTFLength(bytes, 1);
-                        int sStart = 3;
-                        int c = 0;
-                        int idxPos1 = 0;
-
-                        // skip to start
-                        while (idxPos1 < start && c < utflen) {
-                            c += UTF8StringPointable.charSize(bytes, sStart + c);
-                            ++idxPos1;
-                        }
-                        int startSubstr = c;
-
-                        while (c < utflen) {
-                            c += UTF8StringPointable.charSize(bytes, sStart + c);
+                        string.set(bytes, 1, bytes.length);
+                        array.reset();
+                        try {
+                            UTF8StringPointable.substr(string, start, Integer.MAX_VALUE, builder, array);
+                        } catch (StringIndexOutOfBoundsException e) {
+                            throw new AlgebricksException(AsterixBuiltinFunctions.SUBSTRING.getName() + ": start="
+                                    + start + "\tgoing past the input length.");
+                        } catch (IOException e) {
+                            throw new AlgebricksException(e);
                         }
 
-                        int substrByteLen = c - startSubstr;
                         try {
                             out.writeByte(stt);
-                            out.writeByte((byte) ((substrByteLen >>> 8) & 0xFF));
-                            out.writeByte((byte) ((substrByteLen >>> 0) & 0xFF));
-                            out.write(bytes, sStart + startSubstr, substrByteLen);
-
+                            out.write(array.getByteArray(), 0, array.getLength());
                         } catch (IOException e) {
                             throw new AlgebricksException(e);
                         }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringAfterDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringAfterDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringAfterDescriptor.java
index f2439ab..ff84986 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringAfterDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringAfterDescriptor.java
@@ -34,6 +34,8 @@ import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import org.apache.hyracks.data.std.api.IDataOutputProvider;
 import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
+import org.apache.hyracks.data.std.util.GrowableArray;
+import org.apache.hyracks.data.std.util.UTF8StringBuilder;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
 public class SubstringAfterDescriptor extends AbstractScalarFunctionDynamicDescriptor {
@@ -66,6 +68,11 @@ public class SubstringAfterDescriptor extends AbstractScalarFunctionDynamicDescr
                     private ICopyEvaluator evalPattern = args[1].createEvaluator(array1);
                     private final byte stt = ATypeTag.STRING.serialize();
 
+                    private final GrowableArray array = new GrowableArray();
+                    private final UTF8StringBuilder builder = new UTF8StringBuilder();
+                    private final UTF8StringPointable stringPtr = new UTF8StringPointable();
+                    private final UTF8StringPointable patternPtr = new UTF8StringPointable();
+
                     @Override
                     public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
                         array0.reset();
@@ -84,44 +91,25 @@ public class SubstringAfterDescriptor extends AbstractScalarFunctionDynamicDescr
                                     + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(pattern[0]) + ").");
                         }
 
-                        int srcLen = UTF8StringPointable.getUTFLength(src, 1);
-                        int patternLen = UTF8StringPointable.getUTFLength(pattern, 1);
-                        int posSrc = 3;
-                        int posPattern = 3;
-
-                        int offset = 0;
-                        // boolean found = false;
-                        while (posSrc - 3 < srcLen - patternLen) {
-                            offset = 0;
-                            while (posPattern + offset - 3 < patternLen && posSrc + offset - 3 < srcLen) {
-                                char c1 = UTF8StringPointable.charAt(src, posSrc + offset);
-                                char c2 = UTF8StringPointable.charAt(pattern, posPattern + offset);
-                                if (c1 != c2)
-                                    break;
-                                offset++;
-                            }
-                            if (offset == patternLen) {
-                                // found = true;
-                                break;
-                            }
-                            posSrc += UTF8StringPointable.charSize(src, posSrc);
-                        }
-
-                        posSrc += patternLen;
-                        int substrByteLen = srcLen - posSrc + 3;
+                        stringPtr.set(src, 1, src.length);
+                        patternPtr.set(pattern, 1, pattern.length);
+                        array.reset();
                         try {
+                            UTF8StringPointable.substrAfter(stringPtr, patternPtr, builder, array);
                             out.writeByte(stt);
-                            out.writeByte((byte) ((substrByteLen >>> 8) & 0xFF));
-                            out.writeByte((byte) ((substrByteLen >>> 0) & 0xFF));
-                            out.write(src, posSrc, substrByteLen);
-
+                            out.write(array.getByteArray(), 0, array.getLength());
                         } catch (IOException e) {
                             throw new AlgebricksException(e);
                         }
+
                     }
-                };
+                }
+
+                        ;
             }
-        };
+        }
+
+                ;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringBeforeDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringBeforeDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringBeforeDescriptor.java
index 9f6de3e..3871ed7 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringBeforeDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringBeforeDescriptor.java
@@ -34,6 +34,8 @@ import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import org.apache.hyracks.data.std.api.IDataOutputProvider;
 import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
+import org.apache.hyracks.data.std.util.GrowableArray;
+import org.apache.hyracks.data.std.util.UTF8StringBuilder;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
 public class SubstringBeforeDescriptor extends AbstractScalarFunctionDynamicDescriptor {
@@ -66,6 +68,11 @@ public class SubstringBeforeDescriptor extends AbstractScalarFunctionDynamicDesc
                     private ICopyEvaluator evalPattern = args[1].createEvaluator(array1);
                     private final byte stt = ATypeTag.STRING.serialize();
 
+                    private final GrowableArray array = new GrowableArray();
+                    private final UTF8StringBuilder builder = new UTF8StringBuilder();
+                    private final UTF8StringPointable stringPtr = new UTF8StringPointable();
+                    private final UTF8StringPointable patternPtr = new UTF8StringPointable();
+
                     @Override
                     public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
                         array0.reset();
@@ -84,37 +91,17 @@ public class SubstringBeforeDescriptor extends AbstractScalarFunctionDynamicDesc
                                     + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(pattern[0]) + ").");
                         }
 
-                        int srcLen = UTF8StringPointable.getUTFLength(src, 1);
-                        int patternLen = UTF8StringPointable.getUTFLength(pattern, 1);
-                        int posSrc = 3;
-                        int posPattern = 3;
-
-                        int offset = 0;
-                        while (posSrc - 3 < srcLen - patternLen) {
-                            while (posPattern + offset - 3 < patternLen && posSrc + offset - 3 < srcLen) {
-                                char c1 = UTF8StringPointable.charAt(src, posSrc + offset);
-                                char c2 = UTF8StringPointable.charAt(pattern, posPattern + offset);
-                                if (c1 != c2)
-                                    break;
-                                offset++;
-                            }
-                            if (offset == patternLen) {
-                                break;
-                            }
-                            posSrc += UTF8StringPointable.charSize(src, posSrc);
-                        }
-                        int startSubstr = 3;
-
-                        int substrByteLen = posSrc - startSubstr;
+                        stringPtr.set(src, 1, src.length);
+                        patternPtr.set(pattern, 1, pattern.length);
+                        array.reset();
                         try {
+                            UTF8StringPointable.substrBefore(stringPtr, patternPtr, builder, array);
                             out.writeByte(stt);
-                            out.writeByte((byte) ((substrByteLen >>> 8) & 0xFF));
-                            out.writeByte((byte) ((substrByteLen >>> 0) & 0xFF));
-                            out.write(src, startSubstr, substrByteLen);
-
+                            out.write(array.getByteArray(), 0, array.getLength());
                         } catch (IOException e) {
                             throw new AlgebricksException(e);
                         }
+
                     }
                 };
             }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringDescriptor.java
index 921bdce..42d64b3 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringDescriptor.java
@@ -38,6 +38,8 @@ import org.apache.hyracks.data.std.primitive.LongPointable;
 import org.apache.hyracks.data.std.primitive.ShortPointable;
 import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
+import org.apache.hyracks.data.std.util.GrowableArray;
+import org.apache.hyracks.data.std.util.UTF8StringBuilder;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
 public class SubstringDescriptor extends AbstractScalarFunctionDynamicDescriptor {
@@ -59,13 +61,17 @@ public class SubstringDescriptor extends AbstractScalarFunctionDynamicDescriptor
             public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
                 return new ICopyEvaluator() {
 
-                    private DataOutput out = output.getDataOutput();
-                    private ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
-                    private ICopyEvaluator evalString = args[0].createEvaluator(argOut);
-                    private ICopyEvaluator evalStart = args[1].createEvaluator(argOut);
-                    private ICopyEvaluator evalLen = args[2].createEvaluator(argOut);
+                    private final DataOutput out = output.getDataOutput();
+                    private final ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
+                    private final ICopyEvaluator evalString = args[0].createEvaluator(argOut);
+                    private final ICopyEvaluator evalStart = args[1].createEvaluator(argOut);
+                    private final ICopyEvaluator evalLen = args[2].createEvaluator(argOut);
                     private final byte stt = ATypeTag.STRING.serialize();
 
+                    private final GrowableArray array = new GrowableArray();
+                    private final UTF8StringBuilder builder = new UTF8StringBuilder();
+                    private final UTF8StringPointable string = new UTF8StringPointable();
+
                     @Override
                     public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
                         argOut.reset();
@@ -140,35 +146,21 @@ public class SubstringDescriptor extends AbstractScalarFunctionDynamicDescriptor
                             throw new AlgebricksException(AsterixBuiltinFunctions.SUBSTRING.getName()
                                     + ": expects type STRING for the first argument but got " + argOutTypeTag);
                         }
-                        int utflen = UTF8StringPointable.getUTFLength(bytes, 1);
-                        int sStart = 3;
-                        int c = 0;
-                        int idxPos1 = 0;
-                        // skip to start
-                        while (idxPos1 < start && c < utflen) {
-                            c += UTF8StringPointable.charSize(bytes, sStart + c);
-                            ++idxPos1;
-                        }
-                        int startSubstr = c;
-                        int idxPos2 = 0;
-                        while (idxPos2 < len && c < utflen) {
-                            c += UTF8StringPointable.charSize(bytes, sStart + c);
-                            ++idxPos2;
-                        }
 
-                        if (idxPos2 < len) {
+                        string.set(bytes, 1, bytes.length);
+                        array.reset();
+                        try {
+                            UTF8StringPointable.substr(string, start, len, builder, array);
+                        } catch (StringIndexOutOfBoundsException e) {
                             throw new AlgebricksException(AsterixBuiltinFunctions.SUBSTRING.getName() + ": start="
-                                    + start + "\tlen=" + len + "\tgoing past the input length=" + (idxPos1 + idxPos2)
-                                    + ".");
+                                    + start + "\tgoing past the input length.");
+                        } catch (IOException e) {
+                            throw new AlgebricksException(e);
                         }
 
-                        int substrByteLen = c - startSubstr;
                         try {
                             out.writeByte(stt);
-                            out.writeByte((byte) ((substrByteLen >>> 8) & 0xFF));
-                            out.writeByte((byte) ((substrByteLen >>> 0) & 0xFF));
-                            out.write(bytes, sStart + startSubstr, substrByteLen);
-
+                            out.write(array.getByteArray(), 0, array.getLength());
                         } catch (IOException e) {
                             throw new AlgebricksException(e);
                         }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/AbstractCopyEvaluator.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/AbstractCopyEvaluator.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/AbstractCopyEvaluator.java
index e90d3a0..6de63a2 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/AbstractCopyEvaluator.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/AbstractCopyEvaluator.java
@@ -76,7 +76,7 @@ public abstract class AbstractCopyEvaluator implements ICopyEvaluator {
     private static final String THIRD = "3rd";
     private static final String TH = "th";
 
-    public static String idToString(int i) {
+    public static String rankToString(int i) {
         String prefix = "";
         if (i >= 10) {
             prefix = String.valueOf(i / 10);
@@ -99,7 +99,7 @@ public abstract class AbstractCopyEvaluator implements ICopyEvaluator {
             if (expected[i] != actual[i]) {
                 if (!ATypeHierarchy.canPromote(actual[i], expected[i])
                         && !ATypeHierarchy.canPromote(expected[i], actual[i])) {
-                    throw new AlgebricksException(title + ": expects " + expected[i] + " at " + idToString(i + 1)
+                    throw new AlgebricksException(title + ": expects " + expected[i] + " at " + rankToString(i + 1)
                             + " argument, but got " + actual[i]);
                 }
             }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/BinaryConcatDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/BinaryConcatDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/BinaryConcatDescriptor.java
index 4a9c143..a6d9b57 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/BinaryConcatDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/BinaryConcatDescriptor.java
@@ -19,6 +19,8 @@
 
 package org.apache.asterix.runtime.evaluators.functions.binary;
 
+import java.io.IOException;
+
 import org.apache.asterix.common.exceptions.AsterixException;
 import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
@@ -34,31 +36,36 @@ import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.data.std.api.IDataOutputProvider;
 import org.apache.hyracks.data.std.primitive.ByteArrayPointable;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
-
-import java.io.IOException;
+import org.apache.hyracks.util.encoding.VarLenIntEncoderDecoder;
 
 public class BinaryConcatDescriptor extends AbstractScalarFunctionDynamicDescriptor {
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
-        @Override public IFunctionDescriptor createFunctionDescriptor() {
+        @Override
+        public IFunctionDescriptor createFunctionDescriptor() {
             return new BinaryConcatDescriptor();
         }
     };
 
-    @Override public FunctionIdentifier getIdentifier() {
+    @Override
+    public FunctionIdentifier getIdentifier() {
         return AsterixBuiltinFunctions.BINARY_CONCAT;
     }
 
-    @Override public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args)
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args)
             throws AlgebricksException {
         return new ICopyEvaluatorFactory() {
-            @Override public ICopyEvaluator createEvaluator(final IDataOutputProvider output)
+            @Override
+            public ICopyEvaluator createEvaluator(final IDataOutputProvider output)
                     throws AlgebricksException {
                 return new AbstractCopyEvaluator(output, args) {
 
                     private final AsterixListAccessor listAccessor = new AsterixListAccessor();
                     private final byte SER_BINARY_TYPE = ATypeTag.BINARY.serialize();
+                    private final byte[] metaBuffer = new byte[5];
 
-                    @Override public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                    @Override
+                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
                         ATypeTag typeTag = evaluateTuple(tuple, 0);
                         if (typeTag != ATypeTag.UNORDEREDLIST && typeTag != ATypeTag.ORDEREDLIST) {
                             throw new AlgebricksException(getIdentifier().getName()
@@ -79,19 +86,19 @@ public class BinaryConcatDescriptor extends AbstractScalarFunctionDynamicDescrip
                                     throw new AlgebricksException(getIdentifier().getName()
                                             + ": expects type STRING/NULL for the list item but got " + itemType);
                                 }
-                                concatLength += ByteArrayPointable.getLength(storages[0].getByteArray(), itemOffset);
-                            }
-                            if (concatLength > ByteArrayPointable.MAX_LENGTH) {
-                                throw new AlgebricksException("the concatenated binary is too long.");
+                                concatLength += ByteArrayPointable.getContentLength(storages[0].getByteArray(),
+                                        itemOffset);
                             }
                             dataOutput.writeByte(SER_BINARY_TYPE);
-                            dataOutput.writeShort(concatLength);
+                            int metaLen = VarLenIntEncoderDecoder.encode(concatLength, metaBuffer, 0);
+                            dataOutput.write(metaBuffer, 0, metaLen);
 
                             for (int i = 0; i < listAccessor.size(); i++) {
                                 int itemOffset = listAccessor.getItemOffset(i);
-                                int length = ByteArrayPointable.getLength(storages[0].getByteArray(), itemOffset);
+                                int length = ByteArrayPointable.getContentLength(storages[0].getByteArray(),
+                                        itemOffset);
                                 dataOutput.write(storages[0].getByteArray(),
-                                        itemOffset + ByteArrayPointable.SIZE_OF_LENGTH, length);
+                                        itemOffset + ByteArrayPointable.getNumberBytesToStoreMeta(length), length);
                             }
                         } catch (HyracksDataException e) {
                             throw new AlgebricksException(e);

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/BinaryLengthDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/BinaryLengthDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/BinaryLengthDescriptor.java
index 9b40fa5..c42e054 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/BinaryLengthDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/BinaryLengthDescriptor.java
@@ -67,7 +67,7 @@ public class BinaryLengthDescriptor extends AbstractScalarFunctionDynamicDescrip
                                 return;
                             }
                             checkTypeMachingThrowsIfNot(getIdentifier().getName(), EXPECTED_TAGS, tag);
-                            int len = ByteArrayPointable.getLength(storages[0].getByteArray(), 1);
+                            int len = ByteArrayPointable.getContentLength(storages[0].getByteArray(), 1);
                             result.setValue(len);
                             intSerde.serialize(result, dataOutput);
                         } catch (HyracksDataException e) {

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/FindBinaryDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/FindBinaryDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/FindBinaryDescriptor.java
index 602c548..af0aaba 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/FindBinaryDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/FindBinaryDescriptor.java
@@ -41,24 +41,29 @@ import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 public class FindBinaryDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
-        @Override public IFunctionDescriptor createFunctionDescriptor() {
+        @Override
+        public IFunctionDescriptor createFunctionDescriptor() {
             return new FindBinaryDescriptor();
         }
     };
 
-    @Override public FunctionIdentifier getIdentifier() {
+    @Override
+    public FunctionIdentifier getIdentifier() {
         return AsterixBuiltinFunctions.FIND_BINARY;
     }
 
     private static final ATypeTag[] EXPECTED_INPUT_TAG = { ATypeTag.BINARY, ATypeTag.BINARY };
 
-    @Override public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args)
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args)
             throws AlgebricksException {
         return new ICopyEvaluatorFactory() {
-            @Override public ICopyEvaluator createEvaluator(final IDataOutputProvider output)
+            @Override
+            public ICopyEvaluator createEvaluator(final IDataOutputProvider output)
                     throws AlgebricksException {
                 return new AbstractFindBinaryCopyEvaluator(output, args, getIdentifier().getName()) {
-                    @Override protected int getFromOffset(IFrameTupleReference tuple) throws AlgebricksException {
+                    @Override
+                    protected int getFromOffset(IFrameTupleReference tuple) throws AlgebricksException {
                         return 0;
                     }
                 };
@@ -76,12 +81,15 @@ public class FindBinaryDescriptor extends AbstractScalarFunctionDynamicDescripto
 
         protected String functionName;
         protected AMutableInt64 result = new AMutableInt64(-1);
+        protected final ByteArrayPointable textPtr = new ByteArrayPointable();
+        protected final ByteArrayPointable wordPtr = new ByteArrayPointable();
 
         @SuppressWarnings("unchecked")
         protected ISerializerDeserializer<AInt64> intSerde = AqlSerializerDeserializerProvider.INSTANCE
                 .getSerializerDeserializer(BuiltinType.AINT64);
 
-        @Override public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+        @Override
+        public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
             ATypeTag textTag = evaluateTuple(tuple, 0);
             ATypeTag wordTag = evaluateTuple(tuple, 1);
             int fromOffset = getFromOffset(tuple);
@@ -93,11 +101,12 @@ public class FindBinaryDescriptor extends AbstractScalarFunctionDynamicDescripto
                 checkTypeMachingThrowsIfNot(functionName, EXPECTED_INPUT_TAG, textTag,
                         wordTag);
 
-                byte[] textBytes = storages[0].getByteArray();
-                byte[] wordBytes = storages[1].getByteArray();
-                int textLength = ByteArrayPointable.getLength(textBytes, 1);
-                int wordLength = ByteArrayPointable.getLength(wordBytes, 1);
-                result.setValue(1 + indexOf(textBytes, 3, textLength, wordBytes, 3, wordLength, fromOffset));
+                textPtr.set(storages[0].getByteArray(), 1, storages[0].getLength() - 1);
+                wordPtr.set(storages[1].getByteArray(), 1, storages[1].getLength() - 1);
+                result.setValue(
+                        1 + indexOf(textPtr.getByteArray(), textPtr.getContentStartOffset(), textPtr.getContentLength(),
+                                wordPtr.getByteArray(), wordPtr.getContentStartOffset(), wordPtr.getContentLength(),
+                                fromOffset));
                 intSerde.serialize(result, dataOutput);
             } catch (HyracksDataException e) {
                 throw new AlgebricksException(e);

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/ParseBinaryDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/ParseBinaryDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/ParseBinaryDescriptor.java
index df23e6e..ffe2c9a 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/ParseBinaryDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/ParseBinaryDescriptor.java
@@ -37,28 +37,13 @@ import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.data.std.api.IDataOutputProvider;
 import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
-import org.apache.hyracks.dataflow.common.data.parsers.ByteArrayBase64ParserFactory;
-import org.apache.hyracks.dataflow.common.data.parsers.ByteArrayHexParserFactory;
+import org.apache.hyracks.util.bytes.Base64Parser;
+import org.apache.hyracks.util.bytes.HexParser;
 
 public class ParseBinaryDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
-    static final String HEX_FORMAT = "hex";
-    static final String BASE64_FORMAT = "base64";
-
-    static boolean isCaseIgnoreEqual(String expectedLowerCaseString, byte[] bytes, int start,
-            int length) {
-        int pos = start;
-        int index = 0;
-        while (pos < start + length) {
-            char c1 = UTF8StringPointable.charAt(bytes, pos);
-            c1 = Character.toLowerCase(c1);
-            if (expectedLowerCaseString.charAt(index++) != c1) {
-                return false;
-            }
-            pos += UTF8StringPointable.charSize(bytes, pos);
-        }
-        return index == expectedLowerCaseString.length();
-    }
+    static final UTF8StringPointable HEX_FORMAT = UTF8StringPointable.generateUTF8Pointable("hex");
+    static final UTF8StringPointable BASE64_FORMAT = UTF8StringPointable.generateUTF8Pointable("base64");
 
     public final static IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         @Override
@@ -69,14 +54,17 @@ public class ParseBinaryDescriptor extends AbstractScalarFunctionDynamicDescript
 
     public static final ATypeTag[] EXPECTED_INPUT_TAGS = { ATypeTag.STRING, ATypeTag.STRING };
 
-    @Override public FunctionIdentifier getIdentifier() {
+    @Override
+    public FunctionIdentifier getIdentifier() {
         return AsterixBuiltinFunctions.PARSE_BINARY;
     }
 
-    @Override public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args)
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args)
             throws AlgebricksException {
         return new ICopyEvaluatorFactory() {
-            @Override public ICopyEvaluator createEvaluator(final IDataOutputProvider output)
+            @Override
+            public ICopyEvaluator createEvaluator(final IDataOutputProvider output)
                     throws AlgebricksException {
                 return new AbstractCopyEvaluator(output, args) {
 
@@ -85,9 +73,14 @@ public class ParseBinaryDescriptor extends AbstractScalarFunctionDynamicDescript
                             .getSerializerDeserializer(BuiltinType.ABINARY);
 
                     private AMutableBinary aBinary = new AMutableBinary(new byte[0], 0, 0);
-                    private final byte[] quadruplet = new byte[4];
+                    private final UTF8StringPointable stringPointable = new UTF8StringPointable();
+                    private final UTF8StringPointable formatPointable = new UTF8StringPointable();
+
+                    private final HexParser hexParser = new HexParser();
+                    private final Base64Parser base64Parser = new Base64Parser();
 
-                    @Override public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                    @Override
+                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
                         ATypeTag binaryTag = evaluateTuple(tuple, 0);
                         ATypeTag formatTag = evaluateTuple(tuple, 1);
 
@@ -97,22 +90,22 @@ public class ParseBinaryDescriptor extends AbstractScalarFunctionDynamicDescript
                             }
                             checkTypeMachingThrowsIfNot(getIdentifier().getName(), EXPECTED_INPUT_TAGS, binaryTag,
                                     formatTag);
-                            int lengthString = UTF8StringPointable.getUTFLength(storages[0].getByteArray(), 1);
-                            int lengthFormat = UTF8StringPointable.getUTFLength(storages[1].getByteArray(), 1);
-                            byte[] buffer;
-                            if (isCaseIgnoreEqual(HEX_FORMAT, storages[1].getByteArray(), 3, lengthFormat)) {
-                                buffer = ByteArrayHexParserFactory
-                                        .extractPointableArrayFromHexString(storages[0].getByteArray(), 3,
-                                                lengthString, aBinary.getBytes());
-                            } else if (isCaseIgnoreEqual(BASE64_FORMAT, storages[1].getByteArray(), 3, lengthFormat)) {
-                                buffer = ByteArrayBase64ParserFactory
-                                        .extractPointableArrayFromBase64String(storages[0].getByteArray(), 3
-                                                , lengthString, aBinary.getBytes(), quadruplet);
+                            stringPointable.set(storages[0].getByteArray(), 1, storages[0].getLength());
+                            formatPointable.set(storages[1].getByteArray(), 1, storages[1].getLength());
+                            if (HEX_FORMAT.ignoreCaseCompareTo(formatPointable) == 0) {
+                                hexParser.generateByteArrayFromHexString(stringPointable.getByteArray(),
+                                        stringPointable.getCharStartOffset(), stringPointable.getUTF8Length());
+
+                                aBinary.setValue(hexParser.getByteArray(), 0, hexParser.getLength());
+                            } else if (BASE64_FORMAT.ignoreCaseCompareTo(formatPointable) == 0) {
+                                base64Parser.generatePureByteArrayFromBase64String(stringPointable.getByteArray(),
+                                        stringPointable.getCharStartOffset(), stringPointable.getUTF8Length());
+
+                                aBinary.setValue(base64Parser.getByteArray(), 0, base64Parser.getLength());
                             } else {
                                 throw new AlgebricksException(getIdentifier().getName()
                                         + ": expects format indicator of \"hex\" or \"base64\" in the 2nd argument");
                             }
-                            aBinary.setValue(buffer, 0, buffer.length);
                             binarySerde.serialize(aBinary, dataOutput);
                         } catch (HyracksDataException e) {
                             e.printStackTrace();

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/PrintBinaryDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/PrintBinaryDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/PrintBinaryDescriptor.java
index 8f52441..75bb628 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/PrintBinaryDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/PrintBinaryDescriptor.java
@@ -19,8 +19,11 @@
 
 package org.apache.asterix.runtime.evaluators.functions.binary;
 
-import org.apache.asterix.dataflow.data.nontagged.printers.PrintTools;
-import org.apache.asterix.dataflow.data.nontagged.printers.adm.ABinaryBase64Printer;
+import static org.apache.asterix.runtime.evaluators.functions.binary.ParseBinaryDescriptor.BASE64_FORMAT;
+import static org.apache.asterix.runtime.evaluators.functions.binary.ParseBinaryDescriptor.HEX_FORMAT;
+
+import java.io.IOException;
+
 import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
@@ -35,16 +38,16 @@ import org.apache.hyracks.data.std.api.IDataOutputProvider;
 import org.apache.hyracks.data.std.primitive.ByteArrayPointable;
 import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
-
-import java.io.IOException;
-
-import static org.apache.asterix.runtime.evaluators.functions.binary.ParseBinaryDescriptor.*;
+import org.apache.hyracks.util.bytes.Base64Printer;
+import org.apache.hyracks.util.bytes.HexPrinter;
+import org.apache.hyracks.util.string.UTF8StringWriter;
 
 public class PrintBinaryDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final byte SER_STRING_BYTE = ATypeTag.STRING.serialize();
 
-    @Override public FunctionIdentifier getIdentifier() {
+    @Override
+    public FunctionIdentifier getIdentifier() {
         return AsterixBuiltinFunctions.PRINT_BINARY;
     }
 
@@ -57,16 +60,22 @@ public class PrintBinaryDescriptor extends AbstractScalarFunctionDynamicDescript
 
     public final static ATypeTag[] EXPECTED_INPUT_TAGS = { ATypeTag.BINARY, ATypeTag.STRING };
 
-    @Override public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args)
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args)
             throws AlgebricksException {
         return new ICopyEvaluatorFactory() {
-            @Override public ICopyEvaluator createEvaluator(final IDataOutputProvider output)
+            @Override
+            public ICopyEvaluator createEvaluator(final IDataOutputProvider output)
                     throws AlgebricksException {
                 return new AbstractCopyEvaluator(output, args) {
 
                     private StringBuilder stringBuilder = new StringBuilder();
+                    private final ByteArrayPointable byteArrayPtr = new ByteArrayPointable();
+                    private final UTF8StringPointable formatPointable = new UTF8StringPointable();
+                    private final UTF8StringWriter writer = new UTF8StringWriter();
 
-                    @Override public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                    @Override
+                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
                         ATypeTag arg0Tag = evaluateTuple(tuple, 0);
                         ATypeTag arg1Tag = evaluateTuple(tuple, 1);
 
@@ -77,25 +86,23 @@ public class PrintBinaryDescriptor extends AbstractScalarFunctionDynamicDescript
                             checkTypeMachingThrowsIfNot(getIdentifier().getName(), EXPECTED_INPUT_TAGS, arg0Tag,
                                     arg1Tag);
 
-                            byte[] binaryBytes = storages[0].getByteArray();
-                            byte[] formatBytes = storages[1].getByteArray();
+                            byteArrayPtr.set(storages[0].getByteArray(), 1, storages[0].getLength());
+                            formatPointable.set(storages[1].getByteArray(), 1, storages[1].getLength());
 
-                            int lengthBinary = ByteArrayPointable.getLength(binaryBytes, 1);
-                            int lengthFormat = UTF8StringPointable.getUTFLength(formatBytes, 1);
+                            int lengthBinary = byteArrayPtr.getContentLength();
                             stringBuilder.setLength(0);
-                            if (isCaseIgnoreEqual(HEX_FORMAT, formatBytes, 3, lengthFormat)) {
-                                PrintTools
-                                        .printHexString(binaryBytes, 3, lengthBinary, stringBuilder);
-
-                            } else if (isCaseIgnoreEqual(BASE64_FORMAT, formatBytes, 3, lengthFormat)) {
-                                ABinaryBase64Printer
-                                        .printBase64Binary(binaryBytes, 3, lengthBinary, stringBuilder);
+                            if (HEX_FORMAT.ignoreCaseCompareTo(formatPointable) == 0) {
+                                HexPrinter.printHexString(byteArrayPtr.getByteArray(),
+                                        byteArrayPtr.getContentStartOffset(), lengthBinary, stringBuilder);
+                            } else if (BASE64_FORMAT.ignoreCaseCompareTo(formatPointable) == 0) {
+                                Base64Printer.printBase64Binary(byteArrayPtr.getByteArray(),
+                                        byteArrayPtr.getContentStartOffset(), lengthBinary, stringBuilder);
                             } else {
                                 throw new AlgebricksException(getIdentifier().getName()
                                         + ": expects format indicator of \"hex\" or \"base64\" in the 2nd argument");
                             }
                             dataOutput.writeByte(SER_STRING_BYTE);
-                            dataOutput.writeUTF(stringBuilder.toString());
+                            writer.writeUTF8(stringBuilder.toString(), dataOutput);
                         } catch (HyracksDataException e) {
                             throw new AlgebricksException(e);
                         } catch (IOException e) {

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/SubBinaryFromDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/SubBinaryFromDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/SubBinaryFromDescriptor.java
index bfd2a38..a5b5e99 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/SubBinaryFromDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/SubBinaryFromDescriptor.java
@@ -51,7 +51,7 @@ public class SubBinaryFromDescriptor extends AbstractScalarFunctionDynamicDescri
                 return new SubBinaryFromToDescriptor.AbstractSubBinaryCopyEvaluator(output, args,
                         getIdentifier().getName()) {
                     @Override protected int getSubLength(IFrameTupleReference tuple) throws AlgebricksException {
-                        return ByteArrayPointable.MAX_LENGTH;
+                        return Integer.MAX_VALUE;
                     }
                 };
             }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/SubBinaryFromToDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/SubBinaryFromToDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/SubBinaryFromToDescriptor.java
index 70b380a..4f35de8 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/SubBinaryFromToDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/SubBinaryFromToDescriptor.java
@@ -35,6 +35,7 @@ import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.data.std.api.IDataOutputProvider;
 import org.apache.hyracks.data.std.primitive.ByteArrayPointable;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+import org.apache.hyracks.util.encoding.VarLenIntEncoderDecoder;
 
 public class SubBinaryFromToDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
@@ -80,6 +81,8 @@ public class SubBinaryFromToDescriptor extends AbstractScalarFunctionDynamicDesc
             this.functionName = functionName;
         }
 
+        private ByteArrayPointable byteArrayPointable = new ByteArrayPointable();
+        private byte[] metaBuffer = new byte[5];
         protected final String functionName;
 
         static final ATypeTag[] EXPECTED_INPUT_TAGS = { ATypeTag.BINARY, ATypeTag.INT32 };
@@ -96,30 +99,33 @@ public class SubBinaryFromToDescriptor extends AbstractScalarFunctionDynamicDesc
                 }
                 checkTypeMachingThrowsIfNot(functionName, EXPECTED_INPUT_TAGS, argTag0, argTag1);
 
-                byte[] binaryBytes = storages[0].getByteArray();
+                byteArrayPointable.set(storages[0].getByteArray(), 1, storages[0].getLength() - 1);
                 byte[] startBytes = storages[1].getByteArray();
 
-                int start = 0;
+                int subStart = 0;
 
                 // strange SQL index convention
-                start = ATypeHierarchy.getIntegerValue(startBytes, 0) - 1;
+                subStart = ATypeHierarchy.getIntegerValue(startBytes, 0) - 1;
 
-                int totalLength = ByteArrayPointable.getLength(binaryBytes, 1);
+                int totalLength = byteArrayPointable.getContentLength();
                 int subLength = getSubLength(tuple);
 
-                if (start < 0) {
-                    start = 0;
+                if (subStart < 0) {
+                    subStart = 0;
                 }
 
-                if (start >= totalLength || subLength < 0) {
+                if (subStart >= totalLength || subLength < 0) {
                     subLength = 0;
-                } else if (start + subLength > totalLength) {
-                    subLength = totalLength - start;
+                } else if (subLength > totalLength // for the IntMax case
+                        || subStart + subLength > totalLength) {
+                    subLength = totalLength - subStart;
                 }
 
                 dataOutput.write(ATypeTag.BINARY.serialize());
-                dataOutput.writeShort(subLength);
-                dataOutput.write(binaryBytes, 1 + ByteArrayPointable.SIZE_OF_LENGTH + start, subLength);
+                int metaLength = VarLenIntEncoderDecoder.encode(subLength, metaBuffer, 0);
+                dataOutput.write(metaBuffer, 0, metaLength);
+                dataOutput.write(byteArrayPointable.getByteArray(),
+                        byteArrayPointable.getContentStartOffset() + subStart, subLength);
             } catch (HyracksDataException e) {
                 throw new AlgebricksException(e);
             } catch (IOException e) {

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldValueEvalFactory.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldValueEvalFactory.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldValueEvalFactory.java
index 0ca24c6..05e7292 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldValueEvalFactory.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldValueEvalFactory.java
@@ -41,7 +41,7 @@ public class GetRecordFieldValueEvalFactory implements ICopyEvaluatorFactory {
 
     private ICopyEvaluatorFactory recordEvalFactory;
     private ICopyEvaluatorFactory fldNameEvalFactory;
-    private ARecordType recordType;
+    private final ARecordType recordType;
 
     private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
 
@@ -72,10 +72,10 @@ public class GetRecordFieldValueEvalFactory implements ICopyEvaluatorFactory {
             private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                     .getSerializerDeserializer(BuiltinType.ANULL);
 
+            private ARecordType mRecordType = recordType.deepCopy(recordType);
             {
                 abvsFields[0] = new ArrayBackedValueStorage();
                 doFields[0] = abvsFields[0].getDataOutput();
-                recordType = recordType.deepCopy(recordType);
             }
 
             @Override
@@ -92,7 +92,7 @@ public class GetRecordFieldValueEvalFactory implements ICopyEvaluatorFactory {
                     abvsFields[0].reset();
                     doFields[0].write(serFldName);
 
-                    FieldAccessUtil.evaluate(tuple, out, eval0, abvsFields, outInput0, subRecordTmpStream, recordType);
+                    FieldAccessUtil.evaluate(tuple, out, eval0, abvsFields, outInput0, subRecordTmpStream, mRecordType);
                 } catch (IOException e) {
                     throw new AlgebricksException(e);
                 }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldsEvalFactory.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldsEvalFactory.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldsEvalFactory.java
index 804f91b..3fc5db1 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldsEvalFactory.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldsEvalFactory.java
@@ -43,7 +43,7 @@ public class GetRecordFieldsEvalFactory implements ICopyEvaluatorFactory {
     private static final long serialVersionUID = 1L;
 
     private ICopyEvaluatorFactory recordEvalFactory;
-    private ARecordType recordType;
+    private final ARecordType recordType;
 
     private final byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
     private final byte SER_RECORD_TYPE_TAG = ATypeTag.RECORD.serialize();
@@ -69,9 +69,7 @@ public class GetRecordFieldsEvalFactory implements ICopyEvaluatorFactory {
             private DataOutput out = output.getDataOutput();
             private RecordFieldsUtil rfu = new RecordFieldsUtil();
 
-            {
-                recordType = recordType.deepCopy(recordType);
-            }
+            protected ARecordType mRecordType = recordType.deepCopy(recordType);
 
             public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
                 outInput0.reset();
@@ -93,7 +91,7 @@ public class GetRecordFieldsEvalFactory implements ICopyEvaluatorFactory {
                 recordPointable.set(outInput0.getByteArray(), outInput0.getStartOffset(), outInput0.getLength());
 
                 try {
-                    rfu.processRecord(recordPointable, recordType, out, 0);
+                    rfu.processRecord(recordPointable, mRecordType, out, 0);
                 } catch (IOException e) {
                     e.printStackTrace();
                 } catch (AsterixException e) {

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordFieldsUtil.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordFieldsUtil.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordFieldsUtil.java
index 08bc8bf..76716b1 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordFieldsUtil.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordFieldsUtil.java
@@ -76,11 +76,12 @@ public class RecordFieldsUtil {
             AListPointable.ALLOCATOR);
 
     private final static AOrderedListType listType = new AOrderedListType(BuiltinType.ANY, "fields");
+    //Better not be a static object.
     @SuppressWarnings("unchecked")
-    protected final static ISerializerDeserializer<AString> stringSerde = AqlSerializerDeserializerProvider.INSTANCE
+    protected final ISerializerDeserializer<AString> stringSerde = AqlSerializerDeserializerProvider.INSTANCE
             .getSerializerDeserializer(BuiltinType.ASTRING);
     @SuppressWarnings("unchecked")
-    protected final static ISerializerDeserializer<ABoolean> booleanSerde = AqlSerializerDeserializerProvider.INSTANCE
+    protected final ISerializerDeserializer<ABoolean> booleanSerde = AqlSerializerDeserializerProvider.INSTANCE
             .getSerializerDeserializer(BuiltinType.ABOOLEAN);
 
     private final static ARecordType openType = DefaultOpenFieldType.NESTED_OPEN_RECORD_TYPE;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordMergeDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordMergeDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordMergeDescriptor.java
index 02a2666..df52f90 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordMergeDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordMergeDescriptor.java
@@ -90,6 +90,7 @@ public class RecordMergeDescriptor extends AbstractScalarFunctionDynamicDescript
             @SuppressWarnings("unchecked")
             private final ISerializerDeserializer<ANull> nullSerDe = AqlSerializerDeserializerProvider.INSTANCE
                     .getSerializerDeserializer(BuiltinType.ANULL);
+            private final AStringSerializerDeserializer aStringSerDer = new AStringSerializerDeserializer();
 
             @Override
             public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
@@ -220,7 +221,7 @@ public class RecordMergeDescriptor extends AbstractScalarFunctionDynamicDescript
                         nameOutputStream.write(fieldNamePointable.getByteArray(),
                                 fieldNamePointable.getStartOffset() + 1, fieldNamePointable.getLength());
                         namedis.reset();
-                        String fieldName = AStringSerializerDeserializer.INSTANCE.deserialize(namedis).getStringValue();
+                        String fieldName = aStringSerDer.deserialize(namedis).getStringValue();
 
                         //Add the merged field
                         if (combinedType.isClosedField(fieldName)) {



Mime
View raw message