Skip to content

Commit 7153d18

Browse files
author
Jove Zhong
committed
add a page for table functions
1 parent 8834f36 commit 7153d18

File tree

3 files changed

+201
-0
lines changed

3 files changed

+201
-0
lines changed

docs/functions_for_table.md

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
# Table Functions
2+
Table functions are methods for constructing tables or streams from various data sources or formats. They allow you to read data from files, databases, or other sources directly into a Timeplus stream or table.
3+
4+
### values
5+
6+
The `values` table function allows you to create temporary storage which fills
7+
columns with values. It is useful for quick testing or generating sample data.
8+
9+
The basic syntax of the `values` table function is:
10+
11+
```sql
12+
VALUES([structure,] values...)
13+
```
14+
15+
It is commonly used as:
16+
17+
```sql
18+
VALUES(
19+
['column1_name Type1, column2_name Type2, ...'],
20+
(value1_row1, value2_row1, ...),
21+
(value1_row2, value2_row2, ...),
22+
...
23+
)
24+
```
25+
26+
- `column1_name Type1, ...` (optional). string
27+
specifying the column names and types. If this argument is omitted columns will
28+
be named as `c1`, `c2`, etc.
29+
- `(value1_row1, value2_row1)`. tuples
30+
containing values of any type.
31+
32+
:::note
33+
Comma separated tuples can be replaced by single values as well. In this case
34+
each value is taken to be a new row.
35+
:::
36+
37+
Returns a temporary table containing the provided values.
38+
39+
```sql title="Query"
40+
SELECT *
41+
FROM VALUES(
42+
'person string, place string',
43+
('Noah', 'Paris'),
44+
('Emma', 'Tokyo'),
45+
('Liam', 'Sydney'),
46+
('Olivia', 'Berlin'),
47+
('Ilya', 'London'),
48+
('Sophia', 'London'),
49+
('Jackson', 'Madrid'),
50+
('Alexey', 'Amsterdam'),
51+
('Mason', 'Venice'),
52+
('Isabella', 'Prague')
53+
)
54+
```
55+
56+
```response title="Response"
57+
┌─person───┬─place─────┐
58+
1. │ Noah │ Paris │
59+
2. │ Emma │ Tokyo │
60+
3. │ Liam │ Sydney │
61+
4. │ Olivia │ Berlin │
62+
5. │ Ilya │ London │
63+
6. │ Sophia │ London │
64+
7. │ Jackson │ Madrid │
65+
8. │ Alexey │ Amsterdam │
66+
9. │ Mason │ Venice │
67+
10. │ Isabella │ Prague │
68+
└──────────┴───────────┘
69+
```
70+
71+
`VALUES` can also be used with single values rather than tuples. For example:
72+
73+
```sql title="Query"
74+
SELECT *
75+
FROM VALUES(
76+
'person string',
77+
'Noah',
78+
'Emma',
79+
'Liam',
80+
'Olivia',
81+
'Ilya',
82+
'Sophia',
83+
'Jackson',
84+
'Alexey',
85+
'Mason',
86+
'Isabella'
87+
)
88+
```
89+
90+
```response title="Response"
91+
┌─person───┐
92+
1. │ Noah │
93+
2. │ Emma │
94+
3. │ Liam │
95+
4. │ Olivia │
96+
5. │ Ilya │
97+
6. │ Sophia │
98+
7. │ Jackson │
99+
8. │ Alexey │
100+
9. │ Mason │
101+
10. │ Isabella │
102+
└──────────┘
103+
```
104+
105+
Or without providing a row specification (`'column1_name type1, column2_name type2, ...'`
106+
in the syntax), in which case the columns are automatically named.
107+
108+
For example:
109+
110+
```sql title="Query"
111+
-- tuples as values
112+
SELECT *
113+
FROM VALUES(
114+
('Noah', 'Paris'),
115+
('Emma', 'Tokyo'),
116+
('Liam', 'Sydney'),
117+
('Olivia', 'Berlin'),
118+
('Ilya', 'London'),
119+
('Sophia', 'London'),
120+
('Jackson', 'Madrid'),
121+
('Alexey', 'Amsterdam'),
122+
('Mason', 'Venice'),
123+
('Isabella', 'Prague')
124+
)
125+
```
126+
127+
```response title="Response"
128+
┌─c1───────┬─c2────────┐
129+
1. │ Noah │ Paris │
130+
2. │ Emma │ Tokyo │
131+
3. │ Liam │ Sydney │
132+
4. │ Olivia │ Berlin │
133+
5. │ Ilya │ London │
134+
6. │ Sophia │ London │
135+
7. │ Jackson │ Madrid │
136+
8. │ Alexey │ Amsterdam │
137+
9. │ Mason │ Venice │
138+
10. │ Isabella │ Prague │
139+
└──────────┴───────────┘
140+
```
141+
142+
```sql
143+
-- single values
144+
SELECT *
145+
FROM VALUES(
146+
'Noah',
147+
'Emma',
148+
'Liam',
149+
'Olivia',
150+
'Ilya',
151+
'Sophia',
152+
'Jackson',
153+
'Alexey',
154+
'Mason',
155+
'Isabella'
156+
)
157+
```
158+
159+
```response title="Response"
160+
┌─c1───────┐
161+
1. │ Noah │
162+
2. │ Emma │
163+
3. │ Liam │
164+
4. │ Olivia │
165+
5. │ Ilya │
166+
6. │ Sophia │
167+
7. │ Jackson │
168+
8. │ Alexey │
169+
9. │ Mason │
170+
10. │ Isabella │
171+
└──────────┘
172+
```
173+
174+
### zeros
175+
`zeros(N)` – Returns a table with the single `zero` column (uint8) that contains N zeros.
176+
177+
### zeros_mt
178+
`zeros_mt(N)` – Returns a table with the single `zero` column (uint8) that contains N zeros, using multiple threads for faster generation.

