feat: BigQuery Storage v1beta1 API migration guide#3338
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a migration guide for transitioning the BigQuery Storage API from v1beta1 to v1 in C#. The feedback focuses on making the C# code examples more idiomatic and robust. Key suggestions include using the strongly-typed TableName class instead of a raw string path, clarifying how ReadRowsStream relates to IAsyncEnumerable, and using var to avoid type ambiguity with System.IO.Stream.
| // Table path is now a string: projects/{project}/datasets/{dataset}/tables/{table} | ||
| string tablePath = "projects/bigquery-public-data/datasets/usa_names/tables/usa_1910_current"; | ||
|
|
||
| ReadSession.Types.TableReadOptions readOptions = new ReadSession.Types.TableReadOptions(); | ||
| readOptions.SelectedFields.Add("name"); | ||
| readOptions.RowRestriction = "state = 'WA'"; | ||
|
|
||
| // ReadSession holds the session configuration | ||
| ReadSession readSession = new ReadSession | ||
| { | ||
| Table = tablePath, | ||
| DataFormat = DataFormat.Avro, // Format renamed to DataFormat | ||
| ReadOptions = readOptions | ||
| }; |
There was a problem hiding this comment.
While you can use a string path for Table, Google Cloud .NET libraries provide a strongly-typed TableName class and a TableAsTableName property on ReadSession. This is more idiomatic, less error-prone, and matches the quickstart sample in this repository.
| // Table path is now a string: projects/{project}/datasets/{dataset}/tables/{table} | |
| string tablePath = "projects/bigquery-public-data/datasets/usa_names/tables/usa_1910_current"; | |
| ReadSession.Types.TableReadOptions readOptions = new ReadSession.Types.TableReadOptions(); | |
| readOptions.SelectedFields.Add("name"); | |
| readOptions.RowRestriction = "state = 'WA'"; | |
| // ReadSession holds the session configuration | |
| ReadSession readSession = new ReadSession | |
| { | |
| Table = tablePath, | |
| DataFormat = DataFormat.Avro, // Format renamed to DataFormat | |
| ReadOptions = readOptions | |
| }; | |
| // Table path can be a string or a strongly-typed TableName | |
| var tableName = new Google.Api.Gax.ResourceNames.TableName("bigquery-public-data", "usa_names", "usa_1910_current"); | |
| ReadSession.Types.TableReadOptions readOptions = new ReadSession.Types.TableReadOptions(); | |
| readOptions.SelectedFields.Add("name"); | |
| readOptions.RowRestriction = "state = 'WA'"; | |
| // ReadSession holds the session configuration | |
| ReadSession readSession = new ReadSession | |
| { | |
| TableAsTableName = tableName, | |
| DataFormat = DataFormat.Avro, // Format renamed to DataFormat | |
| ReadOptions = readOptions | |
| }; |
| In C#, `ReadRows` returns a `ReadRowsStream` which implements `IAsyncEnumerable` | ||
| or similar, allowing async iteration. |
There was a problem hiding this comment.
In C#, ReadRowsStream does not implement IAsyncEnumerable<T> directly. Instead, you call GetResponseStream() on it, which returns an AsyncResponseStream<T> that implements IAsyncEnumerable<T>. We should clarify this to avoid confusion.
| In C#, `ReadRows` returns a `ReadRowsStream` which implements `IAsyncEnumerable` | |
| or similar, allowing async iteration. | |
| In C#, ReadRows returns a ReadRowsStream. Calling GetResponseStream() on it returns an AsyncResponseStream which implements IAsyncEnumerable, allowing async iteration. |
| using Google.Cloud.BigQuery.Storage.V1Beta1; | ||
| using System.Threading.Tasks; | ||
|
|
||
| Stream stream = session.Streams[0]; |
There was a problem hiding this comment.
| using Google.Cloud.BigQuery.Storage.V1; | ||
| using System.Threading.Tasks; | ||
|
|
||
| ReadStream stream = session.Streams[0]; |
Fixes b/505001153. BigQuery Storage team is planning to deprecate v1beta1 API. This PR adds a migration guide from v1beta1 to v1.