partially fix issue 602
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/ATypeTag.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/ATypeTag.java
index 9ce9b24..ffbbd64 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/ATypeTag.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/ATypeTag.java
@@ -15,6 +15,9 @@
package edu.uci.ics.asterix.om.types;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* There is a unique tag for each primitive type and for each kind of
* non-primitive type in the object model.
@@ -72,6 +75,20 @@
return value;
}
- public final static int TYPE_COUNT = ATypeTag.values().length;
+ public static final int TYPE_COUNT = ATypeTag.values().length;
+
+ public static final ATypeTag[] VALUE_TYPE_MAPPING;
+
+ static {
+ List<ATypeTag> typeList = new ArrayList<>();
+ for (ATypeTag tt : values()) {
+ int index = tt.value;
+ while (typeList.size() <= index) {
+ typeList.add(null);
+ }
+ typeList.set(index, tt);
+ }
+ VALUE_TYPE_MAPPING = typeList.toArray(new ATypeTag[typeList.size()]);
+ }
}
\ No newline at end of file
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AStringConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AStringConstructorDescriptor.java
index 08105a2..7cf588e 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AStringConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AStringConstructorDescriptor.java
@@ -16,7 +16,16 @@
import java.io.DataOutput;
import java.io.IOException;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ABooleanSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AFloatSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt16SerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt8SerializerDeserializer;
import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
import edu.uci.ics.asterix.om.base.ANull;
import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
@@ -32,13 +41,12 @@
import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.data.std.util.ByteArrayAccessibleOutputStream;
import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
public class AStringConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
private static final long serialVersionUID = 1L;
- private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
- private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
public IFunctionDescriptor createFunctionDescriptor() {
return new AStringConstructorDescriptor();
@@ -52,34 +60,109 @@
@Override
public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
- return new ICopyEvaluator() {
+ try {
+ return new ICopyEvaluator() {
- private DataOutput out = output.getDataOutput();
- private ArrayBackedValueStorage outInput = new ArrayBackedValueStorage();
- private ICopyEvaluator eval = args[0].createEvaluator(outInput);
- private String errorMessage = "This can not be an instance of string";
- @SuppressWarnings("unchecked")
- private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
- .getSerializerDeserializer(BuiltinType.ANULL);
+ private DataOutput out = output.getDataOutput();
+ private ArrayBackedValueStorage outInput = new ArrayBackedValueStorage();
+ private ByteArrayAccessibleOutputStream baaos = new ByteArrayAccessibleOutputStream();
+ private PrintStream ps = new PrintStream(baaos, false, "UTF-8");
+ private ICopyEvaluator eval = args[0].createEvaluator(outInput);
+ @SuppressWarnings("unchecked")
+ private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
+ .getSerializerDeserializer(BuiltinType.ANULL);
- @Override
- public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+ @Override
+ public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+ try {
+ outInput.reset();
+ eval.evaluate(tuple);
+ byte[] serString = outInput.getByteArray();
- try {
- outInput.reset();
- eval.evaluate(tuple);
- byte[] serString = outInput.getByteArray();
- if (serString[0] == SER_STRING_TYPE_TAG) {
- out.write(outInput.getByteArray(), outInput.getStartOffset(), outInput.getLength());
- } else if (serString[0] == SER_NULL_TYPE_TAG)
- nullSerde.serialize(ANull.NULL, out);
- else
- throw new AlgebricksException(errorMessage);
- } catch (IOException e1) {
- throw new AlgebricksException(errorMessage);
+ ATypeTag tt = ATypeTag.VALUE_TYPE_MAPPING[serString[0]];
+ if (tt == ATypeTag.NULL) {
+ nullSerde.serialize(ANull.NULL, out);
+ } else if (tt == ATypeTag.STRING) {
+ out.write(outInput.getByteArray(), outInput.getStartOffset(), outInput.getLength());
+ } else {
+ baaos.write(0);
+ baaos.write(0);
+ switch (tt) {
+ case INT8: {
+ int i = AInt8SerializerDeserializer.getByte(outInput.getByteArray(), 1);
+ ps.print(i);
+ break;
+ }
+ case INT16: {
+ int i = AInt16SerializerDeserializer.getShort(outInput.getByteArray(), 1);
+ ps.print(i);
+ break;
+ }
+ case INT32: {
+ int i = AInt32SerializerDeserializer.getInt(outInput.getByteArray(), 1);
+ ps.print(i);
+ break;
+ }
+ case INT64: {
+ long l = AInt64SerializerDeserializer.getLong(outInput.getByteArray(), 1);
+ ps.print(l);
+ break;
+ }
+ case DOUBLE: {
+ double d = ADoubleSerializerDeserializer.getDouble(outInput.getByteArray(),
+ 1);
+ ps.print(d);
+ break;
+ }
+ case FLOAT: {
+ float f = AFloatSerializerDeserializer.getFloat(outInput.getByteArray(), 1);
+ ps.print(f);
+ break;
+ }
+ case BOOLEAN: {
+ boolean b = ABooleanSerializerDeserializer.getBoolean(
+ outInput.getByteArray(), 1);
+ ps.print(b);
+ break;
+ }
+
+ // NotYetImplemented
+ case CIRCLE:
+ case DATE:
+ case DATETIME:
+ case LINE:
+ case TIME:
+ case DURATION:
+ case YEARMONTHDURATION:
+ case DAYTIMEDURATION:
+ case INTERVAL:
+ case ORDEREDLIST:
+ case POINT:
+ case POINT3D:
+ case RECTANGLE:
+ case POLYGON:
+ case RECORD:
+ case UNORDEREDLIST:
+ case UUID:
+ default:
+ throw new AlgebricksException("string of " + tt + " not supported");
+ }
+ ps.flush();
+ byte[] tmpStrBytes = baaos.getByteArray();
+ int utfLen = baaos.size() - 2;
+ tmpStrBytes[0] = (byte) ((utfLen >>> 8) & 0xFF);
+ tmpStrBytes[1] = (byte) ((utfLen >>> 0) & 0xFF);
+ out.write(ATypeTag.STRING.serialize());
+ out.write(tmpStrBytes);
+ }
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
}
- }
- };
+ };
+ } catch (UnsupportedEncodingException e) {
+ throw new AlgebricksException(e);
+ }
}
};
}