You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by mh...@apache.org on 2018/06/12 01:00:10 UTC

asterixdb git commit: [NO ISSUE][FUN] Implement object-rename()

Repository: asterixdb
Updated Branches:
  refs/heads/master 63a63fd72 -> d8ed19620


[NO ISSUE][FUN] Implement object-rename()

- user model changes: no
- storage format changes: no
- interface changes: no

Details:
- Implement object-rename function that renames a field from
  a given object.
- Add new function to docs.
- Add test case.

Change-Id: I439255137493e3e8dd2639abff32d7bd316d31e5
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2698
Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
Sonar-Qube: Jenkins <je...@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <je...@fulliautomatix.ics.uci.edu>
Reviewed-by: Murtadha Hubail <mh...@apache.org>


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

Branch: refs/heads/master
Commit: d8ed196209283b9d8b1d52197bdcdf1f7cb1421e
Parents: 63a63fd
Author: Murtadha Hubail <mh...@apache.org>
Authored: Tue Jun 12 01:44:31 2018 +0300
Committer: Murtadha Hubail <mh...@apache.org>
Committed: Mon Jun 11 17:59:10 2018 -0700

----------------------------------------------------------------------
 .../queries_sqlpp/objects/ObjectsQueries.xml    |   5 +
 .../object_rename/object_rename.1.ddl.sqlpp     |  49 ++++++
 .../object_rename/object_rename.2.update.sqlpp  |  29 ++++
 .../object_rename/object_rename.3.query.sqlpp   |  52 ++++++
 .../object_rename/object_rename.4.ddl.sqlpp     |  25 +++
 .../objects/object_rename/object_rename.3.adm   |   1 +
 .../src/main/markdown/builtins/8_record.md      |  36 +++++
 .../asterix/om/functions/BuiltinFunctions.java  |   5 +-
 .../records/RecordRenameDescriptor.java         |  76 +++++++++
 .../records/RecordRenameEvaluator.java          | 161 +++++++++++++++++++
 .../runtime/functions/FunctionCollection.java   |   2 +
 11 files changed, 440 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d8ed1962/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/ObjectsQueries.xml
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/ObjectsQueries.xml b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/ObjectsQueries.xml
index 54eb49d..007a3fa 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/ObjectsQueries.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/ObjectsQueries.xml
@@ -123,6 +123,11 @@
     </compilation-unit>
   </test-case>
   <test-case FilePath="objects">
