|
8 | 8 | import tech.ydb.core.Result; |
9 | 9 | import tech.ydb.core.Status; |
10 | 10 | import tech.ydb.core.operation.Operation; |
| 11 | +import tech.ydb.core.operation.OperationTray; |
11 | 12 | import tech.ydb.proto.query.YdbQuery; |
12 | 13 | import tech.ydb.proto.scripting.ScriptingProtos; |
| 14 | +import tech.ydb.query.result.OperationResult; |
13 | 15 | import tech.ydb.query.settings.BeginTransactionSettings; |
14 | 16 | import tech.ydb.query.settings.ExecuteQuerySettings; |
15 | 17 | import tech.ydb.query.settings.ExecuteScriptSettings; |
@@ -74,38 +76,52 @@ public interface QuerySession extends AutoCloseable { |
74 | 76 | */ |
75 | 77 | QueryStream createQuery(String query, TxMode tx, Params params, ExecuteQuerySettings settings); |
76 | 78 |
|
77 | | - |
78 | 79 | /** |
79 | | - * Execute yql script |
80 | | - * @param query text of query |
81 | | - * @param params query parameters |
82 | | - * @param settings additional settings of query execution |
83 | | - * @return future with result of the script execution |
| 80 | + * Executes a YQL script via the scripting service and returns its result as a completed future. |
| 81 | + * |
| 82 | + * <p>This method sends a YQL script for execution and collects the full result set in a single response. |
| 83 | + * It uses {@link ScriptingProtos.ExecuteYqlRequest} under the hood and returns |
| 84 | + * an {@link OperationResult} wrapped in {@link Result} to provide status and issues details.</p> |
| 85 | + * |
| 86 | + * @param query the YQL script text to execute |
| 87 | + * @param params input parameters for the script |
| 88 | + * @param settings execution settings such as statistics collection or tracing |
| 89 | + * @return a future that resolves to a {@link Result} containing {@link ScriptingProtos.ExecuteYqlResult} |
84 | 90 | */ |
85 | | - CompletableFuture<Result<ScriptingProtos.ExecuteYqlResult>> executeScriptYql(String query, Params params, ExecuteScriptSettings settings); |
| 91 | + CompletableFuture<Result<ScriptingProtos.ExecuteYqlResult>> executeScriptYql(String query, |
| 92 | + Params params, |
| 93 | + ExecuteScriptSettings settings); |
86 | 94 |
|
87 | 95 |
|
88 | 96 | /** |
89 | | - * Create {@link QueryStream} for executing query with specified {@link TxMode}. The query can contain DML, DDL and |
90 | | - * DCL statements. Supported mix of different statement types depends on the chosen transaction type. |
| 97 | + * Submits a YQL script for asynchronous execution and returns a handle to the operation. |
| 98 | + * Take a not that join return future will not guarantee that script is finished. It's guarantee that script is passed to ydb |
91 | 99 | * |
92 | | - * @param query text of query |
93 | | - * @param params query parameters |
94 | | - * @param settings additional settings of query execution |
95 | | - * @return a ready to execute instance of {@link QueryStream} |
| 100 | + * <p>This method executes the given script asynchronously and immediately returns |
| 101 | + * a {@link CompletableFuture} for an {@link Operation}, which can be later monitored or fetched |
| 102 | + * via {@link #waitForScript(CompletableFuture)} or {@link #fetchScriptResults(String, Params, FetchScriptSettings)}.</p> |
| 103 | + * |
| 104 | + * @param query the YQL script text to execute |
| 105 | + * @param params input parameters to pass to the script |
| 106 | + * @param settings script execution options such as TTL, statistics mode, or resource pool |
| 107 | + * @return a future resolving to an {@link Operation} representing the submitted script execution |
96 | 108 | */ |
97 | 109 | CompletableFuture<Operation<Status>> executeScript(String query, Params params, ExecuteScriptSettings settings); |
98 | 110 |
|
99 | 111 | /** |
100 | | - * Fetch result from script which has already passed to YDB |
101 | | - * Before use wait for CompletableFuture with operation |
| 112 | + * Fetches partial or complete results from a previously executed YQL script. |
102 | 113 | * |
103 | | - * @param query text of query |
104 | | - * @param params query parameters |
105 | | - * @param settings additional settings of query execution |
106 | | - * @return a ready to execute instance of {@link QueryStream} |
| 114 | + * <p>This method retrieves result sets produced by an asynchronous script execution. |
| 115 | + * It supports incremental fetching using tokens, row limits, and result set index selection.</p> |
| 116 | + * |
| 117 | + * @param query optional query text for context (not used by the server but may help debugging) |
| 118 | + * @param params parameters used during script execution (typically empty) |
| 119 | + * @param settings settings that define which operation to fetch results from, including fetch token, row limit, and index |
| 120 | + * @return a future resolving to a {@link Result} containing {@link YdbQuery.FetchScriptResultsResponse} |
107 | 121 | */ |
108 | | - CompletableFuture<Result<YdbQuery.FetchScriptResultsResponse>> fetchScriptResults(String query, Params params, FetchScriptSettings settings); |
| 122 | + CompletableFuture<Result<YdbQuery.FetchScriptResultsResponse>> fetchScriptResults(String query, |
| 123 | + Params params, |
| 124 | + FetchScriptSettings settings); |
109 | 125 |
|
110 | 126 | @Override |
111 | 127 | void close(); |
@@ -147,23 +163,44 @@ default CompletableFuture<Result<QueryTransaction>> beginTransaction(TxMode txMo |
147 | 163 | } |
148 | 164 |
|
149 | 165 | /** |
150 | | - * Execute Yql script with different type of operation |
| 166 | + * Executes a YQL script via the scripting service and returns its result as a completed future. |
151 | 167 | * |
152 | | - * @param query text of query |
153 | | - * @return a future join on it to wait for script finished |
| 168 | + * <p>This method sends a YQL script for execution and collects the full result set in a single response. |
| 169 | + * It uses {@link ScriptingProtos.ExecuteYqlRequest} under the hood and returns |
| 170 | + * an {@link OperationResult} wrapped in {@link Result} to provide status and issues details.</p> |
| 171 | + * |
| 172 | + * @param query the YQL script text to execute |
| 173 | + * @return a future that resolves to a {@link Result} containing {@link ScriptingProtos.ExecuteYqlResult} |
154 | 174 | */ |
155 | 175 | default CompletableFuture<Result<ScriptingProtos.ExecuteYqlResult>> executeScriptYql(String query) { |
156 | 176 | return executeScriptYql(query, Params.empty(), ExecuteScriptSettings.newBuilder().build()); |
157 | 177 | } |
158 | 178 |
|
159 | 179 | /** |
160 | | - * Execute Yql script with different type of operation |
161 | | - * Take a not join on a future is not granted that script is executed instead join guarantee that script pass to YDB |
| 180 | + * Submits a YQL script for asynchronous execution and returns a handle to the operation. |
| 181 | + * Take a not that join return future will not guarantee that script is finished. It's guarantee that script is passed to ydb |
162 | 182 | * |
163 | | - * @param query text of query |
164 | | - * @return future join on it to wait for script pass to YDB but not get result |
| 183 | + * <p>This method executes the given script asynchronously and immediately returns |
| 184 | + * a {@link CompletableFuture} for an {@link Operation}, which can be later monitored or fetched |
| 185 | + * via {@link #waitForScript(CompletableFuture)} or {@link #fetchScriptResults(String, Params, FetchScriptSettings)}.</p> |
| 186 | + * |
| 187 | + * @param query the YQL script text to execute |
| 188 | + * @return a future resolving to an {@link Operation} representing the submitted script execution |
165 | 189 | */ |
166 | 190 | default CompletableFuture<Operation<Status>> executeScript(String query) { |
167 | 191 | return executeScript(query, Params.empty(), ExecuteScriptSettings.newBuilder().build()); |
168 | 192 | } |
| 193 | + |
| 194 | + /** |
| 195 | + * Waits for a previously submitted script operation to complete. |
| 196 | + * |
| 197 | + * <p>This method polls or fetches the state of the running operation via {@link OperationTray#fetchOperation} |
| 198 | + * until the operation completes successfully or fails. It is typically used after calling |
| 199 | + * {@link #executeScript(String, Params, ExecuteScriptSettings)}.</p> |
| 200 | + * |
| 201 | + * @param scriptFuture a {@link CompletableFuture} returned by {@link #executeScript(String, Params, ExecuteScriptSettings)} |
| 202 | + * @return a future resolving to the final {@link Status} of the script execution |
| 203 | + */ |
| 204 | + CompletableFuture<Status> waitForScript(CompletableFuture<Operation<Status>> scriptFuture); |
| 205 | + |
169 | 206 | } |
0 commit comments