Search in sources :

Example 1 with ParseException

use of org.apache.druid.java.util.common.parsers.ParseException in project druid by druid-io.

the class IncrementalIndexAddResultTest method testIsRowAdded.

@Test
public void testIsRowAdded() {
    Assert.assertTrue(new IncrementalIndexAddResult(0, 0L).isRowAdded());
    Assert.assertFalse(new IncrementalIndexAddResult(0, 0L, "test").isRowAdded());
    Assert.assertFalse(new IncrementalIndexAddResult(0, 0L, new ParseException(null, "test")).isRowAdded());
}
Also used : ParseException(org.apache.druid.java.util.common.parsers.ParseException) Test(org.junit.Test)

Example 2 with ParseException

use of org.apache.druid.java.util.common.parsers.ParseException in project druid by druid-io.

the class ParseExceptionHandlerTest method testLogParseExceptions.

@Test
public void testLogParseExceptions() {
    final ParseException parseException = new ParseException(null, "test");
    final RowIngestionMeters rowIngestionMeters = new SimpleRowIngestionMeters();
    final ParseExceptionHandler parseExceptionHandler = new ParseExceptionHandler(rowIngestionMeters, true, Integer.MAX_VALUE, 0);
    parseExceptionHandler.handle(parseException);
    List<LogEvent> logEvents = logger.getLogEvents();
    Assert.assertEquals(1, logEvents.size());
    String logMessage = logEvents.get(0).getMessage().getFormattedMessage();
    Assert.assertTrue(logMessage.contains("Encountered parse exception"));
}
Also used : LogEvent(org.apache.logging.log4j.core.LogEvent) ParseException(org.apache.druid.java.util.common.parsers.ParseException) Test(org.junit.Test)

Example 3 with ParseException

use of org.apache.druid.java.util.common.parsers.ParseException in project druid by druid-io.

the class ParseExceptionHandlerTest method testMaxAllowedParseExceptionsThrowExceptionWhenItHitsMax.

@Test
public void testMaxAllowedParseExceptionsThrowExceptionWhenItHitsMax() {
    final ParseException parseException = new ParseException(null, "test");
    final int maxAllowedParseExceptions = 3;
    final RowIngestionMeters rowIngestionMeters = new SimpleRowIngestionMeters();
    final ParseExceptionHandler parseExceptionHandler = new ParseExceptionHandler(rowIngestionMeters, false, maxAllowedParseExceptions, 0);
    IntStream.range(0, maxAllowedParseExceptions).forEach(i -> parseExceptionHandler.handle(parseException));
    Assert.assertEquals(3, rowIngestionMeters.getUnparseable());
    expectedException.expect(RuntimeException.class);
    expectedException.expectMessage("Max parse exceptions[3] exceeded");
    try {
        parseExceptionHandler.handle(parseException);
    } catch (RuntimeException e) {
        Assert.assertEquals(4, rowIngestionMeters.getUnparseable());
        throw e;
    }
}
Also used : ParseException(org.apache.druid.java.util.common.parsers.ParseException) Test(org.junit.Test)

Example 4 with ParseException

use of org.apache.druid.java.util.common.parsers.ParseException in project druid by druid-io.

the class ParseExceptionHandlerTest method testGetSavedParseExceptionsReturnMostRecentParseExceptions.

