[NO ISSUE][EXT] Java UDF framework refactoring
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
1. Separated the JObjects and its subtypes.
2. Add JBuiltinTypes so we don't have to create an object to get JType.
3. Dead code removal.
4. Memory usage optimization in JRecord Serialization.
5. Several fixes about incomplete type implementations in Java UDF and
getting JObjects in UDF examples.
Change-Id: I3b648191b73fe4aad4f2a6ba1c2066c872fa16a9
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2405
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <tillw@apache.org>
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/api/IJObject.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/api/IJObject.java
index 250e4faf..9ea400e 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/api/IJObject.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/api/IJObject.java
@@ -21,16 +21,16 @@
import java.io.DataOutput;
import org.apache.asterix.om.base.IAObject;
-import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.IAType;
import org.apache.hyracks.api.exceptions.HyracksDataException;
public interface IJObject {
- public ATypeTag getTypeTag();
+ IAType getIAType();
- public IAObject getIAObject();
+ IAObject getIAObject();
- public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException;
+ void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException;
- public void reset() throws HyracksDataException;
+ void reset() throws HyracksDataException;
}
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/api/IJRecordAccessor.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/api/IJRecordAccessor.java
index 08c5dde..6a5f8fb 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/api/IJRecordAccessor.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/api/IJRecordAccessor.java
@@ -19,7 +19,7 @@
package org.apache.asterix.external.api;
import org.apache.asterix.external.library.java.JObjectPointableVisitor;
-import org.apache.asterix.external.library.java.JObjects.JRecord;
+import org.apache.asterix.external.library.java.base.JRecord;
import org.apache.asterix.om.pointables.ARecordVisitablePointable;
import org.apache.asterix.om.types.ARecordType;
import org.apache.asterix.om.types.IAType;
@@ -28,7 +28,7 @@
public interface IJRecordAccessor {
- public JRecord access(ARecordVisitablePointable pointable, IObjectPool<IJObject, IAType> objectPool,
+ JRecord access(ARecordVisitablePointable pointable, IObjectPool<IJObject, IAType> objectPool,
ARecordType recordType, JObjectPointableVisitor pointableVisitor) throws HyracksDataException;
}
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/api/IJType.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/api/IJType.java
index 9c0ebae..adabf0f 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/api/IJType.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/api/IJType.java
@@ -18,12 +18,9 @@
*/
package org.apache.asterix.external.api;
-import org.apache.asterix.om.base.IAObject;
-import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.IAType;
public interface IJType {
- public ATypeTag getTypeTag();
-
- public IAObject getIAObject();
+ IAType getIAType();
}
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/ExternalFunction.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/ExternalFunction.java
index 3866665..c5b9ad6 100755
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/ExternalFunction.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/ExternalFunction.java
@@ -27,7 +27,6 @@
import org.apache.asterix.external.api.IExternalFunction;
import org.apache.asterix.external.api.IFunctionFactory;
import org.apache.asterix.external.api.IFunctionHelper;
-import org.apache.asterix.formats.nontagged.SerializerDeserializerProvider;
import org.apache.asterix.om.functions.IExternalFunctionInfo;
import org.apache.asterix.om.types.ATypeTag;
import org.apache.asterix.om.types.EnumDeserializer;
@@ -36,7 +35,6 @@
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.dataflow.value.ISerializerDeserializer;
import org.apache.hyracks.api.exceptions.HyracksDataException;
import org.apache.hyracks.data.std.api.IPointable;
import org.apache.hyracks.data.std.primitive.VoidPointable;
@@ -83,14 +81,6 @@
}
}
- public static ISerializerDeserializer<?> getSerDe(Object typeInfo) {
- return SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(typeInfo);
- }
-
- public IExternalFunctionInfo getFinfo() {
- return finfo;
- }
-
public void setArguments(IFrameTupleReference tuple) throws AlgebricksException, IOException {
for (int i = 0; i < evaluatorFactories.length; i++) {
argumentEvaluators[i].evaluate(tuple, inputVal);
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/JTypeObjectFactory.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/JTypeObjectFactory.java
index bc53f0b..f30b940 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/JTypeObjectFactory.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/JTypeObjectFactory.java
@@ -19,27 +19,28 @@
package org.apache.asterix.external.library;
import org.apache.asterix.external.api.IJObject;
-import org.apache.asterix.external.library.java.JObjects;
-import org.apache.asterix.external.library.java.JObjects.JBoolean;
-import org.apache.asterix.external.library.java.JObjects.JCircle;
-import org.apache.asterix.external.library.java.JObjects.JDate;
-import org.apache.asterix.external.library.java.JObjects.JDateTime;
-import org.apache.asterix.external.library.java.JObjects.JDouble;
-import org.apache.asterix.external.library.java.JObjects.JDuration;
-import org.apache.asterix.external.library.java.JObjects.JFloat;
-import org.apache.asterix.external.library.java.JObjects.JInt;
-import org.apache.asterix.external.library.java.JObjects.JInterval;
-import org.apache.asterix.external.library.java.JObjects.JLine;
-import org.apache.asterix.external.library.java.JObjects.JLong;
-import org.apache.asterix.external.library.java.JObjects.JOrderedList;
-import org.apache.asterix.external.library.java.JObjects.JPoint;
-import org.apache.asterix.external.library.java.JObjects.JPoint3D;
-import org.apache.asterix.external.library.java.JObjects.JPolygon;
-import org.apache.asterix.external.library.java.JObjects.JRecord;
-import org.apache.asterix.external.library.java.JObjects.JRectangle;
-import org.apache.asterix.external.library.java.JObjects.JString;
-import org.apache.asterix.external.library.java.JObjects.JTime;
-import org.apache.asterix.external.library.java.JObjects.JUnorderedList;
+import org.apache.asterix.external.library.java.base.JBoolean;
+import org.apache.asterix.external.library.java.base.JCircle;
+import org.apache.asterix.external.library.java.base.JDate;
+import org.apache.asterix.external.library.java.base.JDateTime;
+import org.apache.asterix.external.library.java.base.JDouble;
+import org.apache.asterix.external.library.java.base.JDuration;
+import org.apache.asterix.external.library.java.base.JFloat;
+import org.apache.asterix.external.library.java.base.JInt;
+import org.apache.asterix.external.library.java.base.JInterval;
+import org.apache.asterix.external.library.java.base.JLine;
+import org.apache.asterix.external.library.java.base.JLong;
+import org.apache.asterix.external.library.java.base.JMissing;
+import org.apache.asterix.external.library.java.base.JNull;
+import org.apache.asterix.external.library.java.base.JOrderedList;
+import org.apache.asterix.external.library.java.base.JPoint;
+import org.apache.asterix.external.library.java.base.JPoint3D;
+import org.apache.asterix.external.library.java.base.JPolygon;
+import org.apache.asterix.external.library.java.base.JRecord;
+import org.apache.asterix.external.library.java.base.JRectangle;
+import org.apache.asterix.external.library.java.base.JString;
+import org.apache.asterix.external.library.java.base.JTime;
+import org.apache.asterix.external.library.java.base.JUnorderedList;
import org.apache.asterix.om.types.AOrderedListType;
import org.apache.asterix.om.types.ARecordType;
import org.apache.asterix.om.types.AUnionType;
@@ -110,22 +111,20 @@
retValue = new JLong(0);
break;
case NULL:
- retValue = JObjects.JNull.INSTANCE;
+ retValue = JNull.INSTANCE;
break;
case MISSING:
- retValue = JObjects.JMissing.INSTANCE;
+ retValue = JMissing.INSTANCE;
break;
case ARRAY:
AOrderedListType ot = (AOrderedListType) type;
IAType orderedItemType = ot.getItemType();
- IJObject orderedItemObject = create(orderedItemType);
- retValue = new JOrderedList(orderedItemObject);
+ retValue = new JOrderedList(orderedItemType);
break;
case MULTISET:
AUnorderedListType ut = (AUnorderedListType) type;
IAType unorderedItemType = ut.getItemType();
- IJObject unorderedItemObject = create(unorderedItemType);
- retValue = new JUnorderedList(unorderedItemObject);
+ retValue = new JUnorderedList(unorderedItemType);
break;
case OBJECT:
IAType[] fieldTypes = ((ARecordType) type).getFieldTypes();
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/JavaFunctionHelper.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/JavaFunctionHelper.java
index a250b4c..a264485 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/JavaFunctionHelper.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/JavaFunctionHelper.java
@@ -29,8 +29,7 @@
import org.apache.asterix.external.api.IFunctionHelper;
import org.apache.asterix.external.api.IJObject;
import org.apache.asterix.external.library.java.JObjectPointableVisitor;
-import org.apache.asterix.external.library.java.JObjects;
-import org.apache.asterix.external.library.java.JObjects.JNull;
+import org.apache.asterix.external.library.java.base.JNull;
import org.apache.asterix.external.library.java.JTypeTag;
import org.apache.asterix.om.functions.IExternalFunctionInfo;
import org.apache.asterix.om.pointables.AFlatValuePointable;
@@ -38,7 +37,6 @@
import org.apache.asterix.om.pointables.ARecordVisitablePointable;
import org.apache.asterix.om.pointables.PointableAllocator;
import org.apache.asterix.om.pointables.base.IVisitablePointable;
-import org.apache.asterix.om.types.ATypeTag;
import org.apache.asterix.om.types.BuiltinType;
import org.apache.asterix.om.types.IAType;
import org.apache.asterix.om.util.container.IObjectPool;
@@ -95,12 +93,9 @@
}
private boolean checkInvalidReturnValueType(IJObject result, IAType expectedType) {
- if (expectedType.getTypeTag() != result.getTypeTag()) {
+ if (!expectedType.deepEqual(result.getIAType())) {
return true;
}
- if (expectedType.getTypeTag() == ATypeTag.OBJECT) {
- return !expectedType.getTypeName().equals(((JObjects.JRecord) result).getRecordType().getTypeName());
- }
return false;
}
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/ResultCollector.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/ResultCollector.java
deleted file mode 100755
index 7d8b504..0000000
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/ResultCollector.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.external.library;
-
-import java.io.DataOutput;
-
-import org.apache.asterix.common.exceptions.AsterixException;
-import org.apache.asterix.external.api.IResultCollector;
-import org.apache.asterix.formats.nontagged.SerializerDeserializerProvider;
-import org.apache.asterix.om.base.AMutableDouble;
-import org.apache.asterix.om.base.AMutableFloat;
-import org.apache.asterix.om.base.AMutableInt32;
-import org.apache.asterix.om.base.AMutableOrderedList;
-import org.apache.asterix.om.base.AMutableRecord;
-import org.apache.asterix.om.base.AMutableString;
-import org.apache.asterix.om.base.AOrderedList;
-import org.apache.asterix.om.base.ARecord;
-import org.apache.asterix.om.base.IAObject;
-import org.apache.asterix.om.functions.IExternalFunctionInfo;
-import org.apache.asterix.om.types.AOrderedListType;
-import org.apache.asterix.om.types.ARecordType;
-import org.apache.asterix.om.types.IAType;
-import org.apache.hyracks.api.exceptions.HyracksDataException;
-import org.apache.hyracks.data.std.api.IDataOutputProvider;
-
-public class ResultCollector implements IResultCollector {
-
- private IAObject reusableResultObjectHolder;
- private IDataOutputProvider outputProvider;
- private IExternalFunctionInfo finfo;
-
- public ResultCollector(IExternalFunctionInfo finfo, IDataOutputProvider outputProvider) {
- this.finfo = finfo;
- IAType returnType = finfo.getReturnType();
- reusableResultObjectHolder = allocateResultObjectHolder(returnType);
- this.outputProvider = outputProvider;
- }
-
- private IAObject allocateResultObjectHolder(IAType type) {
- switch (type.getTypeTag()) {
- case INTEGER:
- return new AMutableInt32(0);
- case FLOAT:
- return new AMutableFloat(0f);
- case DOUBLE:
- return new AMutableDouble(0);
- case STRING:
- return new AMutableString("");
- case ARRAY:
- return new AMutableOrderedList((AOrderedListType) type);
- case OBJECT:
- IAType[] fieldType = ((ARecordType) type).getFieldTypes();
- IAObject[] fieldObjects = new IAObject[fieldType.length];
- for (int i = 0; i < fieldType.length; i++) {
- fieldObjects[i] = allocateResultObjectHolder(fieldType[i]);
- }
- return new AMutableRecord((ARecordType) type, fieldObjects);
- default:
- break;
- }
- return null;
- }
-
- @Override
- public void writeDoubleResult(double result) throws AsterixException {
- ((AMutableDouble) reusableResultObjectHolder).setValue(result);
- serializeResult(reusableResultObjectHolder);
- }
-
- @Override
- public void writeFloatResult(float result) throws AsterixException {
- ((AMutableDouble) reusableResultObjectHolder).setValue(result);
- serializeResult(reusableResultObjectHolder);
- }
-
- @Override
- public void writeIntResult(int result) throws AsterixException {
- ((AMutableInt32) reusableResultObjectHolder).setValue(result);
- serializeResult(reusableResultObjectHolder);
- }
-
- @Override
- public void writeStringResult(String result) throws AsterixException {
- ((AMutableString) reusableResultObjectHolder).setValue(result);
- serializeResult(reusableResultObjectHolder);
-
- }
-
- @Override
- public void writeRecordResult(ARecord result) throws AsterixException {
- serializeResult(result);
- }
-
- @Override
- public void writeListResult(AOrderedList list) throws AsterixException {
- serializeResult(list);
- }
-
- @Override
- public IAObject getComplexTypeResultHolder() {
- return reusableResultObjectHolder;
- }
-
- @SuppressWarnings("unchecked")
- private void serializeResult(IAObject object) throws AsterixException {
- try {
- SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(finfo.getReturnType())
- .serialize(reusableResultObjectHolder, outputProvider.getDataOutput());
- } catch (HyracksDataException hde) {
- throw new AsterixException(hde);
- }
- }
-
- @Override
- public DataOutput getDataOutput() {
- return outputProvider.getDataOutput();
- }
-
-}
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JBuiltinType.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JBuiltinType.java
new file mode 100644
index 0000000..7d28ac4
--- /dev/null
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JBuiltinType.java
@@ -0,0 +1,165 @@
+/*
+ * 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.external.library.java;
+
+import org.apache.asterix.external.api.IJType;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.om.types.IAType;
+
+public abstract class JBuiltinType implements IJType {
+
+ private JBuiltinType() {
+ // no op
+ }
+
+ public static final JBuiltinType JBOOLEAN = new JBuiltinType() {
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.ABOOLEAN;
+ }
+ };
+
+ public static final JBuiltinType JBYTE = new JBuiltinType() {
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.AINT8;
+ }
+ };
+ public static final JBuiltinType JCIRCLE = new JBuiltinType() {
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.ACIRCLE;
+ }
+ };
+ public static final JBuiltinType JDATE = new JBuiltinType() {
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.ADATE;
+ }
+ };
+ public static final JBuiltinType JDATETIME = new JBuiltinType() {
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.ADATETIME;
+ }
+ };
+
+ public static final JBuiltinType JDOUBLE = new JBuiltinType() {
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.ADOUBLE;
+ }
+ };
+
+ public static final JBuiltinType JDURATION = new JBuiltinType() {
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.ADURATION;
+ }
+ };
+
+ public static final JBuiltinType JFLOAT = new JBuiltinType() {
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.AFLOAT;
+ }
+ };
+
+ public static final JBuiltinType JINT = new JBuiltinType() {
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.AINT32;
+ }
+ };
+
+ public static final JBuiltinType JINTERVAL = new JBuiltinType() {
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.AINTERVAL;
+ }
+ };
+
+ public static final JBuiltinType JLINE = new JBuiltinType() {
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.ALINE;
+ }
+ };
+ public static final JBuiltinType JLONG = new JBuiltinType() {
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.AINT64;
+ }
+ };
+ public static final JBuiltinType JMISSING = new JBuiltinType() {
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.AMISSING;
+ }
+ };
+ public static final JBuiltinType JNULL = new JBuiltinType() {
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.ANULL;
+ }
+ };
+ public static final JBuiltinType JPOINT = new JBuiltinType() {
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.APOINT;
+ }
+ };
+ public static final JBuiltinType JPOINT3D = new JBuiltinType() {
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.APOINT3D;
+ }
+ };
+ public static final JBuiltinType JPOLYGON = new JBuiltinType() {
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.APOLYGON;
+ }
+ };
+ public static final JBuiltinType JRECTANGLE = new JBuiltinType() {
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.ARECTANGLE;
+ }
+ };
+ public static final JBuiltinType JSHORT = new JBuiltinType() {
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.AINT16;
+ }
+ };
+ public static final JBuiltinType JSTRING = new JBuiltinType() {
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.ASTRING;
+ }
+ };
+ public static final JBuiltinType JTIME = new JBuiltinType() {
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.ATIME;
+ }
+ };
+
+}
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjectAccessors.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjectAccessors.java
index 8f35c80..0a706d1 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjectAccessors.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjectAccessors.java
@@ -49,28 +49,28 @@
import org.apache.asterix.external.api.IJObjectAccessor;
import org.apache.asterix.external.api.IJRecordAccessor;
import org.apache.asterix.external.library.TypeInfo;
-import org.apache.asterix.external.library.java.JObjects.JBoolean;
-import org.apache.asterix.external.library.java.JObjects.JByte;
-import org.apache.asterix.external.library.java.JObjects.JCircle;
-import org.apache.asterix.external.library.java.JObjects.JDate;
-import org.apache.asterix.external.library.java.JObjects.JDateTime;
-import org.apache.asterix.external.library.java.JObjects.JDouble;
-import org.apache.asterix.external.library.java.JObjects.JDuration;
-import org.apache.asterix.external.library.java.JObjects.JFloat;
-import org.apache.asterix.external.library.java.JObjects.JInt;
-import org.apache.asterix.external.library.java.JObjects.JInterval;
-import org.apache.asterix.external.library.java.JObjects.JLine;
-import org.apache.asterix.external.library.java.JObjects.JList;
-import org.apache.asterix.external.library.java.JObjects.JLong;
-import org.apache.asterix.external.library.java.JObjects.JOrderedList;
-import org.apache.asterix.external.library.java.JObjects.JPoint;
-import org.apache.asterix.external.library.java.JObjects.JPoint3D;
-import org.apache.asterix.external.library.java.JObjects.JPolygon;
-import org.apache.asterix.external.library.java.JObjects.JRecord;
-import org.apache.asterix.external.library.java.JObjects.JRectangle;
-import org.apache.asterix.external.library.java.JObjects.JString;
-import org.apache.asterix.external.library.java.JObjects.JTime;
-import org.apache.asterix.external.library.java.JObjects.JUnorderedList;
+import org.apache.asterix.external.library.java.base.JBoolean;
+import org.apache.asterix.external.library.java.base.JByte;
+import org.apache.asterix.external.library.java.base.JCircle;
+import org.apache.asterix.external.library.java.base.JDate;
+import org.apache.asterix.external.library.java.base.JDateTime;
+import org.apache.asterix.external.library.java.base.JDouble;
+import org.apache.asterix.external.library.java.base.JDuration;
+import org.apache.asterix.external.library.java.base.JFloat;
+import org.apache.asterix.external.library.java.base.JInt;
+import org.apache.asterix.external.library.java.base.JInterval;
+import org.apache.asterix.external.library.java.base.JLine;
+import org.apache.asterix.external.library.java.base.JList;
+import org.apache.asterix.external.library.java.base.JLong;
+import org.apache.asterix.external.library.java.base.JOrderedList;
+import org.apache.asterix.external.library.java.base.JPoint;
+import org.apache.asterix.external.library.java.base.JPoint3D;
+import org.apache.asterix.external.library.java.base.JPolygon;
+import org.apache.asterix.external.library.java.base.JRecord;
+import org.apache.asterix.external.library.java.base.JRectangle;
+import org.apache.asterix.external.library.java.base.JString;
+import org.apache.asterix.external.library.java.base.JTime;
+import org.apache.asterix.external.library.java.base.JUnorderedList;
import org.apache.asterix.om.base.ACircle;
import org.apache.asterix.om.base.ADuration;
import org.apache.asterix.om.base.ALine;
@@ -147,6 +147,21 @@
case DURATION:
accessor = new JDurationAccessor();
break;
+ case INTERVAL:
+ accessor = new JIntervalAccessor();
+ break;
+ case CIRCLE:
+ accessor = new JCircleAccessor();
+ break;
+ case POLYGON:
+ accessor = new JPolygonAccessor();
+ break;
+ case RECTANGLE:
+ accessor = new JRectangleAccessor();
+ break;
+ case TIME:
+ accessor = new JTimeAccessor();
+ break;
case NULL:
accessor = new JNullAccessor();
break;
@@ -272,16 +287,14 @@
int s = pointable.getStartOffset();
int l = pointable.getLength();
- String v = null;
+ String v;
try {
v = reader.readUTF(new DataInputStream(new ByteArrayInputStream(b, s + 1, l - 1)));
} catch (IOException e) {
throw HyracksDataException.create(e);
}
- JObjectUtil.getNormalizedString(v);
-
IJObject jObject = objectPool.allocate(BuiltinType.ASTRING);
- ((JString) jObject).setValue(JObjectUtil.getNormalizedString(v));
+ ((JString) jObject).setValue(v);
return jObject;
}
}
@@ -598,14 +611,4 @@
return list;
}
}
-
- public static class JUnorderedListAccessor implements IJObjectAccessor {
-
- @Override
- public IJObject access(IVisitablePointable pointable, IObjectPool<IJObject, IAType> objectPool)
- throws HyracksDataException {
- return null;
- }
-
- }
}
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjectPointableVisitor.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjectPointableVisitor.java
index 960b346..f112ed2 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjectPointableVisitor.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjectPointableVisitor.java
@@ -21,7 +21,6 @@
import java.util.HashMap;
import java.util.Map;
-import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.external.api.IJListAccessor;
import org.apache.asterix.external.api.IJObject;
import org.apache.asterix.external.api.IJObjectAccessor;
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjectUtil.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjectUtil.java
deleted file mode 100644
index 5bc1ec2..0000000
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjectUtil.java
+++ /dev/null
@@ -1,427 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.external.library.java;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.asterix.common.exceptions.ErrorCode;
-import org.apache.asterix.common.exceptions.RuntimeDataException;
-import org.apache.asterix.dataflow.data.nontagged.serde.AStringSerializerDeserializer;
-import org.apache.asterix.dataflow.data.nontagged.serde.SerializerDeserializerUtil;
-import org.apache.asterix.external.api.IJObject;
-import org.apache.asterix.external.library.java.JObjects.ByteArrayAccessibleDataInputStream;
-import org.apache.asterix.external.library.java.JObjects.JBoolean;
-import org.apache.asterix.external.library.java.JObjects.JCircle;
-import org.apache.asterix.external.library.java.JObjects.JDate;
-import org.apache.asterix.external.library.java.JObjects.JDateTime;
-import org.apache.asterix.external.library.java.JObjects.JDouble;
-import org.apache.asterix.external.library.java.JObjects.JDuration;
-import org.apache.asterix.external.library.java.JObjects.JFloat;
-import org.apache.asterix.external.library.java.JObjects.JInt;
-import org.apache.asterix.external.library.java.JObjects.JInterval;
-import org.apache.asterix.external.library.java.JObjects.JLine;
-import org.apache.asterix.external.library.java.JObjects.JOrderedList;
-import org.apache.asterix.external.library.java.JObjects.JPoint;
-import org.apache.asterix.external.library.java.JObjects.JPoint3D;
-import org.apache.asterix.external.library.java.JObjects.JPolygon;
-import org.apache.asterix.external.library.java.JObjects.JRecord;
-import org.apache.asterix.external.library.java.JObjects.JRectangle;
-import org.apache.asterix.external.library.java.JObjects.JString;
-import org.apache.asterix.external.library.java.JObjects.JTime;
-import org.apache.asterix.external.library.java.JObjects.JUnorderedList;
-import org.apache.asterix.om.base.APoint;
-import org.apache.asterix.om.types.AOrderedListType;
-import org.apache.asterix.om.types.ARecordType;
-import org.apache.asterix.om.types.ATypeTag;
-import org.apache.asterix.om.types.AUnionType;
-import org.apache.asterix.om.types.AUnorderedListType;
-import org.apache.asterix.om.types.BuiltinType;
-import org.apache.asterix.om.types.EnumDeserializer;
-import org.apache.asterix.om.types.IAType;
-import org.apache.asterix.om.util.container.IObjectPool;
-import org.apache.asterix.om.utils.NonTaggedFormatUtil;
-
-public class JObjectUtil {
-
- /**
- * Normalize an input string by removing linebreaks, and replace them with space
- * Also remove non-readable special characters
- *
- * @param originalString
- * The input String
- * @return
- * String - the normalized string
- */
- public static String getNormalizedString(String originalString) {
- int len = originalString.length();
- char asciiBuff[] = new char[len];
- int j = 0;
- for (int i = 0; i < len; i++) {
- char c = originalString.charAt(i);
- if (c == '\n' || c == '\t' || c == '\r') {
- asciiBuff[j] = ' ';
- j++;
- } else if (c > 0 && c <= 0x7f) {
- asciiBuff[j] = c;
- j++;
- }
- }
-
- return new String(asciiBuff).trim();
- }
-
- public static IJObject getJType(ATypeTag typeTag, IAType type, ByteArrayAccessibleDataInputStream dis,
- IObjectPool<IJObject, IAType> objectPool) throws IOException {
- IJObject jObject;
-
- switch (typeTag) {
-
- case INTEGER: {
- int v = dis.readInt();
- jObject = objectPool.allocate(BuiltinType.AINT32);
- ((JInt) jObject).setValue(v);
- break;
- }
-
- case FLOAT: {
- float v = dis.readFloat();
- jObject = objectPool.allocate(BuiltinType.AFLOAT);
- ((JFloat) jObject).setValue(v);
- break;
- }
-
- case DOUBLE: {
- double value = dis.readDouble();
- jObject = objectPool.allocate(BuiltinType.ADOUBLE);
- ((JDouble) jObject).setValue(value);
- break;
- }
-
- case STRING: {
- String v = dis.readUTF();
- jObject = objectPool.allocate(BuiltinType.ASTRING);
- ((JString) jObject).setValue(v);
- break;
- }
-
- case BOOLEAN:
- jObject = objectPool.allocate(BuiltinType.ABOOLEAN);
- ((JBoolean) jObject).setValue(dis.readBoolean());
- break;
-
- case DATE: {
- int d = dis.readInt();
- jObject = objectPool.allocate(BuiltinType.ADATE);
- ((JDate) jObject).setValue(d);
- break;
- }
-
- case DATETIME: {
- jObject = objectPool.allocate(BuiltinType.ADATETIME);
- long value = dis.readLong();
- ((JDateTime) jObject).setValue(value);
- break;
- }
-
- case DURATION: {
- jObject = objectPool.allocate(BuiltinType.ADURATION);
- int months = dis.readInt();
- long msecs = dis.readLong();
- ((JDuration) jObject).setValue(months, msecs);
- break;
- }
-
- case TIME: {
- jObject = objectPool.allocate(BuiltinType.ATIME);
- int time = dis.readInt();
- ((JTime) jObject).setValue(time);
- break;
- }
-
- case INTERVAL: {
- jObject = objectPool.allocate(BuiltinType.AINTERVAL);
- long start = dis.readLong();
- long end = dis.readLong();
- byte intervalType = dis.readByte();
- ((JInterval) jObject).setValue(start, end, intervalType);
- break;
- }
-
- case CIRCLE: {
- jObject = objectPool.allocate(BuiltinType.ACIRCLE);
- double x = dis.readDouble();
- double y = dis.readDouble();
- double radius = dis.readDouble();
- JPoint jpoint = (JPoint) objectPool.allocate(BuiltinType.APOINT);
- jpoint.setValue(x, y);
- ((JCircle) jObject).setValue(jpoint, radius);
- break;
- }
-
- case POINT: {
- jObject = objectPool.allocate(BuiltinType.APOINT);
- double x = dis.readDouble();
- double y = dis.readDouble();
- ((JPoint) jObject).setValue(x, y);
- break;
- }
-
- case POINT3D: {
- jObject = objectPool.allocate(BuiltinType.APOINT3D);
- double x = dis.readDouble();
- double y = dis.readDouble();
- double z = dis.readDouble();
- ((JPoint3D) jObject).setValue(x, y, z);
- break;
- }
-
- case LINE: {
- jObject = objectPool.allocate(BuiltinType.ALINE);
- double x1 = dis.readDouble();
- double y1 = dis.readDouble();
- double x2 = dis.readDouble();
- double y2 = dis.readDouble();
- JPoint jpoint1 = (JPoint) objectPool.allocate(BuiltinType.APOINT);
- jpoint1.setValue(x1, y1);
- JPoint jpoint2 = (JPoint) objectPool.allocate(BuiltinType.APOINT);
- jpoint2.setValue(x2, y2);
- ((JLine) jObject).setValue(jpoint1, jpoint2);
- break;
- }
-
- case POLYGON: {
- jObject = objectPool.allocate(BuiltinType.APOLYGON);
- short numberOfPoints = dis.readShort();
- List<JPoint> points = new ArrayList<JPoint>();
- for (int i = 0; i < numberOfPoints; i++) {
- JPoint p1 = (JPoint) objectPool.allocate(BuiltinType.APOINT);
- p1.setValue(dis.readDouble(), dis.readDouble());
- points.add(p1);
- }
- ((JPolygon) jObject).setValue(points.toArray(new APoint[] {}));
- break;
- }
-
- case RECTANGLE: {
- jObject = objectPool.allocate(BuiltinType.ARECTANGLE);
- double x1 = dis.readDouble();
- double y1 = dis.readDouble();
- double x2 = dis.readDouble();
- double y2 = dis.readDouble();
- JPoint jpoint1 = (JPoint) objectPool.allocate(BuiltinType.APOINT);
- jpoint1.setValue(x1, y1);
- JPoint jpoint2 = (JPoint) objectPool.allocate(BuiltinType.APOINT);
- jpoint2.setValue(x2, y2);
- ((JRectangle) jObject).setValue(jpoint1, jpoint2);
- break;
- }
-
- case MULTISET: {
- AUnorderedListType listType = (AUnorderedListType) type;
- IAType elementType = listType.getItemType();
- jObject = objectPool.allocate(listType);
-
- boolean fixedSize = false;
- ATypeTag tag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(dis.readByte());
- switch (tag) {
- case STRING:
- case OBJECT:
- case ARRAY:
- case MULTISET:
- case ANY:
- fixedSize = false;
- break;
- default:
- fixedSize = true;
- break;
- }
- dis.readInt(); // list size
- int numberOfitems;
- numberOfitems = dis.readInt();
- if (numberOfitems <= 0) {
- break;
- }
- if (!fixedSize) {
- for (int i = 0; i < numberOfitems; i++) {
- dis.readInt();
- }
- }
- for (int i = 0; i < numberOfitems; i++) {
- IJObject v = getJType(elementType.getTypeTag(), elementType, dis, objectPool);
- ((JUnorderedList) jObject).add(v);
- }
- break;
- }
- case ARRAY: {
- AOrderedListType listType = (AOrderedListType) type;
- IAType elementType = listType.getItemType();
- jObject = objectPool.allocate(listType);
- boolean fixedSize = false;
- ATypeTag tag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(dis.readByte());
- switch (tag) {
- case STRING:
- case OBJECT:
- case ARRAY:
- case MULTISET:
- case ANY:
- fixedSize = false;
- break;
- default:
- fixedSize = true;
- break;
- }
-
- dis.readInt(); // list size
- int numberOfitems;
- numberOfitems = dis.readInt();
- if (numberOfitems <= 0) {
- break;
- }
- if (!fixedSize) {
- for (int i = 0; i < numberOfitems; i++) {
- dis.readInt();
- }
- }
- for (int i = 0; i < numberOfitems; i++) {
- IJObject v = getJType(elementType.getTypeTag(), elementType, dis, objectPool);
- ((JOrderedList) jObject).add(v);
- }
- break;
- }
- case OBJECT:
- ARecordType recordType = (ARecordType) type;
- int numberOfSchemaFields = recordType.getFieldTypes().length;
- byte[] recordBits = dis.getInputStream().getArray();
- boolean isExpanded = false;
- dis.getInputStream();
- int[] fieldOffsets = new int[numberOfSchemaFields];
- IJObject[] closedFields = new IJObject[numberOfSchemaFields];
-
- dis.skip(4); // reading length is not required.
- if (recordType.isOpen()) {
- isExpanded = dis.readBoolean();
- if (isExpanded) {
- dis.readInt();
- } else {
- }
- } else {
- }
-
- if (numberOfSchemaFields > 0) {
- dis.readInt();
- int nullBitMapOffset = 0;
- boolean hasOptionalFields = NonTaggedFormatUtil.hasOptionalField(recordType);
- if (hasOptionalFields) {
- nullBitMapOffset = dis.getInputStream().getPosition();
- dis.getInputStream();
- } else {
- dis.getInputStream();
- }
- for (int i = 0; i < numberOfSchemaFields; i++) {
- fieldOffsets[i] = dis.readInt();
- }
- for (int fieldNumber = 0; fieldNumber < numberOfSchemaFields; fieldNumber++) {
- if (hasOptionalFields) {
- byte b1 = recordBits[nullBitMapOffset + fieldNumber / 8];
- int p = 1 << (7 - (fieldNumber % 8));
- if ((b1 & p) == 0) {
- continue;
- }
- }
- IAType[] fieldTypes = recordType.getFieldTypes();
- ATypeTag fieldValueTypeTag = null;
-
- IAType fieldType = fieldTypes[fieldNumber];
- if (fieldTypes[fieldNumber].getTypeTag() == ATypeTag.UNION) {
- if (((AUnionType) fieldTypes[fieldNumber]).isUnknownableType()) {
- fieldType = ((AUnionType) fieldTypes[fieldNumber]).getActualType();
- fieldValueTypeTag = fieldType.getTypeTag();
- }
- } else {
- fieldValueTypeTag = fieldTypes[fieldNumber].getTypeTag();
- }
- closedFields[fieldNumber] = getJType(fieldValueTypeTag, fieldType, dis, objectPool);
- }
- }
- if (isExpanded) {
- int numberOfOpenFields = dis.readInt();
- String[] fieldNames = new String[numberOfOpenFields];
- IAType[] fieldTypes = new IAType[numberOfOpenFields];
- IJObject[] openFields = new IJObject[numberOfOpenFields];
- for (int i = 0; i < numberOfOpenFields; i++) {
- dis.readInt();
- dis.readInt();
- }
- for (int i = 0; i < numberOfOpenFields; i++) {
- fieldNames[i] = AStringSerializerDeserializer.INSTANCE.deserialize(dis).getStringValue();
- ATypeTag openFieldTypeTag = SerializerDeserializerUtil.deserializeTag(dis);
- openFields[i] = getJType(openFieldTypeTag, null, dis, objectPool);
- fieldTypes[i] = openFields[i].getIAObject().getType();
- }
- ARecordType openPartRecType = new ARecordType(null, fieldNames, fieldTypes, true);
- if (numberOfSchemaFields > 0) {
- ARecordType mergedRecordType = mergeRecordTypes(recordType, openPartRecType);
- IJObject[] mergedFields = mergeFields(closedFields, openFields);
- jObject = objectPool.allocate(recordType);
- return new JRecord(mergedRecordType, mergedFields);
- } else {
- return new JRecord(recordType, openFields);
- }
- } else {
- return new JRecord(recordType, closedFields);
- }
-
- default:
- throw new RuntimeDataException(ErrorCode.LIBRARY_JOBJECT_UTIL_ILLEGAL_ARGU_TYPE, typeTag);
- }
- return jObject;
- }
-
- private static IJObject[] mergeFields(IJObject[] closedFields, IJObject[] openFields) {
- IJObject[] fields = new IJObject[closedFields.length + openFields.length];
- int i = 0;
- for (; i < closedFields.length; i++) {
- fields[i] = closedFields[i];
- }
- for (int j = 0; j < openFields.length; j++) {
- fields[closedFields.length + j] = openFields[j];
- }
- return fields;
- }
-
- private static ARecordType mergeRecordTypes(ARecordType recType1, ARecordType recType2) {
-
- String[] fieldNames = new String[recType1.getFieldNames().length + recType2.getFieldNames().length];
- IAType[] fieldTypes = new IAType[recType1.getFieldTypes().length + recType2.getFieldTypes().length];
-
- int i = 0;
- for (; i < recType1.getFieldNames().length; i++) {
- fieldNames[i] = recType1.getFieldNames()[i];
- fieldTypes[i] = recType1.getFieldTypes()[i];
- }
-
- for (int j = 0; j < recType2.getFieldNames().length; i++, j++) {
- fieldNames[i] = recType2.getFieldNames()[j];
- fieldTypes[i] = recType2.getFieldTypes()[j];
- }
- return new ARecordType(null, fieldNames, fieldTypes, true);
- }
-}
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjects.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjects.java
deleted file mode 100644
index 819d523..0000000
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JObjects.java
+++ /dev/null
@@ -1,1202 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.external.library.java;
-
-import java.io.ByteArrayInputStream;
-import java.io.DataInputStream;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.apache.asterix.builders.IAsterixListBuilder;
-import org.apache.asterix.builders.RecordBuilder;
-import org.apache.asterix.builders.UnorderedListBuilder;
-import org.apache.asterix.common.exceptions.ErrorCode;
-import org.apache.asterix.common.exceptions.RuntimeDataException;
-import org.apache.asterix.dataflow.data.nontagged.serde.ABooleanSerializerDeserializer;
-import org.apache.asterix.dataflow.data.nontagged.serde.ACircleSerializerDeserializer;
-import org.apache.asterix.dataflow.data.nontagged.serde.ADateSerializerDeserializer;
-import org.apache.asterix.dataflow.data.nontagged.serde.ADateTimeSerializerDeserializer;
-import org.apache.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
-import org.apache.asterix.dataflow.data.nontagged.serde.ADurationSerializerDeserializer;
-import org.apache.asterix.dataflow.data.nontagged.serde.AFloatSerializerDeserializer;
-import org.apache.asterix.dataflow.data.nontagged.serde.AInt16SerializerDeserializer;
-import org.apache.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
-import org.apache.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
-import org.apache.asterix.dataflow.data.nontagged.serde.AInt8SerializerDeserializer;
-import org.apache.asterix.dataflow.data.nontagged.serde.AIntervalSerializerDeserializer;
-import org.apache.asterix.dataflow.data.nontagged.serde.ALineSerializerDeserializer;
-import org.apache.asterix.dataflow.data.nontagged.serde.APoint3DSerializerDeserializer;
-import org.apache.asterix.dataflow.data.nontagged.serde.APointSerializerDeserializer;
-import org.apache.asterix.dataflow.data.nontagged.serde.APolygonSerializerDeserializer;
-import org.apache.asterix.dataflow.data.nontagged.serde.ARectangleSerializerDeserializer;
-import org.apache.asterix.dataflow.data.nontagged.serde.AStringSerializerDeserializer;
-import org.apache.asterix.dataflow.data.nontagged.serde.ATimeSerializerDeserializer;
-import org.apache.asterix.external.api.IJObject;
-import org.apache.asterix.om.base.ABoolean;
-import org.apache.asterix.om.base.ADouble;
-import org.apache.asterix.om.base.AFloat;
-import org.apache.asterix.om.base.AInt32;
-import org.apache.asterix.om.base.AInt64;
-import org.apache.asterix.om.base.AInt8;
-import org.apache.asterix.om.base.AMissing;
-import org.apache.asterix.om.base.AMutableCircle;
-import org.apache.asterix.om.base.AMutableDate;
-import org.apache.asterix.om.base.AMutableDateTime;
-import org.apache.asterix.om.base.AMutableDouble;
-import org.apache.asterix.om.base.AMutableDuration;
-import org.apache.asterix.om.base.AMutableFloat;
-import org.apache.asterix.om.base.AMutableInt16;
-import org.apache.asterix.om.base.AMutableInt32;
-import org.apache.asterix.om.base.AMutableInt64;
-import org.apache.asterix.om.base.AMutableInt8;
-import org.apache.asterix.om.base.AMutableInterval;
-import org.apache.asterix.om.base.AMutableLine;
-import org.apache.asterix.om.base.AMutableOrderedList;
-import org.apache.asterix.om.base.AMutablePoint;
-import org.apache.asterix.om.base.AMutablePoint3D;
-import org.apache.asterix.om.base.AMutablePolygon;
-import org.apache.asterix.om.base.AMutableRecord;
-import org.apache.asterix.om.base.AMutableRectangle;
-import org.apache.asterix.om.base.AMutableString;
-import org.apache.asterix.om.base.AMutableTime;
-import org.apache.asterix.om.base.AMutableUnorderedList;
-import org.apache.asterix.om.base.ANull;
-import org.apache.asterix.om.base.APoint;
-import org.apache.asterix.om.base.ARectangle;
-import org.apache.asterix.om.base.AString;
-import org.apache.asterix.om.base.IAObject;
-import org.apache.asterix.om.types.AOrderedListType;
-import org.apache.asterix.om.types.ARecordType;
-import org.apache.asterix.om.types.ATypeTag;
-import org.apache.asterix.om.types.AUnorderedListType;
-import org.apache.asterix.om.types.IAType;
-import org.apache.hyracks.api.exceptions.HyracksDataException;
-import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
-
-public class JObjects {
-
- public static abstract class JObject implements IJObject {
-
- protected IAObject value;
- protected byte[] bytes;
-
- protected JObject(IAObject value) {
- this.value = value;
- }
-
- @Override
- public ATypeTag getTypeTag() {
- return value.getType().getTypeTag();
- }
-
- @Override
- public IAObject getIAObject() {
- return value;
- }
-
- }
-
- /*
- * This class is necessary to be able to serialize null objects
- * in cases of setting "null" results
- *
- *
- */
- public static class JNull implements IJObject {
- public final static JNull INSTANCE = new JNull();
-
- private JNull() {
- }
-
- @Override
- public ATypeTag getTypeTag() {
- return ATypeTag.NULL;
- }
-
- @Override
- public IAObject getIAObject() {
- return ANull.NULL;
- }
-
- @Override
- public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
- if (writeTypeTag) {
- try {
- dataOutput.writeByte(ATypeTag.SERIALIZED_NULL_TYPE_TAG);
- } catch (IOException e) {
- throw new HyracksDataException(e);
- }
- }
- }
-
- @Override
- public void reset() {
- }
-
- }
-
- public static class JMissing implements IJObject {
- public final static JMissing INSTANCE = new JMissing();
-
- @Override
- public ATypeTag getTypeTag() {
- return ATypeTag.MISSING;
- }
-
- @Override
- public IAObject getIAObject() {
- return AMissing.MISSING;
- }
-
- @Override
- public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
- if (writeTypeTag) {
- try {
- dataOutput.writeByte(ATypeTag.SERIALIZED_MISSING_TYPE_TAG);
- } catch (IOException e) {
- throw new HyracksDataException(e);
- }
- }
- }
-
- @Override
- public void reset() throws HyracksDataException {
- // no op
- }
- }
-
- public static final class JByte extends JObject {
-
- public JByte(byte value) {
- super(new AMutableInt8(value));
- }
-
- public void setValue(byte v) {
- ((AMutableInt8) value).setValue(v);
- }
-
- public byte getValue() {
- return ((AMutableInt8) value).getByteValue();
- }
-
- @Override
- public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
- if (writeTypeTag) {
- try {
- dataOutput.writeByte(value.getType().getTypeTag().serialize());
- } catch (IOException e) {
- throw new HyracksDataException(e);
- }
- }
- AInt8SerializerDeserializer.INSTANCE.serialize((AInt8) value, dataOutput);
- }
-
- @Override
- public void reset() {
- ((AMutableInt8) value).setValue((byte) 0);
- }
- }
-
- public static final class JShort extends JObject {
-
- private AMutableInt16 value;
-
- public JShort(short value) {
- super(new AMutableInt16(value));
- }
-
- public void setValue(byte v) {
- value.setValue(v);
- }
-
- public short getValue() {
- return value.getShortValue();
- }
-
- @Override
- public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
- if (writeTypeTag) {
- try {
- dataOutput.writeByte(value.getType().getTypeTag().serialize());
- } catch (IOException e) {
- throw new HyracksDataException(e);
- }
- }
- AInt16SerializerDeserializer.INSTANCE.serialize(value, dataOutput);
- }
-
- @Override
- public void reset() {
- value.setValue((short) 0);
- }
-
- }
-
- public static final class JInt extends JObject {
-
- public JInt(int value) {
- super(new AMutableInt32(value));
- }
-
- public void setValue(int v) {
- ((AMutableInt32) value).setValue(v);
- }
-
- public int getValue() {
- return ((AMutableInt32) value).getIntegerValue();
- }
-
- @Override
- public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
- if (writeTypeTag) {
- try {
- dataOutput.writeByte(value.getType().getTypeTag().serialize());
- } catch (IOException e) {
- throw new HyracksDataException(e);
- }
- }
- AInt32SerializerDeserializer.INSTANCE.serialize((AInt32) value, dataOutput);
- }
-
- @Override
- public void reset() {
- ((AMutableInt32) value).setValue(0);
- }
- }
-
- public static final class JBoolean implements IJObject {
-
- private boolean value;
-
- public JBoolean(boolean value) {
- this.value = value;
- }
-
- public void setValue(boolean value) {
- this.value = value;
- }
-
- @Override
- public ATypeTag getTypeTag() {
- return ATypeTag.BOOLEAN;
- }
-
- @Override
- public IAObject getIAObject() {
- return value ? ABoolean.TRUE : ABoolean.FALSE;
- }
-
- @Override
- public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
- if (writeTypeTag) {
- try {
- dataOutput.writeByte(ATypeTag.BOOLEAN.serialize());
- } catch (IOException e) {
- throw new HyracksDataException(e);
- }
- }
- ABooleanSerializerDeserializer.INSTANCE.serialize((ABoolean) getIAObject(), dataOutput);
- }
-
- @Override
- public void reset() {
- value = false;
- }
-
- }
-
- public static final class JLong extends JObject {
-
- public JLong(long v) {
- super(new AMutableInt64(v));
- }
-
- public void setValue(long v) {
- ((AMutableInt64) value).setValue(v);
- }
-
- public long getValue() {
- return ((AMutableInt64) value).getLongValue();
- }
-
- @Override
- public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
- if (writeTypeTag) {
- try {
- dataOutput.writeByte(value.getType().getTypeTag().serialize());
- } catch (IOException e) {
- throw new HyracksDataException(e);
- }
- }
- AInt64SerializerDeserializer.INSTANCE.serialize((AInt64) value, dataOutput);
- }
-
- @Override
- public void reset() {
- ((AMutableInt64) value).setValue(0);
- }
-
- }
-
- public static final class JDouble extends JObject {
-
- public JDouble(double v) {
- super(new AMutableDouble(v));
- }
-
- public void setValue(double v) {
- ((AMutableDouble) value).setValue(v);
- }
-
- public double getValue() {
- return ((AMutableDouble) value).getDoubleValue();
- }
-
- @Override
- public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
- if (writeTypeTag) {
- try {
- dataOutput.writeByte(value.getType().getTypeTag().serialize());
- } catch (IOException e) {
- throw new HyracksDataException(e);
- }
- }
- ADoubleSerializerDeserializer.INSTANCE.serialize((ADouble) value, dataOutput);
- }
-
- @Override
- public void reset() {
- ((AMutableDouble) value).setValue(0);
- }
-
- }
-
- public static final class JString extends JObject {
-
- private final AStringSerializerDeserializer aStringSerDer = AStringSerializerDeserializer.INSTANCE;
-
- public JString(String v) {
- super(new AMutableString(v));
- }
-
- public void setValue(String v) {
- ((AMutableString) value).setValue(v);
- }
-
- public String getValue() {
- return ((AMutableString) value).getStringValue();
- }
-
- @Override
- public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
- if (writeTypeTag) {
- try {
- dataOutput.writeByte(value.getType().getTypeTag().serialize());
- } catch (IOException e) {
- throw new HyracksDataException(e);
- }
- }
- aStringSerDer.serialize((AString) value, dataOutput);
- }
-
- @Override
- public void reset() {
- ((AMutableString) value).setValue("");
- }
-
- }
-
- public static final class JFloat extends JObject {
-
- public JFloat(float v) {
- super(new AMutableFloat(v));
- }
-
- public void setValue(float v) {
- ((AMutableFloat) value).setValue(v);
- }
-
- public float getValue() {
- return ((AMutableFloat) value).getFloatValue();
- }
-
- @Override
- public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
- if (writeTypeTag) {
- try {
- dataOutput.writeByte(value.getType().getTypeTag().serialize());
- } catch (IOException e) {
- throw new HyracksDataException(e);
- }
- }
- AFloatSerializerDeserializer.INSTANCE.serialize((AFloat) value, dataOutput);
- }
-
- @Override
- public void reset() {
- ((AMutableFloat) value).setValue(0);
- }
-
- }
-
- public static final class JPoint extends JObject {
-
- public JPoint(double x, double y) {
- super(new AMutablePoint(x, y));
- }
-
- public void setValue(double x, double y) {
- ((AMutablePoint) value).setValue(x, y);
- }
-
- public double getXValue() {
- return ((AMutablePoint) value).getX();
- }
-
- public double getYValue() {
- return ((AMutablePoint) value).getY();
- }
-
- public IAObject getValue() {
- return value;
- }
-
- @Override
- public String toString() {
- return value.toString();
- }
-
- @Override
- public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
- if (writeTypeTag) {
- try {
- dataOutput.writeByte(value.getType().getTypeTag().serialize());
- } catch (IOException e) {
- throw new HyracksDataException(e);
- }
- }
- APointSerializerDeserializer.INSTANCE.serialize((APoint) value, dataOutput);
- }
-
- @Override
- public void reset() {
- ((AMutablePoint) value).setValue(0, 0);
- }
- }
-
- public static final class JRectangle extends JObject {
-
- public JRectangle(JPoint p1, JPoint p2) {
- super(new AMutableRectangle((APoint) p1.getIAObject(), (APoint) p2.getIAObject()));
- }
-
- public void setValue(JPoint p1, JPoint p2) {
- ((AMutableRectangle) value).setValue((APoint) p1.getValue(), (APoint) p2.getValue());
- }
-
- public void setValue(APoint p1, APoint p2) {
- ((AMutableRectangle) value).setValue(p1, p2);
- }
-
- @Override
- public ATypeTag getTypeTag() {
- return ATypeTag.RECTANGLE;
- }
-
- @Override
- public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
- if (writeTypeTag) {
- try {
- dataOutput.writeByte(value.getType().getTypeTag().serialize());
- } catch (IOException e) {
- throw new HyracksDataException(e);
- }
- }
- ARectangleSerializerDeserializer.INSTANCE.serialize((ARectangle) value, dataOutput);
- }
-
- @Override
- public void reset() {
- }
-
- }
-
- public static final class JTime extends JObject {
-
- public JTime(int timeInMillsec) {
- super(new AMutableTime(timeInMillsec));
- }
-
- public void setValue(int timeInMillsec) {
- ((AMutableTime) value).setValue(timeInMillsec);
- }
-
- @Override
- public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
- if (writeTypeTag) {
- try {
- dataOutput.writeByte(ATypeTag.TIME.serialize());
- } catch (IOException e) {
- throw new HyracksDataException(e);
- }
- }
- ATimeSerializerDeserializer.INSTANCE.serialize((AMutableTime) value, dataOutput);
- }
-
- @Override
- public void reset() {
- ((AMutableTime) value).setValue(0);
- }
-
- }
-
- public static final class JInterval extends JObject {
-
- public JInterval(long intervalStart, long intervalEnd) {
- super(new AMutableInterval(intervalStart, intervalEnd, (byte) 0));
- }
-
- public void setValue(long intervalStart, long intervalEnd, byte typetag) throws HyracksDataException {
- ((AMutableInterval) value).setValue(intervalStart, intervalEnd, typetag);
- }
-
- public long getIntervalStart() {
- return ((AMutableInterval) value).getIntervalStart();
- }
-
- public long getIntervalEnd() {
- return ((AMutableInterval) value).getIntervalEnd();
- }
-
- public short getIntervalType() {
- return ((AMutableInterval) value).getIntervalType();
- }
-
- @Override
- public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
- if (writeTypeTag) {
- try {
- dataOutput.writeByte(ATypeTag.INTERVAL.serialize());
- } catch (IOException e) {
- throw new HyracksDataException(e);
- }
- }
- AIntervalSerializerDeserializer.INSTANCE.serialize(((AMutableInterval) value), dataOutput);
- }
-
- @Override
- public void reset() throws HyracksDataException {
- ((AMutableInterval) value).setValue(0L, 0L, (byte) 0);
- }
-
- }
-
- public static final class JDate extends JObject {
-
- public JDate(int chrononTimeInDays) {
- super(new AMutableDate(chrononTimeInDays));
- }
-
- public void setValue(int chrononTimeInDays) {
- ((AMutableDate) value).setValue(chrononTimeInDays);
- }
-
- @Override
- public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
- if (writeTypeTag) {
- try {
- dataOutput.writeByte(ATypeTag.DATE.serialize());
- } catch (IOException e) {
- throw new HyracksDataException(e);
- }
- }
- ADateSerializerDeserializer.INSTANCE.serialize(((AMutableDate) value), dataOutput);
- }
-
- @Override
- public void reset() {
- ((AMutableDate) value).setValue(0);
- }
- }
-
- public static final class JDateTime extends JObject {
-
- public JDateTime(long chrononTime) {
- super(new AMutableDateTime(chrononTime));
- }
-
- public void setValue(long chrononTime) {
- ((AMutableDateTime) value).setValue(chrononTime);
- }
-
- @Override
- public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
- if (writeTypeTag) {
- try {
- dataOutput.writeByte(ATypeTag.DATETIME.serialize());
- } catch (IOException e) {
- throw new HyracksDataException(e);
- }
- }
- ADateTimeSerializerDeserializer.INSTANCE.serialize(((AMutableDateTime) value), dataOutput);
- }
-
- @Override
- public void reset() {
- ((AMutableDateTime) value).setValue(0);
- }
-
- }
-
- public static final class JDuration extends JObject {
-
- public JDuration(int months, long milliseconds) {
- super(new AMutableDuration(months, milliseconds));
- }
-
- public void setValue(int months, long milliseconds) {
- ((AMutableDuration) value).setValue(months, milliseconds);
- }
-
- @Override
- public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
- if (writeTypeTag) {
- try {
- dataOutput.writeByte(ATypeTag.DURATION.serialize());
- } catch (IOException e) {
- throw new HyracksDataException(e);
- }
- }
- ADurationSerializerDeserializer.INSTANCE.serialize(((AMutableDuration) value), dataOutput);
- }
-
- @Override
- public void reset() {
- ((AMutableDuration) value).setValue(0, 0);
- }
-
- }
-
- public static final class JPolygon extends JObject {
-
- public JPolygon(JPoint[] points) {
- super(new AMutablePolygon(getAPoints(points)));
- }
-
- public void setValue(APoint[] points) {
- ((AMutablePolygon) value).setValue(points);
- }
-
- public void setValue(JPoint[] points) {
- ((AMutablePolygon) value).setValue(getAPoints(points));
- }
-
- private static APoint[] getAPoints(JPoint[] jpoints) {
- APoint[] apoints = new APoint[jpoints.length];
- int index = 0;
- for (JPoint jpoint : jpoints) {
- apoints[index++] = (APoint) jpoint.getIAObject();
- }
- return apoints;
- }
-
- @Override
- public ATypeTag getTypeTag() {
- return ATypeTag.POLYGON;
- }
-
- @Override
- public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
- if (writeTypeTag) {
- try {
- dataOutput.writeByte(ATypeTag.POLYGON.serialize());
- } catch (IOException e) {
- throw new HyracksDataException(e);
- }
- }
- APolygonSerializerDeserializer.INSTANCE.serialize((AMutablePolygon) value, dataOutput);
- }
-
- @Override
- public void reset() {
- ((AMutablePolygon) value).setValue(null);
- }
-
- }
-
- public static final class JCircle extends JObject {
-
- public JCircle(JPoint center, double radius) {
- super(new AMutableCircle((APoint) center.getIAObject(), radius));
- }
-
- public void setValue(JPoint center, double radius) {
- ((AMutableCircle) (value)).setValue((APoint) center.getIAObject(), radius);
- }
-
- @Override
- public ATypeTag getTypeTag() {
- return ATypeTag.CIRCLE;
- }
-
- @Override
- public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
- if (writeTypeTag) {
- try {
- dataOutput.writeByte(ATypeTag.CIRCLE.serialize());
- } catch (IOException e) {
- throw new HyracksDataException(e);
- }
- }
- ACircleSerializerDeserializer.INSTANCE.serialize(((AMutableCircle) (value)), dataOutput);
- }
-
- @Override
- public void reset() {
- }
- }
-
- public static final class JLine extends JObject {
-
- public JLine(JPoint p1, JPoint p2) {
- super(new AMutableLine((APoint) p1.getIAObject(), (APoint) p2.getIAObject()));
- }
-
- public void setValue(JPoint p1, JPoint p2) {
- ((AMutableLine) value).setValue((APoint) p1.getIAObject(), (APoint) p2.getIAObject());
- }
-
- public void setValue(APoint p1, APoint p2) {
- ((AMutableLine) value).setValue(p1, p2);
- }
-
- @Override
- public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
- if (writeTypeTag) {
- try {
- dataOutput.writeByte(ATypeTag.LINE.serialize());
- } catch (IOException e) {
- throw new HyracksDataException(e);
- }
- }
- ALineSerializerDeserializer.INSTANCE.serialize(((AMutableLine) value), dataOutput);
- }
-
- @Override
- public void reset() {
- // TODO Auto-generated method stub
-
- }
-
- }
-
- public static final class JPoint3D extends JObject {
-
- public JPoint3D(double x, double y, double z) {
- super(new AMutablePoint3D(x, y, z));
- }
-
- public void setValue(double x, double y, double z) {
- ((AMutablePoint3D) value).setValue(x, y, z);
- }
-
- public double getXValue() {
- return ((AMutablePoint3D) value).getX();
- }
-
- public double getYValue() {
- return ((AMutablePoint3D) value).getY();
- }
-
- public double getZValue() {
- return ((AMutablePoint3D) value).getZ();
- }
-
- @Override
- public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
- if (writeTypeTag) {
- try {
- dataOutput.writeByte(ATypeTag.POINT3D.serialize());
- } catch (IOException e) {
- throw new HyracksDataException(e);
- }
- }
- APoint3DSerializerDeserializer.INSTANCE.serialize(((AMutablePoint3D) value), dataOutput);
- }
-
- @Override
- public void reset() {
- // TODO Auto-generated method stub
-
- }
- }
-
- public static abstract class JList implements IJObject {
- protected List<IJObject> jObjects;
-
- public JList() {
- jObjects = new ArrayList<IJObject>();
- }
-
- public boolean isEmpty() {
- return jObjects.isEmpty();
- }
-
- public void add(IJObject jObject) {
- jObjects.add(jObject);
- }
-
- public void addAll(Collection<IJObject> jObjectCollection) {
- jObjects.addAll(jObjectCollection);
- }
-
- public void clear() {
- jObjects.clear();
- }
-
- public IJObject getElement(int index) {
- return jObjects.get(index);
- }
-
- public int size() {
- return jObjects.size();
- }
-
- public Iterator<IJObject> iterator() {
- return jObjects.iterator();
- }
- }
-
- public static final class JOrderedList extends JList {
-
- private AOrderedListType listType;
-
- public JOrderedList(IJObject jObject) {
- super();
- this.listType = new AOrderedListType(jObject.getIAObject().getType(), null);
- }
-
- public JOrderedList(IAType listItemType) {
- super();
- this.listType = new AOrderedListType(listItemType, null);
- }
-
- @Override
- public ATypeTag getTypeTag() {
- return ATypeTag.ARRAY;
- }
-
- @Override
- public IAObject getIAObject() {
- AMutableOrderedList v = new AMutableOrderedList(listType);
- for (IJObject jObj : jObjects) {
- v.add(jObj.getIAObject());
- }
- return v;
- }
-
- public AOrderedListType getListType() {
- return listType;
- }
-
- @Override
- public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
- IAsterixListBuilder listBuilder = new UnorderedListBuilder();
- listBuilder.reset(listType);
- ArrayBackedValueStorage fieldValue = new ArrayBackedValueStorage();
- for (IJObject jObject : jObjects) {
- fieldValue.reset();
- jObject.serialize(fieldValue.getDataOutput(), true);
- listBuilder.addItem(fieldValue);
- }
- listBuilder.write(dataOutput, writeTypeTag);
-
- }
-
- @Override
- public void reset() {
- // TODO Auto-generated method stub
-
- }
-
- }
-
- public static final class JUnorderedList extends JList {
-
- private AUnorderedListType listType;
-
- public JUnorderedList(IJObject jObject) {
- this.listType = new AUnorderedListType(jObject.getIAObject().getType(), null);
- this.jObjects = new ArrayList<IJObject>();
- }
-
- public JUnorderedList(IAType listItemType) {
- super();
- this.listType = new AUnorderedListType(listItemType, null);
- this.jObjects = new ArrayList<IJObject>();
- }
-
- @Override
- public void add(IJObject jObject) {
- jObjects.add(jObject);
- }
-
- @Override
- public ATypeTag getTypeTag() {
- return ATypeTag.MULTISET;
- }
-
- @Override
- public IAObject getIAObject() {
- AMutableUnorderedList v = new AMutableUnorderedList(listType);
- for (IJObject jObj : jObjects) {
- v.add(jObj.getIAObject());
- }
- return v;
- }
-
- public AUnorderedListType getListType() {
- return listType;
- }
-
- @Override
- public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
- IAsterixListBuilder listBuilder = new UnorderedListBuilder();
- listBuilder.reset(listType);
- ArrayBackedValueStorage fieldValue = new ArrayBackedValueStorage();
- for (IJObject jObject : jObjects) {
- fieldValue.reset();
- jObject.serialize(fieldValue.getDataOutput(), true);
- listBuilder.addItem(fieldValue);
- }
- listBuilder.write(dataOutput, writeTypeTag);
- }
-
- @Override
- public void reset() {
- jObjects.clear();
- }
-
- }
-
- public static final class JRecord implements IJObject {
-
- private AMutableRecord value;
- private ARecordType recordType;
- private IJObject[] fields;
- private Map<String, IJObject> openFields;
- private final AStringSerializerDeserializer aStringSerDer = AStringSerializerDeserializer.INSTANCE;
-
- public JRecord(ARecordType recordType, IJObject[] fields) {
- this.recordType = recordType;
- this.fields = fields;
- this.openFields = new LinkedHashMap<String, IJObject>();
- }
-
- public JRecord(ARecordType recordType, IJObject[] fields, LinkedHashMap<String, IJObject> openFields) {
- this.recordType = recordType;
- this.fields = fields;
- this.openFields = openFields;
- }
-
- public void addField(String fieldName, IJObject fieldValue) throws HyracksDataException {
- int pos = getFieldPosByName(fieldName);
- if (pos >= 0) {
- throw new RuntimeDataException(ErrorCode.LIBRARY_JAVA_JOBJECTS_FIELD_ALREADY_DEFINED, "closed");
- }
- if (openFields.get(fieldName) != null) {
- throw new RuntimeDataException(ErrorCode.LIBRARY_JAVA_JOBJECTS_FIELD_ALREADY_DEFINED, "open");
- }
- openFields.put(fieldName, fieldValue);
- }
-
- public IJObject getValueByName(String fieldName) throws HyracksDataException {
- // check closed part
- int fieldPos = getFieldPosByName(fieldName);
- if (fieldPos >= 0) {
- return fields[fieldPos];
- } else {
- // check open part
- IJObject fieldValue = openFields.get(fieldName);
- if (fieldValue == null) {
- throw new RuntimeDataException(ErrorCode.LIBRARY_JAVA_JOBJECTS_UNKNOWN_FIELD, fieldName);
- }
- return fieldValue;
- }
- }
-
- public void setValueAtPos(int pos, IJObject jObject) {
- fields[pos] = jObject;
- }
-
- @Override
- public ATypeTag getTypeTag() {
- return recordType.getTypeTag();
- }
-
- public void setField(String fieldName, IJObject fieldValue) throws HyracksDataException {
- int pos = getFieldPosByName(fieldName);
- if (pos >= 0) {
- fields[pos] = fieldValue;
- } else {
- if (openFields.get(fieldName) != null) {
- openFields.put(fieldName, fieldValue);
- } else {
- throw new RuntimeDataException(ErrorCode.LIBRARY_JAVA_JOBJECTS_UNKNOWN_FIELD, fieldName);
- }
- }
- }
-
- private int getFieldPosByName(String fieldName) {
- int index = 0;
- String[] fieldNames = recordType.getFieldNames();
- for (String name : fieldNames) {
- if (name.equals(fieldName)) {
- return index;
- }
- index++;
- }
- return -1;
- }
-
- public ARecordType getRecordType() {
- return recordType;
- }
-
- public IJObject[] getFields() {
- return fields;
- }
-
- public Map<String, IJObject> getOpenFields() {
- return this.openFields;
- }
-
- public RecordBuilder getRecordBuilder() {
- RecordBuilder recordBuilder = new RecordBuilder();
- recordBuilder.reset(recordType);
- return recordBuilder;
- }
-
- @Override
- public void serialize(DataOutput output, boolean writeTypeTag) throws HyracksDataException {
- RecordBuilder recordBuilder = new RecordBuilder();
- recordBuilder.reset(recordType);
- int index = 0;
- ArrayBackedValueStorage fieldValue = new ArrayBackedValueStorage();
- for (IJObject jObject : fields) {
- fieldValue.reset();
- jObject.serialize(fieldValue.getDataOutput(), writeTypeTag);
- recordBuilder.addField(index, fieldValue);
- index++;
- }
-
- try {
- if (openFields != null && !openFields.isEmpty()) {
- ArrayBackedValueStorage openFieldName = new ArrayBackedValueStorage();
- ArrayBackedValueStorage openFieldValue = new ArrayBackedValueStorage();
- AMutableString nameValue = new AMutableString(""); // get from the pool
- for (Entry<String, IJObject> entry : openFields.entrySet()) {
- openFieldName.reset();
- openFieldValue.reset();
- nameValue.setValue(entry.getKey());
- openFieldName.getDataOutput().write(ATypeTag.STRING.serialize());
- aStringSerDer.serialize(nameValue, openFieldName.getDataOutput());
- entry.getValue().serialize(openFieldValue.getDataOutput(), true);
- recordBuilder.addField(openFieldName, openFieldValue);
- }
- }
- } catch (IOException ae) {
- throw new HyracksDataException(ae);
- }
- recordBuilder.write(output, writeTypeTag);
- }
-
- @Override
- public IAObject getIAObject() {
- return value;
- }
-
- @Override
- public void reset() throws HyracksDataException {
- if (openFields != null && !openFields.isEmpty()) {
- openFields.clear();
- }
- if (fields != null) {
- for (IJObject field : fields) {
- if (field != null) {
- field.reset();
- }
- }
- }
- }
-
- public void reset(IJObject[] fields, LinkedHashMap<String, IJObject> openFields) throws HyracksDataException {
- this.reset();
- this.fields = fields;
- this.openFields = openFields;
- }
-
- }
-
- public static class ByteArrayAccessibleInputStream extends ByteArrayInputStream {
-
- public ByteArrayAccessibleInputStream(byte[] buf, int offset, int length) {
- super(buf, offset, length);
- }
-
- public void setContent(byte[] buf, int offset, int length) {
- this.buf = buf;
- this.pos = offset;
- this.count = Math.min(offset + length, buf.length);
- this.mark = offset;
- }
-
- public byte[] getArray() {
- return buf;
- }
-
- public int getPosition() {
- return pos;
- }
-
- public int getCount() {
- return count;
- }
-
- }
-
- public static class ByteArrayAccessibleDataInputStream extends DataInputStream {
-
- public ByteArrayAccessibleDataInputStream(ByteArrayAccessibleInputStream in) {
- super(in);
- }
-
- public ByteArrayAccessibleInputStream getInputStream() {
- return (ByteArrayAccessibleInputStream) in;
- }
-
- }
-}
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JTypeTag.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JTypeTag.java
index c40b1d4..80f44ff 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JTypeTag.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/JTypeTag.java
@@ -19,7 +19,6 @@
package org.apache.asterix.external.library.java;
public enum JTypeTag {
-
INT,
STRING,
LONG,
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/ByteArrayAccessibleDataInputStream.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/ByteArrayAccessibleDataInputStream.java
new file mode 100644
index 0000000..b92aa6c
--- /dev/null
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/ByteArrayAccessibleDataInputStream.java
@@ -0,0 +1,33 @@
+/*
+ * 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.external.library.java.base;
+
+import java.io.DataInputStream;
+
+public class ByteArrayAccessibleDataInputStream extends DataInputStream {
+
+ public ByteArrayAccessibleDataInputStream(ByteArrayAccessibleInputStream in) {
+ super(in);
+ }
+
+ public ByteArrayAccessibleInputStream getInputStream() {
+ return (ByteArrayAccessibleInputStream) in;
+ }
+
+}
\ No newline at end of file
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/ByteArrayAccessibleInputStream.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/ByteArrayAccessibleInputStream.java
new file mode 100644
index 0000000..62e354b
--- /dev/null
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/ByteArrayAccessibleInputStream.java
@@ -0,0 +1,48 @@
+/*
+ * 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.external.library.java.base;
+
+import java.io.ByteArrayInputStream;
+
+public class ByteArrayAccessibleInputStream extends ByteArrayInputStream {
+
+ public ByteArrayAccessibleInputStream(byte[] buf, int offset, int length) {
+ super(buf, offset, length);
+ }
+
+ public void setContent(byte[] buf, int offset, int length) {
+ this.buf = buf;
+ this.pos = offset;
+ this.count = Math.min(offset + length, buf.length);
+ this.mark = offset;
+ }
+
+ public byte[] getArray() {
+ return buf;
+ }
+
+ public int getPosition() {
+ return pos;
+ }
+
+ public int getCount() {
+ return count;
+ }
+
+}
\ No newline at end of file
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JBoolean.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JBoolean.java
new file mode 100644
index 0000000..0d05bea
--- /dev/null
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JBoolean.java
@@ -0,0 +1,68 @@
+/*
+ * 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.external.library.java.base;
+
+import org.apache.asterix.dataflow.data.nontagged.serde.ABooleanSerializerDeserializer;
+import org.apache.asterix.om.base.ABoolean;
+import org.apache.asterix.om.base.IAObject;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.om.types.IAType;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+import java.io.DataOutput;
+
+public final class JBoolean extends JObject {
+
+ private boolean aBoolean;
+
+ public JBoolean(boolean value) {
+ this.aBoolean = value;
+ }
+
+ public void setValue(boolean value) {
+ this.aBoolean = value;
+ }
+
+ public boolean getValue() {
+ return aBoolean;
+ }
+
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.ABOOLEAN;
+ }
+
+ @Override
+ public IAObject getIAObject() {
+ return aBoolean ? ABoolean.TRUE : ABoolean.FALSE;
+ }
+
+ @Override
+ public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
+ serializeTypeTag(writeTypeTag, dataOutput, ATypeTag.BOOLEAN);
+ ABooleanSerializerDeserializer.INSTANCE.serialize((ABoolean) getIAObject(), dataOutput);
+ }
+
+ @Override
+ public void reset() {
+ aBoolean = false;
+ }
+
+}
\ No newline at end of file
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JByte.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JByte.java
new file mode 100644
index 0000000..8e5ac17
--- /dev/null
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JByte.java
@@ -0,0 +1,60 @@
+/*
+ * 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.external.library.java.base;
+
+import org.apache.asterix.dataflow.data.nontagged.serde.AInt8SerializerDeserializer;
+import org.apache.asterix.om.base.AInt8;
+import org.apache.asterix.om.base.AMutableInt8;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.om.types.IAType;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+import java.io.DataOutput;
+
+public final class JByte extends JObject {
+
+ public JByte(byte value) {
+ super(new AMutableInt8(value));
+ }
+
+ public void setValue(byte v) {
+ ((AMutableInt8) value).setValue(v);
+ }
+
+ public byte getValue() {
+ return ((AMutableInt8) value).getByteValue();
+ }
+
+ @Override
+ public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
+ serializeTypeTag(writeTypeTag, dataOutput, ATypeTag.TINYINT);
+ AInt8SerializerDeserializer.INSTANCE.serialize((AInt8) value, dataOutput);
+ }
+
+ @Override
+ public void reset() {
+ ((AMutableInt8) value).setValue((byte) 0);
+ }
+
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.AINT8;
+ }
+}
\ No newline at end of file
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JCircle.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JCircle.java
new file mode 100644
index 0000000..c68831c
--- /dev/null
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JCircle.java
@@ -0,0 +1,65 @@
+/*
+ * 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.external.library.java.base;
+
+import org.apache.asterix.dataflow.data.nontagged.serde.ACircleSerializerDeserializer;
+import org.apache.asterix.om.base.AMutableCircle;
+import org.apache.asterix.om.base.APoint;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.om.types.IAType;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+import java.io.DataOutput;
+
+public final class JCircle extends JObject {
+
+ public JCircle(JPoint center, double radius) {
+ super(new AMutableCircle((APoint) center.getIAObject(), radius));
+ }
+
+ public void setValue(JPoint center, double radius) {
+ ((AMutableCircle) (value)).setValue((APoint) center.getIAObject(), radius);
+ }
+
+ public Pair<Double, Double> getCenter() {
+ return Pair.of(((AMutableCircle) (value)).getP().getX(), ((AMutableCircle) (value)).getP().getY());
+ }
+
+ public double getRaidus() {
+ return ((AMutableCircle) (value)).getRadius();
+ }
+
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.ACIRCLE;
+ }
+
+ @Override
+ public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
+ serializeTypeTag(writeTypeTag, dataOutput, ATypeTag.CIRCLE);
+ ACircleSerializerDeserializer.INSTANCE.serialize((AMutableCircle) value, dataOutput);
+ }
+
+ @Override
+ public void reset() {
+ ((AMutableCircle) value).setValue(null, 0);
+ }
+}
\ No newline at end of file
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JDate.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JDate.java
new file mode 100644
index 0000000..919b630
--- /dev/null
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JDate.java
@@ -0,0 +1,59 @@
+/*
+ * 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.external.library.java.base;
+
+import org.apache.asterix.dataflow.data.nontagged.serde.ADateSerializerDeserializer;
+import org.apache.asterix.om.base.AMutableDate;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.om.types.IAType;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+import java.io.DataOutput;
+
+public final class JDate extends JObject {
+
+ public JDate(int chrononTimeInDays) {
+ super(new AMutableDate(chrononTimeInDays));
+ }
+
+ public void setValue(int chrononTimeInDays) {
+ ((AMutableDate) value).setValue(chrononTimeInDays);
+ }
+
+ public int getValue() {
+ return ((AMutableDate) value).getChrononTimeInDays();
+ }
+
+ @Override
+ public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
+ serializeTypeTag(writeTypeTag, dataOutput, ATypeTag.DATE);
+ ADateSerializerDeserializer.INSTANCE.serialize((AMutableDate) value, dataOutput);
+ }
+
+ @Override
+ public void reset() {
+ ((AMutableDate) value).setValue(0);
+ }
+
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.ADATE;
+ }
+}
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JDateTime.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JDateTime.java
new file mode 100644
index 0000000..cce4dc9
--- /dev/null
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JDateTime.java
@@ -0,0 +1,59 @@
+/*
+ * 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.external.library.java.base;
+
+import org.apache.asterix.dataflow.data.nontagged.serde.ADateTimeSerializerDeserializer;
+import org.apache.asterix.om.base.AMutableDateTime;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.om.types.IAType;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+import java.io.DataOutput;
+
+public final class JDateTime extends JObject {
+
+ public JDateTime(long chrononTime) {
+ super(new AMutableDateTime(chrononTime));
+ }
+
+ public void setValue(long chrononTime) {
+ ((AMutableDateTime) value).setValue(chrononTime);
+ }
+
+ public long getValue() {
+ return ((AMutableDateTime) value).getChrononTime();
+ }
+
+ @Override
+ public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
+ serializeTypeTag(writeTypeTag, dataOutput, ATypeTag.DATETIME);
+ ADateTimeSerializerDeserializer.INSTANCE.serialize((AMutableDateTime) value, dataOutput);
+ }
+
+ @Override
+ public void reset() {
+ ((AMutableDateTime) value).setValue(0);
+ }
+
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.ADATETIME;
+ }
+}
\ No newline at end of file
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JDouble.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JDouble.java
new file mode 100644
index 0000000..ee767f7
--- /dev/null
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JDouble.java
@@ -0,0 +1,60 @@
+/*
+ * 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.external.library.java.base;
+
+import org.apache.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
+import org.apache.asterix.om.base.ADouble;
+import org.apache.asterix.om.base.AMutableDouble;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.om.types.IAType;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+import java.io.DataOutput;
+
+public final class JDouble extends JObject {
+
+ public JDouble(double v) {
+ super(new AMutableDouble(v));
+ }
+
+ public void setValue(double v) {
+ ((AMutableDouble) value).setValue(v);
+ }
+
+ public double getValue() {
+ return ((AMutableDouble) value).getDoubleValue();
+ }
+
+ @Override
+ public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
+ serializeTypeTag(writeTypeTag, dataOutput, ATypeTag.DOUBLE);
+ ADoubleSerializerDeserializer.INSTANCE.serialize((ADouble) value, dataOutput);
+ }
+
+ @Override
+ public void reset() {
+ ((AMutableDouble) value).setValue(0);
+ }
+
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.ADOUBLE;
+ }
+}
\ No newline at end of file
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JDuration.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JDuration.java
new file mode 100644
index 0000000..1299ab6
--- /dev/null
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JDuration.java
@@ -0,0 +1,60 @@
+/*
+ * 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.external.library.java.base;
+
+import org.apache.asterix.dataflow.data.nontagged.serde.ADurationSerializerDeserializer;
+import org.apache.asterix.om.base.AMutableDuration;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.om.types.IAType;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+import java.io.DataOutput;
+
+public final class JDuration extends JObject {
+
+ public JDuration(int months, long milliseconds) {
+ super(new AMutableDuration(months, milliseconds));
+ }
+
+ public void setValue(int months, long milliseconds) {
+ ((AMutableDuration) value).setValue(months, milliseconds);
+ }
+
+ public Pair<Integer, Long> getValue() {
+ return Pair.of(((AMutableDuration) value).getMonths(), ((AMutableDuration) value).getMilliseconds());
+ }
+
+ @Override
+ public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
+ serializeTypeTag(writeTypeTag, dataOutput, ATypeTag.DURATION);
+ ADurationSerializerDeserializer.INSTANCE.serialize((AMutableDuration) value, dataOutput);
+ }
+
+ @Override
+ public void reset() {
+ ((AMutableDuration) value).setValue(0, 0);
+ }
+
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.ADURATION;
+ }
+}
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JFloat.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JFloat.java
new file mode 100644
index 0000000..ae3ee9f
--- /dev/null
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JFloat.java
@@ -0,0 +1,60 @@
+/*
+ * 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.external.library.java.base;
+
+import org.apache.asterix.dataflow.data.nontagged.serde.AFloatSerializerDeserializer;
+import org.apache.asterix.om.base.AFloat;
+import org.apache.asterix.om.base.AMutableFloat;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.om.types.IAType;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+import java.io.DataOutput;
+
+public final class JFloat extends JObject {
+
+ public JFloat(float v) {
+ super(new AMutableFloat(v));
+ }
+
+ public void setValue(float v) {
+ ((AMutableFloat) value).setValue(v);
+ }
+
+ public float getValue() {
+ return ((AMutableFloat) value).getFloatValue();
+ }
+
+ @Override
+ public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
+ serializeTypeTag(writeTypeTag, dataOutput, ATypeTag.FLOAT);
+ AFloatSerializerDeserializer.INSTANCE.serialize((AFloat) value, dataOutput);
+ }
+
+ @Override
+ public void reset() {
+ ((AMutableFloat) value).setValue(0);
+ }
+
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.AFLOAT;
+ }
+}
\ No newline at end of file
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JInt.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JInt.java
new file mode 100644
index 0000000..b1f158b
--- /dev/null
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JInt.java
@@ -0,0 +1,60 @@
+/*
+ * 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.external.library.java.base;
+
+import org.apache.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
+import org.apache.asterix.om.base.AInt32;
+import org.apache.asterix.om.base.AMutableInt32;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.om.types.IAType;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+import java.io.DataOutput;
+
+public class JInt extends JObject {
+
+ public JInt(int value) {
+ super(new AMutableInt32(value));
+ }
+
+ public void setValue(int v) {
+ ((AMutableInt32) value).setValue(v);
+ }
+
+ public int getValue() {
+ return ((AMutableInt32) value).getIntegerValue();
+ }
+
+ @Override
+ public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
+ serializeTypeTag(writeTypeTag, dataOutput, ATypeTag.INTEGER);
+ AInt32SerializerDeserializer.INSTANCE.serialize((AInt32) value, dataOutput);
+ }
+
+ @Override
+ public void reset() {
+ ((AMutableInt32) value).setValue(0);
+ }
+
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.AINT32;
+ }
+}
\ No newline at end of file
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JInterval.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JInterval.java
new file mode 100644
index 0000000..fe253bb
--- /dev/null
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JInterval.java
@@ -0,0 +1,67 @@
+/*
+ * 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.external.library.java.base;
+
+import org.apache.asterix.dataflow.data.nontagged.serde.AIntervalSerializerDeserializer;
+import org.apache.asterix.om.base.AMutableInterval;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.om.types.IAType;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+import java.io.DataOutput;
+
+public final class JInterval extends JObject {
+
+ public JInterval(long intervalStart, long intervalEnd) {
+ super(new AMutableInterval(intervalStart, intervalEnd, (byte) 0));
+ }
+
+ public void setValue(long intervalStart, long intervalEnd, byte typetag) throws HyracksDataException {
+ ((AMutableInterval) value).setValue(intervalStart, intervalEnd, typetag);
+ }
+
+ public long getIntervalStart() {
+ return ((AMutableInterval) value).getIntervalStart();
+ }
+
+ public long getIntervalEnd() {
+ return ((AMutableInterval) value).getIntervalEnd();
+ }
+
+ public short getIntervalType() {
+ return ((AMutableInterval) value).getIntervalType();
+ }
+
+ @Override
+ public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
+ serializeTypeTag(writeTypeTag, dataOutput, ATypeTag.INTERVAL);
+ AIntervalSerializerDeserializer.INSTANCE.serialize((AMutableInterval) value, dataOutput);
+ }
+
+ @Override
+ public void reset() throws HyracksDataException {
+ ((AMutableInterval) value).setValue(0L, 0L, (byte) 0);
+ }
+
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.AINTERVAL;
+ }
+}
\ No newline at end of file
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JLine.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JLine.java
new file mode 100644
index 0000000..b24ff74
--- /dev/null
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JLine.java
@@ -0,0 +1,69 @@
+/*
+ * 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.external.library.java.base;
+
+import org.apache.asterix.dataflow.data.nontagged.serde.ALineSerializerDeserializer;
+import org.apache.asterix.om.base.AMutableLine;
+import org.apache.asterix.om.base.APoint;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.om.types.IAType;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+import java.io.DataOutput;
+
+public final class JLine extends JObject {
+
+ public JLine(JPoint p1, JPoint p2) {
+ super(new AMutableLine((APoint) p1.getIAObject(), (APoint) p2.getIAObject()));
+ }
+
+ public void setValue(JPoint p1, JPoint p2) {
+ ((AMutableLine) value).setValue((APoint) p1.getIAObject(), (APoint) p2.getIAObject());
+ }
+
+ public void setValue(APoint p1, APoint p2) {
+ ((AMutableLine) value).setValue(p1, p2);
+ }
+
+ public Pair<Double, Double> getBeginPoint() {
+ return Pair.of(((AMutableLine) value).getP1().getX(), ((AMutableLine) value).getP1().getY());
+ }
+
+ public Pair<Double, Double> getEndPoint() {
+ return Pair.of(((AMutableLine) value).getP2().getX(), ((AMutableLine) value).getP2().getY());
+ }
+
+ @Override
+ public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
+ serializeTypeTag(writeTypeTag, dataOutput, ATypeTag.LINE);
+ ALineSerializerDeserializer.INSTANCE.serialize((AMutableLine) value, dataOutput);
+ }
+
+ @Override
+ public void reset() {
+ ((AMutableLine) value).setValue(null, null);
+ }
+
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.ALINE;
+ }
+}
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JList.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JList.java
new file mode 100644
index 0000000..bfaf6e4
--- /dev/null
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JList.java
@@ -0,0 +1,62 @@
+/*
+ * 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.external.library.java.base;
+
+import org.apache.asterix.external.api.IJObject;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+public abstract class JList implements IJObject {
+ protected List<IJObject> jObjects;
+
+ public JList() {
+ jObjects = new ArrayList<>();
+ }
+
+ public boolean isEmpty() {
+ return jObjects.isEmpty();
+ }
+
+ public void add(IJObject jObject) {
+ jObjects.add(jObject);
+ }
+
+ public void addAll(Collection<IJObject> jObjectCollection) {
+ jObjects.addAll(jObjectCollection);
+ }
+
+ public void clear() {
+ jObjects.clear();
+ }
+
+ public IJObject getElement(int index) {
+ return jObjects.get(index);
+ }
+
+ public int size() {
+ return jObjects.size();
+ }
+
+ public Iterator<IJObject> iterator() {
+ return jObjects.iterator();
+ }
+}
\ No newline at end of file
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JLong.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JLong.java
new file mode 100644
index 0000000..692e135
--- /dev/null
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JLong.java
@@ -0,0 +1,60 @@
+/*
+ * 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.external.library.java.base;
+
+import org.apache.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
+import org.apache.asterix.om.base.AInt64;
+import org.apache.asterix.om.base.AMutableInt64;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.om.types.IAType;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+import java.io.DataOutput;
+
+public final class JLong extends JObject {
+
+ public JLong(long v) {
+ super(new AMutableInt64(v));
+ }
+
+ public void setValue(long v) {
+ ((AMutableInt64) value).setValue(v);
+ }
+
+ public long getValue() {
+ return ((AMutableInt64) value).getLongValue();
+ }
+
+ @Override
+ public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
+ serializeTypeTag(writeTypeTag, dataOutput, ATypeTag.BIGINT);
+ AInt64SerializerDeserializer.INSTANCE.serialize((AInt64) value, dataOutput);
+ }
+
+ @Override
+ public void reset() {
+ ((AMutableInt64) value).setValue(0);
+ }
+
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.AINT64;
+ }
+}
\ No newline at end of file
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JMissing.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JMissing.java
new file mode 100644
index 0000000..6401b49
--- /dev/null
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JMissing.java
@@ -0,0 +1,53 @@
+/*
+ * 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.external.library.java.base;
+
+import org.apache.asterix.om.base.AMissing;
+import org.apache.asterix.om.base.IAObject;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.om.types.IAType;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+import java.io.DataOutput;
+
+public final class JMissing extends JObject {
+
+ public final static JMissing INSTANCE = new JMissing();
+
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.AMISSING;
+ }
+
+ @Override
+ public IAObject getIAObject() {
+ return AMissing.MISSING;
+ }
+
+ @Override
+ public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
+ serializeTypeTag(writeTypeTag, dataOutput, ATypeTag.MISSING);
+ }
+
+ @Override
+ public void reset() throws HyracksDataException {
+ // no op
+ }
+}
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JNull.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JNull.java
new file mode 100644
index 0000000..683a044
--- /dev/null
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JNull.java
@@ -0,0 +1,59 @@
+/*
+ * 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.external.library.java.base;
+
+import org.apache.asterix.om.base.ANull;
+import org.apache.asterix.om.base.IAObject;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.om.types.IAType;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+import java.io.DataOutput;
+
+/*
+ * This class is necessary to be able to serialize null base
+ * in cases of setting "null" results
+ *
+ */
+public final class JNull extends JObject {
+
+ public final static JNull INSTANCE = new JNull();
+
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.ANULL;
+ }
+
+ @Override
+ public IAObject getIAObject() {
+ return ANull.NULL;
+ }
+
+ @Override
+ public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
+ serializeTypeTag(writeTypeTag, dataOutput, ATypeTag.NULL);
+ }
+
+ @Override
+ public void reset() {
+ // no op for NULL
+ }
+
+}
\ No newline at end of file
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JObject.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JObject.java
new file mode 100644
index 0000000..7338b31
--- /dev/null
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JObject.java
@@ -0,0 +1,56 @@
+/*
+ * 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.external.library.java.base;
+
+import org.apache.asterix.external.api.IJObject;
+import org.apache.asterix.om.base.IAObject;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+public abstract class JObject implements IJObject {
+
+ protected IAObject value;
+ protected byte[] bytes;
+
+ protected JObject() {
+ }
+
+ protected JObject(IAObject value) {
+ this.value = value;
+ }
+
+ @Override
+ public IAObject getIAObject() {
+ return value;
+ }
+
+ public void serializeTypeTag(boolean writeTypeTag, DataOutput dataOutput, ATypeTag typeTag)
+ throws HyracksDataException {
+ if (writeTypeTag) {
+ try {
+ dataOutput.writeByte(typeTag.serialize());
+ } catch (IOException e) {
+ throw new HyracksDataException(e);
+ }
+ }
+ }
+}
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JOrderedList.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JOrderedList.java
new file mode 100644
index 0000000..017fc53
--- /dev/null
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JOrderedList.java
@@ -0,0 +1,85 @@
+/*
+ * 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.external.library.java.base;
+
+import org.apache.asterix.builders.IAsterixListBuilder;
+import org.apache.asterix.builders.OrderedListBuilder;
+import org.apache.asterix.external.api.IJObject;
+import org.apache.asterix.external.api.IJType;
+import org.apache.asterix.om.base.AMutableOrderedList;
+import org.apache.asterix.om.base.IAObject;
+import org.apache.asterix.om.types.AOrderedListType;
+import org.apache.asterix.om.types.IAType;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
+
+import java.io.DataOutput;
+import java.util.List;
+
+public final class JOrderedList extends JList {
+
+ private AOrderedListType listType;
+
+ public JOrderedList(IJType listItemType) {
+ super();
+ this.listType = new AOrderedListType(listItemType.getIAType(), null);
+ }
+
+ public JOrderedList(IAType listItemType) {
+ super();
+ this.listType = new AOrderedListType(listItemType, null);
+ }
+
+ public List<IJObject> getValue() {
+ return jObjects;
+ }
+
+ @Override
+ public IAType getIAType() {
+ return listType;
+ }
+
+ @Override
+ public IAObject getIAObject() {
+ AMutableOrderedList v = new AMutableOrderedList(listType);
+ for (IJObject jObj : jObjects) {
+ v.add(jObj.getIAObject());
+ }
+ return v;
+ }
+
+ @Override
+ public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
+ IAsterixListBuilder listBuilder = new OrderedListBuilder();
+ listBuilder.reset(listType);
+ ArrayBackedValueStorage fieldValue = new ArrayBackedValueStorage();
+ for (IJObject jObject : jObjects) {
+ fieldValue.reset();
+ jObject.serialize(fieldValue.getDataOutput(), true);
+ listBuilder.addItem(fieldValue);
+ }
+ listBuilder.write(dataOutput, writeTypeTag);
+
+ }
+
+ @Override
+ public void reset() {
+ jObjects.clear();
+ }
+}
\ No newline at end of file
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JPoint.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JPoint.java
new file mode 100644
index 0000000..e3eba28
--- /dev/null
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JPoint.java
@@ -0,0 +1,74 @@
+/*
+ * 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.external.library.java.base;
+
+import org.apache.asterix.dataflow.data.nontagged.serde.APointSerializerDeserializer;
+import org.apache.asterix.om.base.AMutablePoint;
+import org.apache.asterix.om.base.APoint;
+import org.apache.asterix.om.base.IAObject;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.om.types.IAType;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+import java.io.DataOutput;
+
+public final class JPoint extends JObject {
+
+ public JPoint(double x, double y) {
+ super(new AMutablePoint(x, y));
+ }
+
+ public void setValue(double x, double y) {
+ ((AMutablePoint) value).setValue(x, y);
+ }
+
+ public double getXValue() {
+ return ((AMutablePoint) value).getX();
+ }
+
+ public double getYValue() {
+ return ((AMutablePoint) value).getY();
+ }
+
+ public IAObject getValue() {
+ return value;
+ }
+
+ @Override
+ public String toString() {
+ return value.toString();
+ }
+
+ @Override
+ public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
+ serializeTypeTag(writeTypeTag, dataOutput, ATypeTag.POINT);
+ APointSerializerDeserializer.INSTANCE.serialize((APoint) value, dataOutput);
+ }
+
+ @Override
+ public void reset() {
+ ((AMutablePoint) value).setValue(0, 0);
+ }
+
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.APOINT;
+ }
+}
\ No newline at end of file
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JPoint3D.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JPoint3D.java
new file mode 100644
index 0000000..59d220b
--- /dev/null
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JPoint3D.java
@@ -0,0 +1,67 @@
+/*
+ * 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.external.library.java.base;
+
+import org.apache.asterix.dataflow.data.nontagged.serde.APoint3DSerializerDeserializer;
+import org.apache.asterix.om.base.AMutablePoint3D;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.om.types.IAType;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+import java.io.DataOutput;
+
+public final class JPoint3D extends JObject {
+
+ public JPoint3D(double x, double y, double z) {
+ super(new AMutablePoint3D(x, y, z));
+ }
+
+ public void setValue(double x, double y, double z) {
+ ((AMutablePoint3D) value).setValue(x, y, z);
+ }
+
+ public double getXValue() {
+ return ((AMutablePoint3D) value).getX();
+ }
+
+ public double getYValue() {
+ return ((AMutablePoint3D) value).getY();
+ }
+
+ public double getZValue() {
+ return ((AMutablePoint3D) value).getZ();
+ }
+
+ @Override
+ public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
+ serializeTypeTag(writeTypeTag, dataOutput, ATypeTag.POINT3D);
+ APoint3DSerializerDeserializer.INSTANCE.serialize((AMutablePoint3D) value, dataOutput);
+ }
+
+ @Override
+ public void reset() {
+ ((AMutablePoint3D) value).setValue(0, 0, 0);
+ }
+
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.APOINT3D;
+ }
+}
\ No newline at end of file
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JPolygon.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JPolygon.java
new file mode 100644
index 0000000..520665b
--- /dev/null
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JPolygon.java
@@ -0,0 +1,73 @@
+/*
+ * 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.external.library.java.base;
+
+import org.apache.asterix.dataflow.data.nontagged.serde.APolygonSerializerDeserializer;
+import org.apache.asterix.om.base.AMutablePolygon;
+import org.apache.asterix.om.base.APoint;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.om.types.IAType;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+import java.io.DataOutput;
+
+public final class JPolygon extends JObject {
+
+ public JPolygon(JPoint[] points) {
+ super(new AMutablePolygon(getAPoints(points)));
+ }
+
+ public void setValue(APoint[] points) {
+ ((AMutablePolygon) value).setValue(points);
+ }
+
+ public void setValue(JPoint[] points) {
+ ((AMutablePolygon) value).setValue(getAPoints(points));
+ }
+
+ public APoint[] getValue() {
+ return ((AMutablePolygon) value).getPoints();
+ }
+
+ @Override
+ public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
+ serializeTypeTag(writeTypeTag, dataOutput, ATypeTag.POLYGON);
+ APolygonSerializerDeserializer.INSTANCE.serialize((AMutablePolygon) value, dataOutput);
+ }
+
+ @Override
+ public void reset() {
+ ((AMutablePolygon) value).setValue(null);
+ }
+
+ protected static APoint[] getAPoints(JPoint[] jpoints) {
+ APoint[] apoints = new APoint[jpoints.length];
+ int index = 0;
+ for (JPoint jpoint : jpoints) {
+ apoints[index++] = (APoint) jpoint.getIAObject();
+ }
+ return apoints;
+ }
+
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.APOLYGON;
+ }
+}
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JRecord.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JRecord.java
new file mode 100644
index 0000000..2792cb4
--- /dev/null
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JRecord.java
@@ -0,0 +1,198 @@
+/*
+ * 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.external.library.java.base;
+
+import org.apache.asterix.builders.RecordBuilder;
+import org.apache.asterix.common.exceptions.ErrorCode;
+import org.apache.asterix.common.exceptions.RuntimeDataException;
+import org.apache.asterix.dataflow.data.nontagged.serde.ARecordSerializerDeserializer;
+import org.apache.asterix.dataflow.data.nontagged.serde.AStringSerializerDeserializer;
+import org.apache.asterix.external.api.IJObject;
+import org.apache.asterix.om.base.AMutableString;
+import org.apache.asterix.om.base.ARecord;
+import org.apache.asterix.om.base.IAObject;
+import org.apache.asterix.om.types.ARecordType;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.IAType;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
+
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+public final class JRecord implements IJObject {
+
+ private static final AStringSerializerDeserializer aStringSerDer = AStringSerializerDeserializer.INSTANCE;
+ private ARecordType recordType;
+ private IJObject[] fields;
+ private Map<String, IJObject> openFields;
+ RecordBuilder recordBuilder = new RecordBuilder();
+ ArrayBackedValueStorage fieldNameBuffer = new ArrayBackedValueStorage();
+ ArrayBackedValueStorage fieldValueBuffer = new ArrayBackedValueStorage();
+ AMutableString nameString = new AMutableString("");
+
+ public JRecord(ARecordType recordType, IJObject[] fields) {
+ this.recordType = recordType;
+ this.fields = fields;
+ this.openFields = new LinkedHashMap<>();
+ }
+
+ public JRecord(ARecordType recordType, IJObject[] fields, Map<String, IJObject> openFields) {
+ this(recordType, fields);
+ this.openFields = openFields;
+ }
+
+ public void addField(String fieldName, IJObject fieldValue) throws HyracksDataException {
+ int pos = getFieldPosByName(fieldName);
+ if (pos >= 0) {
+ throw new RuntimeDataException(ErrorCode.LIBRARY_JAVA_JOBJECTS_FIELD_ALREADY_DEFINED, "closed");
+ }
+ if (openFields.get(fieldName) != null) {
+ throw new RuntimeDataException(ErrorCode.LIBRARY_JAVA_JOBJECTS_FIELD_ALREADY_DEFINED, "open");
+ }
+ openFields.put(fieldName, fieldValue);
+ }
+
+ public IJObject getValueByName(String fieldName) throws HyracksDataException {
+ // check closed part
+ int fieldPos = getFieldPosByName(fieldName);
+ if (fieldPos >= 0) {
+ return fields[fieldPos];
+ } else {
+ // check open part
+ IJObject fieldValue = openFields.get(fieldName);
+ if (fieldValue == null) {
+ throw new RuntimeDataException(ErrorCode.LIBRARY_JAVA_JOBJECTS_UNKNOWN_FIELD, fieldName);
+ }
+ return fieldValue;
+ }
+ }
+
+ public void setValueAtPos(int pos, IJObject jObject) {
+ fields[pos] = jObject;
+ }
+
+ public IAType getIAType() {
+ return recordType;
+ }
+
+ public void setField(String fieldName, IJObject fieldValue) throws HyracksDataException {
+ int pos = getFieldPosByName(fieldName);
+ if (pos >= 0) {
+ fields[pos] = fieldValue;
+ } else {
+ if (openFields.get(fieldName) != null) {
+ openFields.put(fieldName, fieldValue);
+ } else {
+ throw new RuntimeDataException(ErrorCode.LIBRARY_JAVA_JOBJECTS_UNKNOWN_FIELD, fieldName);
+ }
+ }
+ }
+
+ private int getFieldPosByName(String fieldName) {
+ int index = 0;
+ String[] fieldNames = recordType.getFieldNames();
+ for (String name : fieldNames) {
+ if (name.equals(fieldName)) {
+ return index;
+ }
+ index++;
+ }
+ return -1;
+ }
+
+ public ARecordType getRecordType() {
+ return recordType;
+ }
+
+ @Override
+ public void serialize(DataOutput output, boolean writeTypeTag) throws HyracksDataException {
+ recordBuilder.reset(recordType);
+ int index = 0;
+ for (IJObject jObject : fields) {
+ fieldValueBuffer.reset();
+ jObject.serialize(fieldValueBuffer.getDataOutput(), writeTypeTag);
+ recordBuilder.addField(index, fieldValueBuffer);
+ index++;
+ }
+
+ try {
+ if (openFields != null && !openFields.isEmpty()) {
+ for (Map.Entry<String, IJObject> entry : openFields.entrySet()) {
+ fieldNameBuffer.reset();
+ fieldValueBuffer.reset();
+ nameString.setValue(entry.getKey());
+ fieldNameBuffer.getDataOutput().write(ATypeTag.STRING.serialize());
+ aStringSerDer.serialize(nameString, fieldNameBuffer.getDataOutput());
+ entry.getValue().serialize(fieldValueBuffer.getDataOutput(), true);
+ recordBuilder.addField(fieldNameBuffer, fieldValueBuffer);
+ }
+ }
+ } catch (IOException ae) {
+ throw new HyracksDataException(ae);
+ }
+ recordBuilder.write(output, writeTypeTag);
+ }
+
+ @Override
+ public IAObject getIAObject() {
+ // As the open part can be changed any time, we cannot pre-allocate the arrays.
+ int numberOfOpenFields = openFields.size();
+ String[] openFieldNames = new String[numberOfOpenFields];
+ IAType[] openFieldTypes = new IAType[numberOfOpenFields];
+ IAObject[] openFieldValues = new IAObject[numberOfOpenFields];
+ IAObject[] closedFieldValues = new IAObject[fields.length];
+ int idx = 0;
+ for (Map.Entry<String, IJObject> entry : openFields.entrySet()) {
+ openFieldNames[idx] = entry.getKey();
+ openFieldTypes[idx] = entry.getValue().getIAObject().getType();
+ openFieldValues[idx] = entry.getValue().getIAObject();
+ }
+ for (int iter1 = 0; iter1 < fields.length; iter1++) {
+ closedFieldValues[iter1] = fields[iter1].getIAObject();
+ }
+ ARecordType openPartRecType = new ARecordType(null, openFieldNames, openFieldTypes, true);
+ ARecordType mergedRecordType = ARecordSerializerDeserializer.mergeRecordTypes(recordType, openPartRecType);
+ IAObject[] mergedFields = ARecordSerializerDeserializer.mergeFields(closedFieldValues, openFieldValues);
+
+ return new ARecord(mergedRecordType, mergedFields);
+ }
+
+ @Override
+ public void reset() throws HyracksDataException {
+ if (openFields != null && !openFields.isEmpty()) {
+ openFields.clear();
+ }
+ if (fields != null) {
+ for (IJObject field : fields) {
+ if (field != null) {
+ field.reset();
+ }
+ }
+ }
+ }
+
+ public void reset(IJObject[] fields, Map<String, IJObject> openFields) throws HyracksDataException {
+ this.reset();
+ this.fields = fields;
+ this.openFields = openFields;
+ }
+}
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JRectangle.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JRectangle.java
new file mode 100644
index 0000000..73c046e
--- /dev/null
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JRectangle.java
@@ -0,0 +1,64 @@
+/*
+ * 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.external.library.java.base;
+
+import org.apache.asterix.dataflow.data.nontagged.serde.ARectangleSerializerDeserializer;
+import org.apache.asterix.om.base.AMutableRectangle;
+import org.apache.asterix.om.base.APoint;
+import org.apache.asterix.om.base.ARectangle;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.om.types.IAType;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+import java.io.DataOutput;
+
+public final class JRectangle extends JObject {
+
+ public JRectangle(JPoint p1, JPoint p2) {
+ super(new AMutableRectangle((APoint) p1.getIAObject(), (APoint) p2.getIAObject()));
+ }
+
+ public void setValue(JPoint p1, JPoint p2) {
+ ((AMutableRectangle) value).setValue((APoint) p1.getValue(), (APoint) p2.getValue());
+ }
+
+ public void setValue(APoint p1, APoint p2) {
+ ((AMutableRectangle) value).setValue(p1, p2);
+ }
+
+ public ARectangle getValue() {
+ return (AMutableRectangle) value;
+ }
+
+ public IAType getIAType() {
+ return BuiltinType.ARECTANGLE;
+ }
+
+ @Override
+ public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
+ serializeTypeTag(writeTypeTag, dataOutput, ATypeTag.RECTANGLE);
+ ARectangleSerializerDeserializer.INSTANCE.serialize((ARectangle) value, dataOutput);
+ }
+
+ @Override
+ public void reset() {
+ ((AMutableRectangle) value).setValue(null, null);
+ }
+}
\ No newline at end of file
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JShort.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JShort.java
new file mode 100644
index 0000000..da9b2ae
--- /dev/null
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JShort.java
@@ -0,0 +1,60 @@
+/*
+ * 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.external.library.java.base;
+
+import org.apache.asterix.dataflow.data.nontagged.serde.AInt16SerializerDeserializer;
+import org.apache.asterix.om.base.AInt16;
+import org.apache.asterix.om.base.AMutableInt16;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.om.types.IAType;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+import java.io.DataOutput;
+
+public final class JShort extends JObject {
+
+ public JShort(short value) {
+ super(new AMutableInt16(value));
+ }
+
+ public void setValue(short v) {
+ ((AMutableInt16) value).setValue(v);
+ }
+
+ public short getValue() {
+ return ((AMutableInt16) value).getShortValue();
+ }
+
+ @Override
+ public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
+ serializeTypeTag(writeTypeTag, dataOutput, ATypeTag.SMALLINT);
+ AInt16SerializerDeserializer.INSTANCE.serialize((AInt16) value, dataOutput);
+ }
+
+ @Override
+ public void reset() {
+ ((AMutableInt16) value).setValue((short) 0);
+ }
+
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.AINT16;
+ }
+}
\ No newline at end of file
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JString.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JString.java
new file mode 100644
index 0000000..a8d5d90
--- /dev/null
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JString.java
@@ -0,0 +1,60 @@
+/*
+ * 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.external.library.java.base;
+
+import org.apache.asterix.dataflow.data.nontagged.serde.AStringSerializerDeserializer;
+import org.apache.asterix.om.base.AMutableString;
+import org.apache.asterix.om.base.AString;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.om.types.IAType;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+import java.io.DataOutput;
+
+public final class JString extends JObject {
+
+ public JString(String v) {
+ super(new AMutableString(v));
+ }
+
+ public void setValue(String v) {
+ ((AMutableString) value).setValue(v);
+ }
+
+ public String getValue() {
+ return ((AMutableString) value).getStringValue();
+ }
+
+ @Override
+ public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
+ serializeTypeTag(writeTypeTag, dataOutput, ATypeTag.STRING);
+ AStringSerializerDeserializer.INSTANCE.serialize((AString) value, dataOutput);
+ }
+
+ @Override
+ public void reset() {
+ ((AMutableString) value).setValue("");
+ }
+
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.ASTRING;
+ }
+}
\ No newline at end of file
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JTime.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JTime.java
new file mode 100644
index 0000000..1226dd5
--- /dev/null
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JTime.java
@@ -0,0 +1,59 @@
+/*
+ * 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.external.library.java.base;
+
+import org.apache.asterix.dataflow.data.nontagged.serde.ATimeSerializerDeserializer;
+import org.apache.asterix.om.base.AMutableTime;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.om.types.IAType;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+import java.io.DataOutput;
+
+public final class JTime extends JObject {
+
+ public JTime(int timeInMillsec) {
+ super(new AMutableTime(timeInMillsec));
+ }
+
+ public void setValue(int timeInMillsec) {
+ ((AMutableTime) value).setValue(timeInMillsec);
+ }
+
+ public int getValue() {
+ return ((AMutableTime) value).getChrononTime();
+ }
+
+ @Override
+ public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
+ serializeTypeTag(writeTypeTag, dataOutput, ATypeTag.TIME);
+ ATimeSerializerDeserializer.INSTANCE.serialize((AMutableTime) value, dataOutput);
+ }
+
+ @Override
+ public void reset() {
+ ((AMutableTime) value).setValue(0);
+ }
+
+ @Override
+ public IAType getIAType() {
+ return BuiltinType.ATIME;
+ }
+}
\ No newline at end of file
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JUnorderedList.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JUnorderedList.java
new file mode 100644
index 0000000..2d45ef9
--- /dev/null
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/library/java/base/JUnorderedList.java
@@ -0,0 +1,90 @@
+/*
+ * 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.external.library.java.base;
+
+import org.apache.asterix.builders.IAsterixListBuilder;
+import org.apache.asterix.builders.UnorderedListBuilder;
+import org.apache.asterix.external.api.IJObject;
+import org.apache.asterix.external.api.IJType;
+import org.apache.asterix.om.base.AMutableUnorderedList;
+import org.apache.asterix.om.base.IAObject;
+import org.apache.asterix.om.types.AUnorderedListType;
+import org.apache.asterix.om.types.IAType;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
+
+import java.io.DataOutput;
+import java.util.List;
+
+public final class JUnorderedList extends JList {
+
+ private AUnorderedListType listType;
+
+ public JUnorderedList(IJType elementType) {
+ super();
+ this.listType = new AUnorderedListType(elementType.getIAType(), null);
+ }
+
+ public JUnorderedList(IAType elementType) {
+ super();
+ this.listType = new AUnorderedListType(elementType, null);
+ }
+
+ public List<IJObject> getValue() {
+ return jObjects;
+ }
+
+ @Override
+ public void add(IJObject jObject) {
+ jObjects.add(jObject);
+ }
+
+ @Override
+ public IAType getIAType() {
+ return listType;
+ }
+
+ @Override
+ public IAObject getIAObject() {
+ AMutableUnorderedList v = new AMutableUnorderedList(listType);
+ for (IJObject jObj : jObjects) {
+ v.add(jObj.getIAObject());
+ }
+ return v;
+ }
+
+ @Override
+ public void serialize(DataOutput dataOutput, boolean writeTypeTag) throws HyracksDataException {
+ IAsterixListBuilder listBuilder = new UnorderedListBuilder();
+ listBuilder.reset(listType);
+ ArrayBackedValueStorage fieldValue = new ArrayBackedValueStorage();
+ for (IJObject jObject : jObjects) {
+ fieldValue.reset();
+ jObject.serialize(fieldValue.getDataOutput(), true);
+ listBuilder.addItem(fieldValue);
+ }
+ listBuilder.write(dataOutput, writeTypeTag);
+ }
+
+ @Override
+ public void reset() {
+ jObjects.clear();
+ }
+
+}
diff --git a/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/AddHashTagsFunction.java b/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/AddHashTagsFunction.java
index 3c6881a..1b5fecd 100644
--- a/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/AddHashTagsFunction.java
+++ b/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/AddHashTagsFunction.java
@@ -18,11 +18,12 @@
*/
package org.apache.asterix.external.library;
-import org.apache.asterix.external.library.java.JObjects.JDouble;
-import org.apache.asterix.external.library.java.JObjects.JPoint;
-import org.apache.asterix.external.library.java.JObjects.JRecord;
-import org.apache.asterix.external.library.java.JObjects.JString;
-import org.apache.asterix.external.library.java.JObjects.JUnorderedList;
+import org.apache.asterix.external.library.java.JBuiltinType;
+import org.apache.asterix.external.library.java.base.JDouble;
+import org.apache.asterix.external.library.java.base.JPoint;
+import org.apache.asterix.external.library.java.base.JRecord;
+import org.apache.asterix.external.library.java.base.JString;
+import org.apache.asterix.external.library.java.base.JUnorderedList;
import org.apache.asterix.external.api.IExternalScalarFunction;
import org.apache.asterix.external.api.IFunctionHelper;
import org.apache.asterix.external.library.java.JTypeTag;
@@ -34,8 +35,8 @@
private JPoint location = null;
@Override
- public void initialize(IFunctionHelper functionHelper) throws Exception {
- list = new JUnorderedList(functionHelper.getObject(JTypeTag.STRING));
+ public void initialize(IFunctionHelper functionHelper) {
+ list = new JUnorderedList(JBuiltinType.JSTRING);
location = new JPoint(0, 0);
}
diff --git a/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/AddHashTagsInPlaceFunction.java b/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/AddHashTagsInPlaceFunction.java
index 57c8f1d..7873835 100644
--- a/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/AddHashTagsInPlaceFunction.java
+++ b/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/AddHashTagsInPlaceFunction.java
@@ -18,9 +18,10 @@
*/
package org.apache.asterix.external.library;
-import org.apache.asterix.external.library.java.JObjects.JRecord;
-import org.apache.asterix.external.library.java.JObjects.JString;
-import org.apache.asterix.external.library.java.JObjects.JUnorderedList;
+import org.apache.asterix.external.library.java.JBuiltinType;
+import org.apache.asterix.external.library.java.base.JRecord;
+import org.apache.asterix.external.library.java.base.JString;
+import org.apache.asterix.external.library.java.base.JUnorderedList;
import org.apache.asterix.external.api.IExternalScalarFunction;
import org.apache.asterix.external.api.IFunctionHelper;
import org.apache.asterix.external.library.java.JTypeTag;
@@ -31,8 +32,8 @@
private JUnorderedList list = null;
@Override
- public void initialize(IFunctionHelper functionHelper) throws Exception {
- list = new JUnorderedList(functionHelper.getObject(JTypeTag.STRING));
+ public void initialize(IFunctionHelper functionHelper) {
+ list = new JUnorderedList(JBuiltinType.JSTRING);
}
@Override
diff --git a/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/AllTypesFunction.java b/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/AllTypesFunction.java
index aad83dd..1932d4c 100644
--- a/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/AllTypesFunction.java
+++ b/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/AllTypesFunction.java
@@ -18,23 +18,24 @@
*/
package org.apache.asterix.external.library;
-import org.apache.asterix.external.library.java.JObjects.JBoolean;
-import org.apache.asterix.external.library.java.JObjects.JCircle;
-import org.apache.asterix.external.library.java.JObjects.JDate;
-import org.apache.asterix.external.library.java.JObjects.JDateTime;
-import org.apache.asterix.external.library.java.JObjects.JDouble;
-import org.apache.asterix.external.library.java.JObjects.JDuration;
-import org.apache.asterix.external.library.java.JObjects.JFloat;
-import org.apache.asterix.external.library.java.JObjects.JInt;
-import org.apache.asterix.external.library.java.JObjects.JLine;
-import org.apache.asterix.external.library.java.JObjects.JOrderedList;
-import org.apache.asterix.external.library.java.JObjects.JPoint;
-import org.apache.asterix.external.library.java.JObjects.JPoint3D;
-import org.apache.asterix.external.library.java.JObjects.JPolygon;
-import org.apache.asterix.external.library.java.JObjects.JRecord;
-import org.apache.asterix.external.library.java.JObjects.JString;
-import org.apache.asterix.external.library.java.JObjects.JTime;
-import org.apache.asterix.external.library.java.JObjects.JUnorderedList;
+import org.apache.asterix.external.library.java.base.JBoolean;
+import org.apache.asterix.external.library.java.JBuiltinType;
+import org.apache.asterix.external.library.java.base.JCircle;
+import org.apache.asterix.external.library.java.base.JDate;
+import org.apache.asterix.external.library.java.base.JDateTime;
+import org.apache.asterix.external.library.java.base.JDouble;
+import org.apache.asterix.external.library.java.base.JDuration;
+import org.apache.asterix.external.library.java.base.JFloat;
+import org.apache.asterix.external.library.java.base.JInt;
+import org.apache.asterix.external.library.java.base.JLine;
+import org.apache.asterix.external.library.java.base.JOrderedList;
+import org.apache.asterix.external.library.java.base.JPoint;
+import org.apache.asterix.external.library.java.base.JPoint3D;
+import org.apache.asterix.external.library.java.base.JPolygon;
+import org.apache.asterix.external.library.java.base.JRecord;
+import org.apache.asterix.external.library.java.base.JString;
+import org.apache.asterix.external.library.java.base.JTime;
+import org.apache.asterix.external.library.java.base.JUnorderedList;
import org.apache.asterix.external.api.IExternalScalarFunction;
import org.apache.asterix.external.api.IFunctionHelper;
import org.apache.asterix.external.library.java.JTypeTag;
@@ -45,7 +46,7 @@
@Override
public void initialize(IFunctionHelper functionHelper) throws Exception {
- newFieldList = new JOrderedList(functionHelper.getObject(JTypeTag.INT));
+ newFieldList = new JOrderedList(JBuiltinType.JINT);
}
@Override
diff --git a/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/CapitalFinderFunction.java b/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/CapitalFinderFunction.java
index cc32f45..4f7e410 100644
--- a/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/CapitalFinderFunction.java
+++ b/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/CapitalFinderFunction.java
@@ -21,11 +21,10 @@
import java.io.InputStream;
import java.util.Properties;
-import org.apache.asterix.external.library.java.JObjects.JRecord;
-import org.apache.asterix.external.library.java.JObjects.JString;
+import org.apache.asterix.external.library.java.base.JRecord;
+import org.apache.asterix.external.library.java.base.JString;
import org.apache.asterix.external.api.IExternalScalarFunction;
import org.apache.asterix.external.api.IFunctionHelper;
-import org.apache.asterix.external.library.java.JTypeTag;
public class CapitalFinderFunction implements IExternalScalarFunction {
@@ -56,7 +55,7 @@
CapitalFinderFunction.class.getClassLoader().getResourceAsStream("data/countriesCapitals.properties");
capitalList = new Properties();
capitalList.load(in);
- capital = (JString) functionHelper.getObject(JTypeTag.STRING);
+ capital = new JString("");
}
}
diff --git a/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/EchoDelayFunction.java b/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/EchoDelayFunction.java
index c115ac4..e3a0741 100644
--- a/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/EchoDelayFunction.java
+++ b/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/EchoDelayFunction.java
@@ -22,7 +22,7 @@
import org.apache.asterix.external.api.IExternalScalarFunction;
import org.apache.asterix.external.api.IFunctionHelper;
-import org.apache.asterix.external.library.java.JObjects.JRecord;
+import org.apache.asterix.external.library.java.base.JRecord;
public class EchoDelayFunction implements IExternalScalarFunction {
diff --git a/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/KeywordsDetectorFunction.java b/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/KeywordsDetectorFunction.java
index d12f080..1745e40 100644
--- a/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/KeywordsDetectorFunction.java
+++ b/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/KeywordsDetectorFunction.java
@@ -21,7 +21,9 @@
import org.apache.asterix.external.api.IExternalScalarFunction;
import org.apache.asterix.external.api.IFunctionHelper;
-import org.apache.asterix.external.library.java.JObjects;
+import org.apache.asterix.external.library.java.base.JRecord;
+import org.apache.asterix.external.library.java.base.JBoolean;
+import org.apache.asterix.external.library.java.base.JString;
import java.nio.file.Files;
import java.nio.file.Paths;
@@ -36,10 +38,10 @@
@Override
public void evaluate(IFunctionHelper functionHelper) throws Exception {
- JObjects.JRecord inputRecord = (JObjects.JRecord) functionHelper.getArgument(0);
- JObjects.JRecord outputRecord = (JObjects.JRecord) functionHelper.getResultObject();
- JObjects.JBoolean chkVal = new JObjects.JBoolean(false);
- String fieldValue = ((JObjects.JString) inputRecord.getValueByName(fieldName)).getValue();
+ JRecord inputRecord = (JRecord) functionHelper.getArgument(0);
+ JRecord outputRecord = (JRecord) functionHelper.getResultObject();
+ JBoolean chkVal = new JBoolean(false);
+ String fieldValue = ((JString) inputRecord.getValueByName(fieldName)).getValue();
chkVal.setValue(keywordsList.contains(fieldValue));
diff --git a/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/ParseTweetFunction.java b/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/ParseTweetFunction.java
index 7167ac9..c2aca5d 100644
--- a/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/ParseTweetFunction.java
+++ b/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/ParseTweetFunction.java
@@ -18,21 +18,21 @@
*/
package org.apache.asterix.external.library;
-import org.apache.asterix.external.library.java.JObjects.JRecord;
-import org.apache.asterix.external.library.java.JObjects.JString;
-import org.apache.asterix.external.library.java.JObjects.JUnorderedList;
+import org.apache.asterix.external.library.java.base.JRecord;
+import org.apache.asterix.external.library.java.JBuiltinType;
+import org.apache.asterix.external.library.java.base.JString;
+import org.apache.asterix.external.library.java.base.JUnorderedList;
import org.apache.asterix.external.api.IExternalScalarFunction;
import org.apache.asterix.external.api.IFunctionHelper;
import org.apache.asterix.external.library.java.JTypeTag;
-import org.apache.hyracks.api.exceptions.HyracksDataException;
public class ParseTweetFunction implements IExternalScalarFunction {
private JUnorderedList list = null;
@Override
- public void initialize(IFunctionHelper functionHelper) throws Exception {
- list = new JUnorderedList(functionHelper.getObject(JTypeTag.STRING));
+ public void initialize(IFunctionHelper functionHelper) {
+ list = new JUnorderedList(JBuiltinType.JSTRING);
}
@Override
diff --git a/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/SumFunction.java b/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/SumFunction.java
index d81f01b..e16d779 100644
--- a/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/SumFunction.java
+++ b/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/SumFunction.java
@@ -20,7 +20,7 @@
import org.apache.asterix.external.api.IExternalScalarFunction;
import org.apache.asterix.external.api.IFunctionHelper;
-import org.apache.asterix.external.library.java.JObjects.JInt;
+import org.apache.asterix.external.library.java.base.JInt;
public class SumFunction implements IExternalScalarFunction {
diff --git a/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/UpperCaseFunction.java b/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/UpperCaseFunction.java
index 16f8b0a..82f77ac 100644
--- a/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/UpperCaseFunction.java
+++ b/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/UpperCaseFunction.java
@@ -20,9 +20,9 @@
import org.apache.asterix.external.api.IExternalScalarFunction;
import org.apache.asterix.external.api.IFunctionHelper;
-import org.apache.asterix.external.library.java.JObjects.JInt;
-import org.apache.asterix.external.library.java.JObjects.JRecord;
-import org.apache.asterix.external.library.java.JObjects.JString;
+import org.apache.asterix.external.library.java.base.JInt;
+import org.apache.asterix.external.library.java.base.JRecord;
+import org.apache.asterix.external.library.java.base.JString;
/**
* Accepts an input record of type Open{ id: int32, text: string }
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/serde/ARecordSerializerDeserializer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/serde/ARecordSerializerDeserializer.java
index af36c78..97c49e0 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/serde/ARecordSerializerDeserializer.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/serde/ARecordSerializerDeserializer.java
@@ -235,7 +235,7 @@
confRecordBuilder.write(dataOutput, writeTypeTag);
}
- private IAObject[] mergeFields(IAObject[] closedFields, IAObject[] openFields) {
+ public static IAObject[] mergeFields(IAObject[] closedFields, IAObject[] openFields) {
IAObject[] fields = new IAObject[closedFields.length + openFields.length];
int i = 0;
for (; i < closedFields.length; i++) {
@@ -247,7 +247,7 @@
return fields;
}
- private ARecordType mergeRecordTypes(ARecordType recType1, ARecordType recType2) {
+ public static ARecordType mergeRecordTypes(ARecordType recType1, ARecordType recType2) {
String[] fieldNames = new String[recType1.getFieldNames().length + recType2.getFieldNames().length];
IAType[] fieldTypes = new IAType[recType1.getFieldTypes().length + recType2.getFieldTypes().length];