Add explicit useLegacySql flag to UpdateSnapshotViewAction

It turns out the Bigquery JSON api selects its validator exclusively through
the useLegacySql flag (the #standardSQL directive isn't considered). To fix
this, we add back the explicit flag.

This also logs unexpected API errors, instead of allowing the job to quietly fail.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=166757569
This commit is contained in:
larryruili 2017-08-28 14:27:38 -07:00 committed by Ben McIlwain
parent c86fd96654
commit 63fdb506df

View file

@ -92,13 +92,13 @@ public class UpdateSnapshotViewAction implements Runnable {
SqlTemplate.create( SqlTemplate.create(
"#legacySQL\nSELECT * FROM [%PROJECT%:%SOURCE_DATASET%.%SOURCE_TABLE%]"); "#legacySQL\nSELECT * FROM [%PROJECT%:%SOURCE_DATASET%.%SOURCE_TABLE%]");
updateSnapshotView( updateSnapshotView(
datasetId, tableId, kindName, LEGACY_LATEST_SNAPSHOT_DATASET, legacyTemplate); datasetId, tableId, kindName, LEGACY_LATEST_SNAPSHOT_DATASET, legacyTemplate, true);
SqlTemplate standardTemplate = SqlTemplate standardTemplate =
SqlTemplate.create( SqlTemplate.create(
"#standardSQL\nSELECT * FROM `%PROJECT%.%SOURCE_DATASET%.%SOURCE_TABLE%`"); "#standardSQL\nSELECT * FROM `%PROJECT%.%SOURCE_DATASET%.%SOURCE_TABLE%`");
updateSnapshotView( updateSnapshotView(
datasetId, tableId, kindName, STANDARD_LATEST_SNAPSHOT_DATASET, standardTemplate); datasetId, tableId, kindName, STANDARD_LATEST_SNAPSHOT_DATASET, standardTemplate, false);
} catch (Throwable e) { } catch (Throwable e) {
logger.severefmt(e, "Could not update snapshot view for table %s", tableId); logger.severefmt(e, "Could not update snapshot view for table %s", tableId);
@ -111,7 +111,8 @@ public class UpdateSnapshotViewAction implements Runnable {
String sourceTableId, String sourceTableId,
String kindName, String kindName,
String viewDataset, String viewDataset,
SqlTemplate viewQueryTemplate) SqlTemplate viewQueryTemplate,
boolean useLegacySql)
throws IOException { throws IOException {
Bigquery bigquery = bigqueryFactory.create(projectId, viewDataset); Bigquery bigquery = bigqueryFactory.create(projectId, viewDataset);
@ -125,6 +126,7 @@ public class UpdateSnapshotViewAction implements Runnable {
.setTableId(kindName)) .setTableId(kindName))
.setView( .setView(
new ViewDefinition() new ViewDefinition()
.setUseLegacySql(useLegacySql)
.setQuery( .setQuery(
viewQueryTemplate viewQueryTemplate
.put("PROJECT", projectId) .put("PROJECT", projectId)
@ -148,6 +150,8 @@ public class UpdateSnapshotViewAction implements Runnable {
} catch (GoogleJsonResponseException e) { } catch (GoogleJsonResponseException e) {
if (e.getDetails().getCode() == 404) { if (e.getDetails().getCode() == 404) {
bigquery.tables().insert(ref.getProjectId(), ref.getDatasetId(), table).execute(); bigquery.tables().insert(ref.getProjectId(), ref.getDatasetId(), table).execute();
} else {
logger.warningfmt("UpdateSnapshotViewAction failed, caught exception %s", e.getDetails());
} }
} }
} }