Search in sources :

Example 1 with BIGQUERY_FAILED_TO_EXECUTE_QUERY

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);
    }
}
Also used : Logger(com.facebook.airlift.log.Logger) ConnectorSplitSource(com.facebook.presto.spi.ConnectorSplitSource) ReadSession(com.google.cloud.bigquery.storage.v1beta1.Storage.ReadSession) IntStream.range(java.util.stream.IntStream.range) Inject(com.google.inject.Inject) ConnectorTableLayoutHandle(com.facebook.presto.spi.ConnectorTableLayoutHandle) TableId(com.google.cloud.bigquery.TableId) BigQueryException(com.google.cloud.bigquery.BigQueryException) PrestoException(com.facebook.presto.spi.PrestoException) OptionalInt(java.util.OptionalInt) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) BIGQUERY_FAILED_TO_EXECUTE_QUERY(com.facebook.presto.plugin.bigquery.BigQueryErrorCode.BIGQUERY_FAILED_TO_EXECUTE_QUERY) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) TableResult(com.google.cloud.bigquery.TableResult) ConnectorSplitManager(com.facebook.presto.spi.connector.ConnectorSplitManager) NodeManager(com.facebook.presto.spi.NodeManager) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) FixedSplitSource(com.facebook.presto.spi.FixedSplitSource) String.format(java.lang.String.format) ConnectorSession(com.facebook.presto.spi.ConnectorSession) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ColumnHandle(com.facebook.presto.spi.ColumnHandle) Optional(java.util.Optional) TableResult(com.google.cloud.bigquery.TableResult) PrestoException(com.facebook.presto.spi.PrestoException) BigQueryException(com.google.cloud.bigquery.BigQueryException)

Aggregations

Logger (com.facebook.airlift.log.Logger)1 BIGQUERY_FAILED_TO_EXECUTE_QUERY (com.facebook.presto.plugin.bigquery.BigQueryErrorCode.BIGQUERY_FAILED_TO_EXECUTE_QUERY)1 ColumnHandle (com.facebook.presto.spi.ColumnHandle)1 ConnectorSession (com.facebook.presto.spi.ConnectorSession)1 ConnectorSplitSource (com.facebook.presto.spi.ConnectorSplitSource)1 ConnectorTableLayoutHandle (com.facebook.presto.spi.ConnectorTableLayoutHandle)1 FixedSplitSource (com.facebook.presto.spi.FixedSplitSource)1 NodeManager (com.facebook.presto.spi.NodeManager)1 PrestoException (com.facebook.presto.spi.PrestoException)1 ConnectorSplitManager (com.facebook.presto.spi.connector.ConnectorSplitManager)1 ConnectorTransactionHandle (com.facebook.presto.spi.connector.ConnectorTransactionHandle)1 BigQueryException (com.google.cloud.bigquery.BigQueryException)1 TableId (com.google.cloud.bigquery.TableId)1 TableResult (com.google.cloud.bigquery.TableResult)1 ReadSession (com.google.cloud.bigquery.storage.v1beta1.Storage.ReadSession)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 Inject (com.google.inject.Inject)1 String.format (java.lang.String.format)1 List (java.util.List)1