Skip to content

Commit

Permalink
make case sensitive by default, minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
shcheklein committed Aug 19, 2024
1 parent a23248a commit 087ddd5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
3 changes: 1 addition & 2 deletions src/datachain/sql/functions/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class regexp_replace(GenericFunction): # noqa: N801
inherit_cache = True


compiler_not_implemented(regexp_replace)

compiler_not_implemented(length)
compiler_not_implemented(split)
compiler_not_implemented(regexp_replace)
8 changes: 2 additions & 6 deletions src/datachain/sql/sqlite/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def setup():
compiles(array.length, "sqlite")(compile_array_length)
compiles(string.length, "sqlite")(compile_string_length)
compiles(string.split, "sqlite")(compile_string_split)
compiles(string.regexp_replace, "sqlite")(compile_regexp_replace)
compiles(conditional.greatest, "sqlite")(compile_greatest)
compiles(conditional.least, "sqlite")(compile_least)
compiles(Values, "sqlite")(compile_values)
Expand Down Expand Up @@ -180,7 +181,7 @@ def create_vector_functions(conn):
_registered_function_creators["vector_functions"] = create_vector_functions

def sqlite_regexp_replace(string: str, pattern: str, replacement: str) -> str:
return re.sub(pattern, replacement, string, flags=re.IGNORECASE)
return re.sub(pattern, replacement, string)

def create_string_functions(conn):
conn.create_function("split", 2, sqlite_string_split, deterministic=True)
Expand Down Expand Up @@ -407,8 +408,3 @@ def load_usearch_extension(conn) -> bool:

except Exception: # noqa: BLE001
return False


@compiles(string.regexp_replace, "sqlite")
def _compile_regexp_replace_sqlite(element, compiler, **kwargs):
return compile_regexp_replace(element, compiler, **kwargs)
4 changes: 2 additions & 2 deletions tests/unit/sql/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ def test_split(warehouse, args, expected):
("abc123def456", r"\d+", "X", "abcXdefX"),
("cat.1001.jpg", r"\.(\w+)\.", r"_\1_", "cat_1001_jpg"),
(
"dog_photo.JPG",
"dog_photo.jpg",
r"(\w+)\.(jpg|jpeg|png|gif)$",
r"\1_thumb.\2",
"dog_photo_thumb.JPG",
"dog_photo_thumb.jpg",
),
("file.with...dots.txt", r"\.+", ".", "file.with.dots.txt"),
],
Expand Down

0 comments on commit 087ddd5

Please sign in to comment.