public static void main(String... args) throws InterruptedException, TimeoutException { BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService(); TableId tableId = TableId.of("dataset", "table"); Table table = bigquery.getTable(tableId); if (table == null) { System.out.println("Creating table " + tableId); Field integerField = Field.of("fieldName", LegacySQLTypeName.INTEGER); Schema schema = Schema.of(integerField); table = bigquery.create(TableInfo.of(tableId, StandardTableDefinition.of(schema))); } System.out.println("Loading data into table " + tableId); Job loadJob = table.load(FormatOptions.csv(), "gs://bucket/path"); loadJob = loadJob.waitFor(); if (loadJob.getStatus().getError() != null) { System.out.println("Job completed with errors"); } else { System.out.println("Job succeeded"); } } }
BigQuery bq = BigQueryOptions.getDefaultInstance().getService();
public static void main(String... args) throws InterruptedException { BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
public static void implicit() { // Instantiate a client. If you don't specify credentials when constructing a client, the // client library will look for credentials in the environment, such as the // GOOGLE_APPLICATION_CREDENTIALS environment variable. BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService(); // Use the client. System.out.println("Datasets:"); for (Dataset dataset : bigquery.listDatasets().iterateAll()) { System.out.printf("%s%n", dataset.getDatasetId().getDataset()); } } // [END bigquery_client_default_credentials]
public static void main(String... args) throws Exception { // Instantiate a client. If you don't specify credentials when constructing a client, the // client library will look for credentials in the environment, such as the // GOOGLE_APPLICATION_CREDENTIALS environment variable. BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService(); // The name for the new dataset String datasetName = "my_new_dataset"; // Prepares a new dataset Dataset dataset = null; DatasetInfo datasetInfo = DatasetInfo.newBuilder(datasetName).build(); // Creates the dataset dataset = bigquery.create(datasetInfo); System.out.printf("Dataset %s created.%n", dataset.getDatasetId().getDataset()); } }
public static void main(String... args) throws Exception { BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
public static BigQuery createClient(BigQueryDatastoreProperties datastore) { if (StringUtils.isEmpty(datastore.serviceAccountFile.getValue())) { return BigQueryOptions.getDefaultInstance().getService(); } else { return BigQueryOptions.newBuilder().setProjectId(datastore.projectName.getValue()) .setCredentials(createCredentials(datastore)).build().getService(); } }
public static BigQuery createClient(BigQueryDatastoreProperties datastore) { if (StringUtils.isEmpty(datastore.serviceAccountFile.getValue())) { return BigQueryOptions.getDefaultInstance().getService(); } else { return BigQueryOptions.newBuilder().setProjectId(datastore.projectName.getValue()) .setCredentials(createCredentials(datastore)).build().getService(); } }
BigQuery bq = BigQueryOptions.getDefaultInstance().getService();