Commit f780a96
committed
Add Java table functions support
This PR is a continuation of duckdb#630, it adds support for writing DuckDB
table functions in Java.
Example:
```java
try (Connection conn = DriverManager.getConnection(JDBC_URL);
Statement stmt = conn.createStatement()) {
DuckDBFunctions.tableFunction()
.withName("java_table_basic")
.withParameter(int.class)
.withFunction(new DuckDBTableFunction<Integer, AtomicBoolean, Object>() {
@OverRide
public Integer bind(DuckDBTableFunctionBindInfo info) throws Exception {
info.addResultColumn("col1", Integer.TYPE)
.addResultColumn("col2", String.class);
return info.getParameter(0).getInt();
}
@OverRide
public AtomicBoolean init(DuckDBTableFunctionInitInfo info) throws Exception {
info.setMaxThreads(1);
return new AtomicBoolean(false);
}
@OverRide
public long apply(DuckDBTableFunctionCallInfo info, DuckDBDataChunkWriter output) throws Exception {
Integer bindData = info.getBindData();
AtomicBoolean done = info.getInitData();
if (done.get()) {
return 0;
}
output.vector(0).setInt(0, bindData);
output.vector(1).setString(0, "foo");
output.vector(0).setNull(1);
output.vector(1).setString(1, "bar");
done.set(true);
return 2;
}
})
.register(conn);
...
}
```
```sql
FROM java_table_basic(42);
```
Documentation is pending.
Testing: new test added1 parent 2f4ed44 commit f780a96
File tree
29 files changed
+2530
-205
lines changed- src
- jni
- main/java/org/duckdb
- test/java/org/duckdb
29 files changed
+2530
-205
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
592 | 592 | | |
593 | 593 | | |
594 | 594 | | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
595 | 598 | | |
596 | 599 | | |
| 600 | + | |
597 | 601 | | |
598 | 602 | | |
599 | 603 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
113 | 116 | | |
114 | 117 | | |
| 118 | + | |
115 | 119 | | |
116 | 120 | | |
117 | 121 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
116 | 176 | | |
117 | 177 | | |
118 | 178 | | |
| |||
0 commit comments