Search in sources :

Example 11 with AMutableTime

use of org.apache.asterix.om.base.AMutableTime in project asterixdb by apache.

the class CurrentTimeDescriptor method createEvaluatorFactory.

/* (non-Javadoc)
     * @see org.apache.asterix.runtime.base.IScalarFunctionDynamicDescriptor#createEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory[])
     */
@Override
public IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) {
    return new IScalarEvaluatorFactory() {

        private static final long serialVersionUID = 1L;

        @Override
        public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
            return new IScalarEvaluator() {

                private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                private DataOutput out = resultStorage.getDataOutput();

                @SuppressWarnings("unchecked")
                private ISerializerDeserializer<ATime> timeSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ATIME);

                private AMutableTime aTime = new AMutableTime(0);

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    resultStorage.reset();
                    int timeChronon = (int) (System.currentTimeMillis() % GregorianCalendarSystem.CHRONON_OF_DAY);
                    aTime.setValue(timeChronon);
                    timeSerde.serialize(aTime, out);
                    result.set(resultStorage);
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) IPointable(org.apache.hyracks.data.std.api.IPointable) AMutableTime(org.apache.asterix.om.base.AMutableTime) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)

Aggregations

DataOutput (java.io.DataOutput)11 AMutableTime (org.apache.asterix.om.base.AMutableTime)11 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)10 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)10 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)10 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)10 IPointable (org.apache.hyracks.data.std.api.IPointable)10 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)10 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)10 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)9 TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)8 IOException (java.io.IOException)6 InvalidDataFormatException (org.apache.asterix.runtime.exceptions.InvalidDataFormatException)6 AMutableDate (org.apache.asterix.om.base.AMutableDate)4 AMutableDateTime (org.apache.asterix.om.base.AMutableDateTime)4 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)4 UTF8StringPointable (org.apache.hyracks.data.std.primitive.UTF8StringPointable)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1