-
-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: support -Merge suffix on AggregateFunction types #258
Comments
Current workaround: from sqlalchemy import Numeric, Column
class AggregateFunctionType:
pass
class AggregateFunctionNumericType(AggregateFunctionType, Numeric):
pass
class MvVisits(AggregatingMergeTree):
Visits = Column(AggregateFunctionNumericType(26, 12))
# ... from sqlalchemy.sql.functions import sum as sql_sum
@compiles(sql_sum, "clickhouse")
def clickhouse_merge_sum(
element: sql_sum,
compiler: SQLCompiler,
*_: Any,
**__: Any,
) -> str:
if isinstance(element.type, AggregateFunctionType):
element.name = "sumMerge"
return compiler.visit_function(element) So doing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
First of all, thanks for all the work done here!
To the point, currently there's no way to deal w/ AggregateFunction types, so we need a way to issue, say,
sumMerge
instead ofsum
,uniqMerge
instead ofuniq
, etc.See this example of an Aggregated Mat View:
Selecting data:
So, doing
session.query(MatViewModel.StartDate, func.sum(MatViewModel.Visits), func.uniq(MatViewModel.Users)).group_by(MatViewModel.StartDate).order_by(MatViewModel.StartDate)
should produce the correct SQL syntax.Yes, I know we can do
func.sumMerge
, but that is not the solution if I'm trying to transparently change the underlying DB w/o changing my query.On this line, would you know of a workaround for this? I'm currently exploring on letting SQLAlchemy know how to compile
sum
for CH.The text was updated successfully, but these errors were encountered: