TsReaper commented on a change in pull request #12473:
URL: https://github.com/apache/flink/pull/12473#discussion_r435684144
##########
File path:
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/TableResult.java
##########
@@ -49,9 +49,33 @@
ResultKind getResultKind();
/**
- * Get the result contents as a row iterator.
+ * Get the result contents as a closeable row iterator.
+ *
+ * <p><strong>NOTE:</strong>If this result corresponds to a flink job,
+ * the job will not be finished unless all result data has been
collected.
+ * So we should actively close the job to avoid resource leak.
+ *
+ * <p>There are two approaches to close a job:
+ * 1. close the job through JobClient, for example:
+ * <pre>{@code
Review comment:
This is actually not recommended. If user cancels the job but the
iterator does not know it, the next call to the iterator might throw exception.
We should only recommend the users to close the iterator if they don't need
more data.
##########
File path:
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/TableResult.java
##########
@@ -49,9 +49,33 @@
ResultKind getResultKind();
/**
- * Get the result contents as a row iterator.
+ * Get the result contents as a closeable row iterator.
+ *
+ * <p><strong>NOTE:</strong>If this result corresponds to a flink job,
+ * the job will not be finished unless all result data has been
collected.
+ * So we should actively close the job to avoid resource leak.
+ *
+ * <p>There are two approaches to close a job:
+ * 1. close the job through JobClient, for example:
+ * <pre>{@code
+ * TableResult result = tEnv.execute("select ...");
+ * CloseableIterator<Row> it = result.collect();
+ * it... // collect same data
+ * result.getJobClient().get().cancel();
+ * }</pre>
+ *
+ * <p>2. close the job through CloseableIterator
+ * (calling CloseableIterator#close method will trigger
JobClient#cancel method),
+ * for example:
Review comment:
For insert job this method can not cancel the job.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]