Skip to content
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

Merged
merged 3 commits into from Feb 10, 2020

Conversation

HuangXingBo
Copy link
Contributor

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

  • Add AbstractPythonTableFunctionOperator and PythonTableFunctionOperator
  • Add AbstractPythonStatelessFunctionRunner
  • Add AbstractPythonTableFunctionRunner and PythonTableFunctionRunner
  • TableSerializer and RowTableSerializer
  • Add Table Type in flink-fn-execution.proto

Verifying this change

This change added tests and can be verified as follows:

  • Add runner test in PythonTableFunctionRunnerTest
  • Add operator test in PythonTableFunctionOperatorTestBase

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): (no)
  • The public API, i.e., is any changed class annotated with @Public(Evolving): (no)
  • The serializers: (no)
  • The runtime per-record code paths (performance sensitive): (no)
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Yarn/Mesos, ZooKeeper: (no)
  • The S3 file system connector: (yes / no / don't know)

Documentation

  • Does this pull request introduce a new feature? (yes / no)
  • If yes, how is the feature documented? (not applicable)

@flinkbot
Copy link
Collaborator

flinkbot commented Feb 5, 2020

Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community
to review your pull request. We will use this comment to track the progress of the review.

Automated Checks

Last check on commit 024d27c (Wed Feb 05 10:08:29 UTC 2020)

Warnings:

  • No documentation files were touched! Remember to keep the Flink docs up to date!
  • This pull request references an unassigned Jira ticket. According to the code contribution guide, tickets need to be assigned before starting with the implementation work.

Mention the bot in a comment to re-run the automated checks.

Review Progress

  • ❓ 1. The [description] looks good.
  • ❓ 2. There is [consensus] that the contribution should go into to Flink.
  • ❓ 3. Needs [attention] from.
  • ❓ 4. The change fits into the overall [architecture].
  • ❓ 5. Overall code [quality] is good.

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 commands
The @flinkbot bot supports the following commands:

  • @flinkbot approve description to approve one or more aspects (aspects: description, consensus, architecture and quality)
  • @flinkbot approve all to approve all aspects
  • @flinkbot approve-until architecture to approve everything until architecture
  • @flinkbot attention @username1 [@username2 ..] to require somebody's attention
  • @flinkbot disapprove architecture to remove an approval you gave earlier

@flinkbot
Copy link
Collaborator

flinkbot commented Feb 5, 2020

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run travis re-run the last Travis build
  • @flinkbot run azure re-run the last Azure build

@hequn8128 hequn8128 changed the title [FLINK-15913][python] Add Python Table Function Runner And Operator In Legacy Planner [FLINK-15913][python] Add Python TableFunction Runner and Operator in old planner Feb 6, 2020
Copy link
Contributor

@hequn8128 hequn8128 left a 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

@@ -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;
Copy link
Contributor

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.

return new RowTableSerializer(fieldTypeSerializers);
}

public static FlinkFnApi.Schema.FieldType toTableProtoType(LogicalType logicalType) {
Copy link
Contributor

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> {
Copy link
Contributor

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>
Copy link
Contributor

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>
Copy link
Contributor

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> {
Copy link
Contributor

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> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add @Internal

@HuangXingBo
Copy link
Contributor Author

Thanks a lot for @hequn8128 review, I have addressed the comments at the latest commit.

Copy link
Contributor

@hequn8128 hequn8128 left a 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;
Copy link
Contributor

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.
Copy link
Contributor

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
Copy link
Contributor

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;
Copy link
Contributor

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.
Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the blank after =

@HuangXingBo
Copy link
Contributor Author

Thanks a lot for @hequn8128 review, I have addressed the comments at the latest commit.

Copy link
Contributor

@hequn8128 hequn8128 left a 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.

hequn8128 pushed a commit to hequn8128/flink that referenced this pull request Feb 7, 2020
@hequn8128
Copy link
Contributor

It seems the test failure has nothing to do with this PR. I will merge this.

@hequn8128 hequn8128 merged commit fee187e into apache:master Feb 10, 2020
@HuangXingBo HuangXingBo deleted the FLINK-15913 branch February 10, 2020 02:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants