BigQueryHelpers { public static TableReference parseTableSpec(String tableSpec) { Matcher match = BigQueryIO.TABLE_SPEC.matcher(tableSpec); if (!match.matches()) { throw new IllegalArgumentException( "Table reference is not in [project_id]:[dataset_id].[table_id] " + "format: " + tableSpec); } TableReference ref = new TableReference(); ref.setProjectId(match.group("PROJECT")); return ref.setDatasetId(match.group("DATASET")).setTableId(match.group("TABLE")); }  static String toTableSpec(TableReference ref); static TableReference parseTableSpec(String tableSpec); static String stripPartitionDecorator(String tableSpec); static String toJsonString(Object item); static T fromJsonString(String json, Class<T> clazz); static @Nullable BigInteger getNumRows(BigQueryOptions options, TableReference tableRef);  }
@Test public void testTableParsing() { TableReference ref = BigQueryHelpers.parseTableSpec("my-project:data_set.table_name"); assertEquals("my-project", ref.getProjectId()); assertEquals("data_set", ref.getDatasetId()); assertEquals("table_name", ref.getTableId()); }
@Test public void testTableParsing_validPatterns() { BigQueryHelpers.parseTableSpec("a123-456:foo_bar.d"); BigQueryHelpers.parseTableSpec("a12345:b.c"); BigQueryHelpers.parseTableSpec("b12345.c"); }
@Test public void testTableParsing_noProjectId() { TableReference ref = BigQueryHelpers.parseTableSpec("data_set.table_name"); assertEquals(null, ref.getProjectId()); assertEquals("data_set", ref.getDatasetId()); assertEquals("table_name", ref.getTableId()); }
@Test public void testTableParsingError() { thrown.expect(IllegalArgumentException.class); BigQueryHelpers.parseTableSpec("0123456:foo.bar"); }
@Test public void testTableParsingError_2() { thrown.expect(IllegalArgumentException.class); BigQueryHelpers.parseTableSpec("myproject:.bar"); }
@Test public void testTableParsingError_3() { thrown.expect(IllegalArgumentException.class); BigQueryHelpers.parseTableSpec(":a.b"); }
@Test public void testTableParsingError_slash() { thrown.expect(IllegalArgumentException.class); BigQueryHelpers.parseTableSpec("a\\b12345:c.d"); }