-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Add view text and reference chain information to TableInfo #18871
Add view text and reference chain information to TableInfo #18871
Conversation
1c3d81b
to
2dee6b3
Compare
FYI @Praveen2112 |
2dee6b3
to
88aa2df
Compare
cc a few folks from #7330: @martint @skrzypo987 @kokosing @kasiafi |
Thanks for the detailed write up explaining the motivation. This is a model that we should emulate in other PRs. |
Hi @Praveen2112 @hashhar @skrzypo987 @kokosing @kasiafi , friendly ping, anyone interested in taking a look at this? Thanks! :) |
core/trino-spi/src/main/java/io/trino/spi/eventlistener/ViewLikeInfo.java
Outdated
Show resolved
Hide resolved
core/trino-spi/src/main/java/io/trino/spi/eventlistener/ViewType.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java
Show resolved
Hide resolved
testing/trino-tests/src/test/java/io/trino/execution/TestEventListenerBasic.java
Outdated
Show resolved
Hide resolved
88aa2df
to
dedf808
Compare
Hi @Praveen2112 any more comments on the current version? |
I'll take a look |
Friendly ping @Praveen2112 in case you are able to take a look cc also @phd3 in case you have a chance to review |
Sorry for the delay !! Will take a look by this week |
272e727
to
e8d0b44
Compare
Hi @Praveen2112 friendly reminder :) |
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 working on this and apologies for the delay. I personally like adding additional information on views or MVs - I'm not sure if we need to capture the row filter and column masks along with this - as we already have them in TableInfo#getFilters
and TableInfo#getColumns
where we maintain each information about the column.
core/trino-main/src/main/java/io/trino/sql/analyzer/Analysis.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/sql/analyzer/Analysis.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java
Show resolved
Hide resolved
core/trino-spi/src/main/java/io/trino/spi/eventlistener/ViewLikeInfo.java
Outdated
Show resolved
Hide resolved
e8d0b44
to
5d483b8
Compare
Just updated based on last round of comments @Praveen2112 . Thanks, they were super helpful! I've left in the row-filter/column-mask info for now, LMK what you think based on my latest comment. I don't have a strong opinion here -- I am also primarily interested in the view info rather than mask/filter -- so if you still feel it should be removed after this, no concerns from my side. |
49ba984
to
d574c4d
Compare
The build says failed on the
Going to re-push to try again ... |
d574c4d
to
309d875
Compare
🤔 This time the trino-main test step succeeded, but the artifact-checks step failed with:
Trying one more time ... |
309d875
to
47f6a01
Compare
okay all checks passing this time 😌 |
Hey @Praveen2112 any chance you can take another look? I'm going to be OOO for a couple of weeks starting this Fri, would love to get this merged before then 🤞🏻 |
47f6a01
to
8e544ac
Compare
8e544ac
to
e9c2b4d
Compare
21ed66d
to
b47a921
Compare
Hi @Praveen2112 happy new year! Friendly reminder on this PR, let me know what you think on the discussion re: MVs. Thanks! |
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 working on this. I think the PR looks great !! Trino has a concept of redirected tables and it would be nice if we could add a test case for those kind of tables. LMK if you need additional help wrt to re-directed tables.
testing/trino-tests/src/test/java/io/trino/execution/TestEventListenerBasic.java
Outdated
Show resolved
Hide resolved
testing/trino-tests/src/test/java/io/trino/execution/TestEventListenerBasic.java
Outdated
Show resolved
Hide resolved
core/trino-spi/src/main/java/io/trino/spi/eventlistener/TableReferenceInfo.java
Outdated
Show resolved
Hide resolved
@JsonTypeInfo( | ||
use = JsonTypeInfo.Id.NAME, | ||
property = "@type") | ||
@JsonSubTypes({ | ||
@JsonSubTypes.Type(value = ViewReferenceInfo.class, name = "view"), | ||
@JsonSubTypes.Type(value = RowFilterReferenceInfo.class, name = "rowFilter"), | ||
@JsonSubTypes.Type(value = ColumnMaskReferenceInfo.class, name = "columnMask")}) |
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.
airlift/airlift@d4e8ad9#diff-d272f3f6c0303cb179e0582fded0e5ed882dfdf944eef173dfcb6725d4a3e1d8
This could potentially allow us to remove these annotation
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.
No changes requested for my reference
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.
cool!
testing/trino-tests/src/test/java/io/trino/execution/TestEventListenerBasic.java
Show resolved
Hide resolved
testing/trino-tests/src/test/java/io/trino/execution/TestEventListenerBasic.java
Outdated
Show resolved
Hide resolved
testing/trino-tests/src/test/java/io/trino/execution/TestEventListenerBasic.java
Outdated
Show resolved
Hide resolved
testing/trino-tests/src/test/java/io/trino/execution/TestEventListenerBasic.java
Outdated
Show resolved
Hide resolved
testing/trino-tests/src/test/java/io/trino/execution/TestEventListenerBasic.java
Outdated
Show resolved
Hide resolved
4677de5
to
03746dc
Compare
Quick reminder on this @Praveen2112 |
03746dc
to
ee31c0f
Compare
Will take a look by early next week !! |
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 cleanup looks great !! Thanks for working on this
testing/trino-tests/src/test/java/io/trino/execution/TestEventListenerBasic.java
Outdated
Show resolved
Hide resolved
testing/trino-tests/src/test/java/io/trino/execution/TestEventListenerBasic.java
Outdated
Show resolved
Hide resolved
testing/trino-tests/src/test/java/io/trino/execution/TestEventListenerBasic.java
Outdated
Show resolved
Hide resolved
testing/trino-tests/src/test/java/io/trino/execution/TestEventListenerBasic.java
Outdated
Show resolved
Hide resolved
testing/trino-tests/src/test/java/io/trino/execution/TestEventListenerBasic.java
Outdated
Show resolved
Hide resolved
testing/trino-tests/src/test/java/io/trino/execution/TestEventListenerBasic.java
Outdated
Show resolved
Hide resolved
testing/trino-tests/src/test/java/io/trino/execution/TestEventListenerBasic.java
Outdated
Show resolved
Hide resolved
testing/trino-tests/src/test/java/io/trino/execution/TestEventListenerBasic.java
Outdated
Show resolved
Hide resolved
b4d7238
to
2582208
Compare
Can we fix the maven failures (related to codestyle) |
2582208
to
432c4e9
Compare
Yup fixed and made sure to run |
Failures don't look related:
Going to re-trigger ... |
432c4e9
to
11166fa
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 working on this. Minor nits
testing/trino-tests/src/test/java/io/trino/common/assertions/TableInfoAssert.java
Outdated
Show resolved
Hide resolved
testing/trino-tests/src/test/java/io/trino/common/assertions/TableInfoAssert.java
Outdated
Show resolved
Hide resolved
public static TableInfoAssert assertThat(TableInfo actual) | ||
{ | ||
return new TableInfoAssert(actual); | ||
} |
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: Can we move this assertion method to TableInfoAssert.java
as a public static method.
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.
Are you suggesting this only for the TableInfoAssert
, for for all 4 of the methods in this class? (Note that the second commit adds 3 more methods here.)
I pulled everything into this one class to allow for a single static import, that then selects the correct assert based on the static type of the object:
import io.trino.common.assertions.TrinoAssertions.assertThat;
As opposed to:
import io.trino.common.assertions.TableInfoAssert.assertThat;
import io.trino.common.assertions.TableReferenceInfoAssert.assertThat;
import io.trino.common.assertions.BaseViewReferenceInfoAssert.assertThat;
import io.trino.common.assertions.FilterMaskReferenceInfoAssert.assertThat;
Especially if more fluent assertions are added in the future, this will provide a nifty entrypoint to discover all of the existing ones.
This is in line with how AssertJ itself works (see Assertions), and how they show adding custom assertions in their examples, e.g.: https://github.com/assertj/assertj-examples/blob/main/assertions-examples/src/test/java/org/assertj/examples/custom/UberSoftAssertions.java
11166fa
to
346908b
Compare
346908b
to
ffd971a
Compare
@xkrogen Thanks for working on this |
Woohoo! Thanks a lot for all of the help @Praveen2112 , very happy with the end state of this. And thanks for putting up with my many nagging reminders :) |
Does this need a release note? @xkrogen @Praveen2112 |
Yeah !! We could have something like
|
In #7330, a flag
directlyReferenced
was added toTableInfo
to indicate whether a given table or view was directly referenced, or indirectly referenced via a view/filter/mask. This is useful, but lacks the information necessary to understand what caused the indirect reference. Understanding the context can be useful for auditing purposes, as well as general lineage use cases.As one motivating example, let us say we have have the following:
foo
contains user data (PII)foo_sanitized
provides a view overfoo
with PII columns removedfoo_dirty
defined asSELECT * FROM foo
bar
, PII cannot be usedAuditing is one way to enforce that queries run for
bar
only make use offoo_sanitized
rather than accessingfoo
directly. However currently we can only tell thatfoo
was indirectly referenced, e.g. we don't know if it was accessed viafoo_dirty
orfoo_sanitized
, and thus cannot determine if the access met the requirement.Similarly, let us envision that we want to notify all consumers of a table
foo
of some impending migration/deprecation. It's not sufficient to just know thatfoo
was accessed by way of a view; we need to know which view caused that access, so that we can identify the view owner to notify.To achieve this, a new field
referenceChain
is added toTableInfo
. This shows the chain of references leading from the direct reference to the view/table. For example assume we have the following:For the
SELECT
query we will see the following values forTableInfo#referenceChain
:In this way we can clearly identify where the access originated from. This PR also proposes including the text of a view in the
TableInfo
entry for views, to make it easier to understand which transformations were applied.This mainly focuses on views, but also accommodates column masks and row filters as part of the reference chain. Assuming the same setup as above, but also with a row filter applied on table
foo
likeuserid IN (SELECT userid FROM allowed_users)
, we would see:Since row filters / column masks aren't named, they are identified by their target table and the expression.
This creates a new interface
TableReferenceInfo
in the SPI to represent these entities that can reference other tables. There are concrete subclasses for views, column masks, and row filters.