private void onTableGet(Table table) throws IOException { when(mockClient.tables()).thenReturn(mockTables); when(mockTables.get(anyString(), anyString(), anyString())).thenReturn(mockTablesGet); when(mockTablesGet.execute()).thenReturn(table); }
private void verifyTableGet() throws IOException { verify(mockClient).tables(); verify(mockTables).get("project", "dataset", "table"); verify(mockTablesGet, atLeastOnce()).execute(); }
@VisibleForTesting @Nullable Table getTable(TableReference ref, BackOff backoff, Sleeper sleeper) throws IOException, InterruptedException { try { return executeWithRetries( client.tables().get(ref.getProjectId(), ref.getDatasetId(), ref.getTableId()), String.format( "Unable to get table: %s, aborting after %d retries.", ref.getTableId(), MAX_RPC_RETRIES), sleeper, backoff, DONT_RETRY_NOT_FOUND); } catch (IOException e) { if (errorExtractor.itemNotFound(e)) { return null; } throw e; } }
boolean found = true; try { bigquery.tables().get(exporterConfig.getBigqueryProjectId(), exporterConfig.getBigqueryDatasetId(), kind).execute();
Table table = executeNullIfNotFound(tableService.get(projectId, datasetId, tableId)); if (table == null) { Table newTable =
/** * Returns true if the table exists, or false if not. */ public boolean tableExists(TableReference tableRef) throws IOException { try { Table fetchedTable = service.tables().get( tableRef.getProjectId(), tableRef.getDatasetId(), tableRef.getTableId()).execute(); logger.atFine().log( "Successfully fetched table '%s' for tableRef '%s'", fetchedTable, tableRef); return true; } catch (IOException ioe) { if (errorExtractor.itemNotFound(ioe)) { return false; } else { // Unhandled exceptions should just propagate up. throw ioe; } } }
@Override public Table getTable( String projectId, String datasetId, String tableId, Map<Option, ?> options) { try { return bigquery .tables() .get(projectId, datasetId, tableId) .setFields(Option.FIELDS.getString(options)) .execute(); } catch (IOException ex) { BigQueryException serviceException = translate(ex); if (serviceException.getCode() == HTTP_NOT_FOUND) { return null; } throw serviceException; } }
@Test public void testExecuteWithRetries() throws IOException, InterruptedException { Table testTable = new Table(); when(response.getContentType()).thenReturn(Json.MEDIA_TYPE); when(response.getStatusCode()).thenReturn(200); when(response.getContent()).thenReturn(toStream(testTable)); Table table = BigQueryServicesImpl.executeWithRetries( bigquery.tables().get("projectId", "datasetId", "tableId"), "Failed to get table.", Sleeper.DEFAULT, BackOff.STOP_BACKOFF, BigQueryServicesImpl.ALWAYS_RETRY); assertEquals(testTable, table); verify(response, times(1)).getStatusCode(); verify(response, times(1)).getContent(); verify(response, times(1)).getContentType(); }
@Override public Table getTable(String datasetId, String tableId, Map<Option, ?> options) { try { return bigquery.tables() .get(this.options.projectId(), datasetId, tableId) .setFields(FIELDS.getString(options)) .execute(); } catch (IOException ex) { BigQueryException serviceException = translate(ex); if (serviceException.code() == HTTP_NOT_FOUND) { return null; } throw serviceException; } }
@Override public Table getTable(String datasetId, String tableId, Map<Option, ?> options) { try { return bigquery.tables() .get(this.options.projectId(), datasetId, tableId) .setFields(FIELDS.getString(options)) .execute(); } catch (IOException ex) { BigQueryException serviceException = translate(ex); if (serviceException.code() == HTTP_NOT_FOUND) { return null; } throw serviceException; } }
/** * Gets the specified table resource by table ID. This method does not return the data in the * table, it only returns the table resource, which describes the structure of this table. * * @param tableRef The BigQuery table reference. * @return The table resource, which describes the structure of this table. * @throws IOException */ public Table getTable(TableReference tableRef) throws IOException { Bigquery.Tables.Get getTablesReply = service.tables().get( tableRef.getProjectId(), tableRef.getDatasetId(), tableRef.getTableId()); return getTablesReply.execute(); }
private TableSchema getSchema(Bigquery bq) { try { return bq.tables() .get( pipelineOptions.getProject(), pipelineOptions.getTargetDataset(), table.getTableReference().getTableId()) .execute() .getSchema(); } catch (IOException e) { throw new RuntimeException(e); } }
private Table getTable(TableReference ref) throws IOException, InterruptedException { Bigquery.Tables.Get get = client.tables().get(ref.getProjectId(), ref.getDatasetId(), ref.getTableId()); return executeWithBackOff( get, String.format( "Error opening BigQuery table %s of dataset %s.", ref.getTableId(), ref.getDatasetId())); }
@Override public Table getTable( String projectId, String datasetId, String tableId, Map<Option, ?> options) { try { return bigquery .tables() .get(projectId, datasetId, tableId) .setFields(Option.FIELDS.getString(options)) .execute(); } catch (IOException ex) { BigQueryException serviceException = translate(ex); if (serviceException.getCode() == HTTP_NOT_FOUND) { return null; } throw serviceException; } }