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

Require that materialized view has owner #7489

Merged
merged 1 commit into from
Apr 9, 2021

Conversation

sopel39
Copy link
Member

@sopel39 sopel39 commented Apr 2, 2021

Materialized views can only be analyzed with definer context.
Therefore view owner needs to be present.

@sopel39 sopel39 force-pushed the ks/mtv_owner branch 2 times, most recently from c585c56 to ccd3dba Compare April 7, 2021 12:50
@@ -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");
Copy link
Member

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

Copy link
Member Author

@sopel39 sopel39 Apr 7, 2021

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?

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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)

Copy link
Member Author

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

Copy link
Member Author

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)

Copy link
Member

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.

Copy link
Member Author

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");
}
Copy link
Member

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

@findepi
Copy link
Member

findepi commented Apr 7, 2021

Materialized views can only be analyzed with definer context.

should StatementAnalyzer reflect this too?

@sopel39
Copy link
Member Author

sopel39 commented Apr 7, 2021

should StatementAnalyzer reflect this too?

@findepi What do you mean?

@findepi
Copy link
Member

findepi commented Apr 7, 2021

should StatementAnalyzer reflect this too?

@findepi What do you mean?

this will be nothing to do if #7489 (comment)

Copy link
Member Author

@sopel39 sopel39 left a 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");
Copy link
Member Author

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}

@sopel39
Copy link
Member Author

sopel39 commented Apr 9, 2021

@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,
Copy link
Member

Choose a reason for hiding this comment

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

All these @JsonPropertys are misleading, since this is not a @JsonCreator.

Copy link
Member Author

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",
Copy link
Member

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"?

@findepi
Copy link
Member

findepi commented Apr 9, 2021

should StatementAnalyzer reflect this too?

statement analyzer cannot get empty now since MV constructor prevents that

yes, but this should be enforced in StatementAnalyzer, since it's its job.
And it still doesn't know that, since getOwner returns Optional

(will you change this in a followup?)

@findepi I would like to change JSON object in separate PR.

fine, please add a TODO for now

Materialized views can only be analyzed with definer context.
Therefore view owner needs to be present.
Copy link
Member Author

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

#7537

@@ -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,
Copy link
Member Author

Choose a reason for hiding this comment

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

added todo: #7537

@sopel39 sopel39 merged commit 987b1dc into trinodb:master Apr 9, 2021
@sopel39 sopel39 deleted the ks/mtv_owner branch April 9, 2021 13:49
@sopel39 sopel39 mentioned this pull request Apr 9, 2021
9 tasks
@martint martint added this to the 356 milestone Apr 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants