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 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] = (CSVPrinterFactoryProvider.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 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);
}
}
};
}
use of org.apache.hyracks.algebricks.data.IPrinter in project asterixdb by apache.
the class ClassAdToADMTest method testSchemaful.
@SuppressWarnings("rawtypes")
public void testSchemaful() {
try {
File file = new File("target/classad-wtih-temporals.adm");
File expected = new File(getClass().getResource("/classad/results/classad-with-temporals.adm").toURI().getPath());
FileUtils.deleteQuietly(file);
PrintStream printStream = new PrintStream(Files.newOutputStream(Paths.get(file.toURI())));
String[] recordFieldNames = { "GlobalJobId", "Owner", "ClusterId", "ProcId", "RemoteWallClockTime", "CompletionDate", "QDate", "JobCurrentStartDate", "JobStartDate", "JobCurrentStartExecutingDate" };
IAType[] recordFieldTypes = { BuiltinType.ASTRING, BuiltinType.ASTRING, BuiltinType.AINT32, BuiltinType.AINT32, BuiltinType.ADURATION, BuiltinType.ADATETIME, BuiltinType.ADATETIME, BuiltinType.ADATETIME, BuiltinType.ADATETIME, BuiltinType.ADATETIME };
ARecordType recordType = new ARecordType("value", recordFieldNames, recordFieldTypes, true);
int numOfTupleFields = 1;
ISerializerDeserializer[] serdes = new ISerializerDeserializer[1];
serdes[0] = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(recordType);
IPrinterFactory[] printerFactories = new IPrinterFactory[1];
printerFactories[0] = ADMPrinterFactoryProvider.INSTANCE.getPrinterFactory(recordType);
// create output descriptor
IPrinter[] printers = new IPrinter[printerFactories.length];
for (int i = 0; i < printerFactories.length; i++) {
printers[i] = printerFactories[i].createPrinter();
}
ClassAdObjectPool objectPool = new ClassAdObjectPool();
String[] files = new String[] { "/classad/classad-with-temporals.classads" };
ClassAdParser parser = new ClassAdParser(recordType, false, false, false, null, null, null, objectPool);
ArrayTupleBuilder tb = new ArrayTupleBuilder(numOfTupleFields);
for (String path : files) {
List<Path> paths = new ArrayList<>();
Map<String, String> config = new HashMap<>();
config.put(ExternalDataConstants.KEY_RECORD_START, "[");
config.put(ExternalDataConstants.KEY_RECORD_END, "]");
paths.add(Paths.get(getClass().getResource(path).toURI()));
FileSystemWatcher watcher = new FileSystemWatcher(paths, null, false);
LocalFSInputStream in = new LocalFSInputStream(watcher);
SemiStructuredRecordReader recordReader = new SemiStructuredRecordReader();
recordReader.configure(in, config);
while (recordReader.hasNext()) {
tb.reset();
IRawRecord<char[]> record = recordReader.next();
parser.parse(record, tb.getDataOutput());
tb.addFieldEndOffset();
printTuple(tb, printers, printStream);
}
recordReader.close();
printStream.close();
Assert.assertTrue(FileUtils.contentEquals(file, expected));
}
} catch (Throwable th) {
System.err.println("TEST FAILED");
th.printStackTrace();
Assert.assertTrue(false);
}
System.err.println("TEST PASSED");
}
Aggregations