Abstract
Industrial AI systems are mostly end-to-end machine learning (ML) workflows. A typical recommendation or business intelligence system includes many online micro-services and offline jobs. We describe SQLFlow for developing such workflows efficiently in SQL. SQL enables developers to write short programs focusing on the purpose (what) and ignoring the procedure (how). Previous database systems extended their SQL dialect to support ML. SQLFlow takes another strategy to work as a bridge over various database systems, including MySQL, Apache Hive, and Alibaba MaxCompute, and ML engines like TensorFlow, XGBoost, and scikit-learn. We extended SQL syntax carefully to make the extension working with various SQL dialects. We implement the extension by inventing a collaborative parsing algorithm. SQLFlow is efficient and expressive to a wide variety of ML techniques—supervised and unsupervised learning; deep networks and tree models; visual model explanation in addition to training and prediction; data processing and feature extraction in addition to ML. SQLFlow compiles a SQL program into a Kubernetes-native workflow for fault-tolerable execution and on-cloud deployment. Current industrial users include Ant Financial, DiDi, and Alibaba Group.
The Challenge of Industrial AI Workflows
In industrial settings, building an AI system is rarely just about the model; it is about the entire end-to-end pipeline—from data extraction and cleaning to training and deployment. Traditionally, this requires a "context switch" between SQL for data retrieval and Python or C++ for machine learning.
Existing solutions that integrate ML into SQL often suffer from three major flaws:
- Vendor Lock-in: They are tied to a specific database (e.g., Google BigQuery or SQL Server).
- Closed Ecosystems: They do not easily allow for community-contributed ML features.
- Infrastructure Rigidity: They often run on the database's own computing infrastructure rather than modern, scalable, fault-tolerant clusters like Kubernetes.
System Architecture and Methods
SQLFlow acts as a "bridge" rather than a standalone database. Its architecture relies on several main pillars:
Syntax Extension and Collaborative Parsing
SQLFlow introduces intuitive clauses like TO TRAIN, TO PREDICT, and TO EXPLAIN. To support multiple SQL dialects (MySQL, Hive, etc.), SQLFlow uses a collaborative parsing strategy. It first passes the query to the original database's parser. If it hits an error at the SQLFlow-specific keywords, it splits the query, handles the ML part with its own parser, and reconciles the two.
Two-Tier Compilation
SQLFlow compiles the SQL program into a Kubernetes-native workflow (using Argo or Tekton).
- Tier 1: The SQL is translated into a YAML workflow where each step is a container.
- Tier 2: Inside the container, the specific SQL/ML task is translated into a Python program that handles data fetching, feature engineering, and model execution via the Couler intermediate representation.
Key Insights: Declarative Machine Learning
SQLFlow leans into the declarative nature of SQL, allowing users to specify what they want (e.g., train a model on specific data) rather than how to manage data pointers and memory buffers. By appending ML clauses to SELECT statements, feature extraction becomes a first-class citizen of the query. The system automatically handles the "gap" between raw table rows and the tensors required by ML models. Furthermore, by decoupling compute from storage, SQLFlow executes heavy lifting on Kubernetes, allowing for better resource scaling and fault tolerance.
Versatility and Industrial Adoption
SQLFlow’s versatility is demonstrated across various database systems and ML engines. It supports a wide range of learning paradigms, from supervised deep learning to unsupervised clustering.
The system has seen significant industrial adoption, currently in use at major tech firms including Ant Financial, DiDi, and Alibaba Group. It successfully integrates complex explainability tools like SHAP (SHapley Additive exPlanations) directly into the SQL syntax, allowing users to visualize model logic as easily as they query data.
Limitations and Future Work
While SQLFlow simplifies the user experience, several areas for improvement remain. The system does not yet support database transactions within its workflows. Additionally, while users can manually set parameters in the WITH clause, the authors are working on integrating automated hyperparameter tuning via tools like Katib. Finally, the complexity of the underlying generated YAML and Python code remains a challenge for power users requiring deep-level debugging.
Summary updated