+    <compilation-unit name="object_rename">
+      <output-dir compare="Text">object_rename</output-dir>
+    </compilation-unit>
+  </test-case>
+  <test-case FilePath="objects">
     <compilation-unit name="object_pairs">
       <output-dir compare="Text">object_pairs</output-dir>
     </compilation-unit>

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d8ed1962/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_rename/object_rename.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_rename/object_rename.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_rename/object_rename.1.ddl.sqlpp
new file mode 100644
index 0000000..f6710f4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_rename/object_rename.1.ddl.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ */
+
+/*
+ * Description  : Testing object_rename under different queries.
+ * Expected Res : Success
+ */
+
+drop  dataverse TinySocial if exists;
+create  dataverse TinySocial;
+
+use TinySocial;
+
+create type TinySocial.TwitterUserType as
+{
+  `screen-name` : string,
+  lang : string,
+  friends_count : bigint,
+  statuses_count : bigint
+};
+
+create type TinySocial.TweetMessageType as closed {
+  tweetid : string,
+  user : TwitterUserType,
+  `sender-location` : point?,
+  `send-time` : datetime,
+  `referred-topics` : {{string}},
+  `message-text` : string
+};
+
+create  dataset TwitterUsers(TwitterUserType) primary key `screen-name`;
+
+create  dataset TweetMessages(TweetMessageType) primary key tweetid;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d8ed1962/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_rename/object_rename.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_rename/object_rename.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_rename/object_rename.2.update.sqlpp
new file mode 100644
index 0000000..5457dc9
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_rename/object_rename.2.update.sqlpp
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+/*
+ * Description  : Testing object_rename under different queries.
+ * Expected Res : Success
+ */
+
+use TinySocial;
+
+load  dataset TwitterUsers using localfs ((`path`=`asterix_nc1://data/tinysocial/twu.adm`),(`format`=`adm`));
+
+load  dataset TweetMessages using localfs ((`path`=`asterix_nc1://data/tinysocial/twm.adm`),(`format`=`adm`));

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d8ed1962/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_rename/object_rename.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_rename/object_rename.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_rename/object_rename.3.query.sqlpp
new file mode 100644
index 0000000..5f74fc1
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_rename/object_rename.3.query.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+
+/*
+ * Description  : Testing object_rename under different queries.
+ * Expected Res : Success
+ */
+
+use TinySocial;
+
+{
+  "t1": [
+    object_rename(missing, missing, missing) is missing,
+    object_rename(null, missing, missing) is missing,
+    object_rename(null, null, missing) is missing,
+    object_rename(null, null, null) is null
+  ],
+  "t2": object_rename({"a":1, "b":2}, "b", "c"),
+  "t3": object_rename({"a":1, "b":2}, "z", "a"),
+
+  /* open type */
+  "t5": (
+    select value object_rename(u, "lang", "language")
+    from TwitterUsers as u
+    order by u.screen-name
+    limit 1
+  ),
+
+  /* closed type */
+  "t6": (
+    select value object_rename(m, "user", "user_details")
+    from TweetMessages as m
+    order by m.tweetid
+    limit 1
+  )
+};
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d8ed1962/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_rename/object_rename.4.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_rename/object_rename.4.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_rename/object_rename.4.ddl.sqlpp
new file mode 100644
index 0000000..22bc025
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/objects/object_rename/object_rename.4.ddl.sqlpp
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+
+/*
+ * Description  : Testing object_rename under different queries.
+ * Expected Res : Success
+ */
+
+drop  dataverse TinySocial;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d8ed1962/asterixdb/asterix-app/src/test/resources/runtimets/results/objects/object_rename/object_rename.3.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/objects/object_rename/object_rename.3.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/objects/object_rename/object_rename.3.adm
new file mode 100644
index 0000000..197fec1
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/objects/object_rename/object_rename.3.adm
@@ -0,0 +1 @@
+{ "t1": [ true, true, true, true ], "t2": { "a": 1, "c": 2 }, "t3": { "a": 1, "b": 2 }, "t5": [ { "screen-name": "ChangEwing_573", "language": "en", "friends_count": 182, "statuses_count": 394, "name": "Chang Ewing", "followers_count": 32136 } ], "t6": [ { "tweetid": "1", "user_details": { "screen-name": "NathanGiesen@211", "lang": "en", "friends_count": 39339, "statuses_count": 473, "name": "Nathan Giesen", "followers_count": 49416 }, "sender-location": point("47.44,80.65"), "send-time": datetime("2008-04-26T10:10:00.000Z"), "referred-topics": {{ "t-mobile", "customization" }}, "message-text": " love t-mobile its customization is good:)" } ] }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d8ed1962/asterixdb/asterix-doc/src/main/markdown/builtins/8_record.md
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-doc/src/main/markdown/builtins/8_record.md b/asterixdb/asterix-doc/src/main/markdown/builtins/8_record.md
index fbee7b4..32c796d 100644
--- a/asterixdb/asterix-doc/src/main/markdown/builtins/8_record.md
+++ b/asterixdb/asterix-doc/src/main/markdown/builtins/8_record.md
@@ -318,4 +318,40 @@
         {
           "id": "1",
           "project": "AsterixDB",
+        }
+
+### object_rename ###
+ * Syntax:
+
+        object_name(input_object, old_field, new_field)
+
+ * Returns a new object that has the same fields as `input_object` with field `old_field` replaced by `new_field`
+ * Arguments:
+    * `input_object` : an object value.
+    * `old_field` : a string representing the old (original) field name inside the object `input_object`.
+    * `new_field` : a string representing the new field name to replace `old_field` inside the object `input_object`.
+ * Return Value:
+    * A new object that has the same fields as `input_object` with field `old_field` replaced by `new_field`,
+    * `missing` if any argument is a `missing` value,
+    * `null` if any argument is `null` or `input_object` is non-object value, or `old_field` is non-string value, or
+      `new_field` is any non-string value.
+
+ * Example:
+
+        object_rename(
+                       {
+                         "id": 1,
+                         "project": "AsterixDB",
+                         "address": {"city": "Irvine", "state": "CA"}
+                       }
+                       , "address"
+                       , "location"
+                     );
+
+ * The expected result is:
+
+        {
+          "id": "1",
+          "project": "AsterixDB",
+          "location": {"city": "Irvine", "state": "CA"}
         }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d8ed1962/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
