use of com.facebook.presto.plugin.bigquery.BigQueryErrorCode.BIGQUERY_FAILED_TO_EXECUTE_QUERY in project presto by prestodb.
the class BigQuerySplitManager method createEmptyProjection.
private List<BigQuerySplit> createEmptyProjection(TableId tableId, int actualParallelism, Optional<String> filter) {
try {
long numberOfRows;
if (filter.isPresent()) {
// count the rows based on the filter
String sql = bigQueryClient.createFormatSql(tableId, "COUNT(*)", new String[] { filter.get() });
TableResult result = bigQueryClient.query(sql);
numberOfRows = result.iterateAll().iterator().next().get(0).getLongValue();
} else {
// no filters, so we can take the value from the table info
numberOfRows = bigQueryClient.getTable(tableId).getNumRows().longValue();
}
long rowsPerSplit = numberOfRows / actualParallelism;
// need to be added to one of the split due to integer division
long remainingRows = numberOfRows - (rowsPerSplit * actualParallelism);
List<BigQuerySplit> splits = range(0, actualParallelism).mapToObj(ignored -> BigQuerySplit.emptyProjection(rowsPerSplit)).collect(toList());
splits.set(0, BigQuerySplit.emptyProjection(rowsPerSplit + remainingRows));
return splits;
} catch (BigQueryException e) {
throw new PrestoException(BIGQUERY_FAILED_TO_EXECUTE_QUERY, format("Failed to compute empty projection"), e);
}
}
Aggregations