When I try to fetch count from BigQuery dataset then It's throwing error like :
com.google.cloud.bigquery.BigQueryException: java.lang.NoSuchMethodError: com.google.gson.JsonParser.parseString(Ljava/lang/String;)Lcom/google/gson/JsonElement;
Code :
public static void main(String[] args) {
final String datasetName = "users";
String query =
" SELECT count(1) "
+ " FROM preprod.users.records"
+ " WHERE section_id = 'sectionId'";
query(query);
}
public static void query(String query) {
try {
BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
QueryJobConfiguration queryConfig = QueryJobConfiguration.of(query);
TableResult results = bigquery.query(queryConfig);
results
.iterateAll()
.forEach(row -> row.forEach(val -> System.out.printf("%s,", val.toString())));
System.out.println("Query performed successfully.");
} catch (BigQueryException | InterruptedException e) {
System.out.println("Query not performed \n" + e.toString());
}
}
Version :
implementation platform('com.google.cloud:libraries-bom:26.1.4')
implementation group: 'com.google.cloud', name: 'google-cloud-bigquery', version: '2.18.2'
I've taken reference from the https://cloud.google.com/bigquery/docs/reference/libraries#client-libraries-install-java