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

PengFei Li updated FLINK-35275:
-------------------------------
    Description: 
 

In ArrayContainsFunction, elementGetter is used to get elements of an array, 
but it's created from the needle data type rather than the element data type 
which will lead to wrong results.
{code:java}
public ArrayContainsFunction(SpecializedContext context) {
    super(BuiltInFunctionDefinitions.ARRAY_CONTAINS, context);
    final DataType needleDataType = 
context.getCallContext().getArgumentDataTypes().get(1);
    elementGetter = 
ArrayData.createElementGetter(needleDataType.getLogicalType());
    
} {code}
For example, the following sql returns true, but the expected is false. The 
element type is nullable int, and the needle type is non-nullable int. Using 
the needle type to create element getter will convert the NULL element to 0, so 
the result returns true.
{code:java}
SELECT ARRAY_CONTAINS(ARRAY[1, NULL], 0){code}
 

 

  was:
 

In `ArrayContainsFunction`, `elementGetter` is used to get elements of an 
array, but it's created from the needle data type rather than the element data 
type which will lead to wrong results.
{code:java}
public ArrayContainsFunction(SpecializedContext context) {
    super(BuiltInFunctionDefinitions.ARRAY_CONTAINS, context);
    final DataType needleDataType = 
context.getCallContext().getArgumentDataTypes().get(1);
    elementGetter = 
ArrayData.createElementGetter(needleDataType.getLogicalType());
    
} {code}
For example, the following sql returns true, but the expected is false. The 
element type is nullable int, and the needle type is non-nullable int. Using 
the needle type to create element getter will convert the NULL element to 0, so 
the result returns true.
{code:java}
SELECT ARRAY_CONTAINS(ARRAY[1, NULL], 0){code}
 

 


> ArrayContainsFunction uses wrong DataType to create element getter
> ------------------------------------------------------------------
>
>                 Key: FLINK-35275
>                 URL: https://issues.apache.org/jira/browse/FLINK-35275
>             Project: Flink
>          Issue Type: Bug
>          Components: Table SQL / Runtime
>    Affects Versions: 1.16.0
>            Reporter: PengFei Li
>            Priority: Minor
>
>  
> In ArrayContainsFunction, elementGetter is used to get elements of an array, 
> but it's created from the needle data type rather than the element data type 
> which will lead to wrong results.
> {code:java}
> public ArrayContainsFunction(SpecializedContext context) {
>     super(BuiltInFunctionDefinitions.ARRAY_CONTAINS, context);
>     final DataType needleDataType = 
> context.getCallContext().getArgumentDataTypes().get(1);
>     elementGetter = 
> ArrayData.createElementGetter(needleDataType.getLogicalType());
>     
> } {code}
> For example, the following sql returns true, but the expected is false. The 
> element type is nullable int, and the needle type is non-nullable int. Using 
> the needle type to create element getter will convert the NULL element to 0, 
> so the result returns true.
> {code:java}
> SELECT ARRAY_CONTAINS(ARRAY[1, NULL], 0){code}
>  
>  



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

Reply via email to