Repository navigation
Closed
Labels
Description
What happens?
I can't seem to compare a string_view Arrow column (via the pyarrow Dataset API) to a literal. Is there anyway to force the literal to be a string_view instead of a string?
I originally reported this in duckdb/duckdb#19861 and was instructed to refile here.
To Reproduce
Install the latest versions of: duckdb, vortex-data, and typing-extensions (due to a missing dependency in vortex).
uv add duckdb vortex-data typing-extensions
Python code:
import vortex as vx
import duckdb
vx.io.write(vx.array([{"column": "a string"}]), 'foo.vortex')
x = vx.open('foo.vortex').to_dataset()
duckdb.execute("select * from x where \"column\" == 'hello world'").to_arrow_table()Python output:
Traceback (most recent call last):
File "<python-input-0>", line 5, in <module>
duckdb.execute("select * from x where \"column\" == 'hello world'").to_arrow_table()
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_duckdb.Error: ArrowNotImplementedError: Function 'equal' has no kernel matching input types (string_view, string)
At:
pyarrow/error.pxi(92): pyarrow.lib.check_status
I can't replicate with the DuckDB CLI. Whatever path that takes must avoid a string_view?
install vortex; load vortex; select * from read_vortex('foo.vortex') where "column" == 'hello world';
┌─────────┐
│ column │
│ varchar │
├─────────┤
│ 0 rows │
└─────────┘The full transcript of what I did:
# mkdir bar
# cd bar
# uv init
Initialized project `bar`
# uv add duckdb vortex-data typing-extensions
Using CPython 3.14.0
Creating virtual environment at: .venv
Resolved 7 packages in 58ms
Installed 6 packages in 15ms
+ duckdb==1.4.2
+ protobuf==5.29.5
+ pyarrow==22.0.0
+ substrait==0.25.0
+ typing-extensions==4.15.0
+ vortex-data==0.56.0
# uv run python
Python 3.14.0 (main, Oct 31 2025, 23:20:55) [Clang 21.1.4 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import vortex as vx
... import duckdb
... vx.io.write(vx.array([{"column": "a string"}]), 'foo.vortex')
... x = vx.open('foo.vortex').to_dataset()
... duckdb.execute("select * from x where \"column\" == 'hello world'").to_arrow_table()
...
Traceback (most recent call last):
File "<python-input-0>", line 5, in <module>
duckdb.execute("select * from x where \"column\" == 'hello world'").to_arrow_table()
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_duckdb.Error: ArrowNotImplementedError: Function 'equal' has no kernel matching input types (string_view, string)
At:
pyarrow/error.pxi(92): pyarrow.lib.check_status
>>> OS:
macOS
DuckDB Package Version:
1.4.2
Python Version:
1.4.2
Full Name:
Daniel King
Affiliation:
SpiralDB, Inc.
What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.
I have tested with a stable release
Did you include all relevant data sets for reproducing the issue?
Yes
Did you include all code required to reproduce the issue?
- Yes, I have
Did you include all relevant configuration to reproduce the issue?
- Yes, I have
Activity
paultiq commentedon Nov 20, 2025
Reproduced with just pyarrow.
Looks like root cause is here in the push down, not also checking for a ArrowVariableSizeType::VIEW:
duckdb-python/src/duckdb_py/arrow/pyarrow_filter_pushdown.cpp
Lines 122 to 130 in 4ebe06f
* trying to query a scanner here will cause a duckdb segfault:
x = vx.open('foo.vortex').to_dataset().scanner()danking commentedon Nov 21, 2025
Yeah, I also noticed the segfault. I’m not sure what’s wrong with the Scanner. It could be our (Vortex’s) fault.
paultiq commentedon Nov 21, 2025
The segfault seems to be inside pyarrow, not duckdb:
(I'll file in Vortex)
MRE of the segfault:
evertlammerts commentedon Dec 11, 2025
Hmm I'll have to look deeper. Comparing a string view column with a string view constant doesn't work either. This is more or less what duckdb does internally:
evertlammerts commentedon Dec 11, 2025
string to string comparison does work:
This can be a workaround as long as string view comparisons aren't implemented in pyarrow for datasets...
edit: looks like the scanner can't be consumed:
evertlammerts commentedon Dec 11, 2025
@danking I'm not very much at home in pyarrow, so please bear with me, and suggestions are very welcome.
Afaict, string view comparison is not implemented in pyarrow yet. It doesn't seem to work on scanners nor on tables:
The only way I've found so far is to project a string view column as a string column if it's being filtered on, but that's a pretty invasive workaround and feels more like hiding the issue. At that point it's more transparent to let users project the columns they want to filter on to string themselves.
Wdyt?
paultiq commentedon Dec 11, 2025
While I like where you're going with this (not casting) -
FYI, also reproducible with Polars (using CompatLevel.newest()):
And reproducible with DuckDB alone:
evertlammerts commentedon Dec 12, 2025
Binary views aren't cast yet either, that code is a placeholder: filters on binary view columns aren't pushed down yet.
The problem here is that (Py)arrow does not support binary and string view filters in scanners / tables / readers yet. Since we rely on pyarrow to apply filters that can be pushed down, we can't yet push down filters on binary and string view columns.
This PR in core makes sure that string view column filters won't be pushed down, but will be applied after scanning. With this change the following will work:
Only pushdown varchar if the arrow type is not a string view (#20165)
tests for string and binary views (#221)
evertlammerts commentedon Dec 13, 2025
Available in the latest 1.4.4dev nightly!
danking commentedon Dec 13, 2025
Awesome, thank you so much @evertlammerts ! I’ll also find the right place to request support in Arrow for string_view equality and link back here.
paultiq commentedon Dec 14, 2025
The root issue is really in to_substrait(), as Vortex provides string_view compatible kernels. to_substrait() only maps where the pyarrow compute layer supports it.
The change here has a significant performance impact: string_view pushdown is, in one test case, 10x faster than no string_view pushdown. In other words: 1.4.4.dev11 is significantly slower than 1.4.3 w/ a patched Vortex.
I opened vortex-data/vortex#5725 to discuss.