@@ -82,7 +82,8 @@ private void processQuery(JobContext context) throws IOException, InterruptedExc
8282 }
8383 Map <String , String > mandatoryConfig = ConfigurationUtil .getMandatoryConfig (
8484 configuration , BigQueryConfiguration .MANDATORY_CONFIG_PROPERTIES_INPUT );
85- String inputProjectId = mandatoryConfig .get (BigQueryConfiguration .INPUT_PROJECT_ID_KEY );
85+ String projectId = mandatoryConfig .get (BigQueryConfiguration .PROJECT_ID_KEY );
86+ String datasetProjectId = mandatoryConfig .get (BigQueryConfiguration .INPUT_PROJECT_ID_KEY );
8687 String datasetId = mandatoryConfig .get (BigQueryConfiguration .INPUT_DATASET_ID_KEY );
8788 String tableName = mandatoryConfig .get (BigQueryConfiguration .INPUT_TABLE_ID_KEY );
8889 String serviceAccount = configuration .get (BigQueryConstants .CONFIG_SERVICE_ACCOUNT , null );
@@ -93,26 +94,26 @@ private void processQuery(JobContext context) throws IOException, InterruptedExc
9394 String partitionToDate = configuration .get (BigQueryConstants .CONFIG_PARTITION_TO_DATE , null );
9495 String filter = configuration .get (BigQueryConstants .CONFIG_FILTER , null );
9596
96- com .google .cloud .bigquery .Table bigQueryTable =
97- BigQueryUtil . getBigQueryTable ( inputProjectId , datasetId , tableName , serviceAccount , isServiceAccountFilePath );
97+ com .google .cloud .bigquery .Table bigQueryTable = BigQueryUtil . getBigQueryTable (
98+ projectId , datasetProjectId , datasetId , tableName , serviceAccount , isServiceAccountFilePath );
9899 Type type = Objects .requireNonNull (bigQueryTable ).getDefinition ().getType ();
99100
100101 String query ;
101102 if (type == Type .VIEW || type == Type .MATERIALIZED_VIEW ) {
102- query = generateQueryForMaterializingView (datasetId , tableName , filter );
103+ query = generateQueryForMaterializingView (datasetProjectId , datasetId , tableName , filter );
103104 } else {
104- query = generateQuery (partitionFromDate , partitionToDate , filter , inputProjectId , datasetId , tableName ,
105- serviceAccount , isServiceAccountFilePath );
105+ query = generateQuery (partitionFromDate , partitionToDate , filter , projectId , datasetProjectId , datasetId ,
106+ tableName , serviceAccount , isServiceAccountFilePath );
106107 }
107108
108109 if (query != null ) {
109- TableReference sourceTable = new TableReference ().setDatasetId (datasetId ).setProjectId (inputProjectId )
110+ TableReference sourceTable = new TableReference ().setDatasetId (datasetId ).setProjectId (datasetProjectId )
110111 .setTableId (tableName );
111112 String location = bigQueryHelper .getTable (sourceTable ).getLocation ();
112113 String temporaryTableName = configuration .get (BigQueryConstants .CONFIG_TEMPORARY_TABLE_NAME );
113- TableReference exportTableReference = createExportTableReference (type , inputProjectId , datasetId ,
114+ TableReference exportTableReference = createExportTableReference (type , datasetProjectId , datasetId ,
114115 temporaryTableName , configuration );
115- runQuery (configuration , bigQueryHelper , inputProjectId , exportTableReference , query , location );
116+ runQuery (configuration , bigQueryHelper , projectId , exportTableReference , query , location );
116117 if (type == Type .VIEW || type == Type .MATERIALIZED_VIEW ) {
117118 configuration .set (BigQueryConfiguration .INPUT_PROJECT_ID_KEY ,
118119 configuration .get (BigQueryConstants .CONFIG_VIEW_MATERIALIZATION_PROJECT ));
@@ -123,14 +124,14 @@ private void processQuery(JobContext context) throws IOException, InterruptedExc
123124 }
124125 }
125126
126- private String generateQuery (String partitionFromDate , String partitionToDate , String filter ,
127- String project , String dataset , String table , @ Nullable String serviceAccount ,
127+ private String generateQuery (String partitionFromDate , String partitionToDate , String filter , String project ,
128+ String datasetProject , String dataset , String table , @ Nullable String serviceAccount ,
128129 @ Nullable Boolean isServiceAccountFilePath ) {
129130 if (partitionFromDate == null && partitionToDate == null && filter == null ) {
130131 return null ;
131132 }
132133 String queryTemplate = "select * from %s where %s" ;
133- com .google .cloud .bigquery .Table sourceTable = BigQueryUtil .getBigQueryTable (project , dataset , table ,
134+ com .google .cloud .bigquery .Table sourceTable = BigQueryUtil .getBigQueryTable (project , datasetProject , dataset , table ,
134135 serviceAccount ,
135136 isServiceAccountFilePath );
136137 StandardTableDefinition tableDefinition = Objects .requireNonNull (sourceTable ).getDefinition ();
@@ -154,35 +155,35 @@ private String generateQuery(String partitionFromDate, String partitionToDate, S
154155 }
155156 }
156157
157- String tableName = dataset + "." + table ;
158+ String tableName = datasetProject + "." + dataset + "." + table ;
158159 return String .format (queryTemplate , tableName , condition .toString ());
159160 }
160161
161- private String generateQueryForMaterializingView (String dataset , String table , String filter ) {
162+ private String generateQueryForMaterializingView (String datasetProject , String dataset , String table , String filter ) {
162163 String queryTemplate = "select * from %s %s" ;
163164 StringBuilder condition = new StringBuilder ();
164165
165166 if (!Strings .isNullOrEmpty (filter )) {
166167 condition .append (String .format (" where %s" , filter ));
167168 }
168169
169- String tableName = dataset + "." + table ;
170+ String tableName = datasetProject + "." + dataset + "." + table ;
170171 return String .format (queryTemplate , tableName , condition .toString ());
171172 }
172173
173174 /**
174175 * Create {@link TableReference} to export Table or View
175176 *
176177 * @param type BigQuery table type
177- * @param inputProjectId project id of source table
178+ * @param datasetProjectId project id of source table
178179 * @param datasetId dataset id of source table
179180 * @param tableId The ID of the table
180181 * @param configuration Configuration that contains View Materialization ProjectId and View
181182 * Materialization Dataset Id
182183 * @return {@link TableReference}
183184 */
184185 private TableReference createExportTableReference (
185- Type type , String inputProjectId ,
186+ Type type , String datasetProjectId ,
186187 String datasetId ,
187188 String tableId ,
188189 Configuration configuration ) {
@@ -193,7 +194,7 @@ private TableReference createExportTableReference(
193194 tableReference .setProjectId (configuration .get (BigQueryConstants .CONFIG_VIEW_MATERIALIZATION_PROJECT ));
194195 tableReference .setDatasetId (configuration .get (BigQueryConstants .CONFIG_VIEW_MATERIALIZATION_DATASET ));
195196 } else {
196- tableReference .setProjectId (inputProjectId );
197+ tableReference .setProjectId (datasetProjectId );
197198 tableReference .setDatasetId (datasetId );
198199 }
199200
0 commit comments