New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FLINK-15913][python] Add Python TableFunction Runner and Operator in old planner #11020
Conversation
Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community Automated ChecksLast check on commit 024d27c (Wed Feb 05 10:08:29 UTC 2020) Warnings:
Mention the bot in a comment to re-run the automated checks. Review Progress
Please see the Pull Request Review Guide for a full explanation of the review process. The Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required Bot commandsThe @flinkbot bot supports the following commands:
|
CI report:
Bot commandsThe @flinkbot bot supports the following commands:
|
024d27c
to
a2f0e14
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HuangXingBo
Thanks a lot for the PR and the great work! I left some comments below. The most important I think is we need to avoid some code duplications. Besides, some implementation may need to be simplified, such as it would be great if we can avoid adding the TABLE type in flink-fn-execution.proto
. More details can be found in the comments below.
Furthermore, it would be great if you can rebase the code to the latest master and solve the conflicts. Thanks.
Best, Hequn
...c/main/java/org/apache/flink/table/runtime/typeutils/serializers/python/TableSerializer.java
Outdated
Show resolved
Hide resolved
flink-python/src/main/java/org/apache/flink/table/runtime/typeutils/PythonTypeUtils.java
Outdated
Show resolved
Hide resolved
@@ -90,6 +91,39 @@ public static TypeSerializer toBlinkTypeSerializer(LogicalType logicalType) { | |||
return logicalType.accept(new LogicalTypeToProtoTypeConverter()); | |||
} | |||
|
|||
public static TypeSerializer toFlinkTableTypeSerializer(LogicalType logicalType) { | |||
RowType rowType = (RowType) logicalType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not good to cast here. It's better to change the method from toFlinkTableTypeSerializer(LogicalType logicalType)
to toFlinkTableTypeSerializer(RowType logicalType)
Same for toTableProtoType
.
flink-python/src/main/java/org/apache/flink/table/runtime/typeutils/PythonTypeUtils.java
Outdated
Show resolved
Hide resolved
return new RowTableSerializer(fieldTypeSerializers); | ||
} | ||
|
||
public static FlinkFnApi.Schema.FieldType toTableProtoType(LogicalType logicalType) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename method name to toTableFunctionProtoType
/** | ||
* The collector is used to convert a {@link Row} to a {@link CRow}. | ||
*/ | ||
private static class StreamRecordCRowWrappingCollector implements Collector<Row> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class is copied from PythonScalarFunctionOperator
. I think we can do some code reuse.
* @param <UDTFIN> Type of the UDF input type. | ||
* @param <UDTFOUT> Type of the UDF input type. | ||
*/ | ||
public abstract class AbstractPythonTableFunctionOperator<IN, OUT, UDTFIN, UDTFOUT> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please try to avoid code deduplication. For example, we can add a StatelessFunctionOperator
and put the same code in this class. What do you think?
* @param <UDTFIN> Type of the UDF input type. | ||
* @param <UDTFOUT> Type of the UDF input type. | ||
*/ | ||
public abstract class AbstractPythonTableFunctionOperator<IN, OUT, UDTFIN, UDTFOUT> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add @Internal
/** | ||
* The Python {@link TableFunction} operator for the legacy planner. | ||
*/ | ||
public class PythonTableFunctionOperator extends AbstractPythonTableFunctionOperator<CRow, CRow, Row, Row> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add @Internal
* @param <IN> Type of the input elements. | ||
* @param <OUT> Type of the execution results. | ||
*/ | ||
public abstract class AbstractPythonTableFunctionRunner<IN, OUT> extends AbstractPythonStatelessFunctionRunner<IN, OUT> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add @Internal
…n Legacy Planner-fix-1
a2f0e14
to
e2ea604
Compare
Thanks a lot for @hequn8128 review, I have addressed the comments at the latest commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HuangXingBo Thanks a lot for the update. The code looks much better now. With some minor comments below.
Best, Hequn
@@ -73,6 +73,7 @@ message Schema { | |||
ARRAY = 16; | |||
MAP = 17; | |||
MULTISET = 18; | |||
TABLEFUNCTIONROW = 19; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TABLE_FUNCTION_ROW ?
} | ||
|
||
/** | ||
* The received udtf execution result is a finish message when it is a byte 0x00. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when it is a byte 0x00 => when it is a byte with value 0x00
protected transient LinkedBlockingQueue<IN> forwardedInputQueue; | ||
|
||
/** | ||
* The queue holding the user-defined table function execution results. The execution results |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
user-defined table function => user-defined function
/** | ||
* The udf output logical type. | ||
*/ | ||
protected transient RowType udfOutputType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about rename udfOutputType
to functionOutputType
or userDefinedFunctionOutputType
? It seems strange to see the udfOutputType
variable in AbstractPythonTableFunctionOperator
.
Same for other variable names.
private transient TypeSerializer<CRow> forwardedInputSerializer; | ||
|
||
/** | ||
* The TypeSerializer for udf execution results. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
udf => udtf
@Override | ||
public void bufferInput(CRow input) { | ||
if (getExecutionConfig().isObjectReuseEnabled()) { | ||
input = forwardedInputSerializer.copy(input); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the blank after =
…n Legacy Planner-fix-2
Thanks a lot for @hequn8128 review, I have addressed the comments at the latest commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Merging this once travis passed.
…n Legacy Planner This closes apache#11020.
It seems the test failure has nothing to do with this PR. I will merge this. |
What is the purpose of the change
This pull request add Python Table Function Runner and Operator for executing Python user-defined table function in legacy Planner
Brief change log
Verifying this change
This change added tests and can be verified as follows:
Does this pull request potentially affect one of the following parts:
@Public(Evolving)
: (no)Documentation