Add check for required avroBytesDecoder property that otherwise causes NPE. (#14177)

This commit is contained in:
Abhishek Radhakrishnan 2023-05-03 10:53:58 -06:00 committed by GitHub
parent ac7181bbda
commit 954f3917ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -25,6 +25,7 @@ import org.apache.druid.data.input.InputEntity;
import org.apache.druid.data.input.InputEntityReader;
import org.apache.druid.data.input.InputRowSchema;
import org.apache.druid.data.input.impl.NestedInputFormat;
import org.apache.druid.java.util.common.IAE;
import org.apache.druid.java.util.common.parsers.JSONPathSpec;
import javax.annotation.Nullable;
@ -48,6 +49,9 @@ public class AvroStreamInputFormat extends NestedInputFormat
)
{
super(flattenSpec);
if (avroBytesDecoder == null) {
throw new IAE("avroBytesDecoder is required to decode Avro records");
}
this.avroBytesDecoder = avroBytesDecoder;
this.binaryAsString = binaryAsString != null && binaryAsString;
this.extractUnionsByType = extractUnionsByType != null && extractUnionsByType;

View File

@ -42,6 +42,7 @@ import org.apache.druid.data.input.impl.TimestampSpec;
import org.apache.druid.data.input.schemarepo.Avro1124RESTRepositoryClientWrapper;
import org.apache.druid.data.input.schemarepo.Avro1124SubjectAndIdConverter;
import org.apache.druid.jackson.DefaultObjectMapper;
import org.apache.druid.java.util.common.IAE;
import org.apache.druid.java.util.common.parsers.JSONPathFieldSpec;
import org.apache.druid.java.util.common.parsers.JSONPathFieldType;
import org.apache.druid.java.util.common.parsers.JSONPathSpec;
@ -202,6 +203,21 @@ public class AvroStreamInputFormatTest extends InitializedNullHandlingTest
Assert.assertEquals(inputFormat, inputFormat2);
}
@Test
public void testMissingAvroBytesDecoderRaisesIAE()
{
Assert.assertThrows(
"avroBytesDecoder is required to decode Avro records",
IAE.class,
() -> new AvroStreamInputFormat(
flattenSpec,
null,
true,
true
)
);
}
@Test
public void testParse() throws SchemaValidationException, IOException
{