Search in sources :

Example 16 with AvroRuntimeException

use of org.apache.avro.AvroRuntimeException in project incubator-gobblin by apache.

the class KafkaAvroJobMonitor method parseJobSpec.

@Override
public Collection<JobSpec> parseJobSpec(byte[] message) throws IOException {
    InputStream is = new ByteArrayInputStream(message);
    this.versionWriter.readSchemaVersioningInformation(new DataInputStream(is));
    Decoder decoder = DecoderFactory.get().binaryDecoder(is, this.decoder.get());
    try {
        T decodedMessage = this.reader.get().read(null, decoder);
        return parseJobSpec(decodedMessage);
    } catch (AvroRuntimeException | IOException exc) {
        this.messageParseFailures.mark();
        if (this.messageParseFailures.getFiveMinuteRate() < 1) {
            log.warn("Unable to decode input message.", exc);
        } else {
            log.warn("Unable to decode input message.");
        }
        return Lists.newArrayList();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataInputStream(java.io.DataInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) AvroRuntimeException(org.apache.avro.AvroRuntimeException) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) BinaryDecoder(org.apache.avro.io.BinaryDecoder) Decoder(org.apache.avro.io.Decoder)

Example 17 with AvroRuntimeException

use of org.apache.avro.AvroRuntimeException in project spf4j by zolyfarkas.

the class CsvDecoder method arrayNext.

@Override
public long arrayNext() throws IOException {
    parser.advance(Symbol.ITEM_END);
    CsvReader.TokenType current = csvReader.current();
    if (current == CsvReader.TokenType.START_DOCUMENT) {
        throw new IllegalStateException("cannot be at the beginning of " + csvReader);
    }
    if (current == CsvReader.TokenType.END_ROW) {
        try {
            current = csvReader.next();
        } catch (CsvParseException ex) {
            throw new AvroRuntimeException(ex);
        }
    }
    if (current == CsvReader.TokenType.ELEMENT) {
        return 1L;
    } else {
        return 0L;
    }
}
Also used : CsvReader(org.spf4j.io.csv.CsvReader) CsvParseException(org.spf4j.io.csv.CsvParseException) AvroRuntimeException(org.apache.avro.AvroRuntimeException)

Aggregations

AvroRuntimeException (org.apache.avro.AvroRuntimeException)17 Schema (org.apache.avro.Schema)8 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Field (org.apache.avro.Schema.Field)3 GenericRecord (org.apache.avro.generic.GenericRecord)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ToString (lombok.ToString)2 CsvParseException (org.spf4j.io.csv.CsvParseException)2 BufferedInputStream (java.io.BufferedInputStream)1 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 File (java.io.File)1 InputStream (java.io.InputStream)1 Field (java.lang.reflect.Field)1 URI (java.net.URI)1 FileSystem (java.nio.file.FileSystem)1