From 63fdb506df24ae886eb968e3f51a074b54b7324b Mon Sep 17 00:00:00 2001 From: larryruili Date: Mon, 28 Aug 2017 14:27:38 -0700 Subject: [PATCH] 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 --- .../registry/export/UpdateSnapshotViewAction.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/java/google/registry/export/UpdateSnapshotViewAction.java b/java/google/registry/export/UpdateSnapshotViewAction.java index 2c0a3659b..b138688d2 100644 --- a/java/google/registry/export/UpdateSnapshotViewAction.java +++ b/java/google/registry/export/UpdateSnapshotViewAction.java @@ -92,13 +92,13 @@ public class UpdateSnapshotViewAction implements Runnable { SqlTemplate.create( "#legacySQL\nSELECT * FROM [%PROJECT%:%SOURCE_DATASET%.%SOURCE_TABLE%]"); updateSnapshotView( - datasetId, tableId, kindName, LEGACY_LATEST_SNAPSHOT_DATASET, legacyTemplate); + datasetId, tableId, kindName, LEGACY_LATEST_SNAPSHOT_DATASET, legacyTemplate, true); SqlTemplate standardTemplate = SqlTemplate.create( "#standardSQL\nSELECT * FROM `%PROJECT%.%SOURCE_DATASET%.%SOURCE_TABLE%`"); updateSnapshotView( - datasetId, tableId, kindName, STANDARD_LATEST_SNAPSHOT_DATASET, standardTemplate); + datasetId, tableId, kindName, STANDARD_LATEST_SNAPSHOT_DATASET, standardTemplate, false); } catch (Throwable e) { logger.severefmt(e, "Could not update snapshot view for table %s", tableId); @@ -111,7 +111,8 @@ public class UpdateSnapshotViewAction implements Runnable { String sourceTableId, String kindName, String viewDataset, - SqlTemplate viewQueryTemplate) + SqlTemplate viewQueryTemplate, + boolean useLegacySql) throws IOException { Bigquery bigquery = bigqueryFactory.create(projectId, viewDataset); @@ -125,6 +126,7 @@ public class UpdateSnapshotViewAction implements Runnable { .setTableId(kindName)) .setView( new ViewDefinition() + .setUseLegacySql(useLegacySql) .setQuery( viewQueryTemplate .put("PROJECT", projectId) @@ -148,6 +150,8 @@ public class UpdateSnapshotViewAction implements Runnable { } catch (GoogleJsonResponseException e) { if (e.getDetails().getCode() == 404) { bigquery.tables().insert(ref.getProjectId(), ref.getDatasetId(), table).execute(); + } else { + logger.warningfmt("UpdateSnapshotViewAction failed, caught exception %s", e.getDetails()); } } }