-
Notifications
You must be signed in to change notification settings - Fork 593
[GLUTEN-11330][VL] Make PartialProject support array and map with null values #11331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jinchengchenghh
merged 2 commits into
apache:main
from
jiangjiangtian:access_null_value_in_map
Jan 2, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
backends-velox/src/test/java/org/apache/gluten/udf/DuplicateArray.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.gluten.udf; | ||
|
|
||
| import org.apache.hadoop.hive.ql.exec.Description; | ||
| import org.apache.hadoop.hive.ql.exec.UDFArgumentException; | ||
| import org.apache.hadoop.hive.ql.metadata.HiveException; | ||
| import org.apache.hadoop.hive.ql.udf.generic.GenericUDF; | ||
| import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector; | ||
| import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; | ||
| import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| /** UDF for duplicating array. */ | ||
| @Description( | ||
| name = "array_duplicate", | ||
| value = | ||
| "_FUNC_(array(obj1, obj2,...)) - " | ||
| + "The function returns an array of the same type as every element" | ||
| + "in array is duplicated.", | ||
| extended = | ||
| "Example:\n" | ||
| + " > SELECT _FUNC_(array('b', 'd')) FROM src LIMIT 1;\n" | ||
| + " ['b', 'b', 'd', 'd']") | ||
| public class DuplicateArray extends GenericUDF { | ||
|
|
||
| ListObjectInspector arrayOI; | ||
|
|
||
| public DuplicateArray() {} | ||
|
|
||
| @Override | ||
| public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { | ||
| if (arguments.length != 1) { | ||
| throw new UDFArgumentException("Argument size of array_duplicate must be 1."); | ||
| } | ||
|
|
||
| arrayOI = (ListObjectInspector) arguments[0]; | ||
| return ObjectInspectorFactory.getStandardListObjectInspector( | ||
| arrayOI.getListElementObjectInspector()); | ||
| } | ||
|
|
||
| @Override | ||
| public Object evaluate(DeferredObject[] arguments) throws HiveException { | ||
|
|
||
| Object array = arguments[0].get(); | ||
|
|
||
| // If the array is empty, return back the empty array | ||
| if (arrayOI.getListLength(array) == 0) { | ||
| return Collections.emptyList(); | ||
| } else if (arrayOI.getListLength(array) < 0) { | ||
| return null; | ||
| } | ||
|
|
||
| List<?> retArray = arrayOI.getList(array); | ||
| List<Object> result = new ArrayList<>(); | ||
| retArray.forEach( | ||
| element -> { | ||
| result.add(element); | ||
| result.add(element); | ||
| }); | ||
| return result; | ||
| } | ||
|
|
||
| @Override | ||
| public String getDisplayString(String[] children) { | ||
| return "array_duplicate"; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
gluten-arrow/src/main/java/org/apache/gluten/vectorized/ArrowColumnarArray.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.gluten.vectorized; | ||
|
|
||
| import org.apache.spark.sql.execution.vectorized.ColumnarArrayShim; | ||
| import org.apache.spark.sql.vectorized.ColumnVector; | ||
|
|
||
| /** | ||
| * Because `get` method in `ColumnarArray` don't check whether the data to get is null and arrow | ||
| * vectors will throw exception when we try to access null value, so we define the following class | ||
| * as a workaround. Its implementation is copied from Spark-4.0, except that the `handleNull` | ||
| * parameter is set to true when we call `SpecializedGettersReader.read` in `get`, which means that | ||
| * when trying to access a value of the array, we will check whether the value to get is null first. | ||
| * | ||
| * <p>The actual implementation is put in [[ColumnarArrayShim]] because Variant data type is | ||
| * introduced in Spark-4.0. | ||
| */ | ||
| public class ArrowColumnarArray extends ColumnarArrayShim { | ||
| public ArrowColumnarArray(ColumnVector data, int offset, int length) { | ||
| super(data, offset, length); | ||
| } | ||
| } | ||
55 changes: 55 additions & 0 deletions
55
gluten-arrow/src/main/java/org/apache/gluten/vectorized/ArrowColumnarMap.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.gluten.vectorized; | ||
|
|
||
| import org.apache.spark.sql.catalyst.util.ArrayBasedMapData; | ||
| import org.apache.spark.sql.catalyst.util.ArrayData; | ||
| import org.apache.spark.sql.catalyst.util.MapData; | ||
| import org.apache.spark.sql.vectorized.ColumnVector; | ||
|
|
||
| /** See [[ArrowColumnarArray]]. */ | ||
| public class ArrowColumnarMap extends MapData { | ||
| private final ArrowColumnarArray keys; | ||
| private final ArrowColumnarArray values; | ||
| private final int length; | ||
|
|
||
| public ArrowColumnarMap(ColumnVector keys, ColumnVector values, int offset, int length) { | ||
| this.length = length; | ||
| this.keys = new ArrowColumnarArray(keys, offset, length); | ||
| this.values = new ArrowColumnarArray(values, offset, length); | ||
| } | ||
|
|
||
| @Override | ||
| public int numElements() { | ||
| return length; | ||
| } | ||
|
|
||
| @Override | ||
| public ArrayData keyArray() { | ||
| return keys; | ||
| } | ||
|
|
||
| @Override | ||
| public ArrayData valueArray() { | ||
| return values; | ||
| } | ||
|
|
||
| @Override | ||
| public MapData copy() { | ||
| return new ArrayBasedMapData(keys.copy(), values.copy()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the Spark shortage or design? What's the Spark usage for ColumnarArray with null value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is Spark shortage. If there exists null values, ColumnarArray will get the value(this might be a default value or previously set value) because call
getonColumnarArraywill eventually callgetXXXonColumnVectorandgetXXXwill not check if it is null value, either.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also raise an issue in Spark?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I will. Thanks.