Search in sources :

Example 11 with IVisitablePointable

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

the class AOrderedlistPrinterFactory method createPrinter.

@Override
public IPrinter createPrinter() {
    final PointableAllocator allocator = new PointableAllocator();
    final IAType inputType = orderedlistType == null ? DefaultOpenFieldType.getDefaultOpenFieldType(ATypeTag.ARRAY) : orderedlistType;
    final IVisitablePointable listAccessor = allocator.allocateListValue(inputType);
    final APrintVisitor printVisitor = new APrintVisitor();
    final Pair<PrintStream, ATypeTag> arg = new Pair<>(null, null);
    return new IPrinter() {

        @Override
        public void init() {
            arg.second = inputType.getTypeTag();
        }

        @Override
        public void print(byte[] b, int start, int l, PrintStream ps) throws HyracksDataException {
            listAccessor.set(b, start, l);
            arg.first = ps;
            listAccessor.accept(printVisitor, arg);
        }
    };
}
Also used : PrintStream(java.io.PrintStream) IVisitablePointable(org.apache.asterix.om.pointables.base.IVisitablePointable) ATypeTag(org.apache.asterix.om.types.ATypeTag) APrintVisitor(org.apache.asterix.om.pointables.printer.json.clean.APrintVisitor) IPrinter(org.apache.hyracks.algebricks.data.IPrinter) PointableAllocator(org.apache.asterix.om.pointables.PointableAllocator) IAType(org.apache.asterix.om.types.IAType) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Example 12 with IVisitablePointable

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

the class AUnorderedlistPrinterFactory method createPrinter.

@Override
public IPrinter createPrinter() {
    PointableAllocator allocator = new PointableAllocator();
    final IAType inputType = unorderedlistType == null ? DefaultOpenFieldType.getDefaultOpenFieldType(ATypeTag.MULTISET) : unorderedlistType;
    final IVisitablePointable listAccessor = allocator.allocateListValue(inputType);
    final APrintVisitor printVisitor = new APrintVisitor();
    final Pair<PrintStream, ATypeTag> arg = new Pair<>(null, null);
    return new IPrinter() {

        @Override
        public void init() {
            arg.second = inputType.getTypeTag();
        }

        @Override
        public void print(byte[] b, int start, int l, PrintStream ps) throws HyracksDataException {
            try {
                listAccessor.set(b, start, l);
                arg.first = ps;
                listAccessor.accept(printVisitor, arg);
            } catch (Exception e) {
                throw new HyracksDataException(e);
            }
        }
    };
}
Also used : PrintStream(java.io.PrintStream) IVisitablePointable(org.apache.asterix.om.pointables.base.IVisitablePointable) ATypeTag(org.apache.asterix.om.types.ATypeTag) APrintVisitor(org.apache.asterix.om.pointables.printer.json.clean.APrintVisitor) IPrinter(org.apache.hyracks.algebricks.data.IPrinter) PointableAllocator(org.apache.asterix.om.pointables.PointableAllocator) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IAType(org.apache.asterix.om.types.IAType) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Example 13 with IVisitablePointable

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

the class ARecordPrinterFactory method createPrinter.

@Override
public IPrinter createPrinter() {
    final PointableAllocator allocator = new PointableAllocator();
    final IAType inputType = recType == null ? DefaultOpenFieldType.getDefaultOpenFieldType(ATypeTag.OBJECT) : recType;
    final IVisitablePointable recAccessor = allocator.allocateRecordValue(inputType);
    final APrintVisitor printVisitor = new APrintVisitor();
    final Pair<PrintStream, ATypeTag> arg = new Pair<>(null, null);
    return new IPrinter() {

        @Override
        public void init() {
            arg.second = inputType.getTypeTag();
        }

        @Override
        public void print(byte[] b, int start, int l, PrintStream ps) throws HyracksDataException {
            recAccessor.set(b, start, l);
            arg.first = ps;
            recAccessor.accept(printVisitor, arg);
        }
    };
}
Also used : PrintStream(java.io.PrintStream) IVisitablePointable(org.apache.asterix.om.pointables.base.IVisitablePointable) ATypeTag(org.apache.asterix.om.types.ATypeTag) APrintVisitor(org.apache.asterix.om.pointables.printer.adm.APrintVisitor) IPrinter(org.apache.hyracks.algebricks.data.IPrinter) PointableAllocator(org.apache.asterix.om.pointables.PointableAllocator) IAType(org.apache.asterix.om.types.IAType) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Example 14 with IVisitablePointable

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

the class ARecordPrinterFactory method createPrinter.

@Override
public IPrinter createPrinter() {
    final PointableAllocator allocator = new PointableAllocator();
    final IAType inputType = recType == null ? DefaultOpenFieldType.getDefaultOpenFieldType(ATypeTag.OBJECT) : recType;
    final IVisitablePointable recAccessor = allocator.allocateRecordValue(inputType);
    final APrintVisitor printVisitor = new APrintVisitor();
    final Pair<PrintStream, ATypeTag> arg = new Pair<>(null, null);
    return new IPrinter() {

        @Override
        public void init() {
            arg.second = inputType.getTypeTag();
        }

        @Override
        public void print(byte[] b, int start, int l, PrintStream ps) throws HyracksDataException {
            recAccessor.set(b, start, l);
            arg.first = ps;
            recAccessor.accept(printVisitor, arg);
        }
    };
}
Also used : PrintStream(java.io.PrintStream) IVisitablePointable(org.apache.asterix.om.pointables.base.IVisitablePointable) ATypeTag(org.apache.asterix.om.types.ATypeTag) APrintVisitor(org.apache.asterix.om.pointables.printer.json.lossless.APrintVisitor) IPrinter(org.apache.hyracks.algebricks.data.IPrinter) PointableAllocator(org.apache.asterix.om.pointables.PointableAllocator) IAType(org.apache.asterix.om.types.IAType) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Example 15 with IVisitablePointable

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

the class JavaFunctionHelper method setArgument.

public void setArgument(int index, IValueReference valueReference) throws IOException, AsterixException {
    IVisitablePointable pointable = null;
    IJObject jObject = null;
    IAType type = finfo.getParamList().get(index);
    switch(type.getTypeTag()) {
        case OBJECT:
            pointable = pointableAllocator.allocateRecordValue(type);
            pointable.set(valueReference);
            jObject = pointableVisitor.visit((ARecordVisitablePointable) pointable, getTypeInfo(index, type));
            break;
        case ARRAY:
        case MULTISET:
            pointable = pointableAllocator.allocateListValue(type);
            pointable.set(valueReference);
            jObject = pointableVisitor.visit((AListVisitablePointable) pointable, getTypeInfo(index, type));
            break;
        case ANY:
            throw new RuntimeDataException(ErrorCode.LIBRARY_JAVA_FUNCTION_HELPER_CANNOT_HANDLE_ARGU_TYPE, type.getTypeTag());
        default:
            pointable = pointableAllocator.allocateFieldValue(type);
            pointable.set(valueReference);
            jObject = pointableVisitor.visit((AFlatValuePointable) pointable, getTypeInfo(index, type));
            break;
    }
    arguments[index] = jObject;
}
Also used : AFlatValuePointable(org.apache.asterix.om.pointables.AFlatValuePointable) ARecordVisitablePointable(org.apache.asterix.om.pointables.ARecordVisitablePointable) AListVisitablePointable(org.apache.asterix.om.pointables.AListVisitablePointable) IVisitablePointable(org.apache.asterix.om.pointables.base.IVisitablePointable) IJObject(org.apache.asterix.external.api.IJObject) IAType(org.apache.asterix.om.types.IAType) RuntimeDataException(org.apache.asterix.common.exceptions.RuntimeDataException)

Aggregations

IVisitablePointable (org.apache.asterix.om.pointables.base.IVisitablePointable)30 ATypeTag (org.apache.asterix.om.types.ATypeTag)19 IAType (org.apache.asterix.om.types.IAType)15 PointableAllocator (org.apache.asterix.om.pointables.PointableAllocator)14 Pair (org.apache.hyracks.algebricks.common.utils.Pair)12 PrintStream (java.io.PrintStream)11 IPrinter (org.apache.hyracks.algebricks.data.IPrinter)10 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)10 ARecordVisitablePointable (org.apache.asterix.om.pointables.ARecordVisitablePointable)6 DataOutput (java.io.DataOutput)5 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)5 IPointable (org.apache.hyracks.data.std.api.IPointable)5 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)5 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)5 IOException (java.io.IOException)4 RecordBuilder (org.apache.asterix.builders.RecordBuilder)4 AListVisitablePointable (org.apache.asterix.om.pointables.AListVisitablePointable)4 APrintVisitor (org.apache.asterix.om.pointables.printer.adm.APrintVisitor)4 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)4 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)4