-
Notifications
You must be signed in to change notification settings - Fork 220
Add kms key to Bigquery config to be used in query #1461
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -378,6 +378,35 @@ public void testReadWithMixedParametersFails() { | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| assertThat(listener.getJobInfos()).isEmpty(); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| @Test | ||||||||||||||||||||||
| public void testReadFromQueryWithKmsKey() { | ||||||||||||||||||||||
| String random = String.valueOf(System.nanoTime()); | ||||||||||||||||||||||
| String query = | ||||||||||||||||||||||
| String.format( | ||||||||||||||||||||||
| "SELECT corpus, word_count FROM `bigquery-public-data.samples.shakespeare` WHERE word='spark' AND '%s'='%s'", | ||||||||||||||||||||||
| random, random); | ||||||||||||||||||||||
| String envKmsKey = System.getenv("BIGQUERY_KMS_KEY_NAME"); | ||||||||||||||||||||||
| String kmsKeyName = | ||||||||||||||||||||||
| envKmsKey != null ? envKmsKey : "projects/p/locations/l/keyRings/k/cryptoKeys/c"; | ||||||||||||||||||||||
| spark | ||||||||||||||||||||||
| .read() | ||||||||||||||||||||||
| .format("bigquery") | ||||||||||||||||||||||
| .option("viewsEnabled", true) | ||||||||||||||||||||||
| .option("materializationDataset", testDataset.toString()) | ||||||||||||||||||||||
| .option("destinationTableKmsKeyName", kmsKeyName) | ||||||||||||||||||||||
| .load(query) | ||||||||||||||||||||||
| .collect(); | ||||||||||||||||||||||
| // validate event publishing | ||||||||||||||||||||||
| List<JobInfo> jobInfos = listener.getJobInfos(); | ||||||||||||||||||||||
| assertThat(jobInfos).hasSize(1); | ||||||||||||||||||||||
| JobInfo jobInfo = jobInfos.iterator().next(); | ||||||||||||||||||||||
| assertThat( | ||||||||||||||||||||||
| ((QueryJobConfiguration) jobInfo.getConfiguration()) | ||||||||||||||||||||||
| .getDestinationEncryptionConfiguration() | ||||||||||||||||||||||
| .getKmsKeyName()) | ||||||||||||||||||||||
| .isEqualTo(kmsKeyName + "/cryptoKeyVersions/1"); | ||||||||||||||||||||||
|
Comment on lines
+404
to
+408
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The assertion for the KMS key name assumes a specific suffix (
Suggested change
|
||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| class TestBigQueryJobCompletionListener extends SparkListener { | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.