use of com.bakdata.conquery.models.preproc.parser.Parser in project conquery by bakdata.
the class Preprocessor method applyOutputs.
/**
* Apply each output for a single row. Returning all resulting values.
*/
private static Object[] applyOutputs(List<OutputDescription.Output> outputs, PPColumn[] columns, String[] row, long lineId) throws ParsingException, OutputDescription.OutputException {
Object[] outRow = new Object[outputs.size()];
for (int index = 0; index < outputs.size(); index++) {
final OutputDescription.Output out = outputs.get(index);
try {
final Parser parser = columns[index].getParser();
final Object result = out.createOutput(row, parser, lineId);
if (result == null) {
continue;
}
outRow[index] = result;
} catch (Exception e) {
throw new OutputDescription.OutputException(out.getDescription(), e);
}
}
return outRow;
}
use of com.bakdata.conquery.models.preproc.parser.Parser in project conquery by bakdata.
the class CompoundDateRangeOutput method createForHeaders.
@Override
public Output createForHeaders(Object2IntArrayMap<String> headers, DateReader dateReader) {
assertRequiredHeaders(headers, startColumn, endColumn);
final int startIndex = headers.getInt(startColumn);
final int endIndex = headers.getInt(endColumn);
// Obviously this mean doing the work twice, but it's still better than storing the data twice also.
return new Output() {
@Override
protected Object parseLine(String[] row, Parser type, long sourceLine) throws ParsingException {
if (Strings.isNullOrEmpty(row[startIndex]) && Strings.isNullOrEmpty(row[endIndex])) {
return false;
}
if (!allowOpen && (Strings.isNullOrEmpty(row[startIndex]) || Strings.isNullOrEmpty(row[endIndex]))) {
throw new IllegalArgumentException("Open Ranges are not allowed.");
}
final LocalDate start = dateReader.parseToLocalDate(row[startIndex]);
final LocalDate end = dateReader.parseToLocalDate(row[endIndex]);
return // Since it's not possible that BOTH are null either of them being null already implies an open and therefore valid range.
(start == null || end == null) || // row is included if start <= end
start.isBefore(end) || start.isEqual(end);
}
};
}
use of com.bakdata.conquery.models.preproc.parser.Parser in project conquery by bakdata.
the class DateRangeOutput method createForHeaders.
@Override
public Output createForHeaders(Object2IntArrayMap<String> headers, DateReader dateReader) {
assertRequiredHeaders(headers, startColumn, endColumn);
final int startIndex = headers.getInt(startColumn);
final int endIndex = headers.getInt(endColumn);
return new Output() {
@Override
protected Object parseLine(String[] row, Parser type, long sourceLine) throws ParsingException {
if (Strings.isNullOrEmpty(row[startIndex]) && Strings.isNullOrEmpty(row[endIndex])) {
return null;
}
if (!allowOpen && (Strings.isNullOrEmpty(row[startIndex]) || Strings.isNullOrEmpty(row[endIndex]))) {
throw new IllegalArgumentException("Open Ranges are not allowed.");
}
LocalDate start = dateReader.parseToLocalDate(row[startIndex]);
LocalDate end = dateReader.parseToLocalDate(row[endIndex]);
return CDateRange.of(start, end);
}
};
}
Aggregations