Class TableResultImpl
- java.lang.Object
-
- org.apache.flink.table.api.internal.TableResultImpl
-
- All Implemented Interfaces:
TableResultInternal
,TableResult
@Internal public class TableResultImpl extends Object implements TableResultInternal
Implementation forTableResult
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TableResultImpl.Builder
Builder for creating aTableResultImpl
.
-
Field Summary
-
Fields inherited from interface org.apache.flink.table.api.internal.TableResultInternal
TABLE_RESULT_OK
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
await()
Wait if necessary until the data is ready.void
await(long timeout, TimeUnit unit)
Wait if necessary for at most the given time for the data to be ready.static TableResultImpl.Builder
builder()
org.apache.flink.util.CloseableIterator<org.apache.flink.types.Row>
collect()
Get the result contents as a closeable row iterator.org.apache.flink.util.CloseableIterator<org.apache.flink.table.data.RowData>
collectInternal()
Returns an iterator that returns the iterator with the internal row data type.CachedPlan
getCachedPlan()
Optional<org.apache.flink.core.execution.JobClient>
getJobClient()
For DML and DQL statement, return theJobClient
which associates the submitted Flink job.org.apache.flink.table.utils.print.PrintStyle
getPrintStyle()
org.apache.flink.table.catalog.ResolvedSchema
getResolvedSchema()
Returns the schema of the result.ResultKind
getResultKind()
Return theResultKind
which represents the result type.org.apache.flink.table.utils.print.RowDataToStringConverter
getRowDataToStringConverter()
void
print()
Print the result contents as tableau form to client console.
-
-
-
Method Detail
-
getJobClient
public Optional<org.apache.flink.core.execution.JobClient> getJobClient()
Description copied from interface:TableResult
For DML and DQL statement, return theJobClient
which associates the submitted Flink job. For other statements (e.g. DDL, DCL) return empty.- Specified by:
getJobClient
in interfaceTableResult
-
await
public void await() throws InterruptedException, ExecutionException
Description copied from interface:TableResult
Wait if necessary until the data is ready.For a select operation, this method will wait until the first row can be accessed locally. For an insert operation, this method will wait for the job to finish, because the result contains only one row. For other operations, this method will return immediately, because the result is already available locally.
- Specified by:
await
in interfaceTableResult
- Throws:
InterruptedException
- if the operation was interrupted while waitingExecutionException
- if a problem occurred
-
await
public void await(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
Description copied from interface:TableResult
Wait if necessary for at most the given time for the data to be ready.For a select operation, this method will wait until the first row can be accessed locally. For an insert operation, this method will wait for the job to finish, because the result contains only one row. For other operations, this method will return immediately, because the result is already available locally.
- Specified by:
await
in interfaceTableResult
- Parameters:
timeout
- the maximum time to waitunit
- the time unit of the timeout argument- Throws:
InterruptedException
- if the operation was interrupted while waitingExecutionException
- if a problem occurredTimeoutException
- if the wait timed out
-
getResolvedSchema
public org.apache.flink.table.catalog.ResolvedSchema getResolvedSchema()
Description copied from interface:TableResult
Returns the schema of the result.- Specified by:
getResolvedSchema
in interfaceTableResult
-
getResultKind
public ResultKind getResultKind()
Description copied from interface:TableResult
Return theResultKind
which represents the result type.For DDL operation and USE operation, the result kind is always
ResultKind.SUCCESS
. For other operations, the result kind is alwaysResultKind.SUCCESS_WITH_CONTENT
.- Specified by:
getResultKind
in interfaceTableResult
-
collect
public org.apache.flink.util.CloseableIterator<org.apache.flink.types.Row> collect()
Description copied from interface:TableResult
Get the result contents as a closeable row iterator.NOTE:
- For SELECT operation, the job will not be finished unless all result data has been collected. So we should actively close the job to avoid resource leak through CloseableIterator#close method. Calling CloseableIterator#close method will cancel the job and release related resources.
- For DML operation, Flink does not support getting the real affected row count now. So the affected row count is always -1 (unknown) for every sink, and them will be returned until the job is finished. Calling CloseableIterator#close method will cancel the job.
- For other operations, no flink job will be submitted (
TableResult.getJobClient()
is always empty), and the result is bounded. Do nothing when calling CloseableIterator#close method.
Recommended code to call CloseableIterator#close method looks like:
TableResult result = tEnv.execute("select ..."); // using try-with-resources statement try (CloseableIterator<Row> it = result.collect()) { it... // collect same data }
This method has slightly different behaviors under different checkpointing settings (to enable checkpointing for a streaming job, set checkpointing properties through
TableConfig
).- For batch jobs or streaming jobs without checkpointing, this method has neither exactly-once nor at-least-once guarantee. Query results are immediately accessible by the clients once they're produced, but exceptions will be thrown when the job fails and restarts.
- For streaming jobs with exactly-once checkpointing, this method guarantees an end-to-end exactly-once record delivery. A result will be accessible by clients only after its corresponding checkpoint completes.
- For streaming jobs with at-least-once checkpointing, this method guarantees an end-to-end at-least-once record delivery. Query results are immediately accessible by the clients once they're produced, but it is possible for the same result to be delivered multiple times.
In order to fetch result to local, you can call either
TableResult.collect()
andTableResult.print()
. But, they can't be called both on the sameTableResult
instance, because the result can only be accessed once.- Specified by:
collect
in interfaceTableResult
-
collectInternal
public org.apache.flink.util.CloseableIterator<org.apache.flink.table.data.RowData> collectInternal()
Description copied from interface:TableResultInternal
Returns an iterator that returns the iterator with the internal row data type.- Specified by:
collectInternal
in interfaceTableResultInternal
-
getRowDataToStringConverter
public org.apache.flink.table.utils.print.RowDataToStringConverter getRowDataToStringConverter()
- Specified by:
getRowDataToStringConverter
in interfaceTableResultInternal
-
getCachedPlan
@Nullable public CachedPlan getCachedPlan()
- Specified by:
getCachedPlan
in interfaceTableResultInternal
-
print
public void print()
Description copied from interface:TableResult
Print the result contents as tableau form to client console.This method has slightly different behaviors under different checkpointing settings (to enable checkpointing for a streaming job, set checkpointing properties through
TableConfig
).- For batch jobs or streaming jobs without checkpointing, this method has neither exactly-once nor at-least-once guarantee. Query results are immediately accessible by the clients once they're produced, but exceptions will be thrown when the job fails and restarts.
- For streaming jobs with exactly-once checkpointing, this method guarantees an end-to-end exactly-once record delivery. A result will be accessible by clients only after its corresponding checkpoint completes.
- For streaming jobs with at-least-once checkpointing, this method guarantees an end-to-end at-least-once record delivery. Query results are immediately accessible by the clients once they're produced, but it is possible for the same result to be delivered multiple times.
In order to fetch result to local, you can call either
TableResult.collect()
andTableResult.print()
. But, they can't be called both on the sameTableResult
instance, because the result can only be accessed once.- Specified by:
print
in interfaceTableResult
-
getPrintStyle
public org.apache.flink.table.utils.print.PrintStyle getPrintStyle()
-
builder
public static TableResultImpl.Builder builder()
-
-