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);
}
}
}
};
}
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);
}
};
}
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);
}
};
}
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);
}
}
}
};
}
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);
}
}
};
}
Aggregations