index e5d0a11..1d33a59 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
@@ -68,9 +68,9 @@ import org.apache.asterix.om.typecomputer.impl.FieldAccessByNameResultType;
 import org.apache.asterix.om.typecomputer.impl.FieldAccessNestedResultType;
 import org.apache.asterix.om.typecomputer.impl.FullTextContainsResultTypeComputer;
 import org.apache.asterix.om.typecomputer.impl.GetOverlappingInvervalTypeComputer;
-import org.apache.asterix.om.typecomputer.impl.IfNanOrInfTypeComputer;
 import org.apache.asterix.om.typecomputer.impl.IfMissingOrNullTypeComputer;
 import org.apache.asterix.om.typecomputer.impl.IfMissingTypeComputer;
+import org.apache.asterix.om.typecomputer.impl.IfNanOrInfTypeComputer;
 import org.apache.asterix.om.typecomputer.impl.IfNullTypeComputer;
 import org.apache.asterix.om.typecomputer.impl.InjectFailureTypeComputer;
 import org.apache.asterix.om.typecomputer.impl.LocalAvgTypeComputer;
@@ -222,6 +222,8 @@ public class BuiltinFunctions {
             new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "st-geom-from-geojson", FunctionIdentifier.VARARGS);
     public static final FunctionIdentifier RECORD_REMOVE =
             new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "object-remove", 2);
+    public static final FunctionIdentifier RECORD_RENAME =
+            new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "object-rename", 3);
 
     // numeric
     public static final FunctionIdentifier NUMERIC_UNARY_MINUS =
