-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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-35707][Table SQL / API] Allow column definition in CREATE TABLE AS (CTAS) #24987
Conversation
6960b4a
to
70a3367
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.
Thanks for the PR @spena.
- We should add at least 3 ITCase tests as well that test the CTAS end-to-end. E.g. next to
org.apache.flink.table.planner.runtime.stream.sql.TableSinkITCase#testCreateTableAsSelectWithoutOptions
. For only left schema, only right schema, mixture of both. - What is the behavior if the table column is NOT NULL and the source schema doesn't fill it.
- It would be great if there is a smart way of reducing code duplication among
MergeTableLikeUtil
andMergeTableAsUtil
.
} | ||
|
||
/** | ||
* Merges the schema part of the {@code sqlCreateTableAs} with the {@code sourceSchema}. |
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.
nit: do you know that you can also use {@param sqlCreateTableAs}
at random locations in JavaDocs? This way you can get full IDE support.
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.
I couldn't find out how it helps. For example. the IDE pop up message shows me this formatted doc after adding the @param:
javadoc: Merges the schema part of the {@code sqlCreateTableAs} with the {@param sourceSchema}
Merges the schema part of the sqlCreateTableAs with the @param sourceSchema.
The sqlCreateTableAs
is in bold in the doc, but the sourceSchema
isn't.
I didn't find docs about how this is helpful. Do you have examples or a doc to read about it?
...-table-planner/src/main/java/org/apache/flink/table/planner/operations/MergeTableAsUtil.java
Outdated
Show resolved
Hide resolved
...-table-planner/src/main/java/org/apache/flink/table/planner/operations/MergeTableAsUtil.java
Outdated
Show resolved
Hide resolved
* Builder class for constructing a {@link Schema} based on the rules of the {@code CREATE TABLE | ||
* ... AS SELECT} statement. | ||
*/ | ||
private static class SchemaBuilder { |
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.
I see a lot of code that is duplicated from MergeTableLikeUtil
. Isn't it somehow possible to merge the two utils? Isn't the sourceSchema similar to the CREATE TABLE x LIKE sourceSchema
?
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.
The way they're merged are different. The LIKE util adds the sourceSchema
at the beginning and the sink columns at the end. It also depends on the LIKE STRATEGIES on how primary/partition keys, watermarks are merged, either OVERWRITING, IGNORING, EXCLUDING. There's no strategy for schema columns yet.
I was tempted to re-use that util class and add the support for column overwriting (currently, the LIKE util throws if a sink column exists in the source column), but I thought I will start messing with the CREATE TABLE LIKE and its behavior. I instead decided to create this other utility to prevent changing logic of another statement.
...-table-planner/src/main/java/org/apache/flink/table/planner/operations/MergeTableAsUtil.java
Outdated
Show resolved
Hide resolved
.../src/test/java/org/apache/flink/table/planner/operations/SqlDdlToOperationConverterTest.java
Outdated
Show resolved
Hide resolved
.../src/test/java/org/apache/flink/table/planner/operations/SqlDdlToOperationConverterTest.java
Outdated
Show resolved
Hide resolved
70a3367
to
bf07667
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.
Thanks for addressing my comments. I think the pull request will be ready in the next iteration.
import static org.apache.flink.table.types.utils.TypeConversions.fromLogicalToDataType; | ||
|
||
/** A utility class for {@link SqlCreateTableConverter} conversions. */ | ||
public final class SqlConverterUtils { |
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 is a very generic name. How about calling it SchemaBuilderUtil or even better: let the other two extend from it. It seems there are no static methods, so why not extending?
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.
Done
.isInstanceOf(ValidationException.class) | ||
.hasMessageContaining( | ||
"Incompatible types for sink column 'f0' at position 0. " | ||
+ "The source column has type [INT NOT NULL], while the target " |
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 [
or ]
. if you want to wrap args use singe quotes
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.
Done
bf07667
to
48bf513
Compare
What is the purpose of the change
Allow defining new columns and/or overriding source column types in the
CREATE
clause on CTAS statements.Syntax supported:
Brief change log
Verifying this change
This change added tests and can be verified as follows:
Quick test using a compute column to check the expression is evaluated using source columns:
Does this pull request potentially affect one of the following parts:
@Public(Evolving)
: noDocumentation