You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by jo...@apache.org on 2017/07/02 13:25:34 UTC

zeppelin git commit: ZEPPELIN-2637: Make useLegacySql configurable, in Bigquery Interpreter

Repository: zeppelin
Updated Branches:
  refs/heads/master effc28a1f -> 1d93d3db8


ZEPPELIN-2637: Make useLegacySql configurable, in Bigquery Interpreter

### What is this PR for?
Make useLegacySql configurable, in Bigquery Interpreter

### What type of PR is it?
Improvement

### Todos - NA
* [ ] - Task

### What is the Jira issue?
ZEPPELIN-2637

### How should this be tested?
Set true/false for the property in interpreter setting and check the functionality.

### Screenshots (if appropriate)

### Questions:
* Does the licenses files need update? NA
* Is there breaking changes for older versions? NA
* Does this needs documentation? NA

Author: Karup <ka...@qubole.com>
Author: karuppayya <ka...@qubole.com>

Closes #2403 from karuppayya/ZEPPELIN-2637 and squashes the following commits:

8858e339 [karuppayya] Format code
d2263492 [Karup] Add use legacysql option


Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/1d93d3db
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/1d93d3db
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/1d93d3db

Branch: refs/heads/master
Commit: 1d93d3db81c8ea32f5557b30acf34a13ec352d64
Parents: effc28a
Author: Karup <ka...@qubole.com>
Authored: Sat Jun 17 20:48:45 2017 +0530
Committer: Jongyoul Lee <jo...@apache.org>
Committed: Sun Jul 2 22:25:26 2017 +0900

----------------------------------------------------------------------
 .../zeppelin/bigquery/BigQueryInterpreter.java  | 24 +++++++++++++-------
 .../src/main/resources/interpreter-setting.json |  6 +++++
 2 files changed, 22 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/1d93d3db/bigquery/src/main/java/org/apache/zeppelin/bigquery/BigQueryInterpreter.java
----------------------------------------------------------------------
diff --git a/bigquery/src/main/java/org/apache/zeppelin/bigquery/BigQueryInterpreter.java b/bigquery/src/main/java/org/apache/zeppelin/bigquery/BigQueryInterpreter.java
index d0c23e5..ca06964 100644
--- a/bigquery/src/main/java/org/apache/zeppelin/bigquery/BigQueryInterpreter.java
+++ b/bigquery/src/main/java/org/apache/zeppelin/bigquery/BigQueryInterpreter.java
@@ -99,7 +99,7 @@ import java.util.NoSuchElementException;
 
 public class BigQueryInterpreter extends Interpreter {
 
-  private Logger logger = LoggerFactory.getLogger(BigQueryInterpreter.class);
+  private static Logger logger = LoggerFactory.getLogger(BigQueryInterpreter.class);
   private static final char NEWLINE = '\n';
   private static final char TAB = '\t';
   private static Bigquery service = null;
@@ -109,6 +109,7 @@ public class BigQueryInterpreter extends Interpreter {
   static final String PROJECT_ID = "zeppelin.bigquery.project_id";
   static final String WAIT_TIME = "zeppelin.bigquery.wait_time";
   static final String MAX_ROWS = "zeppelin.bigquery.max_no_of_rows";
+  static final String LEGACY_SQL = "zeppelin.bigquery.use_legacy_sql";
 
   private static String jobId = null;
   private static String projectId = null;
@@ -245,9 +246,11 @@ public class BigQueryInterpreter extends Interpreter {
     String projId = getProperty(PROJECT_ID);
     long wTime = Long.parseLong(getProperty(WAIT_TIME));
     long maxRows = Long.parseLong(getProperty(MAX_ROWS));
+    String legacySql = getProperty(LEGACY_SQL);
+    boolean useLegacySql = legacySql == null ? true : Boolean.parseBoolean(legacySql);
     Iterator<GetQueryResultsResponse> pages;
     try {
-      pages = run(sql, projId, wTime, maxRows);
+      pages = run(sql, projId, wTime, maxRows, useLegacySql);
     } catch ( IOException ex ) {
       logger.error(ex.getMessage());
       return new InterpreterResult(Code.ERROR, ex.getMessage());
@@ -263,14 +266,19 @@ public class BigQueryInterpreter extends Interpreter {
   }
 
   //Function to run the SQL on bigQuery service
-  public static Iterator<GetQueryResultsResponse> run(final String queryString, 
-    final String projId, final long wTime, final long maxRows) 
+  public static Iterator<GetQueryResultsResponse> run(final String queryString,
+    final String projId, final long wTime, final long maxRows, boolean useLegacySql)
       throws IOException {
     try {
-      QueryResponse query = service.jobs().query(
-          projId,
-          new QueryRequest().setTimeoutMs(wTime).setQuery(queryString).setMaxResults(maxRows))
-          .execute();
+      logger.info("Use legacy sql: {}", useLegacySql);
+      QueryResponse query;
+      query = service
+          .jobs()
+          .query(
+              projId,
+              new QueryRequest().setTimeoutMs(wTime)
+                  .setUseLegacySql(useLegacySql).setQuery(queryString)
+                  .setMaxResults(maxRows)).execute();
       jobId = query.getJobReference().getJobId();
       projectId = query.getJobReference().getProjectId();
       GetQueryResults getRequest = service.jobs().getQueryResults(

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/1d93d3db/bigquery/src/main/resources/interpreter-setting.json
----------------------------------------------------------------------
diff --git a/bigquery/src/main/resources/interpreter-setting.json b/bigquery/src/main/resources/interpreter-setting.json
index b99a763..f782495 100644
--- a/bigquery/src/main/resources/interpreter-setting.json
+++ b/bigquery/src/main/resources/interpreter-setting.json
@@ -21,6 +21,12 @@
         "propertyName": "zeppelin.bigquery.max_no_of_rows",
         "defaultValue": "100000",
         "description": "Maximum number of rows to fetch from BigQuery"
+      },
+      "zeppelin.bigquery.use_legacy_sql": {
+        "envName": null,
+        "propertyName": "zeppelin.bigquery.use_legacy_sql",
+        "defaultValue": "true",
+        "description": "set true to use legacy sql"
       }
     },
     "editor": {