-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(bigquery-jdbc): support qualified project delimiter in DefaultDataset property
#14240
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
Open
keshavdandeva
wants to merge
4
commits into
main
Choose a base branch
from
jdbc/pcnt-support-conn-prop
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
07dab29
feat(jdbc): support qualified project delimiter in `DefaultDataset` p…
keshavdandeva 5da078c
add domain-scoped project support
keshavdandeva 7cd894d
add test for tpc
keshavdandeva c6edfae
Merge branch 'main' into jdbc/pcnt-support-conn-prop
keshavdandeva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
|
|
||
| import com.google.api.client.util.escape.CharEscapers; | ||
| import com.google.cloud.bigquery.BigQueryOptions; | ||
| import com.google.cloud.bigquery.DatasetId; | ||
| import com.google.cloud.bigquery.exception.BigQueryJdbcRuntimeException; | ||
| import com.google.common.base.Splitter; | ||
| import com.google.common.collect.ImmutableList; | ||
|
|
@@ -924,4 +925,44 @@ static Map<String, String> parsePropertiesMapFromValue( | |
| } | ||
| return propertiesMap; | ||
| } | ||
|
|
||
| static DatasetId parseDefaultDataset(String defaultDataset) { | ||
| if (defaultDataset == null || defaultDataset.trim().isEmpty()) { | ||
| return null; | ||
| } | ||
|
|
||
| String trimmed = defaultDataset.trim(); | ||
| int colonIdx = trimmed.lastIndexOf(':'); | ||
| if (colonIdx >= 0) { | ||
| return splitQualifiedDataset(trimmed, colonIdx, ':'); | ||
| } | ||
|
|
||
| int dotIdx = trimmed.indexOf('.'); | ||
| if (dotIdx >= 0) { | ||
| return splitQualifiedDataset(trimmed, dotIdx, '.'); | ||
| } | ||
|
|
||
| return DatasetId.of(trimmed); | ||
| } | ||
|
keshavdandeva marked this conversation as resolved.
|
||
|
|
||
| private static DatasetId splitQualifiedDataset(String trimmed, int delimiterIdx, char delimiter) { | ||
| if (trimmed.indexOf(delimiter, delimiterIdx + 1) >= 0) { | ||
| throw invalidDefaultDatasetException(); | ||
| } | ||
| String project = trimmed.substring(0, delimiterIdx).trim(); | ||
| String dataset = trimmed.substring(delimiterIdx + 1).trim(); | ||
| if (project.isEmpty() || dataset.isEmpty()) { | ||
| throw invalidDefaultDatasetException(); | ||
| } | ||
| return DatasetId.of(project, dataset); | ||
| } | ||
|
|
||
| private static IllegalArgumentException invalidDefaultDatasetException() { | ||
|
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. We have separate |
||
| IllegalArgumentException ex = | ||
| new IllegalArgumentException( | ||
| "DefaultDataset format is invalid. Supported options are datasetId," | ||
| + " projectId:datasetId, or projectId.datasetId"); | ||
| LOG.severe(ex.getMessage(), ex); | ||
| return ex; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,10 +18,13 @@ | |
|
|
||
| import static com.google.common.truth.Truth.assertThat; | ||
| import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| import com.google.cloud.bigquery.DatasetId; | ||
| import com.google.cloud.bigquery.exception.BigQueryJdbcRuntimeException; | ||
| import java.util.Collections; | ||
| import java.util.Map; | ||
|
|
@@ -279,4 +282,84 @@ public void testParseEnableProjectDiscovery() { | |
| String result2 = BigQueryJdbcUrlUtility.parseUriProperty(url2, "EnableProjectDiscovery"); | ||
| assertThat(result2).isEqualTo("false"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testParseDefaultDataset_singleIdentifier() { | ||
| DatasetId datasetId = BigQueryJdbcUrlUtility.parseDefaultDataset("my_dataset"); | ||
| assertNotNull(datasetId); | ||
| assertEquals("my_dataset", datasetId.getDataset()); | ||
| assertNull(datasetId.getProject()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testParseDefaultDataset_colonDelimited() { | ||
| DatasetId datasetId = BigQueryJdbcUrlUtility.parseDefaultDataset("my-project:my_dataset"); | ||
| assertNotNull(datasetId); | ||
| assertEquals("my_dataset", datasetId.getDataset()); | ||
| assertEquals("my-project", datasetId.getProject()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testParseDefaultDataset_dotDelimited() { | ||
| DatasetId datasetId = BigQueryJdbcUrlUtility.parseDefaultDataset("my-project.my_dataset"); | ||
| assertNotNull(datasetId); | ||
| assertEquals("my_dataset", datasetId.getDataset()); | ||
| assertEquals("my-project", datasetId.getProject()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testParseDefaultDataset_threeTierPcntNamespace() { | ||
| DatasetId datasetId = | ||
| BigQueryJdbcUrlUtility.parseDefaultDataset("my-project:my-warehouse.my_namespace"); | ||
| assertNotNull(datasetId); | ||
| assertEquals("my-warehouse.my_namespace", datasetId.getDataset()); | ||
| assertEquals("my-project", datasetId.getProject()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testParseDefaultDataset_twoTierPcntNamespace() { | ||
|
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. This test is incorrect, |
||
| DatasetId datasetId = BigQueryJdbcUrlUtility.parseDefaultDataset("my-warehouse.my_namespace"); | ||
| assertNotNull(datasetId); | ||
| assertEquals("my_namespace", datasetId.getDataset()); | ||
| assertEquals("my-warehouse", datasetId.getProject()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testParseDefaultDataset_tpcProject() { | ||
| DatasetId datasetId = BigQueryJdbcUrlUtility.parseDefaultDataset("tpc:my-project:my_dataset"); | ||
| assertNotNull(datasetId); | ||
| assertEquals("my_dataset", datasetId.getDataset()); | ||
| assertEquals("tpc:my-project", datasetId.getProject()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testParseDefaultDataset_tpcProject_threeTierPcntNamespace() { | ||
| DatasetId datasetId = | ||
| BigQueryJdbcUrlUtility.parseDefaultDataset("tpc:my-project:my-warehouse.my_namespace"); | ||
| assertNotNull(datasetId); | ||
| assertEquals("my-warehouse.my_namespace", datasetId.getDataset()); | ||
| assertEquals("tpc:my-project", datasetId.getProject()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testParseDefaultDataset_invalidFormats() { | ||
|
keshavdandeva marked this conversation as resolved.
|
||
| assertThrows( | ||
| IllegalArgumentException.class, | ||
| () -> BigQueryJdbcUrlUtility.parseDefaultDataset("my-project:")); | ||
| assertThrows( | ||
| IllegalArgumentException.class, | ||
| () -> BigQueryJdbcUrlUtility.parseDefaultDataset(":my_dataset")); | ||
| assertThrows( | ||
| IllegalArgumentException.class, | ||
| () -> BigQueryJdbcUrlUtility.parseDefaultDataset("tpc:my-project:")); | ||
| assertThrows( | ||
| IllegalArgumentException.class, | ||
| () -> BigQueryJdbcUrlUtility.parseDefaultDataset("my-project.")); | ||
| assertThrows( | ||
| IllegalArgumentException.class, | ||
| () -> BigQueryJdbcUrlUtility.parseDefaultDataset(".my_dataset")); | ||
| assertThrows( | ||
| IllegalArgumentException.class, | ||
| () -> BigQueryJdbcUrlUtility.parseDefaultDataset("part1.part2.part3")); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 won't support
.as a delimeter forprojectId<>datasetId. The reason is that we can't distinguishprojectId.datasetIdfromcatalog.namespace