/** * Tries to create the BigQuery table. If a table with the same name already exists in the * dataset, the table creation fails, and the function returns null. In such a case, the existing * table doesn't necessarily have the same schema as specified by the parameter. * * @param schema Schema of the new BigQuery table. * @return The newly created BigQuery table information, or null if the table with the same name * already exists. * @throws IOException if other error than already existing table occurs. */ @Nullable public Table tryCreateTable(TableSchema schema) throws IOException { LOG.info("Trying to create BigQuery table: {}", BigQueryIO.toTableSpec(ref)); Table content = new Table(); content.setTableReference(ref); content.setSchema(schema); try { return client.tables().insert(ref.getProjectId(), ref.getDatasetId(), content).execute(); } catch (IOException e) { if (new ApiErrorExtractor().itemAlreadyExists(e)) { LOG.info("The BigQuery table already exists."); return null; } throw e; } }