sidebars.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ const sidebars = {
376376
},
377377
"functions_for_agg",
378378
"functions_for_streaming",
379+
"functions_for_table",
379380
{
380381
type: "category",
381382
label: "User Defined Functions",

tools/list-functions.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@
1919
import { readdir, readFile } from "fs/promises";
2020
import { join } from "path";
2121

22+
/**
23+
* Functions to ignore from the CSV - these are internal or system functions
24+
* that should not be listed in the documentation
25+
*/
26+
const IGNORED_FUNCTIONS = new Set([
27+
"validate_nested_array_sizes",
28+
"_internal_function_1",
29+
]);
30+
2231
interface FunctionInfo {
2332
name: string;
2433
file: string;
@@ -54,6 +63,11 @@ Options:
5463
--debug Show CSV filtering debug information
5564
--help Show this help message
5665
66+
Configuration:
67+
The script ignores certain internal functions defined in IGNORED_FUNCTIONS
68+
within this file. Add function names to this list to exclude them from
69+
all outputs.
70+
5771
Examples:
5872
bun run tools/list-functions.ts # Formatted output with categories
5973
bun run tools/list-functions.ts --plain # Plain text list
@@ -141,6 +155,7 @@ function filterCSVFunctions(csvFunctions: CSVFunctionInfo[]): {
141155
pythonUdf: 0,
142156
empty: 0,
143157
invalid: 0,
158+
ignored: 0,
144159
final: 0,
145160
};
146161

@@ -182,6 +197,12 @@ function filterCSVFunctions(csvFunctions: CSVFunctionInfo[]): {
182197
return false;
183198
}
184199

200+
// Skip functions in the ignore list
201+
if (IGNORED_FUNCTIONS.has(func.name)) {
202+
stats.ignored++;
203+
return false;
204+
}
205+
185206
return true;
186207
})
187208
.map((func) => func.name.toLowerCase())
@@ -275,6 +296,7 @@ async function main() {
275296
console.log(`🐍 Python UDF functions: ${stats.pythonUdf}`);
276297
console.log(`❌ Empty names: ${stats.empty}`);
277298
console.log(`⚠️ Invalid function names: ${stats.invalid}`);
299+
console.log(`🚫 Ignored functions: ${stats.ignored}`);
278300
console.log(`✅ Final filtered functions: ${stats.final}`);
279301
console.log(`📉 Filtered out: ${stats.total - stats.final}`);
280302
} else if (showStats) {

0 commit comments

Comments
 (0)