Skip to content

Commit 94ffdb7

Browse files
cecilycarvercecily_carver
and
cecily_carver
authored
fix: addressing mismatch in STR_POSITION argument order in executor. (#4574)
Co-authored-by: cecily_carver <[email protected]>
1 parent 83595b6 commit 94ffdb7

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

sqlglot/executor/env.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ def _func(*args):
7575
return decorator
7676

7777

78-
@null_if_any("substr", "this")
79-
def str_position(substr, this, position=None):
78+
@null_if_any("this", "substr")
79+
def str_position(this, substr, position=None):
8080
position = position - 1 if position is not None else position
8181
return this.find(substr, position) + 1
8282

tests/test_executor.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -613,10 +613,10 @@ def test_scalar_functions(self):
613613
("CONCAT('a', 'b')", "ab"),
614614
("CONCAT('a', NULL)", None),
615615
("CONCAT_WS('_', 'a', 'b')", "a_b"),
616-
("STR_POSITION('bar', 'foobarbar')", 4),
617-
("STR_POSITION('bar', 'foobarbar', 5)", 7),
618-
("STR_POSITION(NULL, 'foobarbar')", None),
619-
("STR_POSITION('bar', NULL)", None),
616+
("STR_POSITION('foobarbar', 'bar')", 4),
617+
("STR_POSITION('foobarbar', 'bar', 5)", 7),
618+
("STR_POSITION('foobarbar', NULL)", None),
619+
("STR_POSITION(NULL, 'bar')", None),
620620
("UPPER('foo')", "FOO"),
621621
("UPPER(NULL)", None),
622622
("LOWER('FOO')", "foo"),

tests/test_expressions.py

+6
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,12 @@ def test_walk(self):
632632
self.assertTrue(all(isinstance(e, exp.Expression) for e in expression.walk()))
633633
self.assertTrue(all(isinstance(e, exp.Expression) for e in expression.walk(bfs=False)))
634634

635+
def test_str_position_order(self):
636+
str_position_exp = parse_one("STR_POSITION('mytest', 'test')")
637+
self.assertIsInstance(str_position_exp, exp.StrPosition)
638+
self.assertEqual(str_position_exp.args.get("this").this, "mytest")
639+
self.assertEqual(str_position_exp.args.get("substr").this, "test")
640+
635641
def test_functions(self):
636642
self.assertIsInstance(parse_one("x LIKE ANY (y)"), exp.Like)
637643
self.assertIsInstance(parse_one("x ILIKE ANY (y)"), exp.ILike)

0 commit comments

Comments
 (0)