feat(snowflake)!: Transpilation support for Snowflake REGEXP_COUNT to DuckDB#7054
feat(snowflake)!: Transpilation support for Snowflake REGEXP_COUNT to DuckDB#7054georgesittas merged 2 commits intomainfrom
Conversation
SQLGlot Integration Test ResultsComparing:
By Dialect
Overallmain: 9121 total, 8217 passed (pass rate: 90.1%), sqlglot version: sqlglot:feature/transpile-regex-count: 9121 total, 8224 passed (pass rate: 90.2%), sqlglot version: Transitions: |
sqlglot/dialects/duckdb.py
Outdated
| elif "e" in flag_str: | ||
| self.unsupported("'e' (extract) flag is not supported in DuckDB") | ||
| flag_str = flag_str.replace("e", "") |
There was a problem hiding this comment.
Should this branch be consolidated with the one in L3220? So, we'd pass the supported flags wherever this helper is used.
There was a problem hiding this comment.
will do, yes, it's better to explicitly force the flags that are supported.
| if position: | ||
| this = exp.Substring(this=this, start=position) | ||
|
|
||
| # Embed flags in pattern (REGEXP_EXTRACT_ALL doesn't support flags argument) |
There was a problem hiding this comment.
What happens if the pattern already contains the flags in validated_flags? Does it cause any issues?
There was a problem hiding this comment.
I don't think that would be a valid query in Snowflake, something like REGEXP_COUNT(text, '(?i)hello', 1, 'i') won't even run. The flags for REGEXP_COUNT are meant to be in parameters.
Also, on DuckDB side, prepending another one seems to run:
select REGEXP_EXTRACT_ALL('Hello World', '(?im)L');
select REGEXP_EXTRACT_ALL('Hello World', '(?i)(?im)L');
099b756 to
ba34492
Compare
Adds transpilation for Snowflake's REGEXP_COUNT function to DuckDB. It uses DuckDB's
REGEXP_EXTRACT_ALL, which requires flags embedded in pattern as(?ims), not as a separate argument.