Skip to content

Commit

Permalink
BigQuery empty table and projectId casing issues fix (#2068)
Browse files Browse the repository at this point in the history
  • Loading branch information
VenkatasivareddyTR authored Jul 31, 2024
1 parent 21a6e11 commit 71bc398
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public class BigQueryMetadataHandler
extends MetadataHandler
{
private static final Logger logger = LoggerFactory.getLogger(BigQueryMetadataHandler.class);
private final String projectName = configOptions.get(BigQueryConstants.GCP_PROJECT_ID);
private final String projectName = configOptions.get(BigQueryConstants.GCP_PROJECT_ID) != null ?
configOptions.get(BigQueryConstants.GCP_PROJECT_ID).toLowerCase() : null;

private final BigQueryQueryPassthrough queryPassthrough = new BigQueryQueryPassthrough();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private void handleStandardQuery(BlockSpiller spiller,
List<QueryParameterValue> parameterValues,
BigQuery bigQueryClient) throws Exception
{
String projectName = configOptions.get(BigQueryConstants.GCP_PROJECT_ID);
String projectName = configOptions.get(BigQueryConstants.GCP_PROJECT_ID).toLowerCase();
String datasetName = fixCaseForDatasetName(projectName, recordsRequest.getTableName().getSchemaName(), bigQueryClient);
String tableName = fixCaseForTableName(projectName, datasetName, recordsRequest.getTableName().getTableName(), bigQueryClient);

Expand Down Expand Up @@ -263,7 +263,13 @@ private void getTableData(BlockSpiller spiller, ReadRecordsRequest recordsReques
// data available. If no sessions are available for an anonymous (cached) table, consider
// writing results of a query to a named table rather than consuming cached results
// directly.
Preconditions.checkState(session.getStreamsCount() > 0);
try {
Preconditions.checkState(session.getStreamsCount() > 0);
}
catch (IllegalStateException exp) {
logger.warn("No records found in the table: " + tableName);
return;
}

// Use the first stream to perform reading.
String streamName = session.getStreams(0).getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static BigQuery getBigQueryClient(java.util.Map<String, String> configOpt
if (StringUtils.isNotEmpty(endpoint)) {
bigqueryBuilder.setHost(endpoint);
}
bigqueryBuilder.setProjectId(configOptions.get(BigQueryConstants.GCP_PROJECT_ID));
bigqueryBuilder.setProjectId(configOptions.get(BigQueryConstants.GCP_PROJECT_ID).toLowerCase());
bigqueryBuilder.setCredentials(getCredentialsFromSecretsManager(configOptions));
return bigqueryBuilder.build().getService();
}
Expand Down

0 comments on commit 71bc398

Please sign in to comment.