Skip to content

Commit 8d7ad5e

Browse files
committed
Fix bug when handling 'flags' as only parameter
1 parent b22166e commit 8d7ad5e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

python/datafusion/functions.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,11 +1582,18 @@ def regexp_count(
15821582
>>> result.collect_column("c")[0].as_py()
15831583
1
15841584
"""
1585+
pattern = _to_raw_literal_expr(pattern)
15851586
flags = _to_raw_literal_expr(flags) if flags is not None else None
15861587
start = _to_raw_literal_expr(start) if start is not None else None
1587-
return Expr(
1588-
f.regexp_count(string.expr, _to_raw_literal_expr(pattern), start, flags)
1589-
)
1588+
1589+
# If Python callers pass only flags, supply the default start=1.
1590+
# because Datafusion accepts:
1591+
# regexp_count(string, pattern, start)
1592+
# regexp_count(string, pattern, start, flags)
1593+
if start is None and flags is not None:
1594+
start = _to_raw_literal_expr(1)
1595+
1596+
return Expr(f.regexp_count(string.expr, pattern, start, flags))
15901597

15911598

15921599
def regexp_instr(

0 commit comments

Comments
 (0)