claudevdm commented on code in PR #39597:
URL: https://github.com/apache/beam/pull/39597#discussion_r3814375386
##########
sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryHelpersTest.java:
##########
@@ -101,13 +103,368 @@ public void testTableParsing_noProjectId() {
assertEquals("table_name", ref.getTableId());
}
+ @Test
+ public void testTableParsing_lakehouseCatalogDotted() {
+ // 4-part Lakehouse runtime catalog reference:
project.catalog.namespace.table. The
+ // catalog+namespace form a composite dataset id, including when the
catalog name uses the
+ // GCS-bucket charset (lowercase, digits, dashes).
+ TableReference ref =
BigQueryHelpers.parseTableSpec("my-project.my-bucket-catalog.my_ns.tbl");
+ assertEquals("my-project", ref.getProjectId());
+ assertEquals("my-bucket-catalog.my_ns", ref.getDatasetId());
+ assertEquals("tbl", ref.getTableId());
+ }
+
+ @Test
+ public void testTableParsing_lakehouseCatalogColon() {
+ TableReference ref =
BigQueryHelpers.parseTableSpec("my-project:my-catalog.my_ns.tbl");
+ assertEquals("my-project", ref.getProjectId());
+ assertEquals("my-catalog.my_ns", ref.getDatasetId());
+ assertEquals("tbl", ref.getTableId());
+ }
+
+ @Test
+ public void testTableParsing_lakehouseCatalogNoProject() {
+ // Dataset ids may contain characters that project ids may not (e.g. '_'),
in which case the
+ // whole prefix is the (composite) dataset id.
+ TableReference ref =
BigQueryHelpers.parseTableSpec("my_catalog.my_ns.tbl");
+ assertEquals(null, ref.getProjectId());
+ assertEquals("my_catalog.my_ns", ref.getDatasetId());
+ assertEquals("tbl", ref.getTableId());
+ }
+
+ @Test
+ public void testTableParsing_multiLevelNamespace() {
+ // More than four segments: everything between the project and the table
becomes the dataset.
+ TableReference ref =
BigQueryHelpers.parseTableSpec("my-project.cat.ns1.ns2.tbl");
+ assertEquals("my-project", ref.getProjectId());
+ assertEquals("cat.ns1.ns2", ref.getDatasetId());
+ assertEquals("tbl", ref.getTableId());
+ }
+
+ @Test
+ public void testTableParsing_lakehouseWithPartitionDecorator() {
+ TableReference ref =
BigQueryHelpers.parseTableSpec("my-project.my-catalog.ns.tbl$20260101");
+ assertEquals("my-project", ref.getProjectId());
+ assertEquals("my-catalog.ns", ref.getDatasetId());
+ assertEquals("tbl$20260101", ref.getTableId());
+ }
+
+ @Test
+ public void testTableParsing_domainScopedProjectPreserved() {
+ // Legacy domain-scoped projects keep their historical binding.
+ TableReference ref =
BigQueryHelpers.parseTableSpec("example.com:project:data_set.tbl");
+ assertEquals("example.com:project", ref.getProjectId());
+ assertEquals("data_set", ref.getDatasetId());
+ assertEquals("tbl", ref.getTableId());
+
+ ref = BigQueryHelpers.parseTableSpec("example.com:project.data_set.tbl");
+ assertEquals("example.com:project", ref.getProjectId());
+ assertEquals("data_set", ref.getDatasetId());
+ assertEquals("tbl", ref.getTableId());
+ }
+
+ @Test
+ public void testTableParsing_domainScopedProjectWithCompositeDataset() {
+ // With two colons, the last colon is an explicit project terminator, so a
domain-scoped
+ // project can address a Lakehouse catalog table: the remainder binds as a
composite
+ // dataset.
+ TableReference ref =
BigQueryHelpers.parseTableSpec("example.com:project:cat.ns.tbl");
+ assertEquals("example.com:project", ref.getProjectId());
+ assertEquals("cat.ns", ref.getDatasetId());
+ assertEquals("tbl", ref.getTableId());
+
+ // The dotted spelling binds consistently: the first segment after the
colon completes the
+ // domain-scoped project id; further middle segments form the composite
dataset. (Project
+ // names cannot contain dots, so the pre-fix greedy binding of this string
was invalid.)
+ ref = BigQueryHelpers.parseTableSpec("example.com:project.cat.ns.tbl");
+ assertEquals("example.com:project", ref.getProjectId());
+ assertEquals("cat.ns", ref.getDatasetId());
+ assertEquals("tbl", ref.getTableId());
+ }
+
+ @Test
+ public void testTableParsing_partitionDecoratorColonForm() {
+ TableReference ref =
BigQueryHelpers.parseTableSpec("my-project:my-catalog.ns.tbl$20260101");
+ assertEquals("my-project", ref.getProjectId());
+ assertEquals("my-catalog.ns", ref.getDatasetId());
+ assertEquals("tbl$20260101", ref.getTableId());
+ }
+
+ @Test
+ public void testTableParsing_tableIdSpecialCharacters() {
+ // Table ids may contain spaces, '@', '$', dashes, and unicode letters,
none of which
+ // affect segment binding (only '.' and ':' are structural).
+ TableReference ref =
BigQueryHelpers.parseTableSpec("my-project.data_set.my table@x-1");
+ assertEquals("my-project", ref.getProjectId());
+ assertEquals("data_set", ref.getDatasetId());
+ assertEquals("my table@x-1", ref.getTableId());
+
+ ref = BigQueryHelpers.parseTableSpec("my-project.my-catalog.ns.ग्राहक");
+ assertEquals("my-project", ref.getProjectId());
+ assertEquals("my-catalog.ns", ref.getDatasetId());
+ assertEquals("ग्राहक", ref.getTableId());
+ }
+
+ @Test
+ public void testTableParsing_colonFormMultiLevelNamespace() {
+ TableReference ref =
BigQueryHelpers.parseTableSpec("my-project:cat.ns1.ns2.tbl");
+ assertEquals("my-project", ref.getProjectId());
+ assertEquals("cat.ns1.ns2", ref.getDatasetId());
+ assertEquals("tbl", ref.getTableId());
+ }
+
+ @Test
+ public void testTableParsing_domainScopedMultiLevelNamespace() {
+ // Single-colon domain-scoped spelling with a multi-level composite
dataset: the first
+ // segment after the colon completes the project id; everything else up to
the table binds
+ // as the dataset.
+ TableReference ref =
BigQueryHelpers.parseTableSpec("example.com:proj.cat.ns1.ns2.tbl");
+ assertEquals("example.com:proj", ref.getProjectId());
+ assertEquals("cat.ns1.ns2", ref.getDatasetId());
+ assertEquals("tbl", ref.getTableId());
+ }
+
+ @Test
+ public void testTableParsing_moreThanTwoColonsBindsAtLastColon() {
+ // More than two colons cannot form a valid reference (project ids contain
at most one
+ // colon), but such specs pass the character-set gate; they bind at the
last colon so the
+ // impossible project id is rejected by the service rather than producing
a malformed
+ // dataset id.
+ TableReference ref =
BigQueryHelpers.parseTableSpec("d1:d2:d3:data_set.tbl");
+ assertEquals("d1:d2:d3", ref.getProjectId());
+ assertEquals("data_set", ref.getDatasetId());
+ assertEquals("tbl", ref.getTableId());
+ }
Review Comment:
It passed the regex, but would fail on BQ api requests. I think failing
early is better but can revert if you want to be conservative here
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]