## 3 Model Design and Implementation
### Pre-Processing
When using the NL2 PY followed by the PY2 SQL method, the iterative processing steps may result in significant computational overhead, especially in scenarios with large-scale data sets. Each transformation step (from natural language to Python code to SQL query) consumes computational resources, and as the complexity of the query increases, so do the model's processing time and memory requirements. This overhead is particularly prominent in systems with high real-time requirements and may affect the overall query efficiency and system response time. To solve this problem, we first reduce unnecessary intermediate steps by optimizing the conversion process. Secondly, parallel processing and distributed computing are used to distribute tasks to multiple nodes to improve processing efficiency. For common query patterns, caching and precomputation can avoid repeated calculations and reduce the computational cost of each query. Finally, according to the complexity of the query, an adaptive simplification strategy is adopted to save computing resources further. Through these methods, the computational overhead is balanced while improving accuracy, and the system's efficiency is ensured. Figure 7: The checkpoints of Post-Process. We must check the generated SQL in columns, fields, functions, numbers, etc. ### Application Cases

The NL2 PY2 SQL method we proposed in this article has been effectively used in application scenarios, demonstrating its significant advantages in processing complex business logic, improving query efficiency, and reducing maintenance costs. The details are shown in Figure 8.

As shown in Figure 8, by converting natural language into Python code and then generating SQL from the Python code, this method makes full use of the flexibility and efficiency of Python to achieve accurate expression of business needs and in-depth optimization of data queries. It is especially suitable for finance; fields such as medical and legal fields that require complex data processing have further verified its broad applicability and innovative value. The NL2 PY2 SQL method proposed in this paper and NL2 SQL have characteristics in applications outside of finance (such as education and supply chain). NL2 PY2 SQL first converts natural language into Python code, using Python's flexibility and rich library support to achieve complex logic expression and data analysis. For example, it can be used in education to design dynamic learning paths and evaluate student performance; in the supply chain, it can handle complex inventory management algorithms, transportation optimization problems, etc. Python code is easy to debug, expand, and modularize, can more intuitively reflect business logic, and convert logic into efficient database operations through PY2 SQL. In contrast, NL2 SQL directly generates SQL from natural language, which is suitable for quickly executing simple queries. Still, dealing with complex multi-table associations, nested logic, and dynamic calculation tasks is difficult. In addition, the SQL statements generated by NL2 SQL need more precise readability and have high maintenance costs. Through two-step processing, NL2 PY2 SQL ensures support for complex logic and considers performance and scalability, providing a more flexible and reliable solution for diversified scenarios such as education and supply chain. ## 4 Experimental Results and Analysis

### Datasets and Evaluation Metrics

Considering that the BIRD dataset is more complex and resembles real-world scenarios more closely, including financial contexts, this paper uses the BIRD development dataset as the test dataset, which aligns with the benchmarks chosen by similar models. Figure 8: Application scenario. The BIRD dataset was released on 21 September 2023. It represents a pioneering cross-domain dataset to study the impact of extensive database content on text-to-SQL parsing. BIRD comprises over 12,751 unique question-SQL pairs, 95 large databases totaling 33.4 GB, and 37 specialized domains such as blockchain, hockey, healthcare, and education.