@@ -1463,6 +1465,7 @@ public class BuiltinFunctions {
         addFunction(RECORD_PAIRS, RecordPairsTypeComputer.INSTANCE, true);
         addFunction(GEOMETRY_CONSTRUCTOR, AGeometryTypeComputer.INSTANCE, true);
         addFunction(RECORD_REMOVE, OpenARecordTypeComputer.INSTANCE, true);
+        addFunction(RECORD_RENAME, OpenARecordTypeComputer.INSTANCE, true);
 
         // temporal type accessors
         addFunction(ACCESSOR_TEMPORAL_YEAR, AInt64TypeComputer.INSTANCE, true);

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d8ed1962/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRenameDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRenameDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRenameDescriptor.java
new file mode 100644
index 0000000..ac1b8e2
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRenameDescriptor.java
@@ -0,0 +1,76 @@
+/*
+ * 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.records;
+
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.asterix.om.functions.IFunctionDescriptor;
+import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
+import org.apache.asterix.om.functions.IFunctionTypeInferer;
+import org.apache.asterix.om.types.ARecordType;
+import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import org.apache.asterix.runtime.functions.FunctionTypeInferers;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+public class RecordRenameDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+
+    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        @Override
+        public IFunctionDescriptor createFunctionDescriptor() {
+            return new RecordRenameDescriptor();
+        }
+
+        @Override
+        public IFunctionTypeInferer createFunctionTypeInferer() {
+            return FunctionTypeInferers.RecordAccessorTypeInferer.INSTANCE_LAX;
+        }
+    };
+
+    private static final long serialVersionUID = 1L;
+    private ARecordType recordType;
+
+    @Override
+    public void setImmutableStates(Object... states) {
+        recordType = (ARecordType) states[0];
+    }
+
+    @Override
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
+        return new IScalarEvaluatorFactory() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
+                final IScalarEvaluator[] argEvals = new IScalarEvaluator[args.length];
+                for (int i = 0; i < args.length; i++) {
+                    argEvals[i] = args[i].createScalarEvaluator(ctx);
+                }
+                return new RecordRenameEvaluator(argEvals[0], argEvals[1], argEvals[2], recordType);
+            }
+        };
+    }
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return BuiltinFunctions.RECORD_RENAME;
+    }
+}

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d8ed1962/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRenameEvaluator.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRenameEvaluator.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRenameEvaluator.java
new file mode 100644
index 0000000..3d46b69
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRenameEvaluator.java
@@ -0,0 +1,161 @@
+/*
+ * 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.records;
+
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.asterix.builders.RecordBuilder;
+import org.apache.asterix.om.pointables.ARecordVisitablePointable;
+import org.apache.asterix.om.pointables.base.DefaultOpenFieldType;
+import org.apache.asterix.om.pointables.base.IVisitablePointable;
+import org.apache.asterix.om.pointables.cast.ACastVisitor;
+import org.apache.asterix.om.types.ARecordType;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.IAType;
+import org.apache.asterix.runtime.evaluators.functions.PointableHelper;
+import org.apache.hyracks.algebricks.common.utils.Triple;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.api.dataflow.value.IBinaryComparator;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.data.std.api.IPointable;
+import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
+import org.apache.hyracks.data.std.primitive.VoidPointable;
+import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
+import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+class RecordRenameEvaluator implements IScalarEvaluator {
+
+    private final IPointable inputRecordPointable = new VoidPointable();
+    private final UTF8StringPointable oldFieldNamePointable = new UTF8StringPointable();
+    private final UTF8StringPointable newFieldNamePointable = new UTF8StringPointable();
+    private final IBinaryComparator stringBinaryComparator = PointableHelper.createStringBinaryComparator();
+    private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+    private final DataOutput resultOutput = resultStorage.getDataOutput();
+    private final RecordBuilder outRecordBuilder = new RecordBuilder();
+    private final IScalarEvaluator eval0;
+    private final IScalarEvaluator eval1;
+    private final IScalarEvaluator eval2;
+    private final ARecordVisitablePointable openRecordPointable;
+    private ARecordVisitablePointable inputRecordVisitable;
+    private boolean requiresCast = false;
+    private ACastVisitor castVisitor;
+    private Triple<IVisitablePointable, IAType, Boolean> castVisitorArg;
+
+    RecordRenameEvaluator(IScalarEvaluator eval0, IScalarEvaluator eval1, IScalarEvaluator eval2,
+            ARecordType recordType) {
+        this.eval0 = eval0;
+        this.eval1 = eval1;
+        this.eval2 = eval2;
+        openRecordPointable = new ARecordVisitablePointable(DefaultOpenFieldType.NESTED_OPEN_RECORD_TYPE);
+        if (recordType != null) {
+            inputRecordVisitable = new ARecordVisitablePointable(recordType);
+            if (hasDerivedType(recordType.getFieldTypes())) {
+                requiresCast = true;
+                castVisitor = new ACastVisitor();
+                castVisitorArg =
+                        new Triple<>(openRecordPointable, openRecordPointable.getInputRecordType(), Boolean.FALSE);
+            }
+        }
+    }
+
+    @Override
+    public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
+        resultStorage.reset();
+        boolean returnNull = false;
+        eval0.evaluate(tuple, inputRecordPointable);
+        byte[] data = inputRecordPointable.getByteArray();
+        int offset = inputRecordPointable.getStartOffset();
+        byte typeTag = data[offset];
+        if (typeTag != ATypeTag.SERIALIZED_RECORD_TYPE_TAG) {
+            returnNull = true;
+        }
+        eval1.evaluate(tuple, oldFieldNamePointable);
+        data = oldFieldNamePointable.getByteArray();
+        offset = oldFieldNamePointable.getStartOffset();
+        typeTag = data[offset];
+        if (typeTag != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
+            returnNull = true;
+        }
+        eval2.evaluate(tuple, newFieldNamePointable);
+        data = newFieldNamePointable.getByteArray();
+        offset = newFieldNamePointable.getStartOffset();
+        typeTag = data[offset];
+        if (typeTag != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
+            returnNull = true;
+        }
+        if (returnNull) {
+            PointableHelper.setNull(result);
+            return;
+        }
+        evaluate();
+        result.set(resultStorage);
+    }
+
+    private void evaluate() throws HyracksDataException {
+        resultStorage.reset();
+        try {
+            final ARecordVisitablePointable inputRecord = getInputRecordVisitablePointable();
+            buildOutputRecord(inputRecord);
+        } catch (IOException e) {
+            throw HyracksDataException.create(e);
+        }
+    }
+
+    private void buildOutputRecord(ARecordVisitablePointable inputRecord) throws HyracksDataException {
+        outRecordBuilder.reset(DefaultOpenFieldType.NESTED_OPEN_RECORD_TYPE);
+        outRecordBuilder.init();
+        final List<IVisitablePointable> fieldNames = inputRecord.getFieldNames();
+        final List<IVisitablePointable> fieldValues = inputRecord.getFieldValues();
+        for (int i = 0, fieldCount = fieldNames.size(); i < fieldCount; i++) {
+            final IVisitablePointable fieldName = fieldNames.get(i);
+            if (!PointableHelper.isEqual(fieldName, oldFieldNamePointable, stringBinaryComparator)) {
+                outRecordBuilder.addField(fieldName, fieldValues.get(i));
+            } else {
+                outRecordBuilder.addField(newFieldNamePointable, fieldValues.get(i));
+            }
+        }
+        outRecordBuilder.write(resultOutput, true);
+    }
+
+    private ARecordVisitablePointable getInputRecordVisitablePointable() throws HyracksDataException {
+        inputRecordVisitable.set(inputRecordPointable);
+        if (requiresCast) {
+            return castToOpenRecord();
+        }
+        return inputRecordVisitable;
+    }
+
+    private boolean hasDerivedType(IAType[] types) {
+        for (IAType type : types) {
+            if (type.getTypeTag().isDerivedType()) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private ARecordVisitablePointable castToOpenRecord() throws HyracksDataException {
+        inputRecordVisitable.accept(castVisitor, castVisitorArg);
+        return openRecordPointable;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d8ed1962/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java
index 9a6a631..3b989be 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/functions/FunctionCollection.java
@@ -283,6 +283,7 @@ import org.apache.asterix.runtime.evaluators.functions.records.RecordNamesDescri
 import org.apache.asterix.runtime.evaluators.functions.records.RecordPairsDescriptor;
 import org.apache.asterix.runtime.evaluators.functions.records.RecordRemoveDescriptor;
 import org.apache.asterix.runtime.evaluators.functions.records.RecordRemoveFieldsDescriptor;
+import org.apache.asterix.runtime.evaluators.functions.records.RecordRenameDescriptor;
 import org.apache.asterix.runtime.evaluators.functions.temporal.AdjustDateTimeForTimeZoneDescriptor;
 import org.apache.asterix.runtime.evaluators.functions.temporal.AdjustTimeForTimeZoneDescriptor;
 import org.apache.asterix.runtime.evaluators.functions.temporal.CalendarDuartionFromDateDescriptor;
@@ -646,6 +647,7 @@ public final class FunctionCollection implements IFunctionCollection {
         fc.addGenerated(RecordLengthDescriptor.FACTORY);
         fc.addGenerated(RecordNamesDescriptor.FACTORY);
         fc.addGenerated(RecordRemoveDescriptor.FACTORY);
+        fc.addGenerated(RecordRenameDescriptor.FACTORY);
 
         // Spatial and temporal type accessors
         fc.addGenerated(TemporalYearAccessor.FACTORY);