pabloem commented on code in PR #17159:
URL: https://github.com/apache/beam/pull/17159#discussion_r864044533


##########
sdks/python/apache_beam/io/gcp/bigquery_test.py:
##########
@@ -482,6 +484,34 @@ def test_temp_dataset_is_configurable(
     delete_table.assert_called_with(
         temp_dataset.projectId, temp_dataset.datasetId, mock.ANY)
 
+  @pytest.mark.it_postcommit
+  def test_table_schema_retrieve(self):
+    the_table = apache_beam.io.gcp.bigquery.bigquery_tools.BigQueryWrapper(
+    ).get_table(
+        project_id="apache-beam-testing",
+        dataset_id="beam_bigquery_io_test",
+        table_id="dfsqltable_3c7d6fd5_16e0460dfd0")
+    table = the_table.schema
+    utype = bigquery_schema_tools.produce_pcoll_with_schema(table)
+    with beam.Pipeline() as p:
+      result = (
+          p | apache_beam.io.gcp.bigquery.ReadFromBigQuery(
+              gcs_location="gs://bqio_schema",
+              table="beam_bigquery_io_test.dfsqltable_3c7d6fd5_16e0460dfd0",
+              project="apache-beam-testing")
+          | apache_beam.io.gcp.bigquery.ReadFromBigQuery.get_pcoll_from_schema(
+              table))
+      assert_that(
+          result,
+          equal_to([
+              utype(id=3, name='customer1', type='test'),
+              utype(id=1, name='customer1', type='test'),
+              utype(id=2, name='customer2', type='test'),
+              utype(id=4, name='customer2', type='test')
+          ]))

Review Comment:
   This suggestion will not work out-of-the-box, but since you're trying to 
verify the data and the schema, you could do something like this:
   
   ```suggestion
                 table))
         assert_that(
             result | beam.Map(lambda x: {id: x.id, name:x.name, type: x.type}),
             equal_to([
                 {id:3, name:'customer1', type:'test'},
                 {id:1, name:'customer1', type:'test'},
                 {id:2, name:'customer2', type:'test'},
                 {id:4, name:'customer2', type:'test'}
             ]))
             
            self.assertEqual(result.schema, {'id': 'INT64', 'name': 'STRING', 
'type': 'STRING'})
   ```



-- 
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]

Reply via email to