[ 
https://issues.apache.org/jira/browse/NIFI-5960?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Pierre Villard resolved NIFI-5960.
----------------------------------
    Resolution: Feedback Received

Apache NiFi 1.x is no longer maintained and no new release is planned on the 
1.x release line. Marking as resolved as part of a cleanup operation. Please 
open a new one with an updated description if this is still relevant for NiFi 
2.x.

> Wrong sub-schema picked for CHOICE datatype
> -------------------------------------------
>
>                 Key: NIFI-5960
>                 URL: https://issues.apache.org/jira/browse/NIFI-5960
>             Project: Apache NiFi
>          Issue Type: Bug
>          Components: Core Framework
>    Affects Versions: 1.8.0
>            Reporter: Alex Savitsky
>            Priority: Major
>          Time Spent: 1.5h
>  Remaining Estimate: 0h
>
> When CHOICE datatype contains multiple RECORD choices, if any of the RECORD 
> schemas have all nullable fields, these schemas will be considered compatible 
> with any input, and can be picked as a valid choice instead of a more 
> appropriate sub-schema. The following unit test showcases the issue:
> {code:java}
> package org.apache.nifi.serialization.record;
> import org.apache.nifi.serialization.SimpleRecordSchema;
> import org.apache.nifi.serialization.record.type.ChoiceDataType;
> import org.apache.nifi.serialization.record.type.RecordDataType;
> import org.apache.nifi.serialization.record.util.DataTypeUtils;
> import org.junit.Test;
> import static java.util.Arrays.asList;
> import static java.util.Collections.*;
> import static org.apache.nifi.serialization.record.RecordFieldType.STRING;
> import static org.junit.Assert.*;
> public class DataTypeUtilsTest {
>       @Test
>       public void testChoiceCompatibility() {
>               DataType choice1 = new RecordDataType(new 
> SimpleRecordSchema(singletonList(new RecordField("field1", 
> STRING.getDataType(), false))));
>               DataType choice2 = new RecordDataType(new 
> SimpleRecordSchema(singletonList(new RecordField("field2", 
> STRING.getDataType()))));
>               Record record = new MapRecord(new 
> SimpleRecordSchema(emptyList()), singletonMap("field1", "value1"));
>               DataType dataType = DataTypeUtils.chooseDataType(record, new 
> ChoiceDataType(asList(choice2, choice1)));
>               assertEquals(dataType, choice1);
>               assertNotEquals(dataType, choice2);
>       }
> }
> {code}
> When presented with an input containing a single field "field1", and a choice 
> of two schemas , one with all nullable unrelated fields ("field2"), and 
> another with fields matching the input ("field1"), the chooseDataType() call 
> will choose the unrelated schema if it's presented first.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to