Skip to content

Commit b3be17f

Browse files
committed
add paper and figure to doc
1 parent 7bfb80c commit b3be17f

10 files changed

Lines changed: 263 additions & 79 deletions

File tree

.gitignore

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,53 @@
1-
*.code-workspace
2-
*.egg-info/
1+
# Python
32
__pycache__/
43
*.py[cod]
5-
*$py.class
4+
*$py.class
5+
*.so
6+
.Python
7+
build/
8+
develop-eggs/
9+
dist/
10+
downloads/
11+
eggs/
12+
.eggs/
13+
lib/
14+
lib64/
15+
parts/
16+
sdist/
17+
var/
18+
wheels/
19+
*.egg-info/
20+
.installed.cfg
21+
*.egg
22+
23+
# Virtual environments
24+
venv/
25+
ENV/
26+
env/
27+
28+
# IDE
29+
*.code-workspace
30+
.vscode/
31+
.idea/
32+
*.swp
33+
*.swo
34+
*~
35+
36+
# Testing
37+
.pytest_cache/
38+
.coverage
39+
htmlcov/
40+
.tox/
41+
42+
# Documentation
43+
docs/_build/
44+
docs/build/
45+
46+
# OS
47+
.DS_Store
48+
Thumbs.db
49+
50+
# Project specific
51+
*.png
52+
!docs/source/_static/*.png
53+
!docs/source/_static/*.jpg

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 rllm-team
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 58 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<div align="center">
22

3-
# TLSQL: SQL-like API for Table Learning
3+
# TLSQL: SQL-like API for Table Learning
4+
5+
46

57
*A Python library that converts custom SQL-like statements into standard SQL queries for machine learning workflows on tables in modern data management systems.*
68

@@ -9,90 +11,93 @@
911
[![Python](https://img.shields.io/badge/Python-3.8+-3776ab?style=flat-square&logo=python&logoColor=white)](https://www.python.org/)
1012
[![License](https://img.shields.io/badge/License-MIT-green?style=flat-square)](LICENSE)
1113
[![Documentation](https://img.shields.io/badge/Documentation-latest-blue?style=flat-square)](https://tlsql.readthedocs.io/en/latest/index.html)
14+
[![Paper](https://img.shields.io/badge/Paper-arXiv:2601.14109-b31b1b?style=flat-square)](https://arxiv.org/abs/2601.14109)
1215

1316

1417
---
1518

1619
</div>
1720

1821
## About
19-
20-
TLSQL simplifies machine learning on structured tables by converting SQL-like statements into standard SQL queries. This allows data scientists and engineers to focus on modeling rather than writing complex SQL or managing datasets manually.
21-
22-
TLSQL supports three types of statements that map directly to ML workflows:
23-
24-
- **`TRAIN WITH`**: Specifies the training set
25-
- **`PREDICT VALUE`**: Specifies the test set
26-
- **`VALIDATE WITH`**: Specifies the validation set
22+
TLSQL is a system designed to simplify machine learning workflows on structured tabular data. It translates SQL-like statements into standard SQL queries and structured learning task descriptions, enabling data scientists and engineers to focus on model development instead of writing complex SQL or manually managing datasets.
2723

2824
TLSQL works seamlessly with **RDBs, data warehouses, and data lakes**, enabling end-to-end table-based ML workflows.
2925

26+
- **`PREDICT VALUE`**: Specifies the test set.
27+
- **`TRAIN WITH`**: Specifies the training set.
28+
- **`VALIDATE WITH`**: Specifies the validation set.
29+
30+
<div align="center">
31+
<img src="docs/source/_static/workflow.jpg" alt="TLSQL Workflow" width="600"/>
32+
<br/>
33+
<small><strong>The TLSQL Workflow</strong></small>
34+
</div>
3035

3136
## TLSQL Syntax
3237

33-
### 1. TRAIN WITH Statement
38+
### 1. PREDICT VALUE Statement
3439

35-
The `TRAIN WITH` statement specifies which columns and tables to use for training data, along with optional filtering conditions. This statement defines the dataset used to train your machine learning model.
40+
The `PREDICT VALUE` statement specifies the target column for prediction and the task type (classification or regression). This statement defines the test set - the data for which you want to make predictions. The `WHERE` clause in this statement filters which rows are included in the test set.
3641

3742
#### Syntax
3843

3944
```sql
40-
TRAIN WITH (column_selectors)
41-
FROM table1, table2, ...
45+
PREDICT VALUE(column_selector, TASK_TYPE)
46+
FROM table
4247
[WHERE conditions]
4348
```
4449

50+
#### Task Types
51+
52+
- **`CLF`**: Classification task - predicts discrete categories
53+
- **`REG`**: Regression task - predicts continuous values
54+
4555
#### Examples
4656

4757
```sql
48-
TRAIN WITH (users.*, movies.*, ratings.*)
49-
FROM users, movies, ratings
50-
WHERE users.Gender='M' AND movies.Year >= 2000
58+
PREDICT VALUE(users.Age, CLF)
59+
FROM users
60+
WHERE users.Gender='F'
5161
```
5262

53-
### 2. PREDICT VALUE Statement
63+
### 2. TRAIN WITH Statement
5464

55-
The `PREDICT VALUE` statement specifies the target column for prediction and the task type (classification or regression). This statement defines the test set - the data for which you want to make predictions. The `WHERE` clause in this statement filters which rows are included in the test set.
65+
The `TRAIN WITH` statement specifies which columns and tables to use for training data, along with optional filtering conditions. This statement defines the dataset used to train your machine learning model.
5666

5767
#### Syntax
5868

5969
```sql
60-
PREDICT VALUE(table.column, TASK_TYPE)
61-
FROM table
70+
TRAIN WITH column_selector
71+
FROM table1, table2, ...
6272
[WHERE conditions]
6373
```
6474

65-
#### Task Types
66-
67-
- **`CLF`**: Classification task - predicts discrete categories
68-
- **`REG`**: Regression task - predicts continuous values
69-
7075
#### Examples
7176

7277
```sql
73-
PREDICT VALUE(users.Age, CLF)
74-
FROM users
75-
WHERE users.Gender='F' OR users.userID IN (1,2,3,4,5)
78+
TRAIN WITH (users.*, movies.*, ratings.*)
79+
FROM users, movies, ratings
80+
WHERE users.Gender='M' AND users.userID<3000
7681
```
7782

7883
### 3. VALIDATE WITH Statement
7984

80-
The `VALIDATE WITH` statement specifies validation data with the same syntax as `TRAIN WITH`. This statement defines the validation set used for model selection. If omitted, the pipeline will use k-fold cross-validation on the training data.
85+
The `VALIDATE WITH` statement specifies validation data with the same syntax as `TRAIN WITH`. This statement defines the validation set used for model selection. If omitted, `validate_result` will be `None`.
8186

8287
#### Syntax
8388

8489
```sql
85-
VALIDATE WITH (column_selectors)
86-
FROM table1, table2, ...
90+
VALIDATE WITH column_selector
91+
FROM table
8792
[WHERE conditions]
8893
```
8994

9095
#### Examples
9196

9297
```sql
93-
VALIDATE WITH (users.*, movies.*, ratings.*)
94-
FROM users, movies, ratings
95-
WHERE users.Gender='M' AND movies.Year < 2000
98+
VALIDATE WITH (users.Age)
99+
FROM users
100+
WHERE users.Gender='M' and users.userID>3000
96101
```
97102

98103
## Supported Operators
@@ -125,11 +130,14 @@ This will install TLSQL in development mode, allowing you to make changes to the
125130
```python
126131
import tlsql
127132

128-
129-
result = tlsql.convert("PREDICT VALUE(users.Age, CLF) FROM users")
130-
print(result.statement_type) # 'PREDICT'
131-
print(result.target_column) # 'users.Age'
132-
print(result.task_type) # 'CLF'
133+
# Workflow mode: PREDICT only (auto-generates TRAIN)
134+
result = tlsql.convert(
135+
predict_query="PREDICT VALUE(users.Age, CLF) FROM users WHERE users.Gender='F'"
136+
)
137+
print(result.predict.statement_type) # 'PREDICT'
138+
print(result.predict.target_column) # 'users.Age'
139+
print(result.predict.task_type) # 'CLF'
140+
print(result.train.sql) # Auto-generated TRAIN SQL
133141
```
134142

135143
### Examples
@@ -145,3 +153,14 @@ Check out the examples directory for more usage examples:
145153

146154

147155

156+
### Citation
157+
158+
```
159+
@article{chen2026tlsql,
160+
title={TLSQL: Table Learning Structured Query Language},
161+
author={Chen, Feiyang and Zhong, Ken and Zhang, Aoqian and Wang, Zheng and Pan, Li and Li, Jianhua},
162+
journal={arXiv preprint arXiv:2601.14109},
163+
year={2026}
164+
}
165+
```
166+
**Paper Link**: [arXiv:2601.14109](https://arxiv.org/abs/2601.14109)

__init__.py

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,82 @@
11
"""TLSQL: A SQL-like language designed for relational table learning tasks and workflows.
22
3-
This package converts three types of custom SQL statements into standard SQL:
4-
1. TRAIN WITH - Training data queries
5-
2. PREDICT VALUE - Prediction target queries
6-
3. VALIDATE WITH - Validation data queries
3+
This package converts TLSQL workflow statements into standard SQL:
4+
- PREDICT VALUE: Prediction target queries (required)
5+
- TRAIN WITH: Training data queries (optional, auto-generated if not provided)
6+
- VALIDATE WITH: Validation data queries (optional)
77
88
Usage:
99
>>> from tlsql import convert
10-
>>> result = convert("PREDICT VALUE(users.Age, CLF) FROM users")
11-
>>> print(result.sql_list) # List of GeneratedSQL objects
10+
>>> result = convert(
11+
... predict_query="PREDICT VALUE(users.Age, CLF) FROM users WHERE users.Gender='F'"
12+
... )
13+
>>> print(result.predict.sql)
14+
>>> print(result.train.sql)
1215
"""
1316

17+
from typing import Optional
18+
from tlsql.tlsql.sql_generator import SQLGenerator, ConversionResult
1419
__version__ = "0.1.0"
1520
__author__ = "TLSQL Team"
1621

1722

18-
def convert(tlsql: str):
19-
"""Convert TLSQL statement to standard SQL.
23+
def convert(
24+
predict_query: str,
25+
train_query: Optional[str] = None,
26+
validate_query: Optional[str] = None
27+
) -> ConversionResult:
28+
"""Convert TLSQL workflow statements to standard SQL.
2029
21-
This is the main entry point for TLSQL conversion.
30+
Converts PREDICT, TRAIN, and VALIDATE TLSQL statements into standard SQL.
31+
PREDICT is required. If TRAIN is not provided, it will be auto-generated
32+
by excluding PREDICT data from the same table.
2233
2334
Args:
24-
tlsql: TLSQL statement string.
35+
predict_query: PREDICT TLSQL statement (required).
36+
train_query: TRAIN TLSQL statement (optional, auto-generated if not provided).
37+
validate_query: VALIDATE TLSQL statement (optional).
2538
2639
Returns:
27-
ConversionResult: Unified result containing statement type and all metadata.
40+
ConversionResult: Contains predict_result, train_result, and validate_result.
2841
2942
"""
30-
from tlsql.tlsql.parser import Parser
31-
from tlsql.tlsql.sql_generator import SQLGenerator
3243

33-
# Parse the TLSQL statement
34-
parser = Parser(tlsql)
35-
ast = parser.parse()
44+
if not predict_query or not predict_query.strip():
45+
raise ValueError("predict_query is required.")
3646

37-
# Generate SQL with metadata
3847
generator = SQLGenerator()
39-
return generator.build(ast)
48+
49+
# Process PREDICT
50+
predict_result = SQLGenerator.convert_query(predict_query)
51+
52+
# Process TRAIN
53+
train_result = (
54+
SQLGenerator.convert_query(train_query)
55+
if train_query and train_query.strip()
56+
else generator.auto_generate_train(predict_result)
57+
)
58+
59+
# Process VALIDATE
60+
validate_result = (
61+
SQLGenerator.convert_query(validate_query)
62+
if validate_query and validate_query.strip()
63+
else None
64+
)
65+
66+
return ConversionResult(
67+
predict_result=predict_result,
68+
train_result=train_result,
69+
validate_result=validate_result
70+
)
4071

4172

4273
# Tokens
4374
from tlsql.tlsql.tokens import Token, TokenType
4475

45-
# Core classes (re-exported for convenience)
76+
# Core classes
4677
from tlsql.tlsql.lexer import Lexer
4778
from tlsql.tlsql.parser import Parser
4879
from tlsql.tlsql.sql_generator import (
49-
SQLGenerator,
5080
GeneratedSQL,
5181
ConversionResult,
5282
)

docs/source/_static/custom.css

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,28 @@ dl.py.method > dt + dd {
13161316
line-height: 1.6 !important;
13171317
}
13181318

1319+
/* Hide list markers in field list (Parameters, Returns, etc.) */
1320+
.field-list dd ul,
1321+
.field-list dd ol,
1322+
.field-list ul,
1323+
.field-list ol {
1324+
list-style: none !important;
1325+
padding-left: 0 !important;
1326+
margin-left: 0 !important;
1327+
}
1328+
1329+
.field-list dd li::marker,
1330+
.field-list li::marker {
1331+
content: none !important;
1332+
}
1333+
1334+
.field-list dd li,
1335+
.field-list li {
1336+
list-style: none !important;
1337+
padding-left: 0 !important;
1338+
margin-left: 0 !important;
1339+
}
1340+
13191341
/* Spacing for paragraphs inside field list */
13201342
.field-list dd p {
13211343
margin-bottom: 0.5em !important;

docs/source/_static/workflow.jpg

270 KB
Loading

0 commit comments

Comments
 (0)