use of org.apache.hyracks.dataflow.common.data.parsers.IValueParser in project asterixdb by apache.
the class DelimitedDataTupleParserFactory method createTupleParser.
@Override
public ITupleParser createTupleParser(final IHyracksTaskContext ctx) {
return new ITupleParser() {
@Override
public void parse(InputStream in, IFrameWriter writer) throws HyracksDataException {
try {
IValueParser[] valueParsers = new IValueParser[valueParserFactories.length];
for (int i = 0; i < valueParserFactories.length; ++i) {
valueParsers[i] = valueParserFactories[i].createValueParser();
}
IFrame frame = new VSizeFrame(ctx);
FrameTupleAppender appender = new FrameTupleAppender();
appender.reset(frame, true);
ArrayTupleBuilder tb = new ArrayTupleBuilder(valueParsers.length);
DataOutput dos = tb.getDataOutput();
FieldCursorForDelimitedDataParser cursor = new FieldCursorForDelimitedDataParser(new InputStreamReader(in), fieldDelimiter, quote);
while (cursor.nextRecord()) {
tb.reset();
for (int i = 0; i < valueParsers.length; ++i) {
if (!cursor.nextField()) {
break;
}
// Eliminate double quotes in the field that we are going to parse
if (cursor.isDoubleQuoteIncludedInThisField) {
cursor.eliminateDoubleQuote(cursor.buffer, cursor.fStart, cursor.fEnd - cursor.fStart);
cursor.fEnd -= cursor.doubleQuoteCount;
cursor.isDoubleQuoteIncludedInThisField = false;
}
valueParsers[i].parse(cursor.buffer, cursor.fStart, cursor.fEnd - cursor.fStart, dos);
tb.addFieldEndOffset();
}
FrameUtils.appendToWriter(writer, appender, tb.getFieldEndOffsets(), tb.getByteArray(), 0, tb.getSize());
}
appender.write(writer, true);
} catch (IOException e) {
throw new HyracksDataException(e);
}
}
};
}
use of org.apache.hyracks.dataflow.common.data.parsers.IValueParser in project asterixdb by apache.
the class ADurationParserFactory method createValueParser.
@Override
public IValueParser createValueParser() {
final AMutableDuration aMutableDuration = new AMutableDuration(0, 0);
return new IValueParser() {
@Override
public void parse(char[] buffer, int start, int length, DataOutput out) throws HyracksDataException {
parseDuration(buffer, start, length, aMutableDuration, ADurationParseOption.All);
try {
out.writeInt(aMutableDuration.getMonths());
out.writeLong(aMutableDuration.getMilliseconds());
} catch (IOException ex) {
throw new HyracksDataException(ex);
}
}
};
}
use of org.apache.hyracks.dataflow.common.data.parsers.IValueParser in project asterixdb by apache.
the class ADateTimeParserFactory method createValueParser.
@Override
public IValueParser createValueParser() {
return new IValueParser() {
@Override
public void parse(char[] buffer, int start, int length, DataOutput out) throws HyracksDataException {
long chrononTimeInMs = 0;
short timeOffset = (short) ((buffer[start] == '-') ? 1 : 0);
timeOffset += 8;
if (buffer[start + timeOffset] != 'T') {
timeOffset += 2;
if (buffer[start + timeOffset] != 'T') {
throw new HyracksDataException(dateTimeErrorMessage + ": missing T");
}
}
chrononTimeInMs = ADateParserFactory.parseDatePart(buffer, start, timeOffset);
chrononTimeInMs += ATimeParserFactory.parseTimePart(buffer, start + timeOffset + 1, length - timeOffset - 1);
try {
out.writeLong(chrononTimeInMs);
} catch (IOException ex) {
throw new HyracksDataException(ex);
}
}
};
}
use of org.apache.hyracks.dataflow.common.data.parsers.IValueParser in project asterixdb by apache.
the class WordTupleParserFactory method createTupleParser.
@Override
public ITupleParser createTupleParser(final IHyracksTaskContext ctx) {
return new ITupleParser() {
@Override
public void parse(InputStream in, IFrameWriter writer) throws HyracksDataException {
try {
FrameTupleAppender appender = new FrameTupleAppender(new VSizeFrame(ctx));
ArrayTupleBuilder tb = new ArrayTupleBuilder(1);
DataOutput dos = tb.getDataOutput();
IValueParser utf8StringParser = UTF8StringParserFactory.INSTANCE.createValueParser();
WordCursor cursor = new WordCursor(new InputStreamReader(in));
while (cursor.nextWord()) {
tb.reset();
utf8StringParser.parse(cursor.buffer, cursor.fStart, cursor.fEnd - cursor.fStart, dos);
tb.addFieldEndOffset();
FrameUtils.appendToWriter(writer, appender, tb.getFieldEndOffsets(), tb.getByteArray(), 0, tb.getSize());
}
appender.write(writer, true);
} catch (IOException e) {
throw new HyracksDataException(e);
}
}
};
}
Aggregations