Implement Spark-compatible `regexp_substr`
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
- 38/100
Hướng nghiên cứu
Start by reading Spark's RegExpSubStr in regexpExpressions.scala, which is defined purely as NullIf(RegExpExtract(left, right, 0), "") — the new function in crates/spark/src/function/string/ must reproduce that nullif-on-empty semantics, not just a regex search. Check whether regexp_extract exists yet in this crate; if not, the shared core decides the shape of the work. Add crates/sqllogictest/test_files/string/regexp_substr.slt covering the listed NULL/empty-match/invalid-pattern cases, and annotate the UDF with #[user_doc].
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_substr(str, regexp) returns the first substring of str that matches the Java regular expression regexp, or NULL if there is no match. It is RuntimeReplaceable: the analyzer rewrites it to nullif(regexp_extract(str, regexp, 0), ''), so an empty match also returns NULL. Available since 3.4.0.
Both arguments are implicitly cast to STRING. Result type is the type of str (STRING; collation-aware in 4.0+). NULL if either argument is NULL. There are no position / occurrence / flags arguments (unlike some other engines' regexp_substr).
Examples
SELECT regexp_substr('Steven Jones and Stephen Smith are the best players', 'Ste(v|ph)en');
-- Steven
SELECT regexp_substr('Steven Jones and Stephen Smith are the best players', 'Jeck');
-- NULL
SELECT regexp_substr('1a 2b 14m', '\\d+');
-- 1
SELECT regexp_substr('1a 2b 14m', '\\d+(a|b|m)');
-- 1a
SELECT regexp_substr('1a 2b 14m', '\\d{2}(a|b|m)');
-- 14m
SELECT regexp_substr('1a 2b 14m', '');
-- NULL
SELECT regexp_substr('Spark', null);
-- NULL
Edge cases to test
- NULL
stror NULLregexp, literal and column: NULL. - Empty pattern returns NULL (the first match is the empty string at position 0, which
nullifturns into NULL). - A pattern whose first match is empty returns NULL even if a later match is non-empty:
regexp_substr('abc', 'b*')matches''at position 0, so the result is NULL. - No match returns NULL (not
''asregexp_extractdoes). - Invalid pattern:
INVALID_PARAMETER_VALUE.PATTERN. Because of the rewrite, thefunctionNamein the error is`regexp_extract`. - Column patterns that differ per row.
spark.sql.parser.escapedStringLiterals(default false) only affects SQL literal parsing before the function. In.slt, DataFusion keeps backslashes literal ('\d+').- Java vs Rust divergences to decline or test: lookaround / backreferences / atomic / possessive (Java only); ASCII
\d\w\sin Java vs Unicode in Rust (regexp_substr('\u0663 1', '\\d')is1in Spark; U+0663 ARABIC-INDIC DIGIT THREE);.excludes\r,\u0085,\u2028,\u2029in Java (regexp_substr('a\rb', 'a.b')is NULL in Spark);$matches before a final line terminator in Java;(?i)ASCII-only in Java; inline flag lettersU/u/d; Java-only\Q..\E,\h,\R,\Z, octal; Rust-only(?P<n>),\<,[[:alpha:]]. Leftmost-first alternation is the same on both sides (regexp_substr('ab', 'a|ab')isa). - Unicode: matches containing multi-byte and supplementary characters are returned whole.
UTF8_LCASEcollation (4.0+) matches case-insensitively.
Differences across Spark versions
- 4.0: collation-aware inputs; the
nullifliteral is created withstr's type. Otherwise none found.
Implementation notes
- Spark:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala,RegExpSubStr(replacement isNullIf(RegExpExtract(left, right, 0), "")). - Because of the rewrite, Spark plans never contain
RegExpSubStr; an engine translating Spark plans seesnullif(regexp_extract(...), '').regexp_extractis not indatafusion-sparkeither; implementing it with the same core (group-index checks as inRegExpExtractBase.checkGroupIndex) would serve both. A directregexp_substrUDF is still useful for SQL users. - DataFusion core has no
regexp_substr.regexp_matchreturns capture groups of the first match as a list and uses Rust syntax. - 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_substr.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ự
-
Độ 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
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
suhina-daw/suhina-daw#1477 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
parity priority: low ui
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
storytold/pdfcraft#7483 · 1 bình luận ·
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 72/100
IngvarConsulting/unica#3097 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement in-progress
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 64/100