korbit-ai[bot] commented on code in PR #35962:
URL: https://github.com/apache/superset/pull/35962#discussion_r2487792945
##########
superset/result_set.py:
##########
@@ -178,8 +178,9 @@ def __init__( # pylint: disable=too-many-locals # noqa:
C901
except Exception as ex: # pylint: disable=broad-except
logger.exception(ex)
- if not pa_data:
- column_names = []
+ if not pa_data and column_names:
+ # Build zero-length arrays so column metadata survives empty
result sets
+ pa_data = [pa.array([], type=pa.null()) for _ in column_names]
Review Comment:
### Column type information lost in empty result sets <sub></sub>
<details>
<summary>Tell me more</summary>
###### What is the issue?
The code creates null-typed arrays for all columns when handling empty
result sets, which loses the original column type information that could be
derived from the cursor description.
###### Why this matters
This will cause all columns in empty result sets to appear as null type
instead of their actual database types (e.g., INTEGER, VARCHAR, DATETIME),
potentially breaking downstream functionality that relies on proper column type
metadata.
###### Suggested change ∙ *Feature Preview*
Instead of using `pa.null()` type for all columns, derive the appropriate
PyArrow types from the cursor description or use a more generic type that
preserves type information:
```python
if not pa_data and column_names:
# Build zero-length arrays so column metadata survives empty result sets
pa_data = []
for i, column_name in enumerate(column_names):
# Try to get type from cursor description if available
if deduped_cursor_desc and i < len(deduped_cursor_desc):
db_type = deduped_cursor_desc[i][1]
try:
# Use database engine spec to determine appropriate type
pa_type = self.db_engine_spec.get_pyarrow_type(db_type) if
hasattr(self.db_engine_spec, 'get_pyarrow_type') else pa.string()
except:
pa_type = pa.string() # fallback to string type
else:
pa_type = pa.string() # default fallback
pa_data.append(pa.array([], type=pa_type))
```
###### Provide feedback to improve future suggestions
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/6aeff4cf-1183-4374-bf00-a97d86d56531/upvote)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/6aeff4cf-1183-4374-bf00-a97d86d56531?what_not_true=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/6aeff4cf-1183-4374-bf00-a97d86d56531?what_out_of_scope=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/6aeff4cf-1183-4374-bf00-a97d86d56531?what_not_in_standard=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/6aeff4cf-1183-4374-bf00-a97d86d56531)
</details>
<sub>
💬 Looking for more details? Reply to this comment to chat with Korbit.
</sub>
<!--- korbi internal id:5cd78dab-bb12-42d8-a9fe-a10235e1917e -->
[](5cd78dab-bb12-42d8-a9fe-a10235e1917e)
##########
superset/result_set.py:
##########
@@ -178,8 +178,9 @@ def __init__( # pylint: disable=too-many-locals # noqa:
C901
except Exception as ex: # pylint: disable=broad-except
logger.exception(ex)
- if not pa_data:
- column_names = []
+ if not pa_data and column_names:
+ # Build zero-length arrays so column metadata survives empty
result sets
+ pa_data = [pa.array([], type=pa.null()) for _ in column_names]
Review Comment:
### Inefficient null array creation in list comprehension <sub></sub>
<details>
<summary>Tell me more</summary>
###### What is the issue?
List comprehension creates multiple PyArrow null arrays with O(n) time
complexity when a single reusable null array could be used for all columns.
###### Why this matters
This creates unnecessary object allocation overhead and repeated PyArrow
array construction calls, which could impact performance when dealing with
result sets that have many columns but no data rows.
###### Suggested change ∙ *Feature Preview*
Create a single null array and reuse it for all columns to reduce object
allocation overhead:
```python
null_array = pa.array([], type=pa.null())
pa_data = [null_array for _ in column_names]
```
###### Provide feedback to improve future suggestions
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/efa7ecc9-1f33-4d33-a0ea-a1208266cf84/upvote)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/efa7ecc9-1f33-4d33-a0ea-a1208266cf84?what_not_true=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/efa7ecc9-1f33-4d33-a0ea-a1208266cf84?what_out_of_scope=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/efa7ecc9-1f33-4d33-a0ea-a1208266cf84?what_not_in_standard=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/efa7ecc9-1f33-4d33-a0ea-a1208266cf84)
</details>
<sub>
💬 Looking for more details? Reply to this comment to chat with Korbit.
</sub>
<!--- korbi internal id:f574eb3d-ebc1-4d66-8d66-3af11561f5f7 -->
[](f574eb3d-ebc1-4d66-8d66-3af11561f5f7)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]