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