-
Notifications
You must be signed in to change notification settings - Fork 4.6k
feat(bigquery): add BigLake configuration support for Storage Write API #36225
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
cfa21a7
feat(bigquery): add BigLake configuration support for Storage Write API
liferoad 9bc296a
fixed errors
liferoad 1a7e5fa
mock
liferoad 81ea948
fixed tests
liferoad 804b9d3
fixed tests
liferoad 96ff0c0
mock tests
liferoad 1596361
added one IT
liferoad 2a9ecdf
added the gcs checks
liferoad fe5a344
fixed tests
liferoad 909898d
lint
liferoad 1bc0104
Merge branch 'master' into biglake-table-create
liferoad 9bc57ae
lint
liferoad 0a91bbf
fixed the tests
liferoad 54de061
fixed the test
liferoad 1b035e5
lint
liferoad 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
2 changes: 1 addition & 1 deletion
2
.github/trigger_files/beam_PostCommit_Python_Xlang_Gcp_Dataflow.json
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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| { | ||
| "comment": "Modify this file in a trivial way to cause this test suite to run", | ||
| "modification": 13 | ||
| "modification": 14 | ||
| } |
2 changes: 1 addition & 1 deletion
2
.github/trigger_files/beam_PostCommit_Python_Xlang_IO_Dataflow.json
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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| { | ||
| "comment": "Modify this file in a trivial way to cause this test suite to run", | ||
| "modification": 4 | ||
| "modification": 5 | ||
| } |
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
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
117 changes: 117 additions & 0 deletions
117
sdks/python/apache_beam/io/gcp/bigquery_biglake_test.py
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 |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| # | ||
|
liferoad marked this conversation as resolved.
|
||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
|
|
||
| """Unit tests for BigQuery BigLake configuration.""" | ||
|
|
||
| import unittest | ||
| from unittest import mock | ||
|
|
||
| from apache_beam.io.gcp import bigquery | ||
|
|
||
|
|
||
| @mock.patch('apache_beam.io.gcp.bigquery.BeamJarExpansionService') | ||
| class BigQueryBigLakeTest(unittest.TestCase): | ||
| """Test BigLake configuration support in BigQuery Storage Write API.""" | ||
| def test_storage_write_to_bigquery_with_biglake_config( | ||
| self, mock_expansion_service): | ||
| """Test that StorageWriteToBigQuery accepts bigLakeConfiguration.""" | ||
| big_lake_config = { | ||
| 'connectionId': ( | ||
| 'projects/test-project/locations/us/connections/test-connection'), | ||
| 'storageUri': 'gs://test-bucket/test-path', | ||
| 'fileFormat': 'parquet', | ||
| 'tableFormat': 'iceberg' | ||
| } | ||
|
|
||
| # Test that the constructor accepts the bigLakeConfiguration parameter | ||
| transform = bigquery.StorageWriteToBigQuery( | ||
| table='test-project:test_dataset.test_table', | ||
| big_lake_configuration=big_lake_config) | ||
|
|
||
| # Verify the configuration is stored | ||
| self.assertEqual(transform._big_lake_configuration, big_lake_config) | ||
|
|
||
| def test_storage_write_to_bigquery_without_biglake_config( | ||
| self, mock_expansion_service): | ||
| """Test that StorageWriteToBigQuery works without bigLakeConfiguration.""" | ||
| transform = bigquery.StorageWriteToBigQuery( | ||
| table='test-project:test_dataset.test_table') | ||
|
|
||
| # Verify the configuration is None by default | ||
| self.assertIsNone(transform._big_lake_configuration) | ||
|
|
||
| def test_biglake_config_passed_to_external_transform( | ||
| self, mock_expansion_service): | ||
| """Test that StorageWriteToBigQuery accepts bigLakeConfiguration.""" | ||
| big_lake_config = { | ||
| 'connection_id': 'projects/my-project/locations/us/connections/my-conn', | ||
| 'table_format': 'ICEBERG' | ||
| } | ||
|
|
||
| # Mock the expansion service to avoid JAR dependency | ||
| mock_expansion_service.return_value = mock.MagicMock() | ||
|
|
||
| # Create the transform | ||
| transform = bigquery.StorageWriteToBigQuery( | ||
| table='my-project:my_dataset.my_table', | ||
| big_lake_configuration=big_lake_config) | ||
|
|
||
| # Verify the big_lake_configuration is stored correctly | ||
| self.assertEqual(transform._big_lake_configuration, big_lake_config) | ||
|
|
||
| # Verify that the transform has the expected identifier | ||
| self.assertEqual( | ||
| transform.IDENTIFIER, | ||
| "beam:schematransform:org.apache.beam:bigquery_storage_write:v2") | ||
|
|
||
| # Verify that the expansion service was created (mocked) | ||
| mock_expansion_service.assert_called_once_with( | ||
| 'sdks:java:io:google-cloud-platform:expansion-service:build') | ||
|
|
||
| def test_biglake_config_validation(self, mock_expansion_service): | ||
| """Test validation of bigLakeConfiguration parameters.""" | ||
| # Test with minimal required configuration | ||
| minimal_config = { | ||
| 'connectionId': ( | ||
| 'projects/test-project/locations/us/connections/test-connection'), | ||
| 'storageUri': 'gs://test-bucket/test-path' | ||
| } | ||
|
|
||
| transform = bigquery.StorageWriteToBigQuery( | ||
| table='test-project:test_dataset.test_table', | ||
| big_lake_configuration=minimal_config) | ||
|
|
||
| self.assertEqual(transform._big_lake_configuration, minimal_config) | ||
|
|
||
| # Test with full configuration | ||
| full_config = { | ||
| 'connectionId': ( | ||
| 'projects/test-project/locations/us/connections/test-connection'), | ||
| 'storageUri': 'gs://test-bucket/test-path', | ||
| 'fileFormat': 'parquet', | ||
| 'tableFormat': 'iceberg' | ||
| } | ||
|
|
||
| transform = bigquery.StorageWriteToBigQuery( | ||
| table='test-project:test_dataset.test_table', | ||
| big_lake_configuration=full_config) | ||
|
|
||
| self.assertEqual(transform._big_lake_configuration, full_config) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() | ||
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.
I dont think we need changes to this file
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.
Need this to run the tests locally on mac