Implement Spark-compatible `regexp_count`
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
Start by reading the existing string functions under crates/spark/src/function/string/, especially the regexp_extract_all implementation, since regexp_count must share its matching core rather than wrap DataFusion's regexpcount.rs. The issue is explicit that the Java-regex compatibility helper proposed for rlike does not exist yet, so confirm with a maintainer whether this work is blocked on it before writing anything. Done means a new regexp_count function with #[user_doc], plus crates/sqllogictest/test_files/string/regexp_count.slt covering the listed edge cases (NULLs, empty pattern, non-overlapping matches, invalid pattern, collation).
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Part of #174 and apache/datafusion-comet#7300.
What the function does
regexp_count(str, regexp) returns the number of times the Java regular expression regexp matches in str. It is RuntimeReplaceable: the analyzer rewrites it to size(regexp_extract_all(str, regexp, 0), legacySizeOfNull = false), so it counts the matches found by repeated Matcher.find(). Available since 3.4.0.
Both arguments are implicitly cast to STRING. Result is INT. NULL if either argument is NULL. There are no start or flags arguments.
Examples
SELECT regexp_count('Steven Jones and Stephen Smith are the best players', 'Ste(v|ph)en');
-- 2
SELECT regexp_count('abcdefghijklmnopqrstuvwxyz', '[a-z]{3}');
-- 8
SELECT regexp_count('1a 2b 14m', '\\d+');
-- 3
SELECT regexp_count('the fox', 'FOX');
-- 0
SELECT regexp_count('the fox', '(?i)FOX');
-- 1
SELECT regexp_count('passwd7 plain A1234 a1234', '(?=[^ ]*[a-z])(?=[^ ]*[0-9])[^ ]+');
-- 2
SELECT regexp_count(null, 'abc');
-- NULL
Edge cases to test
- NULL
stror NULLregexp, literal and column: NULL. - Matches are non-overlapping:
'[a-z]{3}'over 26 letters is 8. - Empty pattern:
regexp_count('abc', '')is 4 (one empty match at each of the 4 positions).regexp_count('', '')is 1. - Empty matches after a non-empty match: Java counts them, the
regexcrate does not (itstestdata/empty.tomlgives 3 matches forb|onabc; Java finds 4).regexp_count('1a 2b 14m', '(\\d+)?')is 9 in Spark (the same matches as theregexp_extract_allgolden result["1","","","2","","","14","",""]). - Invalid pattern:
INVALID_PARAMETER_VALUE.PATTERN. Because of the rewrite, thefunctionNamein the error is`regexp_extract_all`, notregexp_count. - Column patterns (different per row).
spark.sql.parser.escapedStringLiterals(default false) only changes how the SQL literal reaches the function. In.slt, DataFusion keeps backslashes literal.- Java vs Rust divergences to decline or test: lookaround (the
passwd7example above needs it), backreferences, atomic groups, possessive quantifiers; ASCII\d\w\sin Java vs Unicode in Rust (regexp_count('1\u0663', '\\d'), U+0663 ARABIC-INDIC DIGIT THREE, is 1 in Spark);.excludes\r,\u0085,\u2028,\u2029in Java;$matches before a final line terminator in Java (regexp_count('a\n', 'a$')is 1);(?i)ASCII-only in Java (U+212A KELVIN SIGN does not match(?i)k); inline flag lettersU,u,d; Java-only\Q..\E,\h,\R,\Z; Rust-only(?P<n>),\<,[[:alpha:]]. UTF8_LCASEcollation (4.0+) counts case-insensitively.
Differences across Spark versions
- 4.0: collation-aware input types. Otherwise none found (3.4.0 through 4.2.0).
Implementation notes
- Spark:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala,RegExpCount(replacement usesRegExpExtractAllandSize). - Because of the rewrite, Spark plans (and Comet) never contain
RegExpCount; engines that translate Spark plans will seesize(regexp_extract_all(...)). A directregexp_countUDF is still useful for SQL users ofdatafusion-sparkand should share the matching core withregexp_extract_all. - DataFusion core
regexp_count(str, regexp[, start[, flags]])(datafusion/functions/src/regex/regexpcount.rs) returns BIGINT, acceptsstartandflags, and uses Rust regex syntax and Rust empty-match iteration. Do not wrap it unchanged. - Use the shared Java-regex compatibility helper proposed for
rlike(verified subset, decline otherwise, decided at planning time for literal patterns). - Belongs in
crates/spark/src/function/string/. Addcrates/sqllogictest/test_files/string/regexp_count.sltand document with#[user_doc].
This issue was generated by an LLM (Claude) from the Apache Spark source code and tests. Examples come from Spark's ExpressionDescription examples, test suites and .sql.out golden files, but please verify them against Spark before relying on them.
- Ngôn ngữ chính
- Rust
- Star
- 7
- Fork
- 15
- Merge trung bình
- 16 giờ 43 phút
- Pull request đã merge (30 ngày)
- 26
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của apache/datafusion-spark
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
apache/datafusion-spark#287 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
apache/datafusion-spark#266 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] make_dt_interval returns NULL for more than about 1.49 million days, Spark returns the intervalCó thể đã có người làm @Subodh-17 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
apache/datafusion-spark#109 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 18/100
apache/datafusion-spark#299 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
apache/datafusion-spark#298 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của apache/datafusion-spark
Issue tương tự
-
comp-rbac
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
ClickHouse/ClickHouse#131875 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug(python): read_transaction raises TypeError on a Rewrite with rewritten indicesCó thể đã có người làm @Borg93 đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
lance-format/lance#11117 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
storytold/photocraft#15232 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
forge: fork preflight reads still send `requireCanonical: false`, which Rootstock rejects (-32603)Có thể đã có người làm @Ynyesto đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
foundry-rs/foundry#18485 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
bondybondbond/rushcut#238 · 1 bình luận ·