"""Expression wrapper classes for proper type annotations."""
from typing import cast
from sqlglot import exp
__all__ = ("AggregateExpression", "ConversionExpression", "FunctionExpression", "MathExpression", "StringExpression")
[docs]
class ExpressionWrapper:
"""Base wrapper for SQLGlot expressions."""
[docs]
def __init__(self, expression: exp.Expression) -> None:
self._expression = expression
[docs]
def as_(self, alias: str) -> exp.Alias:
"""Create an aliased expression."""
return cast("exp.Alias", exp.alias_(self._expression, alias))
@property
def expression(self) -> exp.Expression:
"""Get the underlying SQLGlot expression."""
return self._expression
def __str__(self) -> str:
return str(self._expression)
[docs]
class AggregateExpression(ExpressionWrapper):
"""Aggregate functions like COUNT, SUM, AVG."""
[docs]
class FunctionExpression(ExpressionWrapper):
"""General SQL functions."""
[docs]
class MathExpression(ExpressionWrapper):
"""Mathematical functions like ROUND."""
[docs]
class StringExpression(ExpressionWrapper):
"""String functions like UPPER, LOWER, LENGTH."""
[docs]
class ConversionExpression(ExpressionWrapper):
"""Conversion functions like CAST, COALESCE."""