Fix latest_snapshot "pointer" query to use to fully-qualified table reference

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=125105776
This commit is contained in:
nickfelt 2016-06-16 14:53:24 -07:00 committed by Ben McIlwain
parent b6da74d424
commit 038d3d5031
2 changed files with 11 additions and 13 deletions

View file

@ -89,17 +89,16 @@ public class UpdateSnapshotViewAction implements Runnable {
.setDatasetId(LATEST_SNAPSHOT_DATASET) .setDatasetId(LATEST_SNAPSHOT_DATASET)
.setTableId(kindName)) .setTableId(kindName))
.setView(new ViewDefinition().setQuery( .setView(new ViewDefinition().setQuery(
SqlTemplate.create("SELECT * FROM [%DATASET%.%TABLE%]") SqlTemplate.create("SELECT * FROM [%PROJECT%:%DATASET%.%TABLE%]")
.put("PROJECT", projectId)
.put("DATASET", datasetId) .put("DATASET", datasetId)
.put("TABLE", tableId) .put("TABLE", tableId)
.build()))); .build())));
logger.infofmt( logger.infofmt(
"Updated view %s:%s to point at snapshot table %s:%s.", "Updated view %s to point at snapshot table %s.",
LATEST_SNAPSHOT_DATASET, String.format("[%s:%s.%s]", projectId, LATEST_SNAPSHOT_DATASET, kindName),
kindName, String.format("[%s:%s.%s]", projectId, datasetId, tableId));
datasetId,
tableId);
} }
private static void updateTable(Bigquery bigquery, Table table) throws IOException { private static void updateTable(Bigquery bigquery, Table table) throws IOException {

View file

@ -82,18 +82,17 @@ public class UpdateSnapshotViewActionTest {
public void before() throws Exception { public void before() throws Exception {
when(bigqueryFactory.create(anyString(), anyString())).thenReturn(bigquery); when(bigqueryFactory.create(anyString(), anyString())).thenReturn(bigquery);
when(bigquery.datasets()).thenReturn(bigqueryDatasets); when(bigquery.datasets()).thenReturn(bigqueryDatasets);
when(bigqueryDatasets.insert(eq("Project-Id"), any(Dataset.class))) when(bigqueryDatasets.insert(anyString(), any(Dataset.class)))
.thenReturn(bigqueryDatasetsInsert); .thenReturn(bigqueryDatasetsInsert);
when(bigquery.tables()).thenReturn(bigqueryTables); when(bigquery.tables()).thenReturn(bigqueryTables);
when(bigqueryTables.update( when(bigqueryTables.update(anyString(), anyString(), anyString(), any(Table.class)))
eq("Project-Id"), anyString(), anyString(), any(Table.class)))
.thenReturn(bigqueryTablesUpdate); .thenReturn(bigqueryTablesUpdate);
action = new UpdateSnapshotViewAction(); action = new UpdateSnapshotViewAction();
action.bigqueryFactory = bigqueryFactory; action.bigqueryFactory = bigqueryFactory;
action.datasetId = "some_dataset"; action.datasetId = "some_dataset";
action.kindName = "fookind"; action.kindName = "fookind";
action.projectId = "Project-Id"; action.projectId = "myproject";
action.tableId = "12345_fookind"; action.tableId = "12345_fookind";
} }
@ -116,14 +115,14 @@ public class UpdateSnapshotViewActionTest {
// Check that the BigQuery factory was called in such a way that the dataset would be created // Check that the BigQuery factory was called in such a way that the dataset would be created
// if it didn't already exist. // if it didn't already exist.
verify(bigqueryFactory).create("Project-Id", "latest_snapshot"); verify(bigqueryFactory).create("myproject", "latest_snapshot");
// Check that we updated the view. // Check that we updated the view.
ArgumentCaptor<Table> tableArg = ArgumentCaptor.forClass(Table.class); ArgumentCaptor<Table> tableArg = ArgumentCaptor.forClass(Table.class);
verify(bigqueryTables).update( verify(bigqueryTables).update(
eq("Project-Id"), eq("latest_snapshot"), eq("fookind"), tableArg.capture()); eq("myproject"), eq("latest_snapshot"), eq("fookind"), tableArg.capture());
assertThat(tableArg.getValue().getView().getQuery()) assertThat(tableArg.getValue().getView().getQuery())
.isEqualTo("SELECT * FROM [some_dataset.12345_fookind]"); .isEqualTo("SELECT * FROM [myproject:some_dataset.12345_fookind]");
} }
@Test @Test