4242import org .apache .beam .sdk .io .gcp .bigquery .BigQueryIO ;
4343import org .apache .beam .sdk .io .gcp .bigquery .BigQueryIO .TypedRead ;
4444import org .apache .beam .sdk .io .gcp .bigquery .BigQueryIO .TypedRead .Method ;
45+ import org .apache .beam .sdk .io .gcp .bigquery .BigQueryOptions ;
4546import org .apache .beam .sdk .io .gcp .bigquery .SchemaAndRecord ;
4647import org .apache .beam .sdk .io .parquet .ParquetIO ;
4748import org .apache .beam .sdk .options .Default ;
@@ -108,14 +109,22 @@ static class ReadSessionFactory {
108109 * Creates ReadSession for schema extraction.
109110 *
110111 * @param client BigQueryStorage client used to create ReadSession.
111- * @param tableString String that represents table to export from .
112+ * @param options BigQueryToParquetOptions options .
112113 * @param tableReadOptions TableReadOptions that specify any fields in the table to filter on.
113114 * @return session ReadSession object that contains the schema for the export.
114115 */
115116 static ReadSession create (
116- BigQueryStorageClient client , String tableString , TableReadOptions tableReadOptions ) {
117+ BigQueryStorageClient client ,
118+ BigQueryToParquetOptions options ,
119+ TableReadOptions tableReadOptions ) {
120+ String tableString = options .getTableRef ();
117121 TableReference tableReference = BigQueryHelpers .parseTableSpec (tableString );
118- String parentProjectId = "projects/" + tableReference .getProjectId ();
122+ BigQueryOptions bigQueryOptions = options .as (BigQueryOptions .class );
123+ String parentProjectId =
124+ bigQueryOptions .getBigQueryProject () == null
125+ ? bigQueryOptions .getProject ()
126+ : bigQueryOptions .getBigQueryProject ();
127+ String parentProjectIdResource = "projects/" + parentProjectId ;
119128
120129 TableReferenceProto .TableReference storageTableRef =
121130 TableReferenceProto .TableReference .newBuilder ()
@@ -126,7 +135,7 @@ static ReadSession create(
126135
127136 CreateReadSessionRequest .Builder builder =
128137 CreateReadSessionRequest .newBuilder ()
129- .setParent (parentProjectId )
138+ .setParent (parentProjectIdResource )
130139 .setReadOptions (tableReadOptions )
131140 .setTableReference (storageTableRef );
132141 try {
@@ -254,8 +263,7 @@ private static PipelineResult run(BigQueryToParquetOptions options) {
254263
255264 TableReadOptions tableReadOptions = builder .build ();
256265 BigQueryStorageClient client = BigQueryStorageClientFactory .create ();
257- ReadSession session =
258- ReadSessionFactory .create (client , options .getTableRef (), tableReadOptions );
266+ ReadSession session = ReadSessionFactory .create (client , options , tableReadOptions );
259267
260268 // Extract schema from ReadSession
261269 Schema schema = getTableSchema (session );
0 commit comments