mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 00:17:20 +02:00
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:
parent
b6da74d424
commit
038d3d5031
2 changed files with 11 additions and 13 deletions
|
@ -89,17 +89,16 @@ public class UpdateSnapshotViewAction implements Runnable {
|
|||
.setDatasetId(LATEST_SNAPSHOT_DATASET)
|
||||
.setTableId(kindName))
|
||||
.setView(new ViewDefinition().setQuery(
|
||||
SqlTemplate.create("SELECT * FROM [%DATASET%.%TABLE%]")
|
||||
SqlTemplate.create("SELECT * FROM [%PROJECT%:%DATASET%.%TABLE%]")
|
||||
.put("PROJECT", projectId)
|
||||
.put("DATASET", datasetId)
|
||||
.put("TABLE", tableId)
|
||||
.build())));
|
||||
|
||||
logger.infofmt(
|
||||
"Updated view %s:%s to point at snapshot table %s:%s.",
|
||||
LATEST_SNAPSHOT_DATASET,
|
||||
kindName,
|
||||
datasetId,
|
||||
tableId);
|
||||
"Updated view %s to point at snapshot table %s.",
|
||||
String.format("[%s:%s.%s]", projectId, LATEST_SNAPSHOT_DATASET, kindName),
|
||||
String.format("[%s:%s.%s]", projectId, datasetId, tableId));
|
||||
}
|
||||
|
||||
private static void updateTable(Bigquery bigquery, Table table) throws IOException {
|
||||
|
|
|
@ -82,18 +82,17 @@ public class UpdateSnapshotViewActionTest {
|
|||
public void before() throws Exception {
|
||||
when(bigqueryFactory.create(anyString(), anyString())).thenReturn(bigquery);
|
||||
when(bigquery.datasets()).thenReturn(bigqueryDatasets);
|
||||
when(bigqueryDatasets.insert(eq("Project-Id"), any(Dataset.class)))
|
||||
when(bigqueryDatasets.insert(anyString(), any(Dataset.class)))
|
||||
.thenReturn(bigqueryDatasetsInsert);
|
||||
when(bigquery.tables()).thenReturn(bigqueryTables);
|
||||
when(bigqueryTables.update(
|
||||
eq("Project-Id"), anyString(), anyString(), any(Table.class)))
|
||||
when(bigqueryTables.update(anyString(), anyString(), anyString(), any(Table.class)))
|
||||
.thenReturn(bigqueryTablesUpdate);
|
||||
|
||||
action = new UpdateSnapshotViewAction();
|
||||
action.bigqueryFactory = bigqueryFactory;
|
||||
action.datasetId = "some_dataset";
|
||||
action.kindName = "fookind";
|
||||
action.projectId = "Project-Id";
|
||||
action.projectId = "myproject";
|
||||
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
|
||||
// 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.
|
||||
ArgumentCaptor<Table> tableArg = ArgumentCaptor.forClass(Table.class);
|
||||
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())
|
||||
.isEqualTo("SELECT * FROM [some_dataset.12345_fookind]");
|
||||
.isEqualTo("SELECT * FROM [myproject:some_dataset.12345_fookind]");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue