shivamgoel commented on code in PR #37815:
URL: https://github.com/apache/superset/pull/37815#discussion_r2903041339


##########
superset-core/src/superset_core/semantic_layers/types.py:
##########
@@ -0,0 +1,327 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from __future__ import annotations
+
+import enum
+from dataclasses import dataclass
+from datetime import date, datetime, time, timedelta
+from functools import total_ordering
+from typing import Type as TypeOf
+
+import pyarrow as pa
+
+__all__ = [
+    "BINARY",
+    "BOOLEAN",
+    "DATE",
+    "DATETIME",
+    "DECIMAL",
+    "Day",
+    "Dimension",
+    "Hour",
+    "INTEGER",
+    "INTERVAL",
+    "Minute",
+    "Month",
+    "NUMBER",
+    "OBJECT",
+    "Quarter",
+    "Second",
+    "STRING",
+    "TIME",
+    "Week",
+    "Year",
+]
+
+
+class Type:
+    """
+    Base class for types.
+    """
+
+
+class INTEGER(Type):
+    """
+    Represents an integer type.
+    """
+
+
+class NUMBER(Type):
+    """
+    Represents a number type.
+    """
+
+
+class DECIMAL(Type):
+    """
+    Represents a decimal type.
+    """
+
+
+class STRING(Type):
+    """
+    Represents a string type.
+    """
+
+
+class BOOLEAN(Type):
+    """
+    Represents a boolean type.
+    """
+
+
+class DATE(Type):
+    """
+    Represents a date type.
+    """
+
+
+class TIME(Type):
+    """
+    Represents a time type.
+    """
+
+
+class DATETIME(DATE, TIME):
+    """
+    Represents a datetime type.
+    """
+
+
+class INTERVAL(Type):
+    """
+    Represents an interval type.
+    """
+
+
+class OBJECT(Type):
+    """
+    Represents an object type.
+    """
+
+
+class BINARY(Type):
+    """
+    Represents a binary type.
+    """
+
+
+@dataclass(frozen=True)
+@total_ordering
+class Grain:

Review Comment:
   Building on the ISO 8601 suggestion above, what about a hybrid approach that 
provides both convenience and flexibility?
   
     ```python
     @dataclass(frozen=True)
     class Grain:
         name: str
         representation: str  # ISO 8601 duration
   
         def __post_init__(self) -> None:
             isodate.parse_duration(self.representation)  # Validates ISO 8601
   
         def __eq__(self, other: object) -> bool:
             # Equality by representation, not name
             return isinstance(other, Grain) and self.representation == 
other.representation
   
   
     class Grains:
         """Pre-defined common grains + factory for custom ones."""
         SECOND = Grain("Second", "PT1S")
         MINUTE = Grain("Minute", "PT1M")
         # ... DAY, WEEK, MONTH, QUARTER, YEAR
   
         _REGISTRY = {"PT1S": SECOND, "PT1M": MINUTE, ...}
   
         @classmethod
         def get(cls, representation: str, name: str | None = None) -> Grain:
             """Returns pre-defined grain if exists, else creates custom."""
             return cls._REGISTRY.get(representation) or Grain(name or 
representation, representation)
     ```python
   
     This gives us:
     - Easy access to common grains (Grains.DAY, Grains.MONTH)
     - Support for arbitrary intermediate grains (Grains.get("PT5S", "5 
Seconds"))
     - Validation via isodate (already a project dependency)
     - Canonical instances for standard grains
     - No timedelta approximations needed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to