Search in sources :

Example 6 with IPrinter

use of org.apache.hyracks.algebricks.data.IPrinter in project asterixdb by apache.

the class AUnionPrinterFactory method createPrinter.

@Override
public IPrinter createPrinter() {
    return new IPrinter() {

        private IPrinter[] printers;

        private List<IAType> unionList;

        @Override
        public void init() throws HyracksDataException {
            unionList = unionType.getUnionList();
            printers = new IPrinter[unionType.getUnionList().size()];
            for (int i = 0; i < printers.length; i++) {
                printers[i] = (LosslessJSONPrinterFactoryProvider.INSTANCE.getPrinterFactory(unionType.getUnionList().get(i))).createPrinter();
                printers[i].init();
            }
        }

        @Override
        public void print(byte[] b, int s, int l, PrintStream ps) throws HyracksDataException {
            ATypeTag tag = unionList.get(b[s + 1]).getTypeTag();
            if (tag == ATypeTag.UNION) {
                printers[b[s + 1]].print(b, s + 1, l, ps);
            } else {
                if (tag == ATypeTag.ANY) {
                    printers[b[s + 1]].print(b, s + 2, l, ps);
                } else {
                    printers[b[s + 1]].print(b, s + 1, l, ps);
                }
            }
        }
    };
}
Also used : PrintStream(java.io.PrintStream) ATypeTag(org.apache.asterix.om.types.ATypeTag) List(java.util.List) IPrinter(org.apache.hyracks.algebricks.data.IPrinter)

Example 7 with IPrinter

use of org.apache.hyracks.algebricks.data.IPrinter 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.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 8 with IPrinter

use of org.apache.hyracks.algebricks.data.IPrinter 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 9 with IPrinter

use of org.apache.hyracks.algebricks.data.IPrinter in project asterixdb by apache.

the class AUnionPrinterFactory method createPrinter.

@Override
public IPrinter createPrinter() {
    return new IPrinter() {

        private IPrinter[] printers;

        private List<IAType> unionList;

        @Override
        public void init() throws HyracksDataException {
            unionList = unionType.getUnionList();
            printers = new IPrinter[unionType.getUnionList().size()];
            for (int i = 0; i < printers.length; i++) {
                printers[i] = (CleanJSONPrinterFactoryProvider.INSTANCE.getPrinterFactory(unionType.getUnionList().get(i))).createPrinter();
                printers[i].init();
            }
        }

        @Override
        public void print(byte[] b, int s, int l, PrintStream ps) throws HyracksDataException {
            ATypeTag tag = unionList.get(b[s + 1]).getTypeTag();
            if (tag == ATypeTag.UNION) {
                printers[b[s + 1]].print(b, s + 1, l, ps);
            } else {
                if (tag == ATypeTag.ANY) {
                    printers[b[s + 1]].print(b, s + 2, l, ps);
                } else {
                    printers[b[s + 1]].print(b, s + 1, l, ps);
                }
            }
        }
    };
}
Also used : PrintStream(java.io.PrintStream) ATypeTag(org.apache.asterix.om.types.ATypeTag) List(java.util.List) IPrinter(org.apache.hyracks.algebricks.data.IPrinter)

Example 10 with IPrinter

use of org.apache.hyracks.algebricks.data.IPrinter 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)

Aggregations

PrintStream (java.io.PrintStream)17 IPrinter (org.apache.hyracks.algebricks.data.IPrinter)17 ATypeTag (org.apache.asterix.om.types.ATypeTag)14 IAType (org.apache.asterix.om.types.IAType)12 PointableAllocator (org.apache.asterix.om.pointables.PointableAllocator)10 IVisitablePointable (org.apache.asterix.om.pointables.base.IVisitablePointable)10 Pair (org.apache.hyracks.algebricks.common.utils.Pair)10 List (java.util.List)4 APrintVisitor (org.apache.asterix.om.pointables.printer.adm.APrintVisitor)3 APrintVisitor (org.apache.asterix.om.pointables.printer.json.clean.APrintVisitor)3 APrintVisitor (org.apache.asterix.om.pointables.printer.json.lossless.APrintVisitor)3 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)3 File (java.io.File)2 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LocalFSInputStream (org.apache.asterix.external.input.stream.LocalFSInputStream)2 FileSystemWatcher (org.apache.asterix.external.util.FileSystemWatcher)2 ARecordType (org.apache.asterix.om.types.ARecordType)2 IPrinterFactory (org.apache.hyracks.algebricks.data.IPrinterFactory)2