Skip to content

Commit

Permalink
refactor(ir): remove now obsolete ops.Named mixin (ibis-project#8244)
Browse files Browse the repository at this point in the history
Co-authored-by: Phillip Cloud <417981+cpcloud@users.noreply.github.com>
  • Loading branch information
kszucs and cpcloud authored Feb 6, 2024
1 parent 2cd7113 commit 6a017f1
Show file tree
Hide file tree
Showing 22 changed files with 36 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SELECT
toDateTime("t0"."int_col") AS "TimestampFromUNIX(int_col)"
toDateTime("t0"."int_col") AS "TimestampFromUNIX(int_col, SECOND)"
FROM "functional_alltypes" AS "t0"
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
SELECT
toDate(parseDateTimeBestEffort('2009-05-17T12:34:56')) AS "TimestampTruncate(datetime.datetime(2009, 5, 17, 12, 34, 56))"
toDate(parseDateTimeBestEffort('2009-05-17T12:34:56')) AS "TimestampTruncate(datetime.datetime(2009, 5, 17, 12, 34, 56), DAY)"
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
SELECT
toStartOfHour(parseDateTimeBestEffort('2009-05-17T12:34:56')) AS "TimestampTruncate(datetime.datetime(2009, 5, 17, 12, 34, 56))"
toStartOfHour(parseDateTimeBestEffort('2009-05-17T12:34:56')) AS "TimestampTruncate(datetime.datetime(2009, 5, 17, 12, 34, 56), HOUR)"
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
SELECT
toStartOfMinute(parseDateTimeBestEffort('2009-05-17T12:34:56')) AS "TimestampTruncate(datetime.datetime(2009, 5, 17, 12, 34, 56))"
toStartOfMinute(parseDateTimeBestEffort('2009-05-17T12:34:56')) AS "TimestampTruncate(datetime.datetime(2009, 5, 17, 12, 34, 56), MINUTE)"
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
SELECT
toStartOfMinute(parseDateTimeBestEffort('2009-05-17T12:34:56')) AS "TimestampTruncate(datetime.datetime(2009, 5, 17, 12, 34, 56))"
toStartOfMinute(parseDateTimeBestEffort('2009-05-17T12:34:56')) AS "TimestampTruncate(datetime.datetime(2009, 5, 17, 12, 34, 56), MINUTE)"
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
SELECT
toMonday(parseDateTimeBestEffort('2009-05-17T12:34:56')) AS "TimestampTruncate(datetime.datetime(2009, 5, 17, 12, 34, 56))"
toMonday(parseDateTimeBestEffort('2009-05-17T12:34:56')) AS "TimestampTruncate(datetime.datetime(2009, 5, 17, 12, 34, 56), WEEK)"
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
SELECT
toStartOfYear(parseDateTimeBestEffort('2009-05-17T12:34:56')) AS "TimestampTruncate(datetime.datetime(2009, 5, 17, 12, 34, 56))"
toStartOfYear(parseDateTimeBestEffort('2009-05-17T12:34:56')) AS "TimestampTruncate(datetime.datetime(2009, 5, 17, 12, 34, 56), YEAR)"
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SELECT
THEN '25 to 50'
ELSE 'error'
END AS `tier2`,
`t1`.`CountStar()`
`t1`.`CountStar(alltypes)`
FROM (
SELECT
CASE
Expand All @@ -36,7 +36,7 @@ FROM (
THEN 3
ELSE CAST(NULL AS TINYINT)
END AS `tier`,
COUNT(*) AS `CountStar()`
COUNT(*) AS `CountStar(alltypes)`
FROM `alltypes` AS `t0`
GROUP BY
1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
WITH `t1` AS (
SELECT
`t0`.`uuid`,
COUNT(*) AS `CountStar()`
COUNT(*) AS `CountStar(t)`
FROM `t` AS `t0`
GROUP BY
1
)
SELECT
`t5`.`uuid`,
`t3`.`CountStar()`
`t3`.`CountStar(t)`
FROM (
SELECT
`t2`.`uuid`,
MAX(`t2`.`CountStar()`) AS `max_count`
MAX(`t2`.`CountStar(t)`) AS `max_count`
FROM `t1` AS `t2`
GROUP BY
1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
WITH `t1` AS (
SELECT
`t0`.`uuid`,
COUNT(*) AS `CountStar()`
COUNT(*) AS `CountStar(t)`
FROM `t` AS `t0`
GROUP BY
1
)
SELECT
`t7`.`uuid`,
`t4`.`CountStar()`,
`t4`.`CountStar(t)`,
`t5`.`last_visit`
FROM (
SELECT
`t2`.`uuid`,
MAX(`t2`.`CountStar()`) AS `max_count`
MAX(`t2`.`CountStar(t)`) AS `max_count`
FROM `t1` AS `t2`
GROUP BY
1
) AS `t7`
LEFT OUTER JOIN `t1` AS `t4`
ON `t7`.`uuid` = `t4`.`uuid` AND `t7`.`max_count` = `t4`.`CountStar()`
ON `t7`.`uuid` = `t4`.`uuid` AND `t7`.`max_count` = `t4`.`CountStar(t)`
LEFT OUTER JOIN (
SELECT
`t0`.`uuid`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SELECT
CAST(FROM_UNIXTIME(CAST(`t0`.`c` AS INT)) AS TIMESTAMP) AS `TimestampFromUNIX(c)`
CAST(FROM_UNIXTIME(CAST(`t0`.`c` AS INT)) AS TIMESTAMP) AS `TimestampFromUNIX(c, SECOND)`
FROM `alltypes` AS `t0`
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SELECT
CAST(FROM_UNIXTIME(CAST(CAST(`t0`.`c` / 1000 AS INT) AS INT)) AS TIMESTAMP) AS `TimestampFromUNIX(c)`
CAST(FROM_UNIXTIME(CAST(CAST(`t0`.`c` / 1000 AS INT) AS INT)) AS TIMESTAMP) AS `TimestampFromUNIX(c, MILLISECOND)`
FROM `alltypes` AS `t0`
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SELECT
CAST(FROM_UNIXTIME(CAST(CAST(`t0`.`c` / 1000000 AS INT) AS INT)) AS TIMESTAMP) AS `TimestampFromUNIX(c)`
CAST(FROM_UNIXTIME(CAST(CAST(`t0`.`c` / 1000000 AS INT) AS INT)) AS TIMESTAMP) AS `TimestampFromUNIX(c, MICROSECOND)`
FROM `alltypes` AS `t0`
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
SELECT
"t1"."string_col",
"t1"."CountStar()"
"t1"."CountStar(functional_alltypes)"
FROM (
SELECT
"t0"."string_col",
COUNT(*) AS "CountStar()",
COUNT(*) AS "CountStar(functional_alltypes)",
MAX("t0"."double_col") AS "Max(double_col)"
FROM "functional_alltypes" AS "t0"
GROUP BY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ FROM (
SELECT
"t0"."foo_id",
SUM("t0"."f") AS "total",
COUNT(*) AS "CountStar()"
COUNT(*) AS "CountStar(star1)"
FROM "star1" AS "t0"
GROUP BY
1
) AS "t1"
WHERE
"t1"."CountStar()" > CAST(100 AS TINYINT)
"t1"."CountStar(star1)" > CAST(100 AS TINYINT)
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SELECT
COUNT(*) AS "CountStar()"
COUNT(*) AS "CountStar(star1)"
FROM "star1" AS "t0"
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ FROM (
SELECT
"t0"."foo_id",
SUM("t0"."f") AS "total",
COUNT(*) AS "CountStar()"
COUNT(*) AS "CountStar(star1)"
FROM "star1" AS "t0"
GROUP BY
1
) AS "t1"
WHERE
"t1"."CountStar()" > CAST(100 AS TINYINT)
"t1"."CountStar(star1)" > CAST(100 AS TINYINT)
26 changes: 4 additions & 22 deletions ibis/expr/operations/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
import ibis.expr.rules as rlz
from ibis import util
from ibis.common.annotations import attribute
from ibis.common.bases import Abstract
from ibis.common.graph import Node as Traversable
from ibis.common.grounds import Concrete
from ibis.common.patterns import Coercible, CoercionError
from ibis.common.typing import DefaultTypeVars, VarTuple
from ibis.common.typing import DefaultTypeVars


@public
Expand All @@ -41,29 +40,12 @@ def op(self) -> Self:
# return super().__children__


# TODO(kszucs): remove this mixin
@public
class Named(Abstract):
__slots__: VarTuple[str] = tuple()

@property
@abstractmethod
def name(self) -> str:
"""Name of the operation.
Returns
-------
str
"""


T = TypeVar("T", bound=dt.DataType, covariant=True)
S = TypeVar("S", bound=ds.DataShape, default=ds.Any, covariant=True)


@public
class Value(Node, Named, Coercible, DefaultTypeVars, Generic[T, S]):
class Value(Node, Coercible, DefaultTypeVars, Generic[T, S]):
@classmethod
def __coerce__(
cls, value: Any, T: Optional[type] = None, S: Optional[type] = None
Expand Down Expand Up @@ -103,8 +85,8 @@ def __coerce__(
# TODO(kszucs): figure out how to represent not named arguments
@property
def name(self) -> str:
args = ", ".join(arg.name for arg in self.__args__ if isinstance(arg, Named))
return f"{self.__class__.__name__}({args})"
names = (arg.name for arg in self.__args__ if hasattr(arg, "name"))
return f"{self.__class__.__name__}({', '.join(names)})"

@property
@abstractmethod
Expand Down
6 changes: 3 additions & 3 deletions ibis/expr/operations/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
from ibis.common.grounds import Singleton
from ibis.common.patterns import InstanceOf, Length # noqa: TCH001
from ibis.common.typing import VarTuple # noqa: TCH001
from ibis.expr.operations.core import Named, Scalar, Unary, Value
from ibis.expr.operations.core import Scalar, Unary, Value
from ibis.expr.operations.relations import Relation # noqa: TCH001


@public
class RowID(Value, Named):
class RowID(Value):
"""The row number (an autonumeric) of the returned result."""

name = "rowid"
Expand Down Expand Up @@ -160,7 +160,7 @@ def name(self):


@public
class ScalarParameter(Scalar, Named):
class ScalarParameter(Scalar):
_counter = itertools.count()

dtype: dt.DataType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ r0 := UnboundTable: t1
a int64
b float64

CountStar(): CountStar(r0)
CountStar(t1): CountStar(r0)
2 changes: 1 addition & 1 deletion ibis/expr/types/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def __bool__(self) -> bool:

def has_name(self):
"""Check whether this expression has an explicit name."""
return isinstance(self._arg, ops.Named)
return hasattr(self._arg, "name")

def get_name(self):
"""Return the name of this expression."""
Expand Down
2 changes: 1 addition & 1 deletion ibis/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ def slice_to_limit_offset(
a int64
b string
<BLANKLINE>
Add(CountStar(), -10): CountStar(r0) + -10
Add(CountStar(t), -10): CountStar(r0) + -10
From 5th row to 10th row
>>> what = slice(5, 10)
Expand Down

0 comments on commit 6a017f1

Please sign in to comment.