Java Code Examples for com.google.cloud.bigquery.TableInfo#of()

The following examples show how to use com.google.cloud.bigquery.TableInfo#of() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BigQueryExample.java    From google-cloud-java with Apache License 2.0 6 votes vote down vote up
@Override
TableInfo parse(String... args) throws Exception {
  String message;
  if (args.length == 3) {
    String dataset = args[0];
    String table = args[1];
    String query = args[2];
    TableId tableId = TableId.of(dataset, table);
    return TableInfo.of(tableId, ViewDefinition.of(query));
  } else if (args.length < 3) {
    message = "Missing required dataset id, table id or query.";
  } else {
    message = "Too many arguments.";
  }
  throw new IllegalArgumentException(message);
}
 
Example 2
Source File: BigQueryExample.java    From google-cloud-java with Apache License 2.0 5 votes vote down vote up
@Override
TableInfo parse(String... args) throws Exception {
  if (args.length >= 3) {
    String dataset = args[0];
    String table = args[1];
    TableId tableId = TableId.of(dataset, table);
    return TableInfo.of(tableId, StandardTableDefinition.of(parseSchema(args, 2, args.length)));
  }
  throw new IllegalArgumentException("Missing required arguments.");
}
 
Example 3
Source File: BigQueryExample.java    From google-cloud-java with Apache License 2.0 5 votes vote down vote up
@Override
TableInfo parse(String... args) throws Exception {
  if (args.length >= 5) {
    String dataset = args[0];
    String table = args[1];
    TableId tableId = TableId.of(dataset, table);
    ExternalTableDefinition externalTableDefinition =
        ExternalTableDefinition.of(
            args[args.length - 1],
            parseSchema(args, 3, args.length - 1),
            FormatOptions.of(args[2]));
    return TableInfo.of(tableId, externalTableDefinition);
  }
  throw new IllegalArgumentException("Missing required arguments.");
}
 
Example 4
Source File: ITBigQuerySnippets.java    From google-cloud-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testInsertAllAndListTableData() throws IOException, InterruptedException {
  String tableName = "test_insert_all_and_list_table_data";
  String fieldName1 = "booleanField";
  String fieldName2 = "bytesField";
  String fieldName3 = "recordField";
  String fieldName4 = "stringField";
  TableId tableId = TableId.of(DATASET, tableName);
  Schema schema =
      Schema.of(
          Field.of(fieldName1, LegacySQLTypeName.BOOLEAN),
          Field.of(fieldName2, LegacySQLTypeName.BYTES),
          Field.of(
              fieldName3,
              LegacySQLTypeName.RECORD,
              Field.of(fieldName4, LegacySQLTypeName.STRING)));
  TableInfo table = TableInfo.of(tableId, StandardTableDefinition.of(schema));
  assertNotNull(bigquery.create(table));
  InsertAllResponse response = bigquerySnippets.insertAll(DATASET, tableName);
  assertFalse(response.hasErrors());
  assertTrue(response.getInsertErrors().isEmpty());
  Page<FieldValueList> listPage = bigquerySnippets.listTableDataFromId(DATASET, tableName);
  while (Iterators.size(listPage.iterateAll().iterator()) < 1) {
    Thread.sleep(500);
    listPage = bigquerySnippets.listTableDataFromId(DATASET, tableName);
  }
  FieldValueList row = listPage.getValues().iterator().next();
  assertEquals(true, row.get(0).getBooleanValue());
  assertArrayEquals(new byte[] {0xA, 0xD, 0xD, 0xE, 0xD}, row.get(1).getBytesValue());
  assertEquals("Hello, World!", row.get(2).getRecordValue().get(0).getStringValue());

  listPage = bigquerySnippets.listTableDataSchema(DATASET, tableName, schema, fieldName1);
  row = listPage.getValues().iterator().next();
  assertNotNull(row.get(fieldName1));
  assertArrayEquals(new byte[] {0xA, 0xD, 0xD, 0xE, 0xD}, row.get(fieldName2).getBytesValue());

  bigquerySnippets.listTableDataSchemaId();

  assertTrue(bigquerySnippets.deleteTable(DATASET, tableName));
}