@Test
public void testGetSavedParseExceptionsReturnMostRecentParseExceptions() {
    final int maxSavedParseExceptions = 3;
    final RowIngestionMeters rowIngestionMeters = new SimpleRowIngestionMeters();
    final ParseExceptionHandler parseExceptionHandler = new ParseExceptionHandler(rowIngestionMeters, false, Integer.MAX_VALUE, maxSavedParseExceptions);
    Assert.assertNotNull(parseExceptionHandler.getSavedParseExceptionReports());
    int exceptionCounter = 0;
    for (; exceptionCounter < maxSavedParseExceptions; exceptionCounter++) {
        parseExceptionHandler.handle(new ParseException(null, StringUtils.format("test %d", exceptionCounter)));
    }
    Assert.assertEquals(3, rowIngestionMeters.getUnparseable());
    Assert.assertEquals(maxSavedParseExceptions, parseExceptionHandler.getSavedParseExceptionReports().size());
    for (int i = 0; i < maxSavedParseExceptions; i++) {
        Assert.assertEquals(StringUtils.format("test %d", i), parseExceptionHandler.getSavedParseExceptionReports().get(i).getDetails().get(0));
    }
    for (; exceptionCounter < 5; exceptionCounter++) {
        parseExceptionHandler.handle(new ParseException(null, StringUtils.format("test %d", exceptionCounter)));
    }
    Assert.assertEquals(5, rowIngestionMeters.getUnparseable());
    Assert.assertEquals(maxSavedParseExceptions, parseExceptionHandler.getSavedParseExceptionReports().size());
    for (int i = 0; i < maxSavedParseExceptions; i++) {
        Assert.assertEquals(StringUtils.format("test %d", i + 2), parseExceptionHandler.getSavedParseExceptionReports().get(i).getDetails().get(0));
    }
}
Also used : ParseException(org.apache.druid.java.util.common.parsers.ParseException) Test(org.junit.Test)

Example 5 with ParseException

use of org.apache.druid.java.util.common.parsers.ParseException in project druid by druid-io.

the class FileBasedProtobufBytesDecoder method getDescriptor.

private Descriptors.Descriptor getDescriptor(String descriptorFilePath) {
    InputStream fin;
    fin = this.getClass().getClassLoader().getResourceAsStream(descriptorFilePath);
    if (fin == null) {
        URL url;
        try {
            url = new URL(descriptorFilePath);
        } catch (MalformedURLException e) {
            throw new ParseException(descriptorFilePath, e, "Descriptor not found in class path or malformed URL:" + descriptorFilePath);
        }
        try {
            fin = url.openConnection().getInputStream();
        } catch (IOException e) {
            throw new ParseException(url.toString(), e, "Cannot read descriptor file: " + url);
        }
    }
    DynamicSchema dynamicSchema;
    try {
        dynamicSchema = DynamicSchema.parseFrom(fin);
    } catch (Descriptors.DescriptorValidationException e) {
        throw new ParseException(null, e, "Invalid descriptor file: " + descriptorFilePath);
    } catch (IOException e) {
        throw new ParseException(null, e, "Cannot read descriptor file: " + descriptorFilePath);
    }
    Set<String> messageTypes = dynamicSchema.getMessageTypes();
    if (messageTypes.size() == 0) {
        throw new ParseException(null, "No message types found in the descriptor: " + descriptorFilePath);
    }
    String messageType = protoMessageType == null ? (String) messageTypes.toArray()[0] : protoMessageType;
    Descriptors.Descriptor desc = dynamicSchema.getMessageDescriptor(messageType);
    if (desc == null) {
        throw new ParseException(null, StringUtils.format("Protobuf message type %s not found in the specified descriptor.  Available messages types are %s", protoMessageType, messageTypes));
    }
    return desc;
}
Also used : MalformedURLException(java.net.MalformedURLException) InputStream(java.io.InputStream) ParseException(org.apache.druid.java.util.common.parsers.ParseException) IOException(java.io.IOException) DynamicSchema(com.github.os72.protobuf.dynamic.DynamicSchema) Descriptors(com.google.protobuf.Descriptors) ByteString(com.google.protobuf.ByteString) URL(java.net.URL)

Aggregations

ParseException (org.apache.druid.java.util.common.parsers.ParseException)30 IOException (java.io.IOException)9 InputRow (org.apache.druid.data.input.InputRow)8 Map (java.util.Map)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)4 MapBasedInputRow (org.apache.druid.data.input.MapBasedInputRow)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 List (java.util.List)3 Nullable (javax.annotation.Nullable)3 Schema (org.apache.avro.Schema)3 GenericDatumReader (org.apache.avro.generic.GenericDatumReader)3 GenericRecord (org.apache.avro.generic.GenericRecord)3 ISE (org.apache.druid.java.util.common.ISE)3 JsonCreator (com.fasterxml.jackson.annotation.JsonCreator)2 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 Descriptors (com.google.protobuf.Descriptors)2 DynamicMessage (com.google.protobuf.DynamicMessage)2 EOFException (java.io.EOFException)2