Search in sources :

Example 1 with ParsingException

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);
}
Also used : ParsingException(com.bakdata.conquery.models.exceptions.ParsingException) LocaleConfig(com.bakdata.conquery.models.config.LocaleConfig) CDateSet(com.bakdata.conquery.models.common.CDateSet)

Example 2 with ParsingException

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;
}
Also used : OutputDescription(com.bakdata.conquery.models.preproc.outputs.OutputDescription) ParsingException(com.bakdata.conquery.models.exceptions.ParsingException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Parser(com.bakdata.conquery.models.preproc.parser.Parser) CsvParser(com.univocity.parsers.csv.CsvParser)

Example 3 with ParsingException

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);
}
Also used : StringParser(com.bakdata.conquery.models.preproc.parser.specific.StringParser) StringTypeEncoded(com.bakdata.conquery.models.events.stores.specific.string.StringTypeEncoded) ParsingException(com.bakdata.conquery.models.exceptions.ParsingException) ConqueryConfig(com.bakdata.conquery.models.config.ConqueryConfig) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 4 with ParsingException

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);
}
Also used : ParsingException(com.bakdata.conquery.models.exceptions.ParsingException) CDateRange(com.bakdata.conquery.models.common.daterange.CDateRange)

Aggregations

ParsingException (com.bakdata.conquery.models.exceptions.ParsingException)4 CDateSet (com.bakdata.conquery.models.common.CDateSet)1 CDateRange (com.bakdata.conquery.models.common.daterange.CDateRange)1 ConqueryConfig (com.bakdata.conquery.models.config.ConqueryConfig)1 LocaleConfig (com.bakdata.conquery.models.config.LocaleConfig)1 StringTypeEncoded (com.bakdata.conquery.models.events.stores.specific.string.StringTypeEncoded)1 OutputDescription (com.bakdata.conquery.models.preproc.outputs.OutputDescription)1 Parser (com.bakdata.conquery.models.preproc.parser.Parser)1 StringParser (com.bakdata.conquery.models.preproc.parser.specific.StringParser)1 CsvParser (com.univocity.parsers.csv.CsvParser)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 DynamicTest (org.junit.jupiter.api.DynamicTest)1 Test (org.junit.jupiter.api.Test)1