Search in sources :

Example 1 with ARecordPointable

use of org.apache.asterix.om.pointables.nonvisitor.ARecordPointable in project asterixdb by apache.

the class RecordFieldsUtil method addNestedField.

public void addNestedField(IValueReference recordArg, IAType fieldType, IARecordBuilder fieldRecordBuilder, int level) throws IOException, AsterixException {
    ArrayBackedValueStorage fieldAbvs = getTempBuffer();
    ArrayBackedValueStorage valueAbvs = getTempBuffer();
    // Name
    fieldAbvs.reset();
    stringSerde.serialize(nestedName, fieldAbvs.getDataOutput());
    // Value
    valueAbvs.reset();
    ARecordType newType;
    if (fieldType == null) {
        newType = openType;
    } else {
        newType = (ARecordType) fieldType;
    }
    ARecordPointable recordP = getRecordPointable();
    recordP.set(recordArg);
    processRecord(recordP, newType, valueAbvs.getDataOutput(), level);
    fieldRecordBuilder.addField(fieldAbvs, valueAbvs);
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) ARecordPointable(org.apache.asterix.om.pointables.nonvisitor.ARecordPointable) ARecordType(org.apache.asterix.om.types.ARecordType)

Example 2 with ARecordPointable

use of org.apache.asterix.om.pointables.nonvisitor.ARecordPointable in project asterixdb by apache.

the class GetRecordFieldsEvalFactory method createScalarEvaluator.

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

        private final ARecordPointable recordPointable = (ARecordPointable) ARecordPointable.FACTORY.createPointable();

        private IPointable inputArg0 = new VoidPointable();

        private IScalarEvaluator eval0 = recordEvalFactory.createScalarEvaluator(ctx);

        private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

        private DataOutput out = resultStorage.getDataOutput();

        private RecordFieldsUtil rfu = new RecordFieldsUtil();

        @Override
        public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
            resultStorage.reset();
            eval0.evaluate(tuple, inputArg0);
            byte[] data = inputArg0.getByteArray();
            int offset = inputArg0.getStartOffset();
            int len = inputArg0.getLength();
            if (data[offset] != ATypeTag.SERIALIZED_RECORD_TYPE_TAG) {
                throw new TypeMismatchException(BuiltinFunctions.GET_RECORD_FIELDS, 0, data[offset], ATypeTag.SERIALIZED_RECORD_TYPE_TAG);
            }
            recordPointable.set(data, offset, len);
            try {
                rfu.processRecord(recordPointable, recordType, out, 0);
            } catch (IOException e) {
                throw new HyracksDataException(e);
            } catch (AsterixException e) {
                throw new HyracksDataException(e);
            }
            result.set(resultStorage);
        }
    };
}
Also used : DataOutput(java.io.DataOutput) TypeMismatchException(org.apache.asterix.runtime.exceptions.TypeMismatchException) IPointable(org.apache.hyracks.data.std.api.IPointable) IOException(java.io.IOException) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) AsterixException(org.apache.asterix.common.exceptions.AsterixException) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) ARecordPointable(org.apache.asterix.om.pointables.nonvisitor.ARecordPointable)

Aggregations

ARecordPointable (org.apache.asterix.om.pointables.nonvisitor.ARecordPointable)2 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)2 DataOutput (java.io.DataOutput)1 IOException (java.io.IOException)1 AsterixException (org.apache.asterix.common.exceptions.AsterixException)1 ARecordType (org.apache.asterix.om.types.ARecordType)1 TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)1 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)1 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)1 IPointable (org.apache.hyracks.data.std.api.IPointable)1 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)1 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)1