getChan commented on code in PR #66: URL: https://github.com/apache/datafusion-site/pull/66#discussion_r2045138173
########## content/blog/2025-04-17-user-defined-window-functions.md: ########## @@ -0,0 +1,427 @@ +--- +layout: post +title: User defined Window Functions in DataFusion +date: 2025-04-17 +author: Aditya Singh Rathore +categories: [tutorial] +--- + +<!-- +{% comment %} +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. +{% endcomment %} +--> + + +Window functions are a powerful feature in SQL, allowing for complex analytical computations over a subset of data. However, efficiently implementing them, especially sliding windows, can be quite challenging. With [Apache DataFusion]'s user-defined window functions, developers can easily take advantage of all the effort put into DataFusion's implementation. + +In this post, we'll explore: + +- What window functions are and why they matter + +- Understanding sliding windows + +- The challenges of computing window aggregates efficiently + +- How to implement user-defined window functions in DataFusion + + +[Apache DataFusion]: https://datafusion.apache.org/ + +## Understanding Window Functions in SQL + + +Imagine you're analyzing sales data and want insights without losing the finer details. This is where **[window functions]** come into play. Unlike **GROUP BY**, which condenses data, window functions let you retain each row while performing calculations over a defined **range** —like having a moving lens over your dataset. + +[window functions]: https://en.wikipedia.org/wiki/Window_function_(SQL) + + +Picture a business tracking daily sales. They need a running total to understand cumulative revenue trends without collapsing individual transactions. SQL makes this easy: +```sql +SELECT id, value, SUM(value) OVER (ORDER BY id) AS running_total +FROM sales; +``` Review Comment: Why did you put the query in here? It seems unrelated to the context. -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org