diff --git a/LICENSE b/LICENSE index 71d3c525f1b..8b209c53681 100644 --- a/LICENSE +++ b/LICENSE @@ -251,6 +251,7 @@ The following components are provided under the Apache License. See project link The text of each license is also included at licenses/LICENSE-[project]-[version].txt. (Apache 2.0) Bootstrap v3.0.2 (http://getbootstrap.com/) - https://github.com/twbs/bootstrap/blob/v3.0.2/LICENSE + (Apache 2.0) Software under ./bigquery/* was developed at Google (http://www.google.com/). Licensed under the Apache v2.0 License. ======================================================================== BSD 3-Clause licenses @@ -270,4 +271,4 @@ BSD 2-Clause licenses The following components are provided under the BSD 3-Clause license. See file headers and project links for details. (BSD 2 Clause) portions of SQLLine (http://sqlline.sourceforge.net/) - http://sqlline.sourceforge.net/#license - jdbc/src/main/java/org/apache/zeppelin/jdbc/SqlCompleter.java \ No newline at end of file + jdbc/src/main/java/org/apache/zeppelin/jdbc/SqlCompleter.java diff --git a/NOTICE b/NOTICE index bfbb6271795..66e4ca0be3e 100644 --- a/NOTICE +++ b/NOTICE @@ -4,5 +4,4 @@ Copyright 2015 - 2016 The Apache Software Foundation This product includes software developed at The Apache Software Foundation (http://www.apache.org/). - Portions of this software were developed at NFLabs, Inc. (http://www.nflabs.com) diff --git a/bigquery/README.md b/bigquery/README.md new file mode 100644 index 00000000000..fc097631a29 --- /dev/null +++ b/bigquery/README.md @@ -0,0 +1,109 @@ +# Overview +BigQuery interpreter for Apache Zeppelin + +# Pre requisities +You can follow the instructions at [Apache Zeppelin on Dataproc](https://github.com/GoogleCloudPlatform/dataproc-initialization-actions/blob/master/apache-zeppelin/README.MD) to bring up Zeppelin on Google dataproc. +You could also install and bring up Zeppelin on Google compute Engine. + +# Unit Tests +BigQuery Unit tests are excluded as these tests depend on the BigQuery external service. This is because BigQuery does not have a local mock at this point. + +If you like to run these tests manually, please follow the following steps: +* [Create a new project](https://support.google.com/cloud/answer/6251787?hl=en) +* [Create a Google Compute Engine instance](https://cloud.google.com/compute/docs/instances/create-start-instance) +* Copy the project ID that you created and add it to the property "projectId" in `resources/constants.json` +* Run the command mvn -Dbigquery.text.exclude='' test -pl bigquery -am + + +# Interpreter Configuration + +Configure the following properties during Interpreter creation. + + + + + + + + + + + + + + + + + + + + + + +
NameDefault ValueDescription
zeppelin.bigquery.project_id Google Project Id
zeppelin.bigquery.wait_time5000Query Timeout in Milliseconds
zeppelin.bigquery.max_no_of_rows100000Max result set size
+ +# Connection +The Interpreter opens a connection with the BigQuery Service using the supplied Google project ID and the compute environment variables. + +# Google BigQuery API Javadoc +[API Javadocs](https://developers.google.com/resources/api-libraries/documentation/bigquery/v2/java/latest/) +[Source] (http://central.maven.org/maven2/com/google/apis/google-api-services-bigquery/v2-rev265-1.21.0/google-api-services-bigquery-v2-rev265-1.21.0-sources.jar) + +We have used the curated veneer version of the Java APIs versus [Idiomatic Java client] (https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-bigquery) to build the interpreter. This is mainly for usability reasons. + +# Enabling the BigQuery Interpreter + +In a notebook, to enable the **BigQuery** interpreter, click the **Gear** icon and select **bigquery**. + +# Using the BigQuery Interpreter + +In a paragraph, use `%bigquery.sql` to select the **BigQuery** interpreter and then input SQL statements against your datasets stored in BigQuery. +You can use [BigQuery SQL Reference](https://cloud.google.com/bigquery/query-reference) to build your own SQL. + +For Example, SQL to query for top 10 departure delays across airports using the flights public dataset + +```bash +%bigquery.sql +SELECT departure_airport,count(case when departure_delay>0 then 1 else 0 end) as no_of_delays +FROM [bigquery-samples:airline_ontime_data.flights] +group by departure_airport +order by 2 desc +limit 10 +``` + +Another Example, SQL to query for most commonly used java packages from the github data hosted in BigQuery + +```bash +%bigquery.sql +SELECT + package, + COUNT(*) count +FROM ( + SELECT + REGEXP_EXTRACT(line, r' ([a-z0-9\._]*)\.') package, + id + FROM ( + SELECT + SPLIT(content, '\n') line, + id + FROM + [bigquery-public-data:github_repos.sample_contents] + WHERE + content CONTAINS 'import' + AND sample_path LIKE '%.java' + HAVING + LEFT(line, 6)='import' ) + GROUP BY + package, + id ) +GROUP BY + 1 +ORDER BY + count DESC +LIMIT + 40 +``` + +# Sample Screenshot + +![Zeppelin BigQuery](https://cloud.githubusercontent.com/assets/10060731/16938817/b9213ea0-4db6-11e6-8c3b-8149a0bdf874.png) diff --git a/bigquery/pom.xml b/bigquery/pom.xml new file mode 100644 index 00000000000..eb3f0fd2b94 --- /dev/null +++ b/bigquery/pom.xml @@ -0,0 +1,177 @@ + + + + + 4.0.0 + + + zeppelin + org.apache.zeppelin + 0.7.0-SNAPSHOT + + + org.apache.zeppelin + zeppelin-bigquery + jar + 0.7.0-SNAPSHOT + Zeppelin: BigQuery interpreter + http://www.apache.org + + + + + com.google.apis + google-api-services-bigquery + v2-rev265-1.21.0 + + + com.google.oauth-client + google-oauth-client + ${project.oauth.version} + + + com.google.http-client + google-http-client-jackson2 + ${project.http.version} + + + com.google.oauth-client + google-oauth-client-jetty + ${project.oauth.version} + + + com.google.code.gson + gson + 2.6 + + + + org.apache.zeppelin + zeppelin-interpreter + ${project.version} + provided + + + + org.slf4j + slf4j-api + + + + org.slf4j + slf4j-log4j12 + + + + junit + junit + test + + + + + 1.21.0 + 1.21.0 + UTF-8 + **/BigQueryInterpreterTest.java + + + + + + maven-enforcer-plugin + 1.3.1 + + + enforce + none + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + ${bigquery.test.exclude} + + + + + + maven-dependency-plugin + 2.8 + + + copy-dependencies + package + + copy-dependencies + + + ${project.build.directory}/../../interpreter/bqsql + false + false + true + runtime + + + + copy-artifact + package + + copy + + + ${project.build.directory}/../../interpreter/bqsql + false + false + true + runtime + + + ${project.groupId} + ${project.artifactId} + ${project.version} + ${project.packaging} + + + + + + + + maven-assembly-plugin + + + + + org.apache.zeppelin.bigquery.BigQueryInterpreter + + + + + jar-with-dependencies + + + + + + diff --git a/bigquery/src/main/java/org/apache/zeppelin/bigquery/BigQueryInterpreter.java b/bigquery/src/main/java/org/apache/zeppelin/bigquery/BigQueryInterpreter.java new file mode 100644 index 00000000000..33e196003b0 --- /dev/null +++ b/bigquery/src/main/java/org/apache/zeppelin/bigquery/BigQueryInterpreter.java @@ -0,0 +1,338 @@ +/* +* Copyright 2016 Google Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 + +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.apache.zeppelin.bigquery; + + +import static org.apache.commons.lang.StringUtils.containsIgnoreCase; + +import com.google.api.client.http.HttpTransport; +import com.google.api.client.http.javanet.NetHttpTransport; +import com.google.api.client.json.JsonFactory; +import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; +import com.google.api.client.json.jackson2.JacksonFactory; + +import com.google.api.services.bigquery.Bigquery; +import com.google.api.services.bigquery.BigqueryScopes; +import com.google.api.client.json.GenericJson; +import com.google.api.services.bigquery.Bigquery.Datasets; +import com.google.api.services.bigquery.BigqueryRequest; +import com.google.api.services.bigquery.model.DatasetList; +import com.google.api.services.bigquery.model.Job; +import com.google.api.services.bigquery.model.TableCell; +import com.google.api.services.bigquery.model.TableFieldSchema; +import com.google.api.services.bigquery.model.TableRow; +import com.google.api.services.bigquery.model.TableSchema; +import com.google.api.services.bigquery.Bigquery.Jobs.GetQueryResults; +import com.google.api.services.bigquery.model.GetQueryResultsResponse; +import com.google.api.services.bigquery.model.QueryRequest; +import com.google.api.services.bigquery.model.QueryResponse; +import com.google.api.services.bigquery.model.JobCancelResponse; +import com.google.gson.Gson; + +import java.io.IOException; +import java.util.Collection; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.util.Properties; +import java.util.Set; + +import org.apache.zeppelin.interpreter.Interpreter; +import org.apache.zeppelin.interpreter.InterpreterContext; +import org.apache.zeppelin.interpreter.InterpreterPropertyBuilder; +import org.apache.zeppelin.interpreter.InterpreterResult; +import org.apache.zeppelin.interpreter.InterpreterResult.Code; +import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion; +import org.apache.zeppelin.scheduler.Scheduler; +import org.apache.zeppelin.scheduler.SchedulerFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.Function; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; +import com.google.common.collect.Sets.SetView; +import java.io.PrintStream; +import java.io.Reader; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; + +/** + * BigQuery interpreter for Zeppelin. + * + * + * + *

+ * How to use:
+ * {@code %bigquery.sql
+ * {@code + * SELECT departure_airport,count(case when departure_delay>0 then 1 else 0 end) as no_of_delays + * FROM [bigquery-samples:airline_ontime_data.flights] + * group by departure_airport + * order by 2 desc + * limit 10 + * } + *

+ * + */ + + +public class BigQueryInterpreter extends Interpreter { + + private Logger logger = LoggerFactory.getLogger(BigQueryInterpreter.class); + private static final char NEWLINE = '\n'; + private static final char TAB = '\t'; + private static Bigquery service = null; + //Mutex created to create the singleton in thread-safe fashion. + private static Object serviceLock = new Object(); + + 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"; + + private static String jobId = null; + private static String projectId = null; + + private static final List NO_COMPLETION = new ArrayList<>(); + private Exception exceptionOnConnect; + + private static final Function sequenceToStringTransformer = + new Function() { + public String apply(CharSequence seq) { + return seq.toString(); + } + }; + + public BigQueryInterpreter(Properties property) { + super(property); + } + + + //Function to return valid BigQuery Service + @Override + public void open() { + if (service == null) { + synchronized (serviceLock) { + if (service == null) { + try { + service = createAuthorizedClient(); + exceptionOnConnect = null; + logger.info("Opened BigQuery SQL Connection"); + } catch (IOException e) { + logger.error("Cannot open connection", e); + exceptionOnConnect = e; + close(); + } + } + } + } + } + + //Function that Creates an authorized client to Google Bigquery. + private static Bigquery createAuthorizedClient() throws IOException { + HttpTransport transport = new NetHttpTransport(); + JsonFactory jsonFactory = new JacksonFactory(); + GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory); + + if (credential.createScopedRequired()) { + Collection bigqueryScopes = BigqueryScopes.all(); + credential = credential.createScoped(bigqueryScopes); + } + + return new Bigquery.Builder(transport, jsonFactory, credential) + .setApplicationName("Zeppelin/1.0 (GPN:Apache Zeppelin;)").build(); + } + + //Function that generates and returns the schema and the rows as string + public static String printRows(final GetQueryResultsResponse response) { + StringBuilder msg = null; + msg = new StringBuilder(); + try { + for (TableFieldSchema schem: response.getSchema().getFields()) { + msg.append(schem.getName()); + msg.append(TAB); + } + msg.append(NEWLINE); + for (TableRow row : response.getRows()) { + for (TableCell field : row.getF()) { + msg.append(field.getV().toString()); + msg.append(TAB); + } + msg.append(NEWLINE); + } + return msg.toString(); + } catch ( NullPointerException ex ) { + throw new NullPointerException("SQL Execution returned an error!"); + } + } + + //Function to poll a job for completion. Future use + public static Job pollJob(final Bigquery.Jobs.Get request, final long interval) + throws IOException, InterruptedException { + Job job = request.execute(); + while (!job.getStatus().getState().equals("DONE")) { + System.out.println("Job is " + + job.getStatus().getState() + + " waiting " + interval + " milliseconds..."); + Thread.sleep(interval); + job = request.execute(); + } + return job; + } + + //Function to page through the results of an arbitrary bigQuery request + public static Iterator getPages( + final BigqueryRequest requestTemplate) { + class PageIterator implements Iterator { + private BigqueryRequest request; + private boolean hasNext = true; + public PageIterator(final BigqueryRequest requestTemplate) { + this.request = requestTemplate; + } + public boolean hasNext() { + return hasNext; + } + public T next() { + if (!hasNext) { + throw new NoSuchElementException(); + } + try { + T response = request.execute(); + if (response.containsKey("pageToken")) { + request = request.set("pageToken", response.get("pageToken")); + } else { + hasNext = false; + } + return response; + } catch (IOException e) { + return null; + } + } + + public void remove() { + this.next(); + } + } + + return new PageIterator(requestTemplate); + } + + //Function to call bigQuery to run SQL and return results to the Interpreter for output + private InterpreterResult executeSql(String sql) { + int counter = 0; + StringBuilder finalmessage = null; + finalmessage = new StringBuilder("%table "); + String projId = getProperty(PROJECT_ID); + long wTime = Long.parseLong(getProperty(WAIT_TIME)); + long maxRows = Long.parseLong(getProperty(MAX_ROWS)); + Iterator pages; + try { + pages = run(sql, projId, wTime, maxRows); + } catch ( IOException ex ) { + logger.error(ex.getMessage()); + return new InterpreterResult(Code.ERROR, ex.getMessage()); + } + try { + while (pages.hasNext()) { + finalmessage.append(printRows(pages.next())); + } + return new InterpreterResult(Code.SUCCESS, finalmessage.toString()); + } catch ( NullPointerException ex ) { + return new InterpreterResult(Code.ERROR, ex.getMessage()); + } + } + + //Function to run the SQL on bigQuery service + public static Iterator run(final String queryString, + final String projId, final long wTime, final long maxRows) + throws IOException { + try { + QueryResponse query = service.jobs().query( + projId, + new QueryRequest().setTimeoutMs(wTime).setQuery(queryString).setMaxResults(maxRows)) + .execute(); + jobId = query.getJobReference().getJobId(); + projectId = query.getJobReference().getProjectId(); + GetQueryResults getRequest = service.jobs().getQueryResults( + projectId, + jobId); + return getPages(getRequest); + } catch (IOException ex) { + throw ex; + } + } + + @Override + public void close() { + + logger.info("Close bqsql connection!"); + + service = null; + } + + @Override + public InterpreterResult interpret(String sql, InterpreterContext contextInterpreter) { + logger.info("Run SQL command '{}'", sql); + return executeSql(sql); + } + + @Override + public Scheduler getScheduler() { + return SchedulerFactory.singleton().createOrGetFIFOScheduler( + BigQueryInterpreter.class.getName() + this.hashCode()); + } + + @Override + public FormType getFormType() { + return FormType.SIMPLE; + } + + @Override + public int getProgress(InterpreterContext context) { + return 0; + } + + @Override + public void cancel(InterpreterContext context) { + + logger.info("Trying to Cancel current query statement."); + + if (service != null && jobId != null && projectId != null) { + try { + Bigquery.Jobs.Cancel request = service.jobs().cancel(projectId, jobId); + JobCancelResponse response = request.execute(); + jobId = null; + logger.info("Query Execution cancelled"); + } catch (IOException ex) { + logger.error("Could not cancel the SQL execution"); + } + } else { + logger.info("Query Execution was already cancelled"); + } + } + + @Override + public List completion(String buf, int cursor) { + return NO_COMPLETION; + } +} diff --git a/bigquery/src/main/resources/constants.json b/bigquery/src/main/resources/constants.json new file mode 100644 index 00000000000..afd950ea52b --- /dev/null +++ b/bigquery/src/main/resources/constants.json @@ -0,0 +1,5 @@ +{ + "projectId": "google.com:babupe-df-test", + "oneQuery": "select 1", + "wrongQuery": "select bad syntax" +} diff --git a/bigquery/src/main/resources/interpreter-setting.json b/bigquery/src/main/resources/interpreter-setting.json new file mode 100644 index 00000000000..3e524ed8362 --- /dev/null +++ b/bigquery/src/main/resources/interpreter-setting.json @@ -0,0 +1,27 @@ +[ + { + "group": "bigquery", + "name": "sql", + "className": "org.apache.zeppelin.bigquery.BigQueryInterpreter", + "properties": { + "zeppelin.bigquery.project_id": { + "envName": null, + "propertyName": "zeppelin.bigquery.project_id", + "defaultValue": " ", + "description": "Google Project ID" + }, + "zeppelin.bigquery.wait_time": { + "envName": null, + "propertyName": "zeppelin.bigquery.wait_time", + "defaultValue": "5000", + "description": "Query timeout in Milliseconds" + }, + "zeppelin.bigquery.max_no_of_rows": { + "envName": null, + "propertyName": "zeppelin.bigquery.max_no_of_rows", + "defaultValue": "100000", + "description": "Maximum number of rows to fetch from BigQuery" + } + } + } +] diff --git a/bigquery/src/test/java/org/apache/zeppelin/bigquery/BigQueryInterpreterTest.java b/bigquery/src/test/java/org/apache/zeppelin/bigquery/BigQueryInterpreterTest.java new file mode 100644 index 00000000000..add109b60c8 --- /dev/null +++ b/bigquery/src/test/java/org/apache/zeppelin/bigquery/BigQueryInterpreterTest.java @@ -0,0 +1,118 @@ +/* +* Copyright 2016 Google Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 + +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +package org.apache.zeppelin.bigquery; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Properties; + +import org.apache.zeppelin.display.AngularObjectRegistry; +import org.apache.zeppelin.display.GUI; +import org.apache.zeppelin.interpreter.InterpreterContext; +import org.apache.zeppelin.interpreter.InterpreterContextRunner; +import org.apache.zeppelin.interpreter.InterpreterGroup; +import org.apache.zeppelin.interpreter.InterpreterOutput; +import org.apache.zeppelin.interpreter.InterpreterOutputListener; +import org.apache.zeppelin.interpreter.InterpreterResult; +import org.apache.zeppelin.interpreter.InterpreterResult.Type; +import org.apache.zeppelin.user.AuthenticationInfo; +import org.junit.Before; +import org.junit.Test; + +import com.google.gson.Gson; +import com.google.gson.JsonIOException; +import com.google.gson.JsonSyntaxException; + +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.io.InputStreamReader; + +public class BigQueryInterpreterTest { + + protected static class Constants { + private String projectId; + private String oneQuery; + private String wrongQuery; + + public String getProjectId() { + return projectId; + } + + public String getOne() { + return oneQuery; + } + + public String getWrong() { + return wrongQuery; + } + + } + + @SuppressWarnings("checkstyle:abbreviationaswordinname") + protected static Constants CONSTANTS = null; + + public BigQueryInterpreterTest() + throws JsonSyntaxException, JsonIOException, FileNotFoundException { + if (CONSTANTS == null) { + InputStream is = this.getClass().getResourceAsStream("/constants.json"); + CONSTANTS = (new Gson()).fromJson(new InputStreamReader(is), Constants.class); + } + } + + private InterpreterGroup intpGroup; + private BigQueryInterpreter bqInterpreter; + + private InterpreterContext context; + + @Before + public void setUp() throws Exception { + Properties p = new Properties(); + p.setProperty("zeppelin.bigquery.project_id", CONSTANTS.getProjectId()); + p.setProperty("zeppelin.bigquery.wait_time", "5000"); + p.setProperty("zeppelin.bigquery.max_no_of_rows", "100"); + + intpGroup = new InterpreterGroup(); + + bqInterpreter = new BigQueryInterpreter(p); + bqInterpreter.setInterpreterGroup(intpGroup); + bqInterpreter.open(); + + } + + @Test + public void sqlSuccess() { + InterpreterResult ret = bqInterpreter.interpret(CONSTANTS.getOne(), context); + + assertEquals(InterpreterResult.Code.SUCCESS, ret.code()); + assertEquals(ret.type(), InterpreterResult.Type.TABLE); + + } + + @Test + public void badSqlSyntaxFails() { + InterpreterResult ret = bqInterpreter.interpret(CONSTANTS.getWrong(), context); + + assertEquals(InterpreterResult.Code.ERROR, ret.code()); + } + +} diff --git a/docs/_includes/themes/zeppelin/_navigation.html b/docs/_includes/themes/zeppelin/_navigation.html index 6c09e2b4bf4..7756f233820 100644 --- a/docs/_includes/themes/zeppelin/_navigation.html +++ b/docs/_includes/themes/zeppelin/_navigation.html @@ -48,6 +48,7 @@
  • Available Interpreters
  • Alluxio
  • +
  • BigQuery
  • Cassandra
  • Elasticsearch
  • Flink
  • @@ -113,4 +114,4 @@ - \ No newline at end of file + diff --git a/docs/assets/themes/zeppelin/img/docs-img/bigqueryZeppelin.png b/docs/assets/themes/zeppelin/img/docs-img/bigqueryZeppelin.png new file mode 100644 index 00000000000..81ee4b2618c Binary files /dev/null and b/docs/assets/themes/zeppelin/img/docs-img/bigqueryZeppelin.png differ diff --git a/docs/interpreter/bigquery.md b/docs/interpreter/bigquery.md new file mode 100644 index 00000000000..1e92aa98757 --- /dev/null +++ b/docs/interpreter/bigquery.md @@ -0,0 +1,113 @@ +--- +layout: page +title: "BigQuery Interpreter" +description: "" +group: interpreter +--- + +# BigQuery Interpreter for Apache Zeppelin + +
    + +## Overview +[BigQuery](https://cloud.google.com/bigquery/what-is-bigquery) is a highly scalable no-ops data warehouse in the Google Cloud Platform. Querying massive datasets can be time consuming and expensive without the right hardware and infrastructure. Google BigQuery solves this problem by enabling super-fast SQL queries against append-only tables using the processing power of Google's infrastructure. Simply move your data into BigQuery and let us handle the hard work. You can control access to both the project and your data based on your business needs, such as giving others the ability to view or query your data. + +## Configuration + + + + + + + + + + + + + + + + + + + + + +
    NameDefault ValueDescription
    zeppelin.bigquery.project_id Google Project Id
    zeppelin.bigquery.wait_time5000Query Timeout in Milliseconds
    zeppelin.bigquery.max_no_of_rows100000Max result set size
    + + +## BigQuery API +Zeppelin is built against BigQuery API version v2-rev265-1.21.0 - [API Javadocs](https://developers.google.com/resources/api-libraries/documentation/bigquery/v2/java/latest/) + +## Enabling the BigQuery Interpreter + +In a notebook, to enable the **BigQuery** interpreter, click the **Gear** icon and select **bigquery**. + +### Setup service account credentials + +In order to run BigQuery interpreter outside of Google Cloud Engine you need to provide authentication credentials, +by [following this instructions](https://developers.google.com/identity/protocols/application-default-credentials): + + - Go to the [API Console Credentials page](https://console.developers.google.com/project/_/apis/credentials) + - From the project drop-down, select your project. + - On the `Credentials` page, select the `Create credentials` drop-down, then select `Service account key`. + - From the Service account drop-down, select an existing service account or create a new one. + - For `Key type`, select the `JSON` key option, then select `Create`. The file automatically downloads to your computer. + - Put the `*.json` file you just downloaded in a directory of your choosing. This directory must be private (you can't let anyone get access to this), but accessible to your Zeppelin instance. + - Set the environment variable `GOOGLE_APPLICATION_CREDENTIALS` to the path of the JSON file downloaded. + * either though GUI: in interpreter configuration page property names in CAPITAL_CASE set up env vars + * or though `zeppelin-env.sh`: just add it to the end of the file. + +## Using the BigQuery Interpreter + +In a paragraph, use `%bigquery.sql` to select the **BigQuery** interpreter and then input SQL statements against your datasets stored in BigQuery. +You can use [BigQuery SQL Reference](https://cloud.google.com/bigquery/query-reference) to build your own SQL. + +For Example, SQL to query for top 10 departure delays across airports using the flights public dataset + +```bash +%bigquery.sql +SELECT departure_airport,count(case when departure_delay>0 then 1 else 0 end) as no_of_delays +FROM [bigquery-samples:airline_ontime_data.flights] +group by departure_airport +order by 2 desc +limit 10 +``` + +Another Example, SQL to query for most commonly used java packages from the github data hosted in BigQuery + +```bash +%bigquery.sql +SELECT + package, + COUNT(*) count +FROM ( + SELECT + REGEXP_EXTRACT(line, r' ([a-z0-9\._]*)\.') package, + id + FROM ( + SELECT + SPLIT(content, '\n') line, + id + FROM + [bigquery-public-data:github_repos.sample_contents] + WHERE + content CONTAINS 'import' + AND sample_path LIKE '%.java' + HAVING + LEFT(line, 6)='import' ) + GROUP BY + package, + id ) +GROUP BY + 1 +ORDER BY + count DESC +LIMIT + 40 +``` + +## Technical description + +For in-depth technical details on current implementation please refer to [bigquery/README.md](https://github.com/apache/zeppelin/blob/master/bigquery/README.md). diff --git a/licenses/LICENSE-bigquery-interpreter-google b/licenses/LICENSE-bigquery-interpreter-google new file mode 100644 index 00000000000..9dd8af7de7a --- /dev/null +++ b/licenses/LICENSE-bigquery-interpreter-google @@ -0,0 +1,176 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS diff --git a/pom.xml b/pom.xml index c5c429bb6cb..24896b39541 100644 --- a/pom.xml +++ b/pom.xml @@ -72,6 +72,7 @@ lens cassandra elasticsearch + bigquery alluxio zeppelin-web zeppelin-server @@ -460,6 +461,7 @@ spark-*-bin*/** .spark-dist/** **/interpreter-setting.json + **/constants.json docs/assets/themes/zeppelin/bootstrap/** diff --git a/zeppelin-distribution/src/bin_license/LICENSE b/zeppelin-distribution/src/bin_license/LICENSE index 52bd82fc4ae..ffecbe21ec0 100644 --- a/zeppelin-distribution/src/bin_license/LICENSE +++ b/zeppelin-distribution/src/bin_license/LICENSE @@ -4,6 +4,7 @@ (Apache 2.0) JavaEWAH v0.7.9 (https://github.com/lemire/javaewah) - https://github.com/lemire/javaewah/blob/master/LICENSE-2.0.txt + The following components are provided under Apache License. @@ -73,7 +74,7 @@ The following components are provided under Apache License. (Apache 2.0) json-flattener (com.github.wnameless:json-flattener:0.1.6 - https://github.com/wnameless/json-flattener) (Apache 2.0) Spatial4J (com.spatial4j:spatial4j:0.4.1 - https://github.com/spatial4j/spatial4j) (Apache 2.0) T-Digest (com.tdunning:t-digest:3.0 - https://github.com/tdunning/t-digest) - (Apache 2.0) Netty (io.netty:netty:3.8.0.Final - http://netty.io/) + (Apache 2.0) Netty (io.netty:netty:3.10.5.Final - http://netty.io/) (Apache 2.0) Lucene Common Analyzers (org.apache.lucene:lucene-analyzers-common:5.3.1 - http://lucene.apache.org/lucene-parent/lucene-analyzers-common) (Apache 2.0) Lucene Memory (org.apache.lucene:lucene-backward-codecs:5.3.1 - http://lucene.apache.org/lucene-parent/lucene-backward-codecs) (Apache 2.0) Lucene Core (org.apache.lucene:lucene-core:5.3.1 - http://lucene.apache.org/lucene-parent/lucene-core) @@ -102,7 +103,17 @@ The following components are provided under Apache License. (Apache 2.0) Roboto Font (https://github.com/google/roboto/) (Apache 2.0) stream (com.clearspring.analytics:stream:2.7.0) - https://github.com/addthis/stream-lib/blob/v2.7.0/LICENSE.txt (Apache 2.0) io.dropwizard.metrics:3.1.2 - https://github.com/dropwizard/metrics/blob/v3.1.2/LICENSE - + (Apache 2.0) Google BigQuery API for Java (com.google.api.services.bigquery:v2-rev265-1.21.0 - https://cloud.google.com/bigquery/) + (Apache 2.0) Google APIs Client Library for Java (com.google.api-client:1.21.0 - https://github.com/google/google-api-java-client) + (Apache 2.0) The Guava project contains several of Google's core libraries that we rely on in our Java-based projects (com.google.guava:guava-jdk5:17.0 - https://github.com/google/guava) + (Apache 2.0) Google OAuth Client Library for Java (com.google.oauth-client:google-oauth-client:1.21.0 - https://github.com/google/google-oauth-java-client) + (Apache 2.0) Google HTTP Client Library for Java (com.google.http-client:google-http-client:1.21.0 - https://github.com/google/google-http-java-client/tree/dev/google-http-client) + (Apache 2.0) Google OAuth Jetty Client Library for Java (com.google.oauth-client:google-oauth-client-jetty:1.21.0 - https://github.com/google/google-oauth-java-client/tree/dev/google-oauth-client-jetty) + (Apache 2.0) Google OAuth Client Library for Java6 (com.google.oauth-client:google-oauth-client-java6:1.21.0 - https://github.com/google/google-oauth-java-client/tree/dev/google-oauth-client-java6) + (Apache 2.0) The core jetty server artifact (org.mortbay.jetty:jetty:6.1.26 - http://javadox.com/org.mortbay.jetty/jetty/6.1.26/overview-tree.html) + (Apache 2.0) Utility classes for Jetty (org.mortbay.jetty:jetty-util:6.1.26 - http://javadox.com/org.mortbay.jetty/jetty/6.1.26/overview-tree.html) + (Apache 2.0) Servlet API (org.mortbay.jetty:servlet-api:2.5-20081211 - https://en.wikipedia.org/wiki/Jetty_(web_server)) + (Apache 2.0) Google HTTP Client Library for Java (com.google.http-client:google-http-client-jackson2:1.21.0 - https://github.com/google/google-http-java-client/tree/dev/google-http-client-jackson2) ======================================================================== MIT licenses @@ -171,7 +182,6 @@ The following components are provided under the BSD-style License. (New BSD License) JGit (org.eclipse.jgit:org.eclipse.jgit:jar:4.1.1.201511131810-r - https://eclipse.org/jgit/) (New BSD License) Kryo (com.esotericsoftware.kryo:kryo:3.0.3 - http://code.google.com/p/kryo/) - (New BSD License) leveldbjni (org.fusesource.leveldbjni:leveldbjni-all:1.8) - https://github.com/fusesource/leveldbjni/blob/leveldbjni-1.8/license.txt (New BSD License) MinLog (com.esotericsoftware.minlog:minlog:1.3 - http://code.google.com/p/minlog/) (New BSD License) ReflectASM (com.esotericsoftware.reflectasm:reflectasm:1.07 - http://code.google.com/p/reflectasm/) (BSD-like) Scala Library (org.scala-lang:scala-library:2.11.7 - http://www.scala-lang.org/)