|
32 | 32 | expr_list_to_raw_expr_list, |
33 | 33 | sort_list_to_raw_sort_list, |
34 | 34 | sort_or_default, |
| 35 | + _to_raw_literal_expr, |
35 | 36 | ) |
36 | 37 |
|
37 | 38 | __all__ = [ |
@@ -1440,7 +1441,7 @@ def radians(arg: Expr) -> Expr: |
1440 | 1441 | return Expr(f.radians(arg.expr)) |
1441 | 1442 |
|
1442 | 1443 |
|
1443 | | -def regexp_like(string: Expr, regex: Expr, flags: Expr | None = None) -> Expr: |
| 1444 | +def regexp_like(string: Expr, regex: Expr | Any, flags: Expr | Any | None = None) -> Expr: |
1444 | 1445 | r"""Find if any regular expression (regex) matches exist. |
1445 | 1446 |
|
1446 | 1447 | Tests a string using a regular expression returning true if at least one match, |
@@ -1468,12 +1469,14 @@ def regexp_like(string: Expr, regex: Expr, flags: Expr | None = None) -> Expr: |
1468 | 1469 | >>> result.collect_column("m")[0].as_py() |
1469 | 1470 | True |
1470 | 1471 | """ |
1471 | | - if flags is not None: |
1472 | | - flags = flags.expr |
1473 | | - return Expr(f.regexp_like(string.expr, regex.expr, flags)) |
| 1472 | + # if flags is not None: |
| 1473 | + # flags = flags.expr |
| 1474 | + # return Expr(f.regexp_like(string.expr, regex.expr, flags)) |
| 1475 | + flags = _to_raw_literal_expr(flags) if flags is not None else None |
| 1476 | + return Expr(f.regexp_like(string.expr, _to_raw_literal_expr(regex), flags)) |
1474 | 1477 |
|
1475 | 1478 |
|
1476 | | -def regexp_match(string: Expr, regex: Expr, flags: Expr | None = None) -> Expr: |
| 1479 | +def regexp_match(string: Expr, regex: Expr | Any, flags: Expr | Any | None = None) -> Expr: |
1477 | 1480 | r"""Perform regular expression (regex) matching. |
1478 | 1481 |
|
1479 | 1482 | Returns an array with each element containing the leftmost-first match of the |
@@ -1501,13 +1504,15 @@ def regexp_match(string: Expr, regex: Expr, flags: Expr | None = None) -> Expr: |
1501 | 1504 | >>> result.collect_column("m")[0].as_py() |
1502 | 1505 | ['hello'] |
1503 | 1506 | """ |
1504 | | - if flags is not None: |
1505 | | - flags = flags.expr |
1506 | | - return Expr(f.regexp_match(string.expr, regex.expr, flags)) |
| 1507 | + # if flags is not None: |
| 1508 | + # flags = flags.expr |
| 1509 | + # return Expr(f.regexp_match(string.expr, regex.expr, flags)) |
| 1510 | + flags = _to_raw_literal_expr(flags) if flags is not None else None |
| 1511 | + return Expr(f.regexp_match(string.expr, _to_raw_literal_expr(regex), flags)) |
1507 | 1512 |
|
1508 | 1513 |
|
1509 | 1514 | def regexp_replace( |
1510 | | - string: Expr, pattern: Expr, replacement: Expr, flags: Expr | None = None |
| 1515 | + string: Expr, pattern: Expr | Any, replacement: Expr | Any, flags: Expr | Any | None = None |
1511 | 1516 | ) -> Expr: |
1512 | 1517 | r"""Replaces substring(s) matching a PCRE-like regular expression. |
1513 | 1518 |
|
@@ -1541,13 +1546,17 @@ def regexp_replace( |
1541 | 1546 | >>> result.collect_column("r")[0].as_py() |
1542 | 1547 | 'aX bX cX' |
1543 | 1548 | """ |
1544 | | - if flags is not None: |
1545 | | - flags = flags.expr |
1546 | | - return Expr(f.regexp_replace(string.expr, pattern.expr, replacement.expr, flags)) |
| 1549 | + # if flags is not None: |
| 1550 | + # flags = flags.expr |
| 1551 | + # return Expr(f.regexp_replace(string.expr, pattern.expr, replacement.expr, flags)) |
| 1552 | + flags = _to_raw_literal_expr(flags) if flags is not None else None |
| 1553 | + pattern = _to_raw_literal_expr(pattern) |
| 1554 | + replacement = _to_raw_literal_expr(replacement) |
| 1555 | + return Expr(f.regexp_replace(string.expr, pattern, replacement, flags)) |
1547 | 1556 |
|
1548 | 1557 |
|
1549 | 1558 | def regexp_count( |
1550 | | - string: Expr, pattern: Expr, start: Expr | None = None, flags: Expr | None = None |
| 1559 | + string: Expr, pattern: Expr | Any, start: Expr | Any | None = None, flags: Expr | Any | None = None |
1551 | 1560 | ) -> Expr: |
1552 | 1561 | """Returns the number of matches in a string. |
1553 | 1562 |
|
@@ -1575,19 +1584,22 @@ def regexp_count( |
1575 | 1584 | >>> result.collect_column("c")[0].as_py() |
1576 | 1585 | 1 |
1577 | 1586 | """ |
1578 | | - if flags is not None: |
1579 | | - flags = flags.expr |
1580 | | - start = start.expr if start is not None else start |
1581 | | - return Expr(f.regexp_count(string.expr, pattern.expr, start, flags)) |
| 1587 | + # if flags is not None: |
| 1588 | + # flags = flags.expr |
| 1589 | + # start = start.expr if start is not None else start |
| 1590 | + # return Expr(f.regexp_count(string.expr, pattern.expr, start, flags)) |
| 1591 | + flags = _to_raw_literal_expr(flags) if flags is not None else None |
| 1592 | + start = _to_raw_literal_expr(start) if start is not None else None |
| 1593 | + return Expr(f.regexp_count(string.expr, _to_raw_literal_expr(pattern), start, flags)) |
1582 | 1594 |
|
1583 | 1595 |
|
1584 | 1596 | def regexp_instr( |
1585 | 1597 | values: Expr, |
1586 | | - regex: Expr, |
1587 | | - start: Expr | None = None, |
1588 | | - n: Expr | None = None, |
1589 | | - flags: Expr | None = None, |
1590 | | - sub_expr: Expr | None = None, |
| 1598 | + regex: Expr | Any, |
| 1599 | + start: Expr | Any | None = None, |
| 1600 | + n: Expr | Any | None = None, |
| 1601 | + flags: Expr | Any | None = None, |
| 1602 | + sub_expr: Expr | Any | None = None, |
1591 | 1603 | ) -> Expr: |
1592 | 1604 | r"""Returns the position of a regular expression match in a string. |
1593 | 1605 |
|
@@ -1635,15 +1647,20 @@ def regexp_instr( |
1635 | 1647 | >>> result.collect_column("pos")[0].as_py() |
1636 | 1648 | 1 |
1637 | 1649 | """ |
1638 | | - start = start.expr if start is not None else None |
1639 | | - n = n.expr if n is not None else None |
1640 | | - flags = flags.expr if flags is not None else None |
1641 | | - sub_expr = sub_expr.expr if sub_expr is not None else None |
| 1650 | + # start = start.expr if start is not None else None |
| 1651 | + # n = n.expr if n is not None else None |
| 1652 | + # flags = flags.expr if flags is not None else None |
| 1653 | + # sub_expr = sub_expr.expr if sub_expr is not None else None |
| 1654 | + regex = _to_raw_literal_expr(regex) |
| 1655 | + start = _to_raw_literal_expr(start) if start is not None else None |
| 1656 | + n = _to_raw_literal_expr(n) if n is not None else None |
| 1657 | + flags = _to_raw_literal_expr(flags) if flags is not None else None |
| 1658 | + sub_expr = _to_raw_literal_expr(sub_expr) if sub_expr is not None else None |
1642 | 1659 |
|
1643 | 1660 | return Expr( |
1644 | 1661 | f.regexp_instr( |
1645 | 1662 | values.expr, |
1646 | | - regex.expr, |
| 1663 | + regex, |
1647 | 1664 | start, |
1648 | 1665 | n, |
1649 | 1666 | flags, |
|
0 commit comments