-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Cleanup DLP Risk Analysis snippets #2069
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
Conversation
Please fix compile problems |
ProjectSubscriptionName.of(projectId, subscriptionId); | ||
|
||
MessageReceiver handleMessage = | ||
(PubsubMessage pubsubMessage, AckReplyConsumer ackReplyConsumer) -> { |
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 probably too long for a lamba - can you surface it out into a full function? I think within the class is still fine
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 was unsure of how to do this when the lambda used variables outside of the scope of the function, like dlpJob
and done
. handleMessage
needs to be callable so I need to return a function. I'm not sure if there's a way to build functions using closures in Java? I ended up nesting the lambda within another function, and passing the DlpJob
and Future
to that function in in c634313, but that seems more complicated and less readable to me? Thoughts?
// Retrieve completed job status | ||
DlpJob completedJob = | ||
dlpServiceClient.getDlpJob( | ||
GetDlpJobRequest.newBuilder() |
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.
Can we pull the request build into a separate var/line? I think that will actually make this shorter.
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.
resolved in 8546690
// Get the result and parse through and process the information | ||
CategoricalStatsResult result = | ||
completedJob.getRiskDetails().getCategoricalStatsResult(); | ||
|
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: remove newline
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.
Resolved
CategoricalStatsResult result = | ||
completedJob.getRiskDetails().getCategoricalStatsResult(); | ||
|
||
for (CategoricalStatsHistogramBucket bucket : |
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: I would pull result.getValueFrequencyHistogramBucketsList()
into it's own line too (still 2 lines, but easier to read)
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.
(same for a couple of statements below, but up to you)
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.
fixed in e6d4f91
String tableId = "your-bigquery-table-id"; | ||
String topicId = "pub-sub-topic"; | ||
String subscriptionId = "pub-sub-subscription"; | ||
List<String> quasiIdColumns = Arrays.asList("name", "age", "zip_code", "..."); |
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.
These should be inline - not required for testing
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.
Resolved in 8546690
ProjectSubscriptionName.of(projectId, subscriptionId); | ||
|
||
MessageReceiver handleMessage = | ||
(PubsubMessage pubsubMessage, AckReplyConsumer ackReplyConsumer) -> { |
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.
Long lamba again
KMapEstimationResult kmapResult = completedJob.getRiskDetails().getKMapEstimationResult(); | ||
|
||
for (KMapEstimationHistogramBucket result : kmapResult.getKMapEstimationHistogramList()) { | ||
|
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: no newline
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.
resolved in 92ea643
.getQuasiIdsValuesList() | ||
.stream() | ||
.map( | ||
v -> { |
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.
A comment on this function would be helpful.
nit: Does there have to be a new line before v -> {
(might be a java format thing, just looks weird to me)?
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.
fixed the weird formatting thing, and also rewrote this part to be a bit clearer and more consistent with other samples in e6d4f91. I can also go in and comment on it if that's still necessary.
String topicId, | ||
String subscriptionId, | ||
String sensitiveAttribute, | ||
List<String> quasiIds) throws Exception { |
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.
sensitiveAttribute, quasiIds inlined
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.
resolved in 82c1f07
ProjectSubscriptionName.of(projectId, subscriptionId); | ||
|
||
MessageReceiver handleMessage = | ||
(PubsubMessage pubsubMessage, AckReplyConsumer ackReplyConsumer) -> { |
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.
Long lambda
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.
See my previous comment about the lambda. Also, this lambda is also used in the Inspect snippets, so if we change it here, we should probably change it there as well.
9d2733f
to
b8e00a5
Compare
b8e00a5
to
0df96fc
Compare
0df96fc
to
c634313
Compare
Presubmit tests are going to fail because of linting errors in other files outside of this PR. Those fixes are handled in #2083, since we probably don't want all of those changes in this PR |
92ea643
to
673fec4
Compare
throw new IllegalArgumentException("The numbers of quasi-IDs and infoTypes must be equal!"); | ||
} | ||
|
||
ArrayList<TaggedField> taggedFields = |
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: Does this need to be an ArrayList
or can it be just a List
?
} | ||
|
||
ArrayList<TaggedField> taggedFields = | ||
IntStream.range(0, quasiIds.size()) |
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: This might just be a case where it is easier to read as a for loop.
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.
replaced with a for loop in 0e72a97
forcing merge - (broken tests tracking in #1479) |
* refactored Risk analysis samples * updated inspect tests and readme * moved parameters to inline, cleaned up files, reformatted for consistency * replaced iterators with intstream in RiskAnalysisKMap * moved message receiver lambda to its own method * ran code formatter * refactored long messageReciever lambda * rewrote lambda for pubsub message receiver * replaced int stream with for loop
Working towards #1479
This ended up being a larger PR than expected. I can split it up if needed.