use of com.bakdata.conquery.models.exceptions.ParsingException in project conquery by bakdata.
the class DateReader method parseToCDateSet.
/**
* Try and parse value to CDateSet using all available layouts, but starting at the last known successful one.
*/
public CDateSet parseToCDateSet(String value) {
if (Strings.isNullOrEmpty(value)) {
return null;
}
final int root = lastDateSetLayoutIndex.get();
for (int offset = 0; offset < dateSetLayouts.size(); offset++) {
final int index = (root + offset) % dateSetLayouts.size();
final LocaleConfig.ListFormat sep = dateSetLayouts.get(index);
try {
final CDateSet result = sep.parse(value, this);
lastDateSetLayoutIndex.set(index);
return result;
} catch (ParsingException e) {
log.trace("Parsing failed for date set '{}' with pattern '{}'", value, sep, e);
}
}
throw new ParsingException("None of the configured formats to parse the date set: " + value);
}
use of com.bakdata.conquery.models.exceptions.ParsingException 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.exceptions.ParsingException in project conquery by bakdata.
the class StringEncodingTest method testHexStreamStringType.
@Test
public void testHexStreamStringType() {
StringParser parser = new StringParser(new ConqueryConfig());
Stream.generate(() -> UUID.randomUUID().toString().replace("-", "")).map(String::toUpperCase).mapToInt(v -> {
try {
return parser.parse(v);
} catch (ParsingException e) {
// We know that StringTypeVarInt is able to parse our strings.
return 0;
}
}).limit(100).forEach(parser::addLine);
StringTypeEncoded subType = (StringTypeEncoded) parser.findBestType();
assertThat(subType).isInstanceOf(StringTypeEncoded.class);
assertThat(subType.getEncoding()).isEqualByComparingTo(StringTypeEncoded.Encoding.Base16UpperCase);
}
use of com.bakdata.conquery.models.exceptions.ParsingException in project conquery by bakdata.
the class DateReader method parseToCDateRange.
/**
* Try and parse value to {@link CDateRange} using all available rangeFormats, starting at the last known successful one.
*/
public CDateRange parseToCDateRange(String value) {
if (Strings.isNullOrEmpty(value)) {
return null;
}
final int root = lastRangeFormatIndex.get();
for (int offset = 0; offset < rangeStartEndSeperators.size(); offset++) {
final int index = (root + offset) % rangeStartEndSeperators.size();
String sep = rangeStartEndSeperators.get(index);
try {
CDateRange result = parseToCDateRange(value, sep);
lastRangeFormatIndex.set(index);
return result;
} catch (ParsingException e) {
log.trace("Parsing failed for date range `{}` using `{}`", value, sep, e);
}
}
throw new ParsingException("None of the configured formats allowed to parse the date range: " + value);
}
Aggregations