Adez017 commented on code in PR #96:
URL: https://github.com/apache/datafusion-site/pull/96#discussion_r2236418787
##########
content/blog/2025-07-25-async-scaler-udf.md:
##########
@@ -0,0 +1,396 @@
+---
+layout: post
+title: Async Scaler User defined Functions in DataFusion
+date: 2025-07-25
+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 %}
+-->
+
+Imagine writing SQL that can call APIs, interact with AI models, or fetch data
from external storage—all natively within your query. This isn't a dream
anymore. [Apache DataFusion] has just introduced **Asynchronous User Defined
Functions (Async UDFs)**, making it one of the **first SQL engines** to support
native asynchronous operations in query execution.
+
+## The Synchronous Limitation
+
+Traditional [User Defined Functions (UDFs)] in DataFusion (and most SQL
engines) are synchronous, limiting them to CPU-bound operations. While perfect
for mathematical calculations or string manipulations, they fall short when you
need to:
+
+- Make HTTP requests to external APIs (Wikipedia, OpenAI, REST services)
+- Fetch data from cloud object storage on demand
+- Perform I/O-heavy operations or long-running computations
+- Integrate with external databases or microservices
+
+These real-world scenarios often require **waiting** for external
resources—something synchronous functions simply can't handle efficiently.
+
+[User Defined Functions (UDFs)]:
https://datafusion.apache.org/python/user-guide/common-operations/udf-and-udfa.html
+
+## Enter Async UDFs: SQL That Talks to the World
+
+DataFusion's async UDFs remove this fundamental limitation. Now you can write
SQL queries that seamlessly integrate with the outside world, opening up
possibilities like:
+
+```sql
+--Note - this is just an Example
+-- Query with AI-powered content analysis
+SELECT content, classify_sentiment(content) as sentiment
+FROM social_posts
+WHERE analyze_toxicity(content) = false;
+
+-- Enrich data with external API calls
+SELECT user_id, enrich_user_profile(user_id) as profile_data
+FROM users
+LIMIT 100;
+```
+
+## Understanding Sync vs Async UDFs
+
+Before diving into implementation, it's crucial to understand when to use each
type:
+**Synchronous UDFs** are perfect for:
+
+- Pure computations (math, string operations)
+- CPU-intensive algorithms
+- Operations that complete instantly
+- Functions that don't need external resources
+
+**Asynchronous UDFs** excel at:
+
+- Network requests (HTTP APIs, database calls)
+- File I/O operations
+- Long-running computations that can yield control
+- Any operation that involves "waiting"
+
+**The key insight**: if your function might block waiting for something
external, make it async.
+
+## Building Your First Async UDF: An AI-Powered Example
+
+Let's create a practical async UDF that simulates asking an LLM whether an
animal is furry. While our example uses mock logic, it demonstrates the pattern
you'd use for real AI service integration.
Review Comment:
sure
--
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]