Skip to content
This repository was archived by the owner on Aug 30, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'master' into get-model
# Conflicts:
#	samples/src/main/java/com/example/bigquery/RelaxTableQuery.java
#	samples/src/test/java/com/example/bigquery/RelaxTableQueryIT.java
  • Loading branch information
stephaniewang526 committed Jan 27, 2020
commit 27eec9e17771c45146a40f010b00348abf805b24
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@
import com.google.cloud.bigquery.BigQueryException;
import com.google.cloud.bigquery.BigQueryOptions;
import com.google.cloud.bigquery.Job;
import com.google.cloud.bigquery.JobId;
import com.google.cloud.bigquery.JobInfo;
import com.google.cloud.bigquery.JobInfo.SchemaUpdateOption;
import com.google.cloud.bigquery.JobInfo.WriteDisposition;
import com.google.cloud.bigquery.QueryJobConfiguration;
import com.google.cloud.bigquery.TableId;
import com.google.cloud.bigquery.TableResult;
import com.google.common.collect.ImmutableList;
import java.util.UUID;

public class RelaxTableQuery {

Expand All @@ -52,8 +50,7 @@ public static void relaxTableQuery(String projectId, String datasetName, String
TableId tableId = TableId.of(datasetName, tableName);

String sourceTable = "`" + projectId + "." + datasetName + "." + tableName + "`";
String query =
"SELECT " + "word\n" + "FROM " + sourceTable + "\n" + "WHERE word like '%is%' ";
String query = "SELECT word FROM " + sourceTable + " WHERE word like '%is%'";

QueryJobConfiguration queryConfig =
QueryJobConfiguration.newBuilder(query)
Expand All @@ -65,9 +62,7 @@ public static void relaxTableQuery(String projectId, String datasetName, String
.setDestinationTable(tableId)
.build();

// Create a job ID so that we can safely retry.
JobId jobId = JobId.of(UUID.randomUUID().toString());
Job queryJob = bigquery.create(JobInfo.newBuilder(queryConfig).setJobId(jobId).build());
Job queryJob = bigquery.create(JobInfo.newBuilder(queryConfig).build());

queryJob = queryJob.waitFor();

Expand Down
38 changes: 18 additions & 20 deletions samples/src/test/java/com/example/bigquery/RelaxTableQueryIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public class RelaxTableQueryIT {

private static final String BIGQUERY_PROJECT_ID = System.getenv("BIGQUERY_PROJECT_ID");
private static final String BIGQUERY_DATASET_NAME = System.getenv("BIGQUERY_DATASET_NAME");
private static final String TABLE_NAME =
"RELAX_TABLE_QUERY_TEST_" + UUID.randomUUID().toString().replace('-', '_');

private static void requireEnvVar(String varName) {
assertNotNull(
Expand All @@ -52,16 +50,21 @@ public static void checkRequirements() {
}

@Before
public void setUp() {
System.out.println("BIGQUERY_DATASET_NAME: " + BIGQUERY_DATASET_NAME);
System.out.println("TABLE_NAME: " + TABLE_NAME);

public void setUp() throws Exception {
bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
System.setOut(out);
}

@After
public void tearDown() {
System.setOut(null);
}

CreateTable.createTable(
BIGQUERY_DATASET_NAME,
TABLE_NAME,
@Test
public void testRelaxTableQuery() throws Exception {
String tableName = "RELAX_TABLE_QUERY_TEST" + UUID.randomUUID().toString().replace('-', '_');
Schema originalSchema =
Schema.of(
Field.newBuilder("word", LegacySQLTypeName.STRING).setMode(Field.Mode.REQUIRED).build(),
Field.newBuilder("word_count", LegacySQLTypeName.STRING)
Expand All @@ -72,20 +75,15 @@ public void setUp() {
.build(),
Field.newBuilder("corpus_date", LegacySQLTypeName.STRING)
.setMode(Field.Mode.REQUIRED)
.build()));
System.setOut(out);
}
.build());

@After
public void tearDown() {
DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, TABLE_NAME);
System.setOut(null);
}
CreateTable.createTable(BIGQUERY_DATASET_NAME, tableName, originalSchema);

@Test
public void testRelaxTableQuery() throws Exception {
RelaxTableQuery.relaxTableQuery(BIGQUERY_PROJECT_ID, BIGQUERY_DATASET_NAME, TABLE_NAME);
RelaxTableQuery.relaxTableQuery(BIGQUERY_PROJECT_ID, BIGQUERY_DATASET_NAME, tableName);
assertThat(bout.toString())
.contains("Successfully relaxed all columns in destination table during query job");

// Clean up
DeleteTable.deleteTable(BIGQUERY_DATASET_NAME, tableName);
}
}
You are viewing a condensed version of this merge commit. You can view the full changes here.