[FLINK-39276][table] CREATE OR ALTER MATERIALIZED TABLE should respect nullability defined in schema#27794
Conversation
…ect nullability defined in schema
| public boolean hasSchemaDefinition() { | ||
| final SqlNodeList sqlNodeList = sqlCreateMaterializedTable.getColumnList(); | ||
| return !sqlNodeList.getList().isEmpty() | ||
| && sqlNodeList.getList().get(0) instanceof SqlRegularColumn; |
There was a problem hiding this comment.
I am curious about this new method. Are there cases when the materialized table does not have columns?
Is it possible for the first column to be a metadata column? I assume the computed column would need to refer to an already defined regular column.
I see the return of this turns into variable schemaDefinedInQuery - I am checking my understanding - does this mean that a as a1`` in your example. Would a better name be schemaDerivedInQuery, as the schema is actually defined in the columns associated with the table not the select (query)
CREATE OR ALTER MATERIALIZED TABLE mt (
a BIGINT NOT NULL, b STRING, c INT, d STRING, a1 BIGINT NOT NULL)
AS SELECT a, b, c, d, a as a1 FROM t3
There was a problem hiding this comment.
this is not about columns for MT, this is about schema
If it is empty, it means no schema is explicitly specified
There was a problem hiding this comment.
Would a better name be schemaDerivedInQuery,
no, schema derived from query and user provided schema might be different
for instance user might slightly change a type (nullability or type widening)
There was a problem hiding this comment.
as the schema is actually defined in the columns associated with the table not the select (query)
this I didn't get
in a query there might be multiple tables
schema is associated with materialized table and could also contain constraint, watermark, metadata column information which is not retrievable from query
gustavodemorais
left a comment
There was a problem hiding this comment.
LGTM. Only one tiny nit
|
|
||
| assertThat(sqlAlterMaterializedTableAsQuery.getTableChanges()) | ||
| .containsExactly( | ||
| // If NOT NULL defined in schema it should stay |
There was a problem hiding this comment.
nit
| // If NOT NULL defined in schema it should stay | |
| // If NOT NULL is defined in schema, it should stay |
There was a problem hiding this comment.
thanks, addressed
|
thanks everyone for taking a look, merging |
What is the purpose of the change
The problem is that
if there is existing materialized table
mtwith schemaand then we use
CREATE OR ALTERlikethen it will update existing schema adding
a1 BIGINT, i.e. it omits nullability.It would make sense if there is no explicit schema mentioned
however in case of schema is present it should respect it
Brief change log
tests are added
Does this pull request potentially affect one of the following parts:
@Public(Evolving): ( no)Documentation