You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by pr...@apache.org on 2015/07/10 05:15:31 UTC
[3/8] incubator-asterixdb git commit: Adding introspection for
getting record details.
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/c66d23a5/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/printer/ARecordPrinter.java
----------------------------------------------------------------------
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/printer/ARecordPrinter.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/printer/ARecordPrinter.java
index 1dd75c3..d48a395 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/printer/ARecordPrinter.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/printer/ARecordPrinter.java
@@ -20,7 +20,7 @@ import java.io.PrintStream;
import java.util.List;
import edu.uci.ics.asterix.common.exceptions.AsterixException;
-import edu.uci.ics.asterix.om.pointables.ARecordPointable;
+import edu.uci.ics.asterix.om.pointables.ARecordVisitablePointable;
import edu.uci.ics.asterix.om.pointables.base.IVisitablePointable;
import edu.uci.ics.asterix.om.types.ATypeTag;
import edu.uci.ics.asterix.om.types.EnumDeserializer;
@@ -43,7 +43,7 @@ class ARecordPrinter {
}
- public void printRecord(ARecordPointable recordAccessor, PrintStream ps, APrintVisitor visitor) throws IOException,
+ public void printRecord(ARecordVisitablePointable recordAccessor, PrintStream ps, APrintVisitor visitor) throws IOException,
AsterixException {
List<IVisitablePointable> fieldNames = recordAccessor.getFieldNames();
List<IVisitablePointable> fieldTags = recordAccessor.getFieldTypeTags();
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/c66d23a5/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/printer/csv/APrintVisitor.java
----------------------------------------------------------------------
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/printer/csv/APrintVisitor.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/printer/csv/APrintVisitor.java
index 8461cc4..549be5f 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/printer/csv/APrintVisitor.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/printer/csv/APrintVisitor.java
@@ -44,8 +44,8 @@ import edu.uci.ics.asterix.dataflow.data.nontagged.printers.csv.AStringPrinter;
import edu.uci.ics.asterix.dataflow.data.nontagged.printers.csv.ATimePrinter;
import edu.uci.ics.asterix.dataflow.data.nontagged.printers.csv.AYearMonthDurationPrinter;
import edu.uci.ics.asterix.om.pointables.AFlatValuePointable;
-import edu.uci.ics.asterix.om.pointables.AListPointable;
-import edu.uci.ics.asterix.om.pointables.ARecordPointable;
+import edu.uci.ics.asterix.om.pointables.AListVisitablePointable;
+import edu.uci.ics.asterix.om.pointables.ARecordVisitablePointable;
import edu.uci.ics.asterix.om.pointables.base.IVisitablePointable;
import edu.uci.ics.asterix.om.pointables.visitor.IVisitablePointableVisitor;
import edu.uci.ics.asterix.om.types.ATypeTag;
@@ -64,12 +64,12 @@ public class APrintVisitor implements IVisitablePointableVisitor<Void, Pair<Prin
private int level = 0;
@Override
- public Void visit(AListPointable accessor, Pair<PrintStream, ATypeTag> arg) throws AsterixException {
+ public Void visit(AListVisitablePointable accessor, Pair<PrintStream, ATypeTag> arg) throws AsterixException {
throw new AsterixException("'List' type unsupported for CSV output");
}
@Override
- public Void visit(ARecordPointable accessor, Pair<PrintStream, ATypeTag> arg) throws AsterixException {
+ public Void visit(ARecordVisitablePointable accessor, Pair<PrintStream, ATypeTag> arg) throws AsterixException {
ARecordPrinter printer = raccessorToPrinter.get(accessor);
if (printer == null) {
printer = new ARecordPrinter();
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/c66d23a5/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/printer/csv/ARecordPrinter.java
----------------------------------------------------------------------
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/printer/csv/ARecordPrinter.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/printer/csv/ARecordPrinter.java
index fbb6d9b..8e2b6ac 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/printer/csv/ARecordPrinter.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/printer/csv/ARecordPrinter.java
@@ -20,7 +20,7 @@ import java.io.PrintStream;
import java.util.List;
import edu.uci.ics.asterix.common.exceptions.AsterixException;
-import edu.uci.ics.asterix.om.pointables.ARecordPointable;
+import edu.uci.ics.asterix.om.pointables.ARecordVisitablePointable;
import edu.uci.ics.asterix.om.pointables.base.IVisitablePointable;
import edu.uci.ics.asterix.om.types.ATypeTag;
import edu.uci.ics.asterix.om.types.EnumDeserializer;
@@ -41,7 +41,7 @@ class ARecordPrinter {
}
- public void printRecord(ARecordPointable recordAccessor, PrintStream ps, APrintVisitor visitor) throws IOException,
+ public void printRecord(ARecordVisitablePointable recordAccessor, PrintStream ps, APrintVisitor visitor) throws IOException,
AsterixException {
List<IVisitablePointable> fieldNames = recordAccessor.getFieldNames();
List<IVisitablePointable> fieldTags = recordAccessor.getFieldTypeTags();
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/c66d23a5/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/printer/json/AListPrinter.java
----------------------------------------------------------------------
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/printer/json/AListPrinter.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/printer/json/AListPrinter.java
index 3328d7f..8b91a06 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/printer/json/AListPrinter.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/printer/json/AListPrinter.java
@@ -20,7 +20,7 @@ import java.io.PrintStream;
import java.util.List;
import edu.uci.ics.asterix.common.exceptions.AsterixException;
-import edu.uci.ics.asterix.om.pointables.AListPointable;
+import edu.uci.ics.asterix.om.pointables.AListVisitablePointable;
import edu.uci.ics.asterix.om.pointables.base.IVisitablePointable;
import edu.uci.ics.asterix.om.types.ATypeTag;
import edu.uci.ics.asterix.om.types.EnumDeserializer;
@@ -45,7 +45,7 @@ class AListPrinter {
}
}
- public void printList(AListPointable listAccessor, PrintStream ps, APrintVisitor visitor) throws IOException,
+ public void printList(AListVisitablePointable listAccessor, PrintStream ps, APrintVisitor visitor) throws IOException,
AsterixException {
List<IVisitablePointable> itemTags = listAccessor.getItemTags();
List<IVisitablePointable> items = listAccessor.getItems();
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/c66d23a5/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/printer/json/APrintVisitor.java
----------------------------------------------------------------------
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/printer/json/APrintVisitor.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/printer/json/APrintVisitor.java
index e284621..0997791 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/printer/json/APrintVisitor.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/printer/json/APrintVisitor.java
@@ -45,8 +45,8 @@ import edu.uci.ics.asterix.dataflow.data.nontagged.printers.json.AStringPrinter;
import edu.uci.ics.asterix.dataflow.data.nontagged.printers.json.ATimePrinter;
import edu.uci.ics.asterix.dataflow.data.nontagged.printers.json.AYearMonthDurationPrinter;
import edu.uci.ics.asterix.om.pointables.AFlatValuePointable;
-import edu.uci.ics.asterix.om.pointables.AListPointable;
-import edu.uci.ics.asterix.om.pointables.ARecordPointable;
+import edu.uci.ics.asterix.om.pointables.AListVisitablePointable;
+import edu.uci.ics.asterix.om.pointables.ARecordVisitablePointable;
import edu.uci.ics.asterix.om.pointables.base.IVisitablePointable;
import edu.uci.ics.asterix.om.pointables.visitor.IVisitablePointableVisitor;
import edu.uci.ics.asterix.om.types.ATypeTag;
@@ -64,7 +64,7 @@ public class APrintVisitor implements IVisitablePointableVisitor<Void, Pair<Prin
private final Map<IVisitablePointable, AListPrinter> laccessorToPrinter = new HashMap<IVisitablePointable, AListPrinter>();
@Override
- public Void visit(AListPointable accessor, Pair<PrintStream, ATypeTag> arg) throws AsterixException {
+ public Void visit(AListVisitablePointable accessor, Pair<PrintStream, ATypeTag> arg) throws AsterixException {
AListPrinter printer = laccessorToPrinter.get(accessor);
if (printer == null) {
printer = new AListPrinter(accessor.ordered());
@@ -79,7 +79,7 @@ public class APrintVisitor implements IVisitablePointableVisitor<Void, Pair<Prin
}
@Override
- public Void visit(ARecordPointable accessor, Pair<PrintStream, ATypeTag> arg) throws AsterixException {
+ public Void visit(ARecordVisitablePointable accessor, Pair<PrintStream, ATypeTag> arg) throws AsterixException {
ARecordPrinter printer = raccessorToPrinter.get(accessor);
if (printer == null) {
printer = new ARecordPrinter();
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/c66d23a5/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/printer/json/ARecordPrinter.java
----------------------------------------------------------------------
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/printer/json/ARecordPrinter.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/printer/json/ARecordPrinter.java
index c7a5654..1fde70f 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/printer/json/ARecordPrinter.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/printer/json/ARecordPrinter.java
@@ -20,7 +20,7 @@ import java.io.PrintStream;
import java.util.List;
import edu.uci.ics.asterix.common.exceptions.AsterixException;
-import edu.uci.ics.asterix.om.pointables.ARecordPointable;
+import edu.uci.ics.asterix.om.pointables.ARecordVisitablePointable;
import edu.uci.ics.asterix.om.pointables.base.IVisitablePointable;
import edu.uci.ics.asterix.om.types.ATypeTag;
import edu.uci.ics.asterix.om.types.EnumDeserializer;
@@ -43,7 +43,7 @@ class ARecordPrinter {
}
- public void printRecord(ARecordPointable recordAccessor, PrintStream ps, APrintVisitor visitor) throws IOException,
+ public void printRecord(ARecordVisitablePointable recordAccessor, PrintStream ps, APrintVisitor visitor) throws IOException,
AsterixException {
List<IVisitablePointable> fieldNames = recordAccessor.getFieldNames();
List<IVisitablePointable> fieldTags = recordAccessor.getFieldTypeTags();
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/c66d23a5/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/visitor/IVisitablePointableVisitor.java
----------------------------------------------------------------------
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/visitor/IVisitablePointableVisitor.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/visitor/IVisitablePointableVisitor.java
index af7e7d2..ec6d2f4 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/visitor/IVisitablePointableVisitor.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/visitor/IVisitablePointableVisitor.java
@@ -17,8 +17,8 @@ package edu.uci.ics.asterix.om.pointables.visitor;
import edu.uci.ics.asterix.common.exceptions.AsterixException;
import edu.uci.ics.asterix.om.pointables.AFlatValuePointable;
-import edu.uci.ics.asterix.om.pointables.AListPointable;
-import edu.uci.ics.asterix.om.pointables.ARecordPointable;
+import edu.uci.ics.asterix.om.pointables.AListVisitablePointable;
+import edu.uci.ics.asterix.om.pointables.ARecordVisitablePointable;
/**
* This interface is a visitor for all the three different IVisitablePointable
@@ -27,9 +27,9 @@ import edu.uci.ics.asterix.om.pointables.ARecordPointable;
*/
public interface IVisitablePointableVisitor<R, T> {
- public R visit(AListPointable accessor, T arg) throws AsterixException;
+ public R visit(AListVisitablePointable accessor, T arg) throws AsterixException;
- public R visit(ARecordPointable accessor, T arg) throws AsterixException;
+ public R visit(ARecordVisitablePointable accessor, T arg) throws AsterixException;
public R visit(AFlatValuePointable accessor, T arg) throws AsterixException;
}
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/c66d23a5/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/AnyTypeComputer.java
----------------------------------------------------------------------
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/AnyTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/AnyTypeComputer.java
new file mode 100644
index 0000000..94d3e1d
--- /dev/null
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/AnyTypeComputer.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2009-2013 by The Regents of the University of California
+ * Licensed 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 from
+ *
+ * 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 edu.uci.ics.asterix.om.typecomputer.impl;
+
+import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.IAType;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment;
+import edu.uci.ics.hyracks.algebricks.core.algebra.metadata.IMetadataProvider;
+
+public class AnyTypeComputer implements IResultTypeComputer {
+
+ public static final AnyTypeComputer INSTANCE = new AnyTypeComputer();
+
+ private AnyTypeComputer() {
+ }
+
+ @Override
+ public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
+ IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
+ return BuiltinType.ANY;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/c66d23a5/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/FieldAccessNestedResultType.java
----------------------------------------------------------------------
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/FieldAccessNestedResultType.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/FieldAccessNestedResultType.java
index 2aef736..fbc2ca8 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/FieldAccessNestedResultType.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/FieldAccessNestedResultType.java
@@ -36,7 +36,7 @@ import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvi
import edu.uci.ics.hyracks.algebricks.core.algebra.metadata.IMetadataProvider;
public class FieldAccessNestedResultType implements IResultTypeComputer {
-
+ private static final long serialVersionUID = 1L;
public static final FieldAccessNestedResultType INSTANCE = new FieldAccessNestedResultType();
private FieldAccessNestedResultType() {
@@ -65,15 +65,24 @@ public class FieldAccessNestedResultType implements IResultTypeComputer {
throw new AlgebricksException("Typing error: expecting a constant value, found " + ce + " instead.");
}
IAObject v = ((AsterixConstantValue) ce.getValue()).getObject();
- if (v.getType().getTypeTag() != ATypeTag.ORDEREDLIST) {
- throw new AlgebricksException("Typing error: expecting a String, found " + ce + " instead.");
- }
List<String> fieldPath = new ArrayList<String>();
- for (int i = 0; i < ((AOrderedList)v).size(); i++){
- fieldPath.add(((AString)((AOrderedList) v).getItem(i)).getStringValue());
+ if (v.getType().getTypeTag() == ATypeTag.ORDEREDLIST) {
+ for (int i = 0; i < ((AOrderedList) v).size(); i++) {
+ fieldPath.add(((AString) ((AOrderedList) v).getItem(i)).getStringValue());
+ }
+ } else if (v.getType().getTypeTag() == ATypeTag.STRING) {
+ fieldPath.add(((AString) v).getStringValue());
+ } else {
+ throw new AlgebricksException("Typing error: expecting a String, found " + ce + " instead.");
}
try {
- return t0.getSubFieldType(fieldPath);
+ IAType subType = t0.getSubFieldType(fieldPath);
+ if (subType != null) {
+ return subType;
+ } else {
+ // Open field. Type can only be determined at runtime.
+ return BuiltinType.ANY;
+ }
} catch (IOException e) {
throw new AlgebricksException("FieldPath was invalid.");
}
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/c66d23a5/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/SubsetCollectionTypeComputer.java
----------------------------------------------------------------------
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/SubsetCollectionTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/SubsetCollectionTypeComputer.java
new file mode 100644
index 0000000..b2b829b
--- /dev/null
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/SubsetCollectionTypeComputer.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2009-2013 by The Regents of the University of California
+ * Licensed 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 from
+ *
+ * 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 edu.uci.ics.asterix.om.typecomputer.impl;
+
+import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.types.AOrderedListType;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.AUnionType;
+import edu.uci.ics.asterix.om.types.AbstractCollectionType;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.IAType;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment;
+import edu.uci.ics.hyracks.algebricks.core.algebra.metadata.IMetadataProvider;
+
+public class SubsetCollectionTypeComputer implements IResultTypeComputer {
+
+ public static final SubsetCollectionTypeComputer INSTANCE = new SubsetCollectionTypeComputer();
+
+ private SubsetCollectionTypeComputer() {
+ }
+
+ @Override
+ public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env, IMetadataProvider<?, ?> mp)
+ throws AlgebricksException {
+ AbstractFunctionCallExpression fun = (AbstractFunctionCallExpression) expression;
+ IAType t;
+ try {
+ t = (IAType) env.getType(fun.getArguments().get(0).getValue());
+ } catch (AlgebricksException e) {
+ throw new AlgebricksException(e);
+ }
+ switch (t.getTypeTag()) {
+ case UNORDEREDLIST:
+ case ORDEREDLIST: {
+ AbstractCollectionType act = (AbstractCollectionType) t;
+ return act.getItemType();
+ }
+ case UNION: {
+ AUnionType ut = (AUnionType) t;
+ if (!ut.isNullableType()) {
+ throw new AlgebricksException("Expecting collection type. Found " + t);
+ }
+ IAType t2 = ut.getUnionList().get(1);
+ ATypeTag tag2 = t2.getTypeTag();
+ if (tag2 == ATypeTag.UNORDEREDLIST || tag2 == ATypeTag.ORDEREDLIST) {
+ AbstractCollectionType act = (AbstractCollectionType) t2;
+ return act.getItemType();
+ }
+ throw new AlgebricksException("Expecting collection type. Found " + t);
+ }
+ default: {
+ throw new AlgebricksException("Expecting collection type. Found " + t);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/c66d23a5/asterix-om/src/main/java/edu/uci/ics/asterix/om/util/NonTaggedFormatUtil.java
----------------------------------------------------------------------
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/util/NonTaggedFormatUtil.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/util/NonTaggedFormatUtil.java
index e141660..db83bf3 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/util/NonTaggedFormatUtil.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/util/NonTaggedFormatUtil.java
@@ -47,6 +47,7 @@ public final class NonTaggedFormatUtil {
case RECORD:
case ORDEREDLIST:
case UNORDEREDLIST:
+ case POLYGON:
case ANY:
return false;
case UNION:
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/c66d23a5/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/FieldAccessByIndexEvalFactory.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/FieldAccessByIndexEvalFactory.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/FieldAccessByIndexEvalFactory.java
deleted file mode 100644
index 3303364..0000000
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/FieldAccessByIndexEvalFactory.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Copyright 2009-2013 by The Regents of the University of California
- * Licensed 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 from
- *
- * 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 edu.uci.ics.asterix.runtime.evaluators.common;
-
-import java.io.DataOutput;
-import java.io.IOException;
-
-import edu.uci.ics.asterix.common.exceptions.AsterixException;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ARecordSerializerDeserializer;
-import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
-import edu.uci.ics.asterix.om.base.ANull;
-import edu.uci.ics.asterix.om.types.ARecordType;
-import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.asterix.om.types.AUnionType;
-import edu.uci.ics.asterix.om.types.BuiltinType;
-import edu.uci.ics.asterix.om.types.EnumDeserializer;
-import edu.uci.ics.asterix.om.types.IAType;
-import edu.uci.ics.asterix.om.util.NonTaggedFormatUtil;
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.common.exceptions.NotImplementedException;
-import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
-import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
-import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
-import edu.uci.ics.hyracks.data.std.primitive.IntegerPointable;
-import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
-import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
-
-public class FieldAccessByIndexEvalFactory implements ICopyEvaluatorFactory {
-
- private static final long serialVersionUID = 1L;
-
- private ICopyEvaluatorFactory recordEvalFactory;
- private ICopyEvaluatorFactory fieldIndexEvalFactory;
- private int nullBitmapSize;
- private ARecordType recordType;
- private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
- private final static byte SER_RECORD_TYPE_TAG = ATypeTag.RECORD.serialize();
-
- public FieldAccessByIndexEvalFactory(ICopyEvaluatorFactory recordEvalFactory,
- ICopyEvaluatorFactory fieldIndexEvalFactory, ARecordType recordType) {
- this.recordEvalFactory = recordEvalFactory;
- this.fieldIndexEvalFactory = fieldIndexEvalFactory;
- this.recordType = recordType;
- this.nullBitmapSize = ARecordType.computeNullBitmapSize(recordType);
-
- }
-
- @Override
- public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
- return new ICopyEvaluator() {
-
- private DataOutput out = output.getDataOutput();
-
- private ArrayBackedValueStorage outInput0 = new ArrayBackedValueStorage();
- private ArrayBackedValueStorage outInput1 = new ArrayBackedValueStorage();
- private ICopyEvaluator eval0 = recordEvalFactory.createEvaluator(outInput0);
- private ICopyEvaluator eval1 = fieldIndexEvalFactory.createEvaluator(outInput1);
- @SuppressWarnings("unchecked")
- private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
- .getSerializerDeserializer(BuiltinType.ANULL);
- private int fieldIndex;
- private int fieldValueOffset;
- private int fieldValueLength;
- private IAType fieldValueType;
- private ATypeTag fieldValueTypeTag = ATypeTag.NULL;
-
- @Override
- public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
- try {
- outInput0.reset();
- eval0.evaluate(tuple);
- outInput1.reset();
- eval1.evaluate(tuple);
- byte[] serRecord = outInput0.getByteArray();
-
- if (serRecord[0] == SER_NULL_TYPE_TAG) {
- nullSerde.serialize(ANull.NULL, out);
- return;
- }
-
- if (serRecord[0] != SER_RECORD_TYPE_TAG) {
- throw new AlgebricksException("Field accessor is not defined for values of type "
- + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serRecord[0]));
- }
-
- fieldIndex = IntegerPointable.getInteger(outInput1.getByteArray(), 1);
- fieldValueOffset = ARecordSerializerDeserializer.getFieldOffsetById(serRecord, fieldIndex,
- nullBitmapSize, recordType.isOpen());
-
- if (fieldValueOffset == 0) {
- // the field is null, we checked the null bit map
- out.writeByte(SER_NULL_TYPE_TAG);
- return;
- }
-
- fieldValueType = recordType.getFieldTypes()[fieldIndex];
- if (fieldValueType.getTypeTag().equals(ATypeTag.UNION)) {
- if (NonTaggedFormatUtil.isOptionalField((AUnionType) fieldValueType)) {
- fieldValueTypeTag = ((AUnionType) fieldValueType).getUnionList()
- .get(AUnionType.OPTIONAL_TYPE_INDEX_IN_UNION_LIST).getTypeTag();
- fieldValueLength = NonTaggedFormatUtil.getFieldValueLength(serRecord, fieldValueOffset,
- fieldValueTypeTag, false);
- out.writeByte(fieldValueTypeTag.serialize());
- } else {
- // union .. the general case
- throw new NotImplementedException();
- }
- } else {
- fieldValueTypeTag = fieldValueType.getTypeTag();
- fieldValueLength = NonTaggedFormatUtil.getFieldValueLength(serRecord, fieldValueOffset,
- fieldValueTypeTag, false);
- out.writeByte(fieldValueTypeTag.serialize());
- }
- out.write(serRecord, fieldValueOffset, fieldValueLength);
-
- } catch (IOException e) {
- throw new AlgebricksException(e);
- } catch (AsterixException e) {
- throw new AlgebricksException(e);
- }
- }
- };
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/c66d23a5/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/FieldAccessNestedEvalFactory.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/FieldAccessNestedEvalFactory.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/FieldAccessNestedEvalFactory.java
deleted file mode 100644
index bb98253..0000000
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/FieldAccessNestedEvalFactory.java
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * Copyright 2009-2013 by The Regents of the University of California
- * Licensed 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 from
- *
- * 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 edu.uci.ics.asterix.runtime.evaluators.common;
-
-import java.io.DataOutput;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.List;
-
-import edu.uci.ics.asterix.common.exceptions.AsterixException;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ARecordSerializerDeserializer;
-import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
-import edu.uci.ics.asterix.om.base.ANull;
-import edu.uci.ics.asterix.om.base.AString;
-import edu.uci.ics.asterix.om.types.ARecordType;
-import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.asterix.om.types.AUnionType;
-import edu.uci.ics.asterix.om.types.BuiltinType;
-import edu.uci.ics.asterix.om.types.EnumDeserializer;
-import edu.uci.ics.asterix.om.types.IAType;
-import edu.uci.ics.asterix.om.util.NonTaggedFormatUtil;
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.common.exceptions.NotImplementedException;
-import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
-import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
-import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
-import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
-import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
-import edu.uci.ics.hyracks.data.std.util.ByteArrayAccessibleOutputStream;
-import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
-
-public class FieldAccessNestedEvalFactory implements ICopyEvaluatorFactory {
-
- private static final long serialVersionUID = 1L;
-
- private ICopyEvaluatorFactory recordEvalFactory;
- private ICopyEvaluatorFactory fldNameEvalFactory;
- private ARecordType recordType;
- private List<String> fieldPath;
-
- private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
- private final static byte SER_RECORD_TYPE_TAG = ATypeTag.RECORD.serialize();
-
- public FieldAccessNestedEvalFactory(ICopyEvaluatorFactory recordEvalFactory,
- ICopyEvaluatorFactory fldNameEvalFactory, ARecordType recordType, List<String> fldName) {
- this.recordEvalFactory = recordEvalFactory;
- this.fldNameEvalFactory = fldNameEvalFactory;
- this.recordType = recordType;
- this.fieldPath = fldName;
-
- }
-
- @Override
- public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
- return new ICopyEvaluator() {
-
- private DataOutput out = output.getDataOutput();
-
- private ArrayBackedValueStorage outInput0 = new ArrayBackedValueStorage();
- private ArrayBackedValueStorage outInput1 = new ArrayBackedValueStorage();
- private ByteArrayAccessibleOutputStream subRecordTmpStream = new ByteArrayAccessibleOutputStream();
- private ICopyEvaluator eval0 = recordEvalFactory.createEvaluator(outInput0);
- private ICopyEvaluator eval1 = fldNameEvalFactory.createEvaluator(outInput1);
- @SuppressWarnings("unchecked")
- private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
- .getSerializerDeserializer(BuiltinType.ANULL);
- private ArrayBackedValueStorage[] abvs = new ArrayBackedValueStorage[fieldPath.size()];
- private DataOutput[] dos = new DataOutput[fieldPath.size()];
- private AString[] as = new AString[fieldPath.size()];
-
- {
- for (int i = 0; i < fieldPath.size(); i++) {
- abvs[i] = new ArrayBackedValueStorage();
- dos[i] = abvs[i].getDataOutput();
- as[i] = new AString(fieldPath.get(i));
- try {
- AqlSerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(as[i].getType())
- .serialize(as[i], dos[i]);
- } catch (HyracksDataException e) {
- throw new AlgebricksException(e);
- }
- }
- recordType = recordType.deepCopy(recordType);
-
- }
-
- public int checkType(byte[] serRecord) throws AlgebricksException {
- if (serRecord[0] == SER_NULL_TYPE_TAG) {
- try {
- nullSerde.serialize(ANull.NULL, out);
- } catch (HyracksDataException e) {
- throw new AlgebricksException(e);
- }
- return -1;
- }
-
- if (serRecord[0] != SER_RECORD_TYPE_TAG) {
- throw new AlgebricksException("Field accessor is not defined for values of type "
- + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serRecord[0]));
- }
- return 0;
- }
-
- @Override
- public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
-
- try {
- outInput0.reset();
- eval0.evaluate(tuple);
- outInput1.reset();
- eval1.evaluate(tuple);
-
- int subFieldIndex = -1;
- int subFieldOffset = -1;
- int subFieldLength = -1;
- int nullBitmapSize = -1;
- IAType subType = recordType;
- ATypeTag subTypeTag = ATypeTag.NULL;
- byte[] subRecord = outInput0.getByteArray();
- boolean openField = false;
- int i = 0;
-
- if (checkType(subRecord) == -1) {
- return;
- }
-
- //Moving through closed fields
- for (; i < fieldPath.size(); i++) {
- if (subType.getTypeTag().equals(ATypeTag.UNION)) {
- //enforced SubType
- subType = ((AUnionType) subType).getUnionList().get(
- AUnionType.OPTIONAL_TYPE_INDEX_IN_UNION_LIST);
- if (subType.getTypeTag().serialize() != SER_RECORD_TYPE_TAG) {
- throw new AlgebricksException("Field accessor is not defined for values of type "
- + subTypeTag);
- }
-
- }
- subFieldIndex = ((ARecordType) subType).findFieldPosition(fieldPath.get(i));
- if (subFieldIndex == -1) {
- break;
- }
- nullBitmapSize = ARecordType.computeNullBitmapSize((ARecordType) subType);
- subFieldOffset = ARecordSerializerDeserializer.getFieldOffsetById(subRecord, subFieldIndex,
- nullBitmapSize, ((ARecordType) subType).isOpen());
- if (subFieldOffset == 0) {
- // the field is null, we checked the null bit map
- out.writeByte(SER_NULL_TYPE_TAG);
- return;
- }
- subType = ((ARecordType) subType).getFieldTypes()[subFieldIndex];
- if (subType.getTypeTag().equals(ATypeTag.UNION)) {
- if (NonTaggedFormatUtil.isOptionalField((AUnionType) subType)) {
- subTypeTag = ((AUnionType) subType).getUnionList()
- .get(AUnionType.OPTIONAL_TYPE_INDEX_IN_UNION_LIST).getTypeTag();
- subFieldLength = NonTaggedFormatUtil.getFieldValueLength(subRecord, subFieldOffset,
- subTypeTag, false);
- } else {
- // union .. the general case
- throw new NotImplementedException();
- }
- } else {
- subTypeTag = subType.getTypeTag();
- subFieldLength = NonTaggedFormatUtil.getFieldValueLength(subRecord, subFieldOffset,
- subTypeTag, false);
- }
-
- if (i < fieldPath.size() - 1) {
- //setup next iteration
- subRecordTmpStream.reset();
- subRecordTmpStream.write(subTypeTag.serialize());
- subRecordTmpStream.write(subRecord, subFieldOffset, subFieldLength);
- subRecord = subRecordTmpStream.getByteArray();
-
- if (checkType(subRecord) == -1) {
- return;
- }
- }
- }
-
- //Moving through open fields
- for (; i < fieldPath.size(); i++) {
- openField = true;
- subFieldOffset = ARecordSerializerDeserializer.getFieldOffsetByName(subRecord,
- abvs[i].getByteArray());
- if (subFieldOffset < 0) {
- out.writeByte(SER_NULL_TYPE_TAG);
- return;
- }
-
- subTypeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(subRecord[subFieldOffset]);
- subFieldLength = NonTaggedFormatUtil.getFieldValueLength(subRecord, subFieldOffset, subTypeTag,
- true) + 1;
-
- if (i < fieldPath.size() - 1) {
- //setup next iteration
- subRecord = Arrays.copyOfRange(subRecord, subFieldOffset, subFieldOffset + subFieldLength);
-
- if (checkType(subRecord) == -1) {
- return;
- }
- }
- }
- if (!openField) {
- out.writeByte(subTypeTag.serialize());
- }
- out.write(subRecord, subFieldOffset, subFieldLength);
-
- } catch (IOException e) {
- throw new AlgebricksException(e);
- } catch (AsterixException e) {
- throw new AlgebricksException(e);
- }
- }
- };
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/c66d23a5/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ClosedRecordConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ClosedRecordConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ClosedRecordConstructorDescriptor.java
new file mode 100644
index 0000000..dceb12a
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ClosedRecordConstructorDescriptor.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2009-2013 by The Regents of the University of California
+ * Licensed 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 from
+ *
+ * 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 edu.uci.ics.asterix.runtime.evaluators.constructors;
+
+import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.ARecordType;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.asterix.runtime.evaluators.common.ClosedRecordConstructorEvalFactory;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+
+public class ClosedRecordConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+
+ public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+ public IFunctionDescriptor createFunctionDescriptor() {
+ return new ClosedRecordConstructorDescriptor();
+ }
+ };
+
+ private static final long serialVersionUID = 1L;
+
+ private ARecordType recType;
+
+ public void reset(ARecordType recType) {
+ this.recType = recType;
+ }
+
+ @Override
+ public FunctionIdentifier getIdentifier() {
+ return AsterixBuiltinFunctions.CLOSED_RECORD_CONSTRUCTOR;
+ }
+
+ @Override
+ public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) {
+ return new ClosedRecordConstructorEvalFactory(args, recType);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/c66d23a5/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/OpenRecordConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/OpenRecordConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/OpenRecordConstructorDescriptor.java
new file mode 100644
index 0000000..2f5ca11
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/OpenRecordConstructorDescriptor.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2009-2013 by The Regents of the University of California
+ * Licensed 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 from
+ *
+ * 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 edu.uci.ics.asterix.runtime.evaluators.constructors;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+import edu.uci.ics.asterix.builders.RecordBuilder;
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
+import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.ARecordType;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
+import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+public class OpenRecordConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+
+ public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+ public IFunctionDescriptor createFunctionDescriptor() {
+ return new OpenRecordConstructorDescriptor();
+ }
+ };
+
+ private static final long serialVersionUID = 1L;
+ private ARecordType recType;
+ private boolean[] openFields;
+
+ public void reset(ARecordType recType, boolean[] openFields) {
+ this.recType = recType;
+ this.openFields = openFields;
+ }
+
+ @Override
+ public FunctionIdentifier getIdentifier() {
+ return AsterixBuiltinFunctions.OPEN_RECORD_CONSTRUCTOR;
+ }
+
+ @Override
+ public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) {
+ return new ICopyEvaluatorFactory() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
+ int n = args.length / 2;
+ final ICopyEvaluator[] evalNames = new ICopyEvaluator[n];
+ final ICopyEvaluator[] evalFields = new ICopyEvaluator[n];
+ final ArrayBackedValueStorage fieldNameBuffer = new ArrayBackedValueStorage();
+ final ArrayBackedValueStorage fieldValueBuffer = new ArrayBackedValueStorage();
+ for (int i = 0; i < n; i++) {
+ evalNames[i] = args[2 * i].createEvaluator(fieldNameBuffer);
+ evalFields[i] = args[2 * i + 1].createEvaluator(fieldValueBuffer);
+ }
+ final DataOutput out = output.getDataOutput();
+ return new ICopyEvaluator() {
+ private RecordBuilder recBuilder = new RecordBuilder();
+ private int closedFieldId;
+ private boolean first = true;
+
+ @Override
+ public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+ try {
+ closedFieldId = 0;
+ if (first) {
+ first = false;
+ recBuilder.reset(recType);
+ }
+ recBuilder.init();
+ for (int i = 0; i < evalFields.length; i++) {
+ fieldValueBuffer.reset();
+ evalFields[i].evaluate(tuple);
+ if (openFields[i]) {
+ fieldNameBuffer.reset();
+ evalNames[i].evaluate(tuple);
+ recBuilder.addField(fieldNameBuffer, fieldValueBuffer);
+ } else {
+ if (fieldValueBuffer.getByteArray()[0] != ATypeTag.NULL.serialize()) {
+ recBuilder.addField(closedFieldId, fieldValueBuffer);
+ }
+ closedFieldId++;
+ }
+ }
+ recBuilder.write(out, true);
+ } catch (IOException | AsterixException e) {
+ throw new AlgebricksException(e);
+ }
+ }
+ };
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/c66d23a5/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/ClosedRecordConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/ClosedRecordConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/ClosedRecordConstructorDescriptor.java
deleted file mode 100644
index 383b7a3..0000000
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/ClosedRecordConstructorDescriptor.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright 2009-2013 by The Regents of the University of California
- * Licensed 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 from
- *
- * 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 edu.uci.ics.asterix.runtime.evaluators.functions;
-
-import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
-import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
-import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
-import edu.uci.ics.asterix.om.types.ARecordType;
-import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
-import edu.uci.ics.asterix.runtime.evaluators.common.ClosedRecordConstructorEvalFactory;
-import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
-
-public class ClosedRecordConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
-
- public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
- public IFunctionDescriptor createFunctionDescriptor() {
- return new ClosedRecordConstructorDescriptor();
- }
- };
-
- private static final long serialVersionUID = 1L;
-
- private ARecordType recType;
-
- public void reset(ARecordType recType) {
- this.recType = recType;
- }
-
- @Override
- public FunctionIdentifier getIdentifier() {
- return AsterixBuiltinFunctions.CLOSED_RECORD_CONSTRUCTOR;
- }
-
- @Override
- public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) {
- return new ClosedRecordConstructorEvalFactory(args, recType);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/c66d23a5/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/FieldAccessByIndexDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/FieldAccessByIndexDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/FieldAccessByIndexDescriptor.java
deleted file mode 100644
index 9a2c19b..0000000
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/FieldAccessByIndexDescriptor.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2009-2013 by The Regents of the University of California
- * Licensed 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 from
- *
- * 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 edu.uci.ics.asterix.runtime.evaluators.functions;
-
-import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
-import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
-import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
-import edu.uci.ics.asterix.om.types.ARecordType;
-import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
-import edu.uci.ics.asterix.runtime.evaluators.common.FieldAccessByIndexEvalFactory;
-import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
-
-public class FieldAccessByIndexDescriptor extends AbstractScalarFunctionDynamicDescriptor {
-
- private static final long serialVersionUID = 1L;
- public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
- public IFunctionDescriptor createFunctionDescriptor() {
- return new FieldAccessByIndexDescriptor();
- }
- };
-
- private ARecordType recType;
-
- public void reset(ARecordType recType) {
- this.recType = recType;
- }
-
- @Override
- public FunctionIdentifier getIdentifier() {
- return AsterixBuiltinFunctions.FIELD_ACCESS_BY_INDEX;
- }
-
- @Override
- public ICopyEvaluatorFactory createEvaluatorFactory(ICopyEvaluatorFactory[] args) {
- return new FieldAccessByIndexEvalFactory(args[0], args[1], recType);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/c66d23a5/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/FieldAccessByNameDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/FieldAccessByNameDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/FieldAccessByNameDescriptor.java
deleted file mode 100644
index 3b7e545..0000000
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/FieldAccessByNameDescriptor.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Copyright 2009-2013 by The Regents of the University of California
- * Licensed 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 from
- *
- * 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 edu.uci.ics.asterix.runtime.evaluators.functions;
-
-import java.io.DataOutput;
-import java.io.IOException;
-
-import edu.uci.ics.asterix.common.exceptions.AsterixException;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ARecordSerializerDeserializer;
-import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
-import edu.uci.ics.asterix.om.base.ANull;
-import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
-import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
-import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
-import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.asterix.om.types.BuiltinType;
-import edu.uci.ics.asterix.om.types.EnumDeserializer;
-import edu.uci.ics.asterix.om.util.NonTaggedFormatUtil;
-import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
-import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
-import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
-import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
-import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
-
-public class FieldAccessByNameDescriptor extends AbstractScalarFunctionDynamicDescriptor {
-
- private static final long serialVersionUID = 1L;
- public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
- public IFunctionDescriptor createFunctionDescriptor() {
- return new FieldAccessByNameDescriptor();
- }
- };
-
- @Override
- public FunctionIdentifier getIdentifier() {
- return AsterixBuiltinFunctions.FIELD_ACCESS_BY_NAME;
- }
-
- @Override
- public ICopyEvaluatorFactory createEvaluatorFactory(ICopyEvaluatorFactory[] args) {
- return new FieldAccessByNameEvalFactory(args[0], args[1]);
- }
-
- private static class FieldAccessByNameEvalFactory implements ICopyEvaluatorFactory {
-
- private static final long serialVersionUID = 1L;
-
- private ICopyEvaluatorFactory recordEvalFactory;
- private ICopyEvaluatorFactory fldNameEvalFactory;
-
- private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
- private final static byte SER_RECORD_TYPE_TAG = ATypeTag.RECORD.serialize();
-
- public FieldAccessByNameEvalFactory(ICopyEvaluatorFactory recordEvalFactory,
- ICopyEvaluatorFactory fldNameEvalFactory) {
- this.recordEvalFactory = recordEvalFactory;
- this.fldNameEvalFactory = fldNameEvalFactory;
- }
-
- @Override
- public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
- return new ICopyEvaluator() {
-
- private DataOutput out = output.getDataOutput();
-
- private ArrayBackedValueStorage outInput0 = new ArrayBackedValueStorage();
- private ArrayBackedValueStorage outInput1 = new ArrayBackedValueStorage();
- private ICopyEvaluator eval0 = recordEvalFactory.createEvaluator(outInput0);
- private ICopyEvaluator eval1 = fldNameEvalFactory.createEvaluator(outInput1);
- @SuppressWarnings("unchecked")
- private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
- .getSerializerDeserializer(BuiltinType.ANULL);
- private int fieldValueOffset;
- private int fieldValueLength;
- private ATypeTag fieldValueTypeTag = ATypeTag.NULL;
-
- @Override
- public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
-
- try {
- outInput0.reset();
- eval0.evaluate(tuple);
- outInput1.reset();
- eval1.evaluate(tuple);
- byte[] serRecord = outInput0.getByteArray();
-
- if (serRecord[0] == SER_NULL_TYPE_TAG) {
- nullSerde.serialize(ANull.NULL, out);
- return;
- }
-
- if (serRecord[0] != SER_RECORD_TYPE_TAG) {
- throw new AlgebricksException(AsterixBuiltinFunctions.FIELD_ACCESS_BY_NAME.getName()
- + ": expects input type NULL or RECORD, but got "
- + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serRecord[0]));
- }
-
- byte[] serFldName = outInput1.getByteArray();
- fieldValueOffset = ARecordSerializerDeserializer.getFieldOffsetByName(serRecord, serFldName);
- if (fieldValueOffset < 0) {
- out.writeByte(ATypeTag.NULL.serialize());
- return;
- }
-
- fieldValueTypeTag = EnumDeserializer.ATYPETAGDESERIALIZER
- .deserialize(serRecord[fieldValueOffset]);
- fieldValueLength = NonTaggedFormatUtil.getFieldValueLength(serRecord, fieldValueOffset,
- fieldValueTypeTag, true) + 1;
- out.write(serRecord, fieldValueOffset, fieldValueLength);
-
- } catch (IOException e) {
- throw new AlgebricksException(e);
- } catch (AsterixException e) {
- throw new AlgebricksException(e);
- }
- }
- };
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/c66d23a5/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/FieldAccessNestedDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/FieldAccessNestedDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/FieldAccessNestedDescriptor.java
deleted file mode 100644
index be2b043..0000000
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/FieldAccessNestedDescriptor.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright 2009-2013 by The Regents of the University of California
- * Licensed 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 from
- *
- * 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 edu.uci.ics.asterix.runtime.evaluators.functions;
-
-import java.util.List;
-
-import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
-import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
-import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
-import edu.uci.ics.asterix.om.types.ARecordType;
-import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
-import edu.uci.ics.asterix.runtime.evaluators.common.FieldAccessNestedEvalFactory;
-import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
-
-public class FieldAccessNestedDescriptor extends AbstractScalarFunctionDynamicDescriptor {
-
- private static final long serialVersionUID = 1L;
- public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
- public IFunctionDescriptor createFunctionDescriptor() {
- return new FieldAccessNestedDescriptor();
- }
- };
-
- private ARecordType recType;
- private List<String> fldName;
-
- public void reset(ARecordType recType, List<String> fldName) {
- this.recType = recType;
- this.fldName = fldName;
- }
-
- @Override
- public FunctionIdentifier getIdentifier() {
- return AsterixBuiltinFunctions.FIELD_ACCESS_NESTED;
- }
-
- @Override
- public ICopyEvaluatorFactory createEvaluatorFactory(ICopyEvaluatorFactory[] args) {
- return new FieldAccessNestedEvalFactory(args[0], args[1], recType, fldName);
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/c66d23a5/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/OpenRecordConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/OpenRecordConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/OpenRecordConstructorDescriptor.java
deleted file mode 100644
index 1babb47..0000000
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/OpenRecordConstructorDescriptor.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright 2009-2013 by The Regents of the University of California
- * Licensed 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 from
- *
- * 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 edu.uci.ics.asterix.runtime.evaluators.functions;
-
-import java.io.DataOutput;
-import java.io.IOException;
-
-import edu.uci.ics.asterix.builders.RecordBuilder;
-import edu.uci.ics.asterix.common.exceptions.AsterixException;
-import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
-import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
-import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
-import edu.uci.ics.asterix.om.types.ARecordType;
-import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
-import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
-import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
-import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
-
-public class OpenRecordConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
-
- public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
- public IFunctionDescriptor createFunctionDescriptor() {
- return new OpenRecordConstructorDescriptor();
- }
- };
-
- private static final long serialVersionUID = 1L;
- private ARecordType recType;
- private boolean[] openFields;
-
- public void reset(ARecordType recType, boolean[] openFields) {
- this.recType = recType;
- this.openFields = openFields;
- }
-
- @Override
- public FunctionIdentifier getIdentifier() {
- return AsterixBuiltinFunctions.OPEN_RECORD_CONSTRUCTOR;
- }
-
- @Override
- public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) {
- return new ICopyEvaluatorFactory() {
- private static final long serialVersionUID = 1L;
-
- @Override
- public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
- int n = args.length / 2;
- final ICopyEvaluator[] evalNames = new ICopyEvaluator[n];
- final ICopyEvaluator[] evalFields = new ICopyEvaluator[n];
- final ArrayBackedValueStorage fieldNameBuffer = new ArrayBackedValueStorage();
- final ArrayBackedValueStorage fieldValueBuffer = new ArrayBackedValueStorage();
- for (int i = 0; i < n; i++) {
- evalNames[i] = args[2 * i].createEvaluator(fieldNameBuffer);
- evalFields[i] = args[2 * i + 1].createEvaluator(fieldValueBuffer);
- }
- final DataOutput out = output.getDataOutput();
- return new ICopyEvaluator() {
- private RecordBuilder recBuilder = new RecordBuilder();
- private int closedFieldId;
- private boolean first = true;
-
- @Override
- public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
- try {
- closedFieldId = 0;
- if (first) {
- first = false;
- recBuilder.reset(recType);
- }
- recBuilder.init();
- for (int i = 0; i < evalFields.length; i++) {
- fieldValueBuffer.reset();
- evalFields[i].evaluate(tuple);
- if (openFields[i]) {
- fieldNameBuffer.reset();
- evalNames[i].evaluate(tuple);
- recBuilder.addField(fieldNameBuffer, fieldValueBuffer);
- } else {
- if (fieldValueBuffer.getByteArray()[0] != ATypeTag.NULL.serialize()) {
- recBuilder.addField(closedFieldId, fieldValueBuffer);
- }
- closedFieldId++;
- }
- }
- recBuilder.write(out, true);
- } catch (IOException | AsterixException e) {
- throw new AlgebricksException(e);
- }
- }
- };
- }
- };
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/c66d23a5/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/RecordMergeDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/RecordMergeDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/RecordMergeDescriptor.java
deleted file mode 100644
index bc09690..0000000
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/RecordMergeDescriptor.java
+++ /dev/null
@@ -1,262 +0,0 @@
-/*
- * Copyright 2009-2013 by The Regents of the University of California
- * Licensed 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 from
- *
- * 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 edu.uci.ics.asterix.runtime.evaluators.functions;
-
-import java.io.ByteArrayInputStream;
-import java.io.DataInputStream;
-import java.io.IOException;
-import java.util.Stack;
-
-import edu.uci.ics.asterix.builders.RecordBuilder;
-import edu.uci.ics.asterix.common.exceptions.AsterixException;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AStringSerializerDeserializer;
-import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
-import edu.uci.ics.asterix.om.base.ANull;
-import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
-import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
-import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
-import edu.uci.ics.asterix.om.pointables.ARecordPointable;
-import edu.uci.ics.asterix.om.pointables.PointableAllocator;
-import edu.uci.ics.asterix.om.pointables.base.IVisitablePointable;
-import edu.uci.ics.asterix.om.typecomputer.impl.RecordMergeTypeComputer;
-import edu.uci.ics.asterix.om.types.ARecordType;
-import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.asterix.om.types.BuiltinType;
-import edu.uci.ics.asterix.om.types.IAType;
-import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
-import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
-import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
-import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
-import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
-import edu.uci.ics.hyracks.data.std.util.ByteArrayAccessibleOutputStream;
-import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
-
-//The record merge evaluator is used to combine two records with no matching fieldnames
-//If both records have the same fieldname for a non-record field anywhere in the schema, the merge will fail
-//This function is performed on a recursive level, meaning that nested records can be combined
-//for instance if both records have a nested field called "metadata"
-//where metadata from A is {"comments":"this rocks"}
-//and metadata from B is {"index":7, "priority":5}
-//Records A and B can be combined yielding a nested record called "metadata"
-//That will have all three fields
-public class RecordMergeDescriptor extends AbstractScalarFunctionDynamicDescriptor {
-
- private static final long serialVersionUID = 1L;
-
- private static final byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
-
- public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
- public IFunctionDescriptor createFunctionDescriptor() {
- return new RecordMergeDescriptor();
- }
- };
-
- private ARecordType outRecType;
- private ARecordType inRecType0;
- private ARecordType inRecType1;
-
- public void reset(IAType outType, IAType inType0, IAType inType1) {
- outRecType = RecordMergeTypeComputer.extractRecordType(outType);
- inRecType0 = RecordMergeTypeComputer.extractRecordType(inType0);
- inRecType1 = RecordMergeTypeComputer.extractRecordType(inType1);
- }
-
- @Override
- public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
- return new ICopyEvaluatorFactory() {
-
- private static final long serialVersionUID = 1L;
-
- @SuppressWarnings("unchecked")
- private final ISerializerDeserializer<ANull> nullSerDe = AqlSerializerDeserializerProvider.INSTANCE
- .getSerializerDeserializer(BuiltinType.ANULL);
-
- @Override
- public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
- final ARecordType recType;
- try {
- recType = new ARecordType(outRecType.getTypeName(), outRecType.getFieldNames(),
- outRecType.getFieldTypes(), outRecType.isOpen());
- } catch (AsterixException | HyracksDataException e) {
- throw new IllegalStateException();
- }
-
- final PointableAllocator pa = new PointableAllocator();
- final IVisitablePointable vp0 = pa.allocateRecordValue(inRecType0);
- final IVisitablePointable vp1 = pa.allocateRecordValue(inRecType1);
-
- final ArrayBackedValueStorage abvs0 = new ArrayBackedValueStorage();
- final ArrayBackedValueStorage abvs1 = new ArrayBackedValueStorage();
-
- final ICopyEvaluator eval0 = args[0].createEvaluator(abvs0);
- final ICopyEvaluator eval1 = args[1].createEvaluator(abvs1);
-
- final Stack<RecordBuilder> rbStack = new Stack<RecordBuilder>();
-
- final ArrayBackedValueStorage tabvs = new ArrayBackedValueStorage();
-
- final ByteArrayAccessibleOutputStream nameOutputStream = new ByteArrayAccessibleOutputStream();
- final ByteArrayInputStream namebais = new ByteArrayInputStream(nameOutputStream.getByteArray());
- final DataInputStream namedis = new DataInputStream(namebais);
-
- return new ICopyEvaluator() {
-
- @Override
- public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
- abvs0.reset();
- abvs1.reset();
-
- eval0.evaluate(tuple);
- eval1.evaluate(tuple);
-
- if (abvs0.getByteArray()[0] == SER_NULL_TYPE_TAG
- || abvs1.getByteArray()[0] == SER_NULL_TYPE_TAG) {
- try {
- nullSerDe.serialize(ANull.NULL, output.getDataOutput());
- } catch (HyracksDataException e) {
- throw new AlgebricksException(e);
- }
- return;
- }
-
- vp0.set(abvs0);
- vp1.set(abvs1);
-
- ARecordPointable rp0 = (ARecordPointable) vp0;
- ARecordPointable rp1 = (ARecordPointable) vp1;
-
- try {
- mergeFields(recType, rp0, rp1, true, 0);
-
- rbStack.get(0).write(output.getDataOutput(), true);
- } catch (IOException | AsterixException e) {
- throw new AlgebricksException(e);
- }
- }
-
- private void mergeFields(ARecordType combinedType, ARecordPointable leftRecord,
- ARecordPointable rightRecord, boolean openFromParent, int nestedLevel) throws IOException,
- AsterixException, AlgebricksException {
- if (rbStack.size() < (nestedLevel + 1)) {
- rbStack.push(new RecordBuilder());
- }
-
- rbStack.get(nestedLevel).reset(combinedType);
- rbStack.get(nestedLevel).init();
- //Add all fields from left record
- for (int i = 0; i < leftRecord.getFieldNames().size(); i++) {
- IVisitablePointable leftName = leftRecord.getFieldNames().get(i);
- IVisitablePointable leftValue = leftRecord.getFieldValues().get(i);
- boolean foundMatch = false;
- for (int j = 0; j < rightRecord.getFieldNames().size(); j++) {
- IVisitablePointable rightName = rightRecord.getFieldNames().get(j);
- IVisitablePointable rightValue = rightRecord.getFieldValues().get(j);
- if (rightName.equals(leftName)) {
- //Field was found on the right. Merge Sub Records
- if (rightValue.getByteArray()[0] != ATypeTag.RECORD.serialize()
- || leftValue.getByteArray()[0] != ATypeTag.RECORD.serialize()) {
- //The fields need to be records in order to merge
- throw new AlgebricksException("Duplicate field found");
- } else {
- //We are merging two sub records
- addFieldToSubRecord(combinedType, leftName, leftValue, rightValue,
- openFromParent, nestedLevel);
- }
- foundMatch = true;
- }
- }
- if (!foundMatch) {
-
- addFieldToSubRecord(combinedType, leftName, leftValue, null, openFromParent,
- nestedLevel);
- }
-
- }
- //Repeat for right side (ignoring duplicates this time)
- for (int j = 0; j < rightRecord.getFieldNames().size(); j++) {
- IVisitablePointable rightName = rightRecord.getFieldNames().get(j);
- IVisitablePointable rightValue = rightRecord.getFieldValues().get(j);
- boolean foundMatch = false;
- for (int i = 0; i < leftRecord.getFieldNames().size(); i++) {
- IVisitablePointable leftName = leftRecord.getFieldNames().get(i);
- if (rightName.equals(leftName)) {
- foundMatch = true;
- }
- }
- if (!foundMatch) {
- addFieldToSubRecord(combinedType, rightName, rightValue, null, openFromParent,
- nestedLevel);
- }
-
- }
-
- }
-
- //Takes in a record type, field name, and the field values (which are record) from two records
- //Merges them into one record of combinedType
- //And adds that record as a field to the Record in subrb
- //the second value can be null, indicated that you just add the value of left as a field to subrb
- private void addFieldToSubRecord(ARecordType combinedType, IVisitablePointable fieldNamePointable,
- IVisitablePointable leftValue, IVisitablePointable rightValue, boolean openFromParent,
- int nestedLevel) throws IOException, AsterixException, AlgebricksException {
-
- nameOutputStream.reset();
- nameOutputStream.write(fieldNamePointable.getByteArray(),
- fieldNamePointable.getStartOffset() + 1, fieldNamePointable.getLength());
- namedis.reset();
- String fieldName = AStringSerializerDeserializer.INSTANCE.deserialize(namedis).getStringValue();
-
- //Add the merged field
- if (combinedType.isClosedField(fieldName)) {
- int pos = combinedType.findFieldPosition(fieldName);
- if (rightValue == null) {
- rbStack.get(nestedLevel).addField(pos, leftValue);
- } else {
- mergeFields((ARecordType) combinedType.getFieldType(fieldName),
- (ARecordPointable) leftValue, (ARecordPointable) rightValue, false,
- nestedLevel + 1);
-
- tabvs.reset();
- rbStack.get(nestedLevel + 1).write(tabvs.getDataOutput(), true);
- rbStack.get(nestedLevel).addField(pos, tabvs);
- }
- } else {
- if (rightValue == null) {
- rbStack.get(nestedLevel).addField(fieldNamePointable, leftValue);
- } else {
- mergeFields((ARecordType) combinedType.getFieldType(fieldName),
- (ARecordPointable) leftValue, (ARecordPointable) rightValue, false,
- nestedLevel + 1);
- tabvs.reset();
- rbStack.get(nestedLevel + 1).write(tabvs.getDataOutput(), true);
- rbStack.get(nestedLevel).addField(fieldNamePointable, tabvs);
- }
- }
- }
-
- };
- }
- };
- }
-
- @Override
- public FunctionIdentifier getIdentifier() {
- return AsterixBuiltinFunctions.RECORD_MERGE;
- }
-}