Search in sources :

Example 1 with APrintVisitor

use of org.apache.asterix.om.pointables.printer.json.lossless.APrintVisitor in project asterixdb by apache.

the class AOrderedlistPrinterFactory method createPrinter.

@Override
public IPrinter createPrinter() {
    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.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 2 with APrintVisitor

use of org.apache.asterix.om.pointables.printer.json.lossless.APrintVisitor in project asterixdb by apache.

the class AObjectPrinterFactory method createPrinter.

@Override
public IPrinter createPrinter() {
    final ARecordVisitablePointable rPointable = new ARecordVisitablePointable(DefaultOpenFieldType.NESTED_OPEN_RECORD_TYPE);
    final AListVisitablePointable olPointable = new AListVisitablePointable(DefaultOpenFieldType.NESTED_OPEN_AORDERED_LIST_TYPE);
    final AListVisitablePointable ulPointable = new AListVisitablePointable(DefaultOpenFieldType.NESTED_OPEN_AUNORDERED_LIST_TYPE);
    final Pair<PrintStream, ATypeTag> streamTag = new Pair<>(null, null);
    final IPrintVisitor visitor = new APrintVisitor();
    return (byte[] b, int s, int l, PrintStream ps) -> {
        ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(b[s]);
        if (!printFlatValue(typeTag, b, s, l, ps)) {
            streamTag.first = ps;
            streamTag.second = typeTag;
            switch(typeTag) {
                case OBJECT:
                    rPointable.set(b, s, l);
                    visitor.visit(rPointable, streamTag);
                    break;
                case ARRAY:
                    olPointable.set(b, s, l);
                    visitor.visit(olPointable, streamTag);
                    break;
                case MULTISET:
                    ulPointable.set(b, s, l);
                    visitor.visit(ulPointable, streamTag);
                    break;
                default:
                    throw new HyracksDataException("No printer for type " + typeTag);
            }
        }
    };
}
Also used : PrintStream(java.io.PrintStream) ARecordVisitablePointable(org.apache.asterix.om.pointables.ARecordVisitablePointable) AListVisitablePointable(org.apache.asterix.om.pointables.AListVisitablePointable) ATypeTag(org.apache.asterix.om.types.ATypeTag) IPrintVisitor(org.apache.asterix.om.pointables.printer.IPrintVisitor) APrintVisitor(org.apache.asterix.om.pointables.printer.json.lossless.APrintVisitor) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Example 3 with APrintVisitor

use of org.apache.asterix.om.pointables.printer.json.lossless.APrintVisitor 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 4 with APrintVisitor

use of org.apache.asterix.om.pointables.printer.json.lossless.APrintVisitor 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.lossless.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)

Aggregations

PrintStream (java.io.PrintStream)4 APrintVisitor (org.apache.asterix.om.pointables.printer.json.lossless.APrintVisitor)4 ATypeTag (org.apache.asterix.om.types.ATypeTag)4 Pair (org.apache.hyracks.algebricks.common.utils.Pair)4 PointableAllocator (org.apache.asterix.om.pointables.PointableAllocator)3 IVisitablePointable (org.apache.asterix.om.pointables.base.IVisitablePointable)3 IAType (org.apache.asterix.om.types.IAType)3 IPrinter (org.apache.hyracks.algebricks.data.IPrinter)3 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)2 AListVisitablePointable (org.apache.asterix.om.pointables.AListVisitablePointable)1 ARecordVisitablePointable (org.apache.asterix.om.pointables.ARecordVisitablePointable)1 IPrintVisitor (org.apache.asterix.om.pointables.printer.IPrintVisitor)1