Search in sources :

Example 1 with DoubleLiteral

use of org.apache.asterix.lang.common.literal.DoubleLiteral in project asterixdb by apache.

the class RangeMapBuilder method parseLiteralToBytes.

@SuppressWarnings("unchecked")
private static void parseLiteralToBytes(Expression item, DataOutput out) throws CompilationException {
    AMutableDouble aDouble = new AMutableDouble(0);
    AMutableFloat aFloat = new AMutableFloat(0);
    AMutableInt64 aInt64 = new AMutableInt64(0);
    AMutableInt32 aInt32 = new AMutableInt32(0);
    AMutableString aString = new AMutableString("");
    @SuppressWarnings("rawtypes") ISerializerDeserializer serde;
    Literal l = ((LiteralExpr) item).getValue();
    try {
        switch(l.getLiteralType()) {
            case DOUBLE:
                DoubleLiteral dl = (DoubleLiteral) l;
                serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADOUBLE);
                aDouble.setValue(dl.getValue());
                serde.serialize(aDouble, out);
                break;
            case FLOAT:
                FloatLiteral fl = (FloatLiteral) l;
                serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AFLOAT);
                aFloat.setValue(fl.getValue());
                serde.serialize(aFloat, out);
                break;
            case INTEGER:
                IntegerLiteral il = (IntegerLiteral) l;
                serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT32);
                aInt32.setValue(il.getValue());
                serde.serialize(aInt32, out);
                break;
            case LONG:
                LongIntegerLiteral lil = (LongIntegerLiteral) l;
                serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
                aInt64.setValue(lil.getValue());
                serde.serialize(aInt64, out);
                break;
            case STRING:
                StringLiteral sl = (StringLiteral) l;
                serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ASTRING);
                aString.setValue(sl.getValue());
                serde.serialize(aString, out);
                break;
            default:
                throw new NotImplementedException("The range map builder has not been implemented for " + item.getKind() + " type of expressions.");
        }
    } catch (HyracksDataException e) {
        throw new CompilationException(e.getMessage());
    }
}
Also used : CompilationException(org.apache.asterix.common.exceptions.CompilationException) FloatLiteral(org.apache.asterix.lang.common.literal.FloatLiteral) NotImplementedException(org.apache.hyracks.algebricks.common.exceptions.NotImplementedException) AMutableString(org.apache.asterix.om.base.AMutableString) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) StringLiteral(org.apache.asterix.lang.common.literal.StringLiteral) LongIntegerLiteral(org.apache.asterix.lang.common.literal.LongIntegerLiteral) AMutableDouble(org.apache.asterix.om.base.AMutableDouble) Literal(org.apache.asterix.lang.common.base.Literal) StringLiteral(org.apache.asterix.lang.common.literal.StringLiteral) IntegerLiteral(org.apache.asterix.lang.common.literal.IntegerLiteral) FloatLiteral(org.apache.asterix.lang.common.literal.FloatLiteral) DoubleLiteral(org.apache.asterix.lang.common.literal.DoubleLiteral) LongIntegerLiteral(org.apache.asterix.lang.common.literal.LongIntegerLiteral) LiteralExpr(org.apache.asterix.lang.common.expression.LiteralExpr) DoubleLiteral(org.apache.asterix.lang.common.literal.DoubleLiteral) AMutableInt64(org.apache.asterix.om.base.AMutableInt64) AMutableInt32(org.apache.asterix.om.base.AMutableInt32) AMutableFloat(org.apache.asterix.om.base.AMutableFloat) IntegerLiteral(org.apache.asterix.lang.common.literal.IntegerLiteral) LongIntegerLiteral(org.apache.asterix.lang.common.literal.LongIntegerLiteral)

Aggregations

CompilationException (org.apache.asterix.common.exceptions.CompilationException)1 Literal (org.apache.asterix.lang.common.base.Literal)1 LiteralExpr (org.apache.asterix.lang.common.expression.LiteralExpr)1 DoubleLiteral (org.apache.asterix.lang.common.literal.DoubleLiteral)1 FloatLiteral (org.apache.asterix.lang.common.literal.FloatLiteral)1 IntegerLiteral (org.apache.asterix.lang.common.literal.IntegerLiteral)1 LongIntegerLiteral (org.apache.asterix.lang.common.literal.LongIntegerLiteral)1 StringLiteral (org.apache.asterix.lang.common.literal.StringLiteral)1 AMutableDouble (org.apache.asterix.om.base.AMutableDouble)1 AMutableFloat (org.apache.asterix.om.base.AMutableFloat)1 AMutableInt32 (org.apache.asterix.om.base.AMutableInt32)1 AMutableInt64 (org.apache.asterix.om.base.AMutableInt64)1 AMutableString (org.apache.asterix.om.base.AMutableString)1 NotImplementedException (org.apache.hyracks.algebricks.common.exceptions.NotImplementedException)1 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)1 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)1