This is an automated email from the ASF dual-hosted git repository. jongyoul pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/zeppelin.git
The following commit(s) were added to refs/heads/master by this push: new 83e672f0c7 Remove geode interpreter (#4430) 83e672f0c7 is described below commit 83e672f0c7d0ee7d6c9a4935eee42ce1924beeb1 Author: Nelljun <34996983+nell...@users.noreply.github.com> AuthorDate: Fri Jul 29 22:30:30 2022 +0900 Remove geode interpreter (#4430) --- .github/workflows/core.yml | 2 +- .github/workflows/frontend.yml | 2 +- conf/interpreter-list | 1 - dev/create_release.sh | 2 +- docs/_includes/themes/zeppelin/_navigation.html | 1 - docs/index.md | 1 - docs/interpreter/geode.md | 218 --------------- docs/usage/interpreter/installation.md | 5 - geode/pom.xml | 80 ------ .../apache/zeppelin/geode/GeodeOqlInterpreter.java | 301 --------------------- geode/src/main/resources/interpreter-setting.json | 33 --- .../zeppelin/geode/GeodeOqlInterpreterTest.java | 178 ------------ pom.xml | 1 - 13 files changed, 3 insertions(+), 822 deletions(-) diff --git a/.github/workflows/core.yml b/.github/workflows/core.yml index 4f7b609f89..93366a5531 100644 --- a/.github/workflows/core.yml +++ b/.github/workflows/core.yml @@ -82,7 +82,7 @@ jobs: interpreter-test-non-core: runs-on: ubuntu-20.04 env: - INTERPRETERS: 'beam,hbase,jdbc,file,flink-cmd,ignite,cassandra,elasticsearch,bigquery,alluxio,livy,groovy,sap,java,geode,neo4j,submarine,sparql,mongodb,influxdb,ksql' + INTERPRETERS: 'beam,hbase,jdbc,file,flink-cmd,ignite,cassandra,elasticsearch,bigquery,alluxio,livy,groovy,sap,java,neo4j,submarine,sparql,mongodb,influxdb,ksql' steps: - name: Checkout uses: actions/checkout@v2 diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index defee2faa5..9ad2bf5045 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -19,7 +19,7 @@ env: SPARK_PRINT_LAUNCH_COMMAND: "true" SPARK_LOCAL_IP: 127.0.0.1 ZEPPELIN_LOCAL_IP: 127.0.0.1 - INTERPRETERS: '!beam,!hbase,!jdbc,!file,!flink,!ignite,!cassandra,!elasticsearch,!bigquery,!alluxio,!livy,!groovy,!sap,!java,!geode,!neo4j,!submarine,!sparql,!mongodb' + INTERPRETERS: '!beam,!hbase,!jdbc,!file,!flink,!ignite,!cassandra,!elasticsearch,!bigquery,!alluxio,!livy,!groovy,!sap,!java,!neo4j,!submarine,!sparql,!mongodb' jobs: run-e2e-tests-in-zeppelin-web: diff --git a/conf/interpreter-list b/conf/interpreter-list index 3be3396aee..51be181f31 100644 --- a/conf/interpreter-list +++ b/conf/interpreter-list @@ -25,7 +25,6 @@ cassandra org.apache.zeppelin:zeppelin-cassandra:0.10.0 Cassand elasticsearch org.apache.zeppelin:zeppelin-elasticsearch:0.10.0 Elasticsearch interpreter file org.apache.zeppelin:zeppelin-file:0.10.0 HDFS file interpreter flink org.apache.zeppelin:zeppelin-flink:0.10.0 Flink interpreter -geode org.apache.zeppelin:zeppelin-geode:0.10.0 Apache Geode interpreter groovy org.apache.zeppelin:zeppelin-groovy:0.10.0 Groovy interpreter hbase org.apache.zeppelin:zeppelin-hbase:0.10.0 Hbase interpreter ignite org.apache.zeppelin:zeppelin-ignite:0.10.0 Ignite interpreter diff --git a/dev/create_release.sh b/dev/create_release.sh index 0fa3b50de7..6e1ae8923d 100755 --- a/dev/create_release.sh +++ b/dev/create_release.sh @@ -98,7 +98,7 @@ function make_binary_release() { git_clone make_source_package -make_binary_release netinst "-Pweb-angular -Phadoop-2.6 -pl !beam,!hbase,!jdbc,!file,!flink,!ignite,!cassandra,!elasticsearch,!bigquery,!alluxio,!livy,!groovy,!sap,!java,!geode,!neo4j,!submarine,!sparql,!mongodb,!ksql -am" +make_binary_release netinst "-Pweb-angular -Phadoop-2.6 -pl !beam,!hbase,!jdbc,!file,!flink,!ignite,!cassandra,!elasticsearch,!bigquery,!alluxio,!livy,!groovy,!sap,!java,!neo4j,!submarine,!sparql,!mongodb,!ksql -am" make_binary_release all "-Pweb-angular -Phadoop-2.6" # remove non release files and dirs diff --git a/docs/_includes/themes/zeppelin/_navigation.html b/docs/_includes/themes/zeppelin/_navigation.html index 1cc4ba02ad..57fe76b8d4 100644 --- a/docs/_includes/themes/zeppelin/_navigation.html +++ b/docs/_includes/themes/zeppelin/_navigation.html @@ -143,7 +143,6 @@ <li><a href="{{BASE_PATH}}/interpreter/bigquery.html">BigQuery</a></li> <li><a href="{{BASE_PATH}}/interpreter/cassandra.html">Cassandra</a></li> <li><a href="{{BASE_PATH}}/interpreter/elasticsearch.html">Elasticsearch</a></li> - <li><a href="{{BASE_PATH}}/interpreter/geode.html">Geode</a></li> <li><a href="{{BASE_PATH}}/interpreter/groovy.html">Groovy</a></li> <li><a href="{{BASE_PATH}}/interpreter/hbase.html">HBase</a></li> <li><a href="{{BASE_PATH}}/interpreter/hdfs.html">HDFS</a></li> diff --git a/docs/index.md b/docs/index.md index e5a068530f..228778df5b 100644 --- a/docs/index.md +++ b/docs/index.md @@ -140,7 +140,6 @@ limitations under the License. * [Cassandra](./interpreter/cassandra.html) * [Elasticsearch](./interpreter/elasticsearch.html) * [Flink](./interpreter/flink.html) - * [Geode](./interpreter/geode.html) * [Groovy](./interpreter/groovy.html) * [HBase](./interpreter/hbase.html) * [HDFS](./interpreter/hdfs.html) diff --git a/docs/interpreter/geode.md b/docs/interpreter/geode.md deleted file mode 100644 index bd6bb7bbf9..0000000000 --- a/docs/interpreter/geode.md +++ /dev/null @@ -1,218 +0,0 @@ ---- -layout: page -title: "Geode/Gemfire OQL Interpreter for Apache Zeppelin" -description: "Apache Geode (incubating) provides a database-like consistency model, reliable transaction processing and a shared-nothing architecture to maintain very low latency performance with high concurrency processing." -group: interpreter ---- -<!-- -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. ---> -{% include JB/setup %} - -# Geode/Gemfire OQL Interpreter for Apache Zeppelin - -<div id="toc"></div> - -## Overview -<table class="table-configuration"> - <tr> - <th>Name</th> - <th>Class</th> - <th>Description</th> - </tr> - <tr> - <td>%geode.oql</td> - <td>GeodeOqlInterpreter</td> - <td>Provides OQL environment for Apache Geode</td> - </tr> -</table> - -This interpreter supports the [Geode](http://geode.incubator.apache.org/) [Object Query Language (OQL)](https://geode.incubator.apache.org/docs/guide/latest/developing/querying_basics/query_basics.html). -With the OQL-based querying language: - -[<img align="right" src="http://img.youtube.com/vi/zvzzA9GXu3Q/3.jpg" alt="zeppelin-view" hspace="10" width="200"></img>](https://www.youtube.com/watch?v=zvzzA9GXu3Q) - -* You can query on any arbitrary object -* You can navigate object collections -* You can invoke methods and access the behavior of objects -* Data mapping is supported -* You are not required to declare types. Since you do not need type definitions, you can work across multiple languages -* You are not constrained by a schema - -This [Video Tutorial](https://www.youtube.com/watch?v=zvzzA9GXu3Q) illustrates some of the features provided by the `Geode Interpreter`. - -## Create Interpreter -By default Zeppelin creates one `Geode/OQL` instance. You can remove it or create more instances. - -Multiple Geode instances can be created, each configured to the same or different backend Geode cluster. -But over time a `Notebook` can have only one Geode interpreter instance `bound`. -That means you _cannot_ connect to different Geode clusters in the same `Notebook`. -This is a known Zeppelin limitation. - -To create new Geode instance open the `Interpreter` section and click the `+Create` button. -Pick a `Name` of your choice and from the `Interpreter` drop-down select `geode`. -Then follow the configuration instructions and `Save` the new instance. - -> Note: The `Name` of the instance is used only to distinguish the instances while binding them to the `Notebook`. The `Name` is irrelevant inside the `Notebook`. In the `Notebook` you must use `%geode.oql` tag. - -## Bind to Notebook -In the `Notebook` click on the `settings` icon in the top right corner. -The select/deselect the interpreters to be bound with the `Notebook`. - -## Configuration -You can modify the configuration of the Geode from the `Interpreter` section. -The Geode interpreter expresses the following properties: - -<table class="table-configuration"> - <tr> - <th>Property Name</th> - <th>Description</th> - <th>Default Value</th> - </tr> - <tr> - <td>geode.locator.host</td> - <td>The Geode Locator Host</td> - <td>localhost</td> - </tr> - <tr> - <td>geode.locator.port</td> - <td>The Geode Locator Port</td> - <td>10334</td> - </tr> - <tr> - <td>geode.max.result</td> - <td>Max number of OQL result to display to prevent the browser overload</td> - <td>1000</td> - </tr> -</table> - -## How to use -> *Tip 1: Use (CTRL + .) for OQL auto-completion.* - -> *Tip 2: Always start the paragraphs with the full `%geode.oql` prefix tag! The short notation: `%geode` would still be able run the OQL queries but the syntax highlighting and the auto-completions will be disabled.* - -### Create / Destroy Regions - -The OQL specification does not support [Geode Regions](https://cwiki.apache.org/confluence/display/GEODE/Index#Index-MainConceptsandComponents) mutation operations. -To `create`/`destroy` regions one should use the [GFSH](https://geode.incubator.apache.org/docs/guide/latest/tools_modules/gfsh/chapter_overview.html) shell tool instead. -In the following it is assumed that the GFSH is colocated with Zeppelin server. - -```bash -%sh -source /etc/geode/conf/geode-env.sh -gfsh << EOF - - connect --locator=ambari.localdomain[10334] - - destroy region --name=/regionEmployee - destroy region --name=/regionCompany - create region --name=regionEmployee --type=REPLICATE - create region --name=regionCompany --type=REPLICATE - - exit; -EOF -``` - -Above snippet re-creates two regions: `regionEmployee` and `regionCompany`. -Note that you have to explicitly specify the locator host and port. -The values should match those you have used in the Geode Interpreter configuration. -Comprehensive list of [GFSH Commands by Functional Area](https://geode.incubator.apache.org/docs/guide/latest/tools_modules/gfsh/gfsh_quick_reference.html). - -### Basic OQL -```sql -%geode.oql -SELECT count(*) FROM /regionEmployee -``` - -OQL `IN` and `SET` filters: - -```sql -%geode.oql -SELECT * FROM /regionEmployee -WHERE companyId IN SET(2) OR lastName IN SET('Tzolov13', 'Tzolov73') -``` - -OQL `JOIN` operations - -```sql -%geode.oql -SELECT e.employeeId, e.firstName, e.lastName, c.id as companyId, c.companyName, c.address -FROM /regionEmployee e, /regionCompany c -WHERE e.companyId = c.id -``` - -By default the QOL responses contain only the region entry values. To access the keys, query the `EntrySet` instead: - -```sql -%geode.oql -SELECT e.key, e.value.companyId, e.value.email -FROM /regionEmployee.entrySet e -``` -Following query will return the EntrySet value as a Blob: - -```sql -%geode.oql -SELECT e.key, e.value FROM /regionEmployee.entrySet e -``` - -> Note: You can have multiple queries in the same paragraph but only the result from the first is displayed. [[1](https://issues.apache.org/jira/browse/ZEPPELIN-178)], [[2](https://issues.apache.org/jira/browse/ZEPPELIN-212)]. - -### GFSH Commands From The Shell -Use the Shell Interpreter (`%sh`) to run OQL commands form the command line: - -```bash -%sh -source /etc/geode/conf/geode-env.sh -gfsh -e "connect" -e "list members" -``` - -### Apply Zeppelin Dynamic Forms -You can leverage [Zeppelin Dynamic Form](../usage/dynamic_form/intro.html) inside your OQL queries. You can use both the `text input` and `select form` parameterization features - -```sql -%geode.oql -SELECT * FROM /regionEmployee e WHERE e.employeeId > ${Id} -``` - -### Auto-completion -The Geode Interpreter provides a basic auto-completion functionality. On `(Ctrl+.)` it list the most relevant suggestions in a pop-up window. - -## Geode REST API -To list the defined regions you can use the [Geode REST API](https://geode.apache.org/docs/guide/latest/rest_apps/chapter_overview.html): - -``` -http://<geode server hostname>phd1.localdomain:8484/gemfire-api/v1/ -``` - -```json -{ - "regions" : [{ - "name" : "regionEmployee", - "type" : "REPLICATE", - "key-constraint" : null, - "value-constraint" : null - }, { - "name" : "regionCompany", - "type" : "REPLICATE", - "key-constraint" : null, - "value-constraint" : null - }] -} -``` - -> To enable Geode REST API with JSON support add the following properties to geode.server.properties.file and restart: - -``` -http-service-port=8484 -start-dev-rest-api=true -``` diff --git a/docs/usage/interpreter/installation.md b/docs/usage/interpreter/installation.md index 36b192f813..48716f6bdb 100644 --- a/docs/usage/interpreter/installation.md +++ b/docs/usage/interpreter/installation.md @@ -152,11 +152,6 @@ You can also find the below community managed interpreter list in `conf/interpre <td>org.apache.zeppelin:zeppelin-hbase:0.10.0</td> <td>Hbase interpreter</td> </tr> - <tr> - <td>geode</td> - <td>org.apache.zeppelin:zeppelin-geode:0.10.0</td> - <td>Apache Geode interpreter</td> - </tr> <tr> <td>groovy</td> <td>org.apache.zeppelin:zeppelin-groovy:0.10.0</td> diff --git a/geode/pom.xml b/geode/pom.xml deleted file mode 100644 index c521581f57..0000000000 --- a/geode/pom.xml +++ /dev/null @@ -1,80 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one or more - ~ contributor license agreements. See the NOTICE file distributed with - ~ this work for additional information regarding copyright ownership. - ~ The ASF licenses this file to You 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. - --> - -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <artifactId>zeppelin-interpreter-parent</artifactId> - <groupId>org.apache.zeppelin</groupId> - <version>0.11.0-SNAPSHOT</version> - <relativePath>../zeppelin-interpreter-parent/pom.xml</relativePath> - </parent> - - <artifactId>zeppelin-geode</artifactId> - <packaging>jar</packaging> - <name>Zeppelin: Apache Geode interpreter</name> - - <properties> - <!--library versions--> - <interpreter.name>geode</interpreter.name> - <geode.version>1.12.5</geode.version> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.geode</groupId> - <artifactId>geode-core</artifactId> - <version>${geode.version}</version> - </dependency> - - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-exec</artifactId> - <version>${commons.exec.version}</version> - </dependency> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-all</artifactId> - <scope>test</scope> - </dependency> - - </dependencies> - - <build> - <plugins> - <plugin> - <artifactId>maven-enforcer-plugin</artifactId> - </plugin> - <plugin> - <artifactId>maven-resources-plugin</artifactId> - </plugin> - <plugin> - <artifactId>maven-shade-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-checkstyle-plugin</artifactId> - <configuration> - <skip>false</skip> - </configuration> - </plugin> - </plugins> - </build> -</project> diff --git a/geode/src/main/java/org/apache/zeppelin/geode/GeodeOqlInterpreter.java b/geode/src/main/java/org/apache/zeppelin/geode/GeodeOqlInterpreter.java deleted file mode 100644 index a83410c17b..0000000000 --- a/geode/src/main/java/org/apache/zeppelin/geode/GeodeOqlInterpreter.java +++ /dev/null @@ -1,301 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to you 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> - * 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.geode; - -import org.apache.commons.lang3.StringUtils; -import org.apache.geode.cache.client.ClientCache; -import org.apache.geode.cache.client.ClientCacheFactory; -import org.apache.geode.cache.query.QueryService; -import org.apache.geode.cache.query.SelectResults; -import org.apache.geode.cache.query.Struct; -import org.apache.geode.pdx.PdxInstance; -import org.apache.zeppelin.interpreter.Interpreter; -import org.apache.zeppelin.interpreter.InterpreterContext; -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 java.util.Iterator; -import java.util.List; -import java.util.Properties; - -/** - * Apache Geode OQL Interpreter (http://geode.apache.org) - * - * <ul> - * <li>{@code geode.locator.host} - The Geode Locator {@code <HOST>} to connect to.</li> - * <li>{@code geode.locator.port} - The Geode Locator {@code <PORT>} to connect to.</li> - * <li>{@code geode.max.result} - Max number of OQL result to display.</li> - * </ul> - * <p> - * Sample usages: <br/> - * {@code %geode.oql} <br/> - * {@code SELECT * FROM /regionEmployee e WHERE e.companyId > 95} <br/> - * {@code SELECT * FROM /regionEmployee ORDER BY employeeId} <br/> - * {@code - * SELECT * FROM /regionEmployee - * WHERE companyId IN SET(1, 3, 7) OR lastName IN SET('NameA', 'NameB') - * } <br/> - * {@code - * SELECT e.employeeId, c.id as companyId FROM /regionEmployee e, /regionCompany c - * WHERE e.companyId = c.id - * } - * </p> - * <p> - * OQL specification and sample queries: - * http://geode-docs.cfapps.io/docs/getting_started/querying_quick_reference.html - * </p> - * <p> - * When the Zeppelin server is collocated with Geode Shell (gfsh) one can use the %sh interpreter to - * run Geode shell commands: <br/> - * {@code - * %sh - * source /etc/geode/conf/geode-env.sh - * gfsh << EOF - * connect --locator=ambari.localdomain[10334] - * destroy region --name=/regionEmployee - * create region --name=regionEmployee --type=REPLICATE - * exit; - * EOF - *} - * </p> - * <p> - * Known issue:http://gemfire.docs.pivotal.io/bugnotes/KnownIssuesGemFire810.html #43673 Using query - * "select * from /exampleRegion.entrySet" fails in a client-server topology and/or in a - * PartitionedRegion. - * </p> - */ -public class GeodeOqlInterpreter extends Interpreter { - - private static final Logger LOGGER = LoggerFactory.getLogger(GeodeOqlInterpreter.class); - - private static final char NEWLINE = '\n'; - private static final char TAB = '\t'; - private static final char WHITESPACE = ' '; - - private static final String TABLE_MAGIC_TAG = "%table "; - - private ClientCache clientCache = null; - private QueryService queryService = null; - private Exception exceptionOnConnect; - private int maxResult; - - public GeodeOqlInterpreter(Properties property) { - super(property); - } - - protected ClientCache getClientCache() { - - String locatorHost = getProperty("geode.locator.host"); - int locatorPort = Integer.valueOf(getProperty("geode.locator.port")); - - ClientCache clientCache = - new ClientCacheFactory().addPoolLocator(locatorHost, locatorPort).create(); - - return clientCache; - } - - @Override - public void open() { - LOGGER.info("Geode open connection called!"); - - // Close the previous open connections. - close(); - - try { - maxResult = Integer.valueOf(getProperty("geode.max.result")); - - clientCache = getClientCache(); - queryService = clientCache.getQueryService(); - - exceptionOnConnect = null; - LOGGER.info("Successfully created Geode connection"); - } catch (Exception e) { - LOGGER.error("Cannot open connection", e); - exceptionOnConnect = e; - } - } - - @Override - public void close() { - try { - if (clientCache != null) { - clientCache.close(); - } - - if (queryService != null) { - queryService.closeCqs(); - } - - } catch (Exception e) { - LOGGER.error("Cannot close connection", e); - } finally { - clientCache = null; - queryService = null; - exceptionOnConnect = null; - } - } - - private InterpreterResult executeOql(String oql) { - try { - - if (getExceptionOnConnect() != null) { - return new InterpreterResult(Code.ERROR, getExceptionOnConnect().getMessage()); - } - - @SuppressWarnings("unchecked") - SelectResults<Object> results = - (SelectResults<Object>) getQueryService().newQuery(oql).execute(); - - StringBuilder msg = new StringBuilder(TABLE_MAGIC_TAG); - boolean isTableHeaderSet = false; - - Iterator<Object> iterator = results.iterator(); - int rowDisplayCount = 0; - - while (iterator.hasNext() && (rowDisplayCount < getMaxResult())) { - - Object entry = iterator.next(); - rowDisplayCount++; - - if (entry instanceof Number) { - handleNumberEntry(isTableHeaderSet, entry, msg); - } else if (entry instanceof Struct) { - handleStructEntry(isTableHeaderSet, entry, msg); - } else if (entry instanceof PdxInstance) { - handlePdxInstanceEntry(isTableHeaderSet, entry, msg); - } else { - handleUnsupportedTypeEntry(isTableHeaderSet, entry, msg); - } - - isTableHeaderSet = true; - msg.append(NEWLINE); - } - - return new InterpreterResult(Code.SUCCESS, msg.toString()); - - } catch (Exception ex) { - LOGGER.error("Cannot run " + oql, ex); - return new InterpreterResult(Code.ERROR, ex.getMessage()); - } - } - - /** - * Zeppelin's %TABLE convention uses tab (\t) to delimit fields and new-line (\n) to delimit rows - * To complain with this convention we need to replace any occurrences of tab and/or newline - * characters in the content. - */ - private String replaceReservedChars(String str) { - - if (StringUtils.isBlank(str)) { - return str; - } - - return str.replace(TAB, WHITESPACE).replace(NEWLINE, WHITESPACE); - } - - private void handleStructEntry(boolean isHeaderSet, Object entry, StringBuilder msg) { - Struct struct = (Struct) entry; - if (!isHeaderSet) { - for (String titleName : struct.getStructType().getFieldNames()) { - msg.append(replaceReservedChars(titleName)).append(TAB); - } - msg.append(NEWLINE); - } - - for (String titleName : struct.getStructType().getFieldNames()) { - msg.append(replaceReservedChars("" + struct.get(titleName))).append(TAB); - } - } - - private void handlePdxInstanceEntry(boolean isHeaderSet, Object entry, StringBuilder msg) { - PdxInstance pdxEntry = (PdxInstance) entry; - if (!isHeaderSet) { - for (String titleName : pdxEntry.getFieldNames()) { - msg.append(replaceReservedChars(titleName)).append(TAB); - } - msg.append(NEWLINE); - } - - for (String titleName : pdxEntry.getFieldNames()) { - msg.append(replaceReservedChars("" + pdxEntry.getField(titleName))).append(TAB); - } - } - - private void handleNumberEntry(boolean isHeaderSet, Object entry, StringBuilder msg) { - if (!isHeaderSet) { - msg.append("Result").append(NEWLINE); - } - msg.append(entry); - } - - private void handleUnsupportedTypeEntry(boolean isHeaderSet, Object entry, StringBuilder msg) { - if (!isHeaderSet) { - msg.append("Unsuppoted Type").append(NEWLINE); - } - msg.append("" + entry); - } - - - @Override - public InterpreterResult interpret(String cmd, InterpreterContext contextInterpreter) { - LOGGER.info("Run OQL command '{}'", cmd); - return executeOql(cmd); - } - - @Override - public void cancel(InterpreterContext context) { - // Do nothing - } - - @Override - public FormType getFormType() { - return FormType.SIMPLE; - } - - @Override - public int getProgress(InterpreterContext context) { - return 0; - } - - @Override - public Scheduler getScheduler() { - return SchedulerFactory.singleton().createOrGetFIFOScheduler( - GeodeOqlInterpreter.class.getName() + this.hashCode()); - } - - @Override - public List<InterpreterCompletion> completion(String buf, int cursor, - InterpreterContext interpreterContext) { - return null; - } - - public int getMaxResult() { - return maxResult; - } - - // Test only - QueryService getQueryService() { - return this.queryService; - } - - Exception getExceptionOnConnect() { - return this.exceptionOnConnect; - } -} diff --git a/geode/src/main/resources/interpreter-setting.json b/geode/src/main/resources/interpreter-setting.json deleted file mode 100644 index 2a0a81da6a..0000000000 --- a/geode/src/main/resources/interpreter-setting.json +++ /dev/null @@ -1,33 +0,0 @@ -[ - { - "group": "geode", - "name": "oql", - "className": "org.apache.zeppelin.geode.GeodeOqlInterpreter", - "properties": { - "geode.locator.host": { - "envName": null, - "propertyName": "geode.locator.host", - "defaultValue": "localhost", - "description": "The Geode Locator Host.", - "type": "string" - }, - "geode.locator.port": { - "envName": null, - "propertyName": "geode.locator.port", - "defaultValue": "10334", - "description": "The Geode Locator Port.", - "type": "number" - }, - "geode.max.result": { - "envName": null, - "propertyName": "geode.max.result", - "defaultValue": "1000", - "description": "Max number of OQL result to display.", - "type": "number" - } - }, - "editor": { - "language": "sql" - } - } -] diff --git a/geode/src/test/java/org/apache/zeppelin/geode/GeodeOqlInterpreterTest.java b/geode/src/test/java/org/apache/zeppelin/geode/GeodeOqlInterpreterTest.java deleted file mode 100644 index 440486334f..0000000000 --- a/geode/src/test/java/org/apache/zeppelin/geode/GeodeOqlInterpreterTest.java +++ /dev/null @@ -1,178 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to you 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> - * 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.geode; - -import org.apache.geode.cache.query.QueryService; -import org.apache.geode.cache.query.SelectResults; -import org.apache.geode.cache.query.Struct; -import org.apache.geode.cache.query.internal.StructImpl; -import org.apache.geode.cache.query.internal.types.StructTypeImpl; -import org.apache.geode.pdx.PdxInstance; -import org.apache.geode.pdx.internal.PdxInstanceImpl; -import org.apache.geode.pdx.internal.PdxType; -import org.apache.zeppelin.interpreter.Interpreter.FormType; -import org.apache.zeppelin.interpreter.InterpreterResult; -import org.apache.zeppelin.interpreter.InterpreterResult.Code; -import org.junit.Test; - -import java.io.ByteArrayInputStream; -import java.io.DataInputStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.Properties; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.RETURNS_DEEP_STUBS; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -public class GeodeOqlInterpreterTest { - - private static final String OQL_QUERY = "select * from /region"; - - private static Iterator<Object> asIterator(Object... items) { - return new ArrayList<Object>(Arrays.asList(items)).iterator(); - } - - @Test - public void testOpenCommandIndempotency() { - - Properties properties = new Properties(); - properties.put("geode.locator.host", "localhost"); - properties.put("geode.locator.port", "10334"); - properties.put("geode.max.result", "1000"); - - GeodeOqlInterpreter spyGeodeOqlInterpreter = spy(new GeodeOqlInterpreter(properties)); - - // Ensure that an attempt to open new connection will clean any remaining connections - spyGeodeOqlInterpreter.open(); - spyGeodeOqlInterpreter.open(); - spyGeodeOqlInterpreter.open(); - - verify(spyGeodeOqlInterpreter, times(3)).open(); - verify(spyGeodeOqlInterpreter, times(3)).close(); - } - - @Test - public void oqlNumberResponse() throws Exception { - testOql(asIterator(66, 67), "Result\n66\n67\n", 10); - testOql(asIterator(66, 67), "Result\n66\n", 1); - } - - @Test - public void oqlStructResponse() throws Exception { - String[] fields = new String[]{"field1", "field2"}; - Struct s1 = new StructImpl(new StructTypeImpl(fields), new String[]{"val11", "val12"}); - Struct s2 = new StructImpl(new StructTypeImpl(fields), new String[]{"val21", "val22"}); - - testOql(asIterator(s1, s2), "field1\tfield2\t\nval11\tval12\t\nval21\tval22\t\n", 10); - testOql(asIterator(s1, s2), "field1\tfield2\t\nval11\tval12\t\n", 1); - } - - @Test - public void oqlStructResponseWithReservedCharacters() throws Exception { - String[] fields = new String[]{"fi\teld1", "f\nield2"}; - Struct s1 = new StructImpl(new StructTypeImpl(fields), new String[]{"v\nal\t1", "val2"}); - - testOql(asIterator(s1), "fi eld1\tf ield2\t\nv al 1\tval2\t\n", 10); - } - - @Test - public void oqlPdxInstanceResponse() throws Exception { - ByteArrayInputStream bais = new ByteArrayInputStream("koza\tboza\n".getBytes()); - PdxInstance pdx1 = new PdxInstanceImpl(new PdxType(), new DataInputStream(bais), 4); - PdxInstance pdx2 = new PdxInstanceImpl(new PdxType(), new DataInputStream(bais), 4); - - testOql(asIterator(pdx1, pdx2), "\n", 10); - testOql(asIterator(pdx1, pdx2), "\n", 1); - } - - private static class DummyUnspportedType { - @Override - public String toString() { - return "Unsupported Indeed"; - } - } - - @Test - public void oqlUnsupportedTypeResponse() throws Exception { - DummyUnspportedType unspported1 = new DummyUnspportedType(); - DummyUnspportedType unspported2 = new DummyUnspportedType(); - - testOql(asIterator(unspported1, unspported2), "Unsuppoted Type\n" + unspported1.toString() - + "\n" + unspported1.toString() + "\n", 10); - } - - private void testOql(Iterator<Object> queryResponseIterator, String expectedOutput, int maxResult) - throws Exception { - - GeodeOqlInterpreter spyGeodeOqlInterpreter = spy(new GeodeOqlInterpreter(new Properties())); - - QueryService mockQueryService = mock(QueryService.class, RETURNS_DEEP_STUBS); - - when(spyGeodeOqlInterpreter.getQueryService()).thenReturn(mockQueryService); - when(spyGeodeOqlInterpreter.getMaxResult()).thenReturn(maxResult); - - @SuppressWarnings("unchecked") - SelectResults<Object> mockResults = mock(SelectResults.class); - - when(mockQueryService.newQuery(eq(OQL_QUERY)).execute()).thenReturn(mockResults); - - when(mockResults.iterator()).thenReturn(queryResponseIterator); - - InterpreterResult interpreterResult = spyGeodeOqlInterpreter.interpret(OQL_QUERY, null); - - assertEquals(Code.SUCCESS, interpreterResult.code()); - assertEquals(expectedOutput, interpreterResult.message().get(0).getData()); - } - - @Test - public void oqlWithQueryException() throws Exception { - - GeodeOqlInterpreter spyGeodeOqlInterpreter = spy(new GeodeOqlInterpreter(new Properties())); - - when(spyGeodeOqlInterpreter.getExceptionOnConnect()).thenReturn( - new RuntimeException("Test Exception On Connect")); - - InterpreterResult interpreterResult = spyGeodeOqlInterpreter.interpret(OQL_QUERY, null); - - assertEquals(Code.ERROR, interpreterResult.code()); - assertEquals("Test Exception On Connect", interpreterResult.message().get(0).getData()); - } - - @Test - public void oqlWithExceptionOnConnect() throws Exception { - - GeodeOqlInterpreter spyGeodeOqlInterpreter = spy(new GeodeOqlInterpreter(new Properties())); - - when(spyGeodeOqlInterpreter.getQueryService()).thenThrow( - new RuntimeException("Expected Test Exception!")); - - InterpreterResult interpreterResult = spyGeodeOqlInterpreter.interpret(OQL_QUERY, null); - - assertEquals(Code.ERROR, interpreterResult.code()); - assertEquals("Expected Test Exception!", interpreterResult.message().get(0).getData()); - } - - @Test - public void testFormType() { - assertEquals(FormType.SIMPLE, new GeodeOqlInterpreter(new Properties()).getFormType()); - } -} diff --git a/pom.xml b/pom.xml index 879e61f726..d842697928 100644 --- a/pom.xml +++ b/pom.xml @@ -86,7 +86,6 @@ <module>sap</module> <module>java</module> <module>beam</module> - <module>geode</module> <module>ksql</module> <module>sparql</module> <module>zeppelin-common</module>