-
Notifications
You must be signed in to change notification settings - Fork 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
Require that materialized view has owner #7489
Conversation
c585c56
to
ccd3dba
Compare
@@ -80,6 +80,10 @@ public ConnectorMaterializedViewDefinition( | |||
if (columns.isEmpty()) { | |||
throw new IllegalArgumentException("columns list is empty"); | |||
} | |||
|
|||
if (owner.isEmpty()) { | |||
throw new IllegalArgumentException("owner must be present"); |
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.
what if we change the @JsonCreator
ctor as well?
i think jackson-produced message would be good as well
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.
what if we change the @JsonCreator ctor as well?
I didn't want to break backward compatibility of already serialized, correct materialized view definitions (with owner) that could have been stored somewhere by connector. Do you think it wouldn't be a problem?
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.
you break it anyway -- if the serialized value doesn't have owner, it will fail during deserialization. It doesn't make a big difference whether it fails in jackson code vs in the constructor validtion as long as the raised message is informative.
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 wouldn't fail if the serialized value does have owner. But if I change jackson constructor it would then fail then too. Technically, someone could already serialized such MV in metastore (we do something like that for ConnectorViewDefinition
in Hive) and this change would break valid MV then.
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 wouldn't fail if the serialized value does have owner. But if I change jackson constructor it would then fail then too.
I don't think this is the case (com.fasterxml.jackson.datatype.jdk8.Jdk8Module
makes Optional<String>
and String
serialize the same way)
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'm pretty sure it's not the case. See #7318 (comment). Optional gets serialized into nested structure
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.
We don't set com.fasterxml.jackson.datatype.jdk8.Jdk8Module#configureAbsentsAsNulls
to true
(default is false
)
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.
That doesn't align with my memory, but i'd need to check this out.
If so, we should definitely have a test exercising the persisted form build with a previous version against current code.
Especially if serialized form is an effect of interaction between SPI class (types, annotations) and a connector setup of ObjectMapper
.
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.
Ok It might work. Experiment:
ConnectorViewDefinition view = new ConnectorViewDefinition("foo", Optional.of("bar"), Optional.empty(), ImmutableList.of(new ConnectorViewDefinition.ViewColumn("f", TypeId.of("foo"))), Optional.empty(), Optional.empty(), false);
String s = VIEW_CODEC.toJson(view);
{"originalSql":"foo","catalog":"bar","columns":[{"name":"f","type":"foo"}],"runAsInvoker":false}
|
||
if (owner.isEmpty()) { | ||
throw new IllegalArgumentException("owner must be present"); | ||
} |
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.
Also change the getter to be String getOwner
should |
@findepi What do you mean? |
this will be nothing to do if #7489 (comment) |
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.
should StatementAnalyzer reflect this too?
statement analyzer cannot get empty now since MV constructor prevents that
@@ -80,6 +80,10 @@ public ConnectorMaterializedViewDefinition( | |||
if (columns.isEmpty()) { | |||
throw new IllegalArgumentException("columns list is empty"); | |||
} | |||
|
|||
if (owner.isEmpty()) { | |||
throw new IllegalArgumentException("owner must be present"); |
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.
Ok It might work. Experiment:
ConnectorViewDefinition view = new ConnectorViewDefinition("foo", Optional.of("bar"), Optional.empty(), ImmutableList.of(new ConnectorViewDefinition.ViewColumn("f", TypeId.of("foo"))), Optional.empty(), Optional.empty(), false);
String s = VIEW_CODEC.toJson(view);
{"originalSql":"foo","catalog":"bar","columns":[{"name":"f","type":"foo"}],"runAsInvoker":false}
@findepi I would like to change JSON object in separate PR. |
@@ -44,10 +44,10 @@ public ConnectorMaterializedViewDefinition( | |||
@JsonProperty("schema") Optional<String> schema, | |||
@JsonProperty("columns") List<Column> columns, | |||
@JsonProperty("comment") Optional<String> comment, | |||
@JsonProperty("owner") Optional<String> owner, | |||
@JsonProperty("owner") String owner, |
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.
All these @JsonProperty
s are misleading, since this is not a @JsonCreator
.
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.
added todo: #7537
@@ -837,7 +837,7 @@ protected final void setup(String databaseName, HiveConfig hiveConfig, HiveMetas | |||
Optional.empty(), | |||
ImmutableList.of(new ConnectorMaterializedViewDefinition.Column("abc", TypeId.of("type"))), | |||
Optional.empty(), | |||
Optional.empty(), | |||
"user", |
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.
is "user" a special value here?
"some mv owner"?
yes, but this should be enforced in (will you change this in a followup?)
fine, please add a TODO for now |
Materialized views can only be analyzed with definer context. Therefore view owner needs to be present.
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.
yes, but this should be enforced in StatementAnalyzer, since it's its job.
And it still doesn't know that, since getOwner returns Optional
done
fine, please add a TODO for now
@@ -44,10 +44,10 @@ public ConnectorMaterializedViewDefinition( | |||
@JsonProperty("schema") Optional<String> schema, | |||
@JsonProperty("columns") List<Column> columns, | |||
@JsonProperty("comment") Optional<String> comment, | |||
@JsonProperty("owner") Optional<String> owner, | |||
@JsonProperty("owner") String owner, |
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.
added todo: #7537
Materialized views can only be analyzed with definer context.
Therefore view owner needs to be present.