Repository: zeppelin Updated Branches: refs/heads/master 8774f8073 -> 9d90ccca6
[ZEPPELIN-2003] Remove PostgresqlInterpreter ### What is this PR for? We don't have to maintain PostgresqlInterpreter because JDBCInterpreter covers all functions of PostgresqlInterpreter. It reduces maintenance costs. ### What type of PR is it? [Feature] ### Todos * [x] - Remove files and lines related to PostgresqlInterpreter ### What is the Jira issue? * https://issues.apache.org/jira/browse/ZEPPELIN-2003 ### How should this be tested? N/A ### Screenshots (if appropriate) ### Questions: * Does the licenses files need update? No * Is there breaking changes for older versions? Yes * Does this needs documentation? Yes, but already documented in jdbc docs Author: Jongyoul Lee <[email protected]> Closes #1945 from jongyoul/ZEPPELIN-2003 and squashes the following commits: 5dc58f2 [Jongyoul Lee] Fixed doc ec31f78 [Jongyoul Lee] Change docs to make a link to jdbc.md bfd70ef [Jongyoul Lee] Removed Postgresql from docs and configurations 98a106e [Jongyoul Lee] Removed whole packages about Postgresql Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/9d90ccca Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/9d90ccca Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/9d90ccca Branch: refs/heads/master Commit: 9d90ccca69b608c8419d34b163a254e4fa3f9f72 Parents: 8774f80 Author: Jongyoul Lee <[email protected]> Authored: Wed Feb 1 22:37:32 2017 +0900 Committer: Jongyoul Lee <[email protected]> Committed: Thu Feb 2 15:54:19 2017 +0900 ---------------------------------------------------------------------- conf/interpreter-list | 1 - conf/zeppelin-site.xml.template | 2 +- docs/interpreter/postgresql.md | 259 ++------------ docs/manual/interpreterinstallation.md | 5 - docs/rest-api/rest-configuration.md | 3 +- pom.xml | 1 - postgresql/README.md | 9 - postgresql/pom.xml | 155 --------- .../postgresql/PostgreSqlInterpreter.java | 344 ------------------- .../zeppelin/postgresql/SqlCompleter.java | 250 -------------- postgresql/src/main/resources/ansi.sql.keywords | 1 - .../postgresql-native-driver-sql.keywords | 1 - .../postgresql/PostgreSqlInterpreterTest.java | 262 -------------- .../zeppelin/postgresql/SqlCompleterTest.java | 197 ----------- .../zeppelin/conf/ZeppelinConfiguration.java | 1 - 15 files changed, 31 insertions(+), 1460 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9d90ccca/conf/interpreter-list ---------------------------------------------------------------------- diff --git a/conf/interpreter-list b/conf/interpreter-list index e0687df..9506122 100644 --- a/conf/interpreter-list +++ b/conf/interpreter-list @@ -33,7 +33,6 @@ lens org.apache.zeppelin:zeppelin-lens:0.7.0 Lens int livy org.apache.zeppelin:zeppelin-livy:0.7.0 Livy interpreter md org.apache.zeppelin:zeppelin-markdown:0.7.0 Markdown support pig org.apache.zeppelin:zeppelin-pig:0.7.0 Pig interpreter -postgresql org.apache.zeppelin:zeppelin-postgresql:0.7.0 Postgresql interpreter python org.apache.zeppelin:zeppelin-python:0.7.0 Python interpreter scio org.apache.zeppelin:zeppelin-scio_2.11:0.7.0 Scio interpreter shell org.apache.zeppelin:zeppelin-shell:0.7.0 Shell command http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9d90ccca/conf/zeppelin-site.xml.template ---------------------------------------------------------------------- diff --git a/conf/zeppelin-site.xml.template b/conf/zeppelin-site.xml.template index f4ce5cd..cbe0b5c 100755 --- a/conf/zeppelin-site.xml.template +++ b/conf/zeppelin-site.xml.template @@ -200,7 +200,7 @@ <property> <name>zeppelin.interpreters</name> - <value>org.apache.zeppelin.spark.SparkInterpreter,org.apache.zeppelin.spark.PySparkInterpreter,org.apache.zeppelin.rinterpreter.RRepl,org.apache.zeppelin.rinterpreter.KnitR,org.apache.zeppelin.spark.SparkRInterpreter,org.apache.zeppelin.spark.SparkSqlInterpreter,org.apache.zeppelin.spark.DepInterpreter,org.apache.zeppelin.markdown.Markdown,org.apache.zeppelin.angular.AngularInterpreter,org.apache.zeppelin.shell.ShellInterpreter,org.apache.zeppelin.file.HDFSFileInterpreter,org.apache.zeppelin.flink.FlinkInterpreter,,org.apache.zeppelin.python.PythonInterpreter,org.apache.zeppelin.python.PythonInterpreterPandasSql,org.apache.zeppelin.python.PythonCondaInterpreter,org.apache.zeppelin.python.PythonDockerInterpreter,org.apache.zeppelin.lens.LensInterpreter,org.apache.zeppelin.ignite.IgniteInterpreter,org.apache.zeppelin.ignite.IgniteSqlInterpreter,org.apache.zeppelin.cassandra.CassandraInterpreter,org.apache.zeppelin.geode.GeodeOqlInterpreter,org.apache.zeppelin.postgresql.PostgreSqlIn terpreter,org.apache.zeppelin.jdbc.JDBCInterpreter,org.apache.zeppelin.kylin.KylinInterpreter,org.apache.zeppelin.elasticsearch.ElasticsearchInterpreter,org.apache.zeppelin.scalding.ScaldingInterpreter,org.apache.zeppelin.alluxio.AlluxioInterpreter,org.apache.zeppelin.hbase.HbaseInterpreter,org.apache.zeppelin.livy.LivySparkInterpreter,org.apache.zeppelin.livy.LivyPySparkInterpreter,org.apache.zeppelin.livy.LivyPySpark3Interpreter,org.apache.zeppelin.livy.LivySparkRInterpreter,org.apache.zeppelin.livy.LivySparkSQLInterpreter,org.apache.zeppelin.bigquery.BigQueryInterpreter,org.apache.zeppelin.beam.BeamInterpreter,org.apache.zeppelin.pig.PigInterpreter,org.apache.zeppelin.pig.PigQueryInterpreter,org.apache.zeppelin.scio.ScioInterpreter</value> + <value>org.apache.zeppelin.spark.SparkInterpreter,org.apache.zeppelin.spark.PySparkInterpreter,org.apache.zeppelin.rinterpreter.RRepl,org.apache.zeppelin.rinterpreter.KnitR,org.apache.zeppelin.spark.SparkRInterpreter,org.apache.zeppelin.spark.SparkSqlInterpreter,org.apache.zeppelin.spark.DepInterpreter,org.apache.zeppelin.markdown.Markdown,org.apache.zeppelin.angular.AngularInterpreter,org.apache.zeppelin.shell.ShellInterpreter,org.apache.zeppelin.file.HDFSFileInterpreter,org.apache.zeppelin.flink.FlinkInterpreter,,org.apache.zeppelin.python.PythonInterpreter,org.apache.zeppelin.python.PythonInterpreterPandasSql,org.apache.zeppelin.python.PythonCondaInterpreter,org.apache.zeppelin.python.PythonDockerInterpreter,org.apache.zeppelin.lens.LensInterpreter,org.apache.zeppelin.ignite.IgniteInterpreter,org.apache.zeppelin.ignite.IgniteSqlInterpreter,org.apache.zeppelin.cassandra.CassandraInterpreter,org.apache.zeppelin.geode.GeodeOqlInterpreter,org.apache.zeppelin.jdbc.JDBCInterpreter,or g.apache.zeppelin.kylin.KylinInterpreter,org.apache.zeppelin.elasticsearch.ElasticsearchInterpreter,org.apache.zeppelin.scalding.ScaldingInterpreter,org.apache.zeppelin.alluxio.AlluxioInterpreter,org.apache.zeppelin.hbase.HbaseInterpreter,org.apache.zeppelin.livy.LivySparkInterpreter,org.apache.zeppelin.livy.LivyPySparkInterpreter,org.apache.zeppelin.livy.LivyPySpark3Interpreter,org.apache.zeppelin.livy.LivySparkRInterpreter,org.apache.zeppelin.livy.LivySparkSQLInterpreter,org.apache.zeppelin.bigquery.BigQueryInterpreter,org.apache.zeppelin.beam.BeamInterpreter,org.apache.zeppelin.pig.PigInterpreter,org.apache.zeppelin.pig.PigQueryInterpreter,org.apache.zeppelin.scio.ScioInterpreter</value> <description>Comma separated interpreter configurations. First interpreter become a default</description> </property> http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9d90ccca/docs/interpreter/postgresql.md ---------------------------------------------------------------------- diff --git a/docs/interpreter/postgresql.md b/docs/interpreter/postgresql.md index 20ef43b..52dac16 100644 --- a/docs/interpreter/postgresql.md +++ b/docs/interpreter/postgresql.md @@ -1,230 +1,29 @@ ---- -layout: page -title: "PostgreSQL, Apache HAWQ (incubating) Interpreter for Apache Zeppelin" -description: "Apache Zeppelin supports PostgreSQL, Apache HAWQ(incubating) and Greenplum SQL data processing engines." -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 %} - -# PostgreSQL, Apache HAWQ (incubating) Interpreter for Apache Zeppelin - -<div id="toc"></div> - -## Important Notice - -Postgresql Interpreter will be deprecated and merged into JDBC Interpreter. You can use Postgresql by using JDBC Interpreter with same functionality. See the example below of settings and dependencies. - -### Properties -<table class="table-configuration"> - <tr> - <th>Property</th> - <th>Value</th> - </tr> - <tr> - <td>psql.driver</td> - <td>org.postgresql.Driver</td> - </tr> - <tr> - <td>psql.url</td> - <td>jdbc:postgresql://localhost:5432/</td> - </tr> - <tr> - <td>psql.user</td> - <td>psqlUser</td> - </tr> - <tr> - <td>psql.password</td> - <td>psqlPassword</td> - </tr> -</table> - -### Dependencies -<table class="table-configuration"> - <tr> - <th>Artifact</th> - <th>Exclude</th> - </tr> - <tr> - <td>org.postgresql:postgresql:9.4-1201-jdbc41</td> - <td></td> - </tr> -</table> ---- - -## Overview - -[<img align="right" src="http://img.youtube.com/vi/wqXXQhJ5Uk8/0.jpg" alt="zeppelin-view" hspace="10" width="250"></img>](https://www.youtube.com/watch?v=wqXXQhJ5Uk8) - -This interpreter seamlessly supports the following SQL data processing engines: - -* [PostgreSQL](http://www.postgresql.org/) - OSS, Object-relational database management system (ORDBMS) -* [pache HAWQ (incubating)](http://hawq.incubator.apache.org/) - Powerful open source SQL-On-Hadoop engine. -* [Greenplum](http://pivotal.io/big-data/pivotal-greenplum-database) - MPP database built on open source PostgreSQL. - -This [Video Tutorial](https://www.youtube.com/watch?v=wqXXQhJ5Uk8) illustrates some of the features provided by the `Postgresql Interpreter`. - -<table class="table-configuration"> - <tr> - <th>Name</th> - <th>Class</th> - <th>Description</th> - </tr> - <tr> - <td>%psql.sql</td> - <td>PostgreSqlInterpreter</td> - <td>Provides SQL environment for PostgreSQL, HAWQ and Greenplum</td> - </tr> -</table> - -## Create Interpreter -By default Zeppelin creates one `PSQL` instance. You can remove it or create new instances. - -Multiple PSQL instances can be created, each configured to the same or different backend databases. But over time a `Notebook` can have only one PSQL interpreter instance `bound`. That means you _cannot_ connect to different databases in the same `Notebook`. This is a known Zeppelin limitation. - -To create new PSQL instance open the `Interpreter` section and click the `+Create` button. Pick a `Name` of your choice and from the `Interpreter` drop-down select `psql`. Then follow the configuration instructions and `Save` the new instance. - -> Note: The `Name` of the instance is used only to distinct the instances while binding them to the `Notebook`. The `Name` is irrelevant inside the `Notebook`. In the `Notebook` you must use `%psql.sql` 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 PSQL from the `Interpreter` section. The PSQL interpreter expenses the following properties: - -<table class="table-configuration"> - <tr> - <th>Property Name</th> - <th>Description</th> - <th>Default Value</th> - </tr> - <tr> - <td>postgresql.url</td> - <td>JDBC URL to connect to </td> - <td>jdbc:postgresql://localhost:5432</td> - </tr> - <tr> - <td>postgresql.user</td> - <td>JDBC user name</td> - <td>gpadmin</td> - </tr> - <tr> - <td>postgresql.password</td> - <td>JDBC password</td> - <td></td> - </tr> - <tr> - <td>postgresql.driver.name</td> - <td>JDBC driver name. In this version the driver name is fixed and should not be changed</td> - <td>org.postgresql.Driver</td> - </tr> - <tr> - <td>postgresql.max.result</td> - <td>Max number of SQL result to display to prevent the browser overload</td> - <td>1000</td> - </tr> -</table> - -## How to use -``` -Tip: Use (CTRL + .) for SQL auto-completion. -``` - -### DDL and SQL commands -Start the paragraphs with the full `%psql.sql` prefix tag! The short notation: `%psql` would still be able run the queries but the syntax highlighting and the auto-completions will be disabled. - -You can use the standard CREATE / DROP / INSERT commands to create or modify the data model: - -```sql -%psql.sql -drop table if exists mytable; -create table mytable (i int); -insert into mytable select generate_series(1, 100); -``` - -Then in a separate paragraph run the query. - -```sql -%psql.sql -select * from mytable; -``` - -> 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)]. - -For example, this will execute both queries but only the count result will be displayed. If you revert the order of the queries the mytable content will be shown instead. - -```sql -%psql.sql -select count(*) from mytable; -select * from mytable; -``` - -### PSQL command line tools -Use the Shell Interpreter (`%sh`) to access the command line [PSQL](http://www.postgresql.org/docs/9.4/static/app-psql.html) interactively: - -```bash -%sh -psql -h phd3.localdomain -U gpadmin -p 5432 <<EOF - \dn - \q -EOF -``` - -This will produce output like this: - -``` - Name | Owner ---------------------+--------- - hawq_toolkit | gpadmin - information_schema | gpadmin - madlib | gpadmin - pg_catalog | gpadmin - pg_toast | gpadmin - public | gpadmin - retail_demo | gpadmin -``` - -### Apply Zeppelin Dynamic Forms -You can leverage [Zeppelin Dynamic Form](../manual/dynamicform.html) inside your queries. You can use both the `text input` and `select form` parametrization features - -```sql -%psql.sql -SELECT ${group_by}, count(*) as count -FROM retail_demo.order_lineitems_pxf -GROUP BY ${group_by=product_id,product_id|product_name|customer_id|store_id} -ORDER BY count ${order=DESC,DESC|ASC} -LIMIT ${limit=10}; -``` - -### Example HAWQ PXF/HDFS Tables -Create HAWQ external table that read data from tab-separated-value data in HDFS. - -```sql -%psql.sql -CREATE EXTERNAL TABLE retail_demo.payment_methods_pxf ( - payment_method_id smallint, - payment_method_code character varying(20) -) LOCATION ('pxf://${NAME_NODE_HOST}:50070/retail_demo/payment_methods.tsv.gz?profile=HdfsTextSimple') FORMAT 'TEXT' (DELIMITER = E'\t'); -``` - -And retrieve content - -```sql -%psql.sql -select * from retail_demo.payment_methods_pxf -``` - -## Auto-completion -The PSQL Interpreter provides a basic auto-completion functionality. On `(Ctrl+.)` it list the most relevant suggestions in a pop-up window. In addition to the SQL keyword the interpreter provides suggestions for the Schema, Table, Column names as well. +--- +layout: page +title: "PostgreSQL, Apache HAWQ (incubating) Interpreter for Apache Zeppelin" +description: "Apache Zeppelin supports PostgreSQL, Apache HAWQ(incubating) and Greenplum SQL data processing engines." +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 %} + +# PostgreSQL, Apache HAWQ (incubating) Interpreter for Apache Zeppelin + +<div id="toc"></div> + +## Important Notice + + +Postgresql interpreter is deprecated and merged into [JDBC Interpreter](./jdbc.html). You can use it with JDBC Interpreter as same functionality. See [Postgresql setting example](./jdbc.html#postgres) for more detailed information. http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9d90ccca/docs/manual/interpreterinstallation.md ---------------------------------------------------------------------- diff --git a/docs/manual/interpreterinstallation.md b/docs/manual/interpreterinstallation.md index 8a08366..a0b6bd6 100644 --- a/docs/manual/interpreterinstallation.md +++ b/docs/manual/interpreterinstallation.md @@ -215,11 +215,6 @@ You can also find the below community managed interpreter list in `conf/interpre <td>Pig interpreter</td> </tr> <tr> - <td>postgresql</td> - <td>org.apache.zeppelin:zeppelin-postgresql:0.7.0</td> - <td>Postgresql interpreter</td> - </tr> - <tr> <td>python</td> <td>org.apache.zeppelin:zeppelin-python:0.7.0</td> <td>Python interpreter</td> http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9d90ccca/docs/rest-api/rest-configuration.md ---------------------------------------------------------------------- diff --git a/docs/rest-api/rest-configuration.md b/docs/rest-api/rest-configuration.md index 525ddaf..47c65f1 100644 --- a/docs/rest-api/rest-configuration.md +++ b/docs/rest-api/rest-configuration.md @@ -77,7 +77,7 @@ nd a need for an additional REST API, please [file an issue or send us mail](../ "zeppelin.server.context.path": "/", "zeppelin.ssl.keystore.type": "JKS", "zeppelin.ssl.truststore.path": "truststore", - "zeppelin.interpreters": "org.apache.zeppelin.spark.SparkInterpreter,org.apache.zeppelin.spark.PySparkInterpreter,org.apache.zeppelin.spark.SparkRInterpreter,org.apache.zeppelin.spark.SparkSqlInterpreter,org.apache.zeppelin.spark.DepInterpreter,org.apache.zeppelin.markdown.Markdown,org.apache.zeppelin.angular.AngularInterpreter,org.apache.zeppelin.shell.ShellInterpreter,org.apache.zeppelin.flink.FlinkInterpreter,org.apache.zeppelin.lens.LensInterpreter,org.apache.zeppelin.ignite.IgniteInterpreter,org.apache.zeppelin.ignite.IgniteSqlInterpreter,org.apache.zeppelin.cassandra.CassandraInterpreter,org.apache.zeppelin.geode.GeodeOqlInterpreter,org.apache.zeppelin.postgresql.PostgreSqlInterpreter,org.apache.zeppelin.kylin.KylinInterpreter,org.apache.zeppelin.elasticsearch.ElasticsearchInterpreter,org.apache.zeppelin.scalding.ScaldingInterpreter", + "zeppelin.interpreters": "org.apache.zeppelin.spark.SparkInterpreter,org.apache.zeppelin.spark.PySparkInterpreter,org.apache.zeppelin.spark.SparkRInterpreter,org.apache.zeppelin.spark.SparkSqlInterpreter,org.apache.zeppelin.spark.DepInterpreter,org.apache.zeppelin.markdown.Markdown,org.apache.zeppelin.angular.AngularInterpreter,org.apache.zeppelin.shell.ShellInterpreter,org.apache.zeppelin.flink.FlinkInterpreter,org.apache.zeppelin.lens.LensInterpreter,org.apache.zeppelin.ignite.IgniteInterpreter,org.apache.zeppelin.ignite.IgniteSqlInterpreter,org.apache.zeppelin.cassandra.CassandraInterpreter,org.apache.zeppelin.geode.GeodeOqlInterpreter,org.apache.zeppelin.kylin.KylinInterpreter,org.apache.zeppelin.elasticsearch.ElasticsearchInterpreter,org.apache.zeppelin.scalding.ScaldingInterpreter", "zeppelin.ssl": "false", "zeppelin.notebook.autoInterpreterBinding": "true", "zeppelin.notebook.homescreen": "", @@ -132,4 +132,3 @@ nd a need for an additional REST API, please [file an issue or send us mail](../ </td> </tr> </table> - \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9d90ccca/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index a677443..fdca381 100644 --- a/pom.xml +++ b/pom.xml @@ -63,7 +63,6 @@ <module>livy</module> <module>hbase</module> <module>pig</module> - <module>postgresql</module> <module>jdbc</module> <module>file</module> <module>flink</module> http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9d90ccca/postgresql/README.md ---------------------------------------------------------------------- diff --git a/postgresql/README.md b/postgresql/README.md deleted file mode 100644 index 3fddf85..0000000 --- a/postgresql/README.md +++ /dev/null @@ -1,9 +0,0 @@ -## PostgreSQL, HAWQ and Greenplum Interpreter for Apache Zeppelin - -This interpreter supports the following SQL engines: -* [PostgreSQL](http://www.postgresql.org/) - OSS, Object-relational database management system (ORDBMS) -* [Apache HAWQ](http://pivotal.io/big-data/pivotal-hawq) - Powerful [Open Source](https://wiki.apache.org/incubator/HAWQProposal) SQL-On-Hadoop engine. -* [Greenplum](http://pivotal.io/big-data/pivotal-greenplum-database) - MPP database built on open source PostgreSQL. - -The official documentation: [PostgreSQL, HAWQ](https://zeppelin.apache.org/docs/interpreter/postgresql.html) - http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9d90ccca/postgresql/pom.xml ---------------------------------------------------------------------- diff --git a/postgresql/pom.xml b/postgresql/pom.xml deleted file mode 100644 index a3a916c..0000000 --- a/postgresql/pom.xml +++ /dev/null @@ -1,155 +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 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <artifactId>zeppelin</artifactId> - <groupId>org.apache.zeppelin</groupId> - <version>0.8.0-SNAPSHOT</version> - </parent> - - <groupId>org.apache.zeppelin</groupId> - <artifactId>zeppelin-postgresql</artifactId> - <packaging>jar</packaging> - <version>0.8.0-SNAPSHOT</version> - <name>Zeppelin: PostgreSQL interpreter</name> - - <properties> - <!--library versions--> - <postgresql.version>9.4-1201-jdbc41</postgresql.version> - <jline.version>2.12.1</jline.version> - - <!--test library versions--> - <mockrunner.jdbc.version>1.0.8</mockrunner.jdbc.version> - - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.zeppelin</groupId> - <artifactId>zeppelin-interpreter</artifactId> - <version>${project.version}</version> - <scope>provided</scope> - </dependency> - - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - </dependency> - - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - </dependency> - - <dependency> - <groupId>org.postgresql</groupId> - <artifactId>postgresql</artifactId> - <version>${postgresql.version}</version> - </dependency> - - <dependency> - <groupId>com.google.guava</groupId> - <artifactId>guava</artifactId> - </dependency> - - <dependency> - <groupId>jline</groupId> - <artifactId>jline</artifactId> - <version>${jline.version}</version> - </dependency> - - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-all</artifactId> - <scope>test</scope> - </dependency> - - <dependency> - <groupId>com.mockrunner</groupId> - <artifactId>mockrunner-jdbc</artifactId> - <version>${mockrunner.jdbc.version}</version> - <scope>test</scope> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <artifactId>maven-enforcer-plugin</artifactId> - <executions> - <execution> - <id>enforce</id> - <phase>none</phase> - </execution> - </executions> - </plugin> - - <plugin> - <artifactId>maven-dependency-plugin</artifactId> - <executions> - <execution> - <id>copy-dependencies</id> - <phase>package</phase> - <goals> - <goal>copy-dependencies</goal> - </goals> - <configuration> - <outputDirectory>${project.build.directory}/../../interpreter/psql</outputDirectory> - <overWriteReleases>false</overWriteReleases> - <overWriteSnapshots>false</overWriteSnapshots> - <overWriteIfNewer>true</overWriteIfNewer> - <includeScope>runtime</includeScope> - </configuration> - </execution> - <execution> - <id>copy-artifact</id> - <phase>package</phase> - <goals> - <goal>copy</goal> - </goals> - <configuration> - <outputDirectory>${project.build.directory}/../../interpreter/psql</outputDirectory> - <overWriteReleases>false</overWriteReleases> - <overWriteSnapshots>false</overWriteSnapshots> - <overWriteIfNewer>true</overWriteIfNewer> - <includeScope>runtime</includeScope> - <artifactItems> - <artifactItem> - <groupId>${project.groupId}</groupId> - <artifactId>${project.artifactId}</artifactId> - <version>${project.version}</version> - <type>${project.packaging}</type> - </artifactItem> - </artifactItems> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> -</project> http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9d90ccca/postgresql/src/main/java/org/apache/zeppelin/postgresql/PostgreSqlInterpreter.java ---------------------------------------------------------------------- diff --git a/postgresql/src/main/java/org/apache/zeppelin/postgresql/PostgreSqlInterpreter.java b/postgresql/src/main/java/org/apache/zeppelin/postgresql/PostgreSqlInterpreter.java deleted file mode 100644 index 88c22d4..0000000 --- a/postgresql/src/main/java/org/apache/zeppelin/postgresql/PostgreSqlInterpreter.java +++ /dev/null @@ -1,344 +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 - * - * 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.postgresql; - -import static org.apache.commons.lang.StringUtils.containsIgnoreCase; - -import java.io.IOException; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.ArrayList; -import java.util.List; -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; - -/** - * PostgreSQL interpreter for Zeppelin. This interpreter can also be used for accessing HAWQ and - * GreenplumDB. - * - * <ul> - * <li>{@code postgresql.url} - JDBC URL to connect to.</li> - * <li>{@code postgresql.user} - JDBC user name..</li> - * <li>{@code postgresql.password} - JDBC password..</li> - * <li>{@code postgresql.driver.name} - JDBC driver name.</li> - * <li>{@code postgresql.max.result} - Max number of SQL result to display.</li> - * </ul> - * - * <p> - * How to use: <br/> - * {@code %psql.sql} <br/> - * {@code - * SELECT store_id, count(*) - * FROM retail_demo.order_lineitems_pxf - * GROUP BY store_id; - * } - * </p> - * - * For SQL auto-completion use the (Ctrl+.) shortcut. - */ -public class PostgreSqlInterpreter extends Interpreter { - - private Logger logger = LoggerFactory.getLogger(PostgreSqlInterpreter.class); - - private static final char WhITESPACE = ' '; - private static final char NEWLINE = '\n'; - private static final char TAB = '\t'; - private static final String TABLE_MAGIC_TAG = "%table "; - private static final String EXPLAIN_PREDICATE = "EXPLAIN "; - private static final String UPDATE_COUNT_HEADER = "Update Count"; - - static final String DEFAULT_JDBC_URL = "jdbc:postgresql://localhost:5432/"; - static final String DEFAULT_JDBC_USER_PASSWORD = ""; - static final String DEFAULT_JDBC_USER_NAME = "gpadmin"; - static final String DEFAULT_JDBC_DRIVER_NAME = "org.postgresql.Driver"; - static final String DEFAULT_MAX_RESULT = "1000"; - - static final String POSTGRESQL_SERVER_URL = "postgresql.url"; - static final String POSTGRESQL_SERVER_USER = "postgresql.user"; - static final String POSTGRESQL_SERVER_PASSWORD = "postgresql.password"; - static final String POSTGRESQL_SERVER_DRIVER_NAME = "postgresql.driver.name"; - static final String POSTGRESQL_SERVER_MAX_RESULT = "postgresql.max.result"; - static final String EMPTY_COLUMN_VALUE = ""; - - static { - Interpreter.register( - "sql", - "psql", - PostgreSqlInterpreter.class.getName(), - new InterpreterPropertyBuilder() - .add(POSTGRESQL_SERVER_URL, DEFAULT_JDBC_URL, "The URL for PostgreSQL.") - .add(POSTGRESQL_SERVER_USER, DEFAULT_JDBC_USER_NAME, "The PostgreSQL user name") - .add(POSTGRESQL_SERVER_PASSWORD, DEFAULT_JDBC_USER_PASSWORD, - "The PostgreSQL user password") - .add(POSTGRESQL_SERVER_DRIVER_NAME, DEFAULT_JDBC_DRIVER_NAME, "JDBC Driver Name") - .add(POSTGRESQL_SERVER_MAX_RESULT, DEFAULT_MAX_RESULT, - "Max number of SQL result to display.").build()); - } - - private Connection jdbcConnection; - private Statement currentStatement; - private Exception exceptionOnConnect; - private int maxResult; - - private SqlCompleter sqlCompleter; - - private static final Function<CharSequence, InterpreterCompletion> sequenceToStringTransformer = - new Function<CharSequence, InterpreterCompletion>() { - public InterpreterCompletion apply(CharSequence seq) { - return new InterpreterCompletion(seq.toString(), seq.toString()); - } - }; - - private static final List NO_COMPLETION = new ArrayList<>(); - - public PostgreSqlInterpreter(Properties property) { - super(property); - } - - @Override - public void open() { - - logger.info("Open psql connection!"); - - // Ensure that no previous connections are left open. - close(); - - try { - - String driverName = getProperty(POSTGRESQL_SERVER_DRIVER_NAME); - String url = getProperty(POSTGRESQL_SERVER_URL); - String user = getProperty(POSTGRESQL_SERVER_USER); - String password = getProperty(POSTGRESQL_SERVER_PASSWORD); - maxResult = Integer.valueOf(getProperty(POSTGRESQL_SERVER_MAX_RESULT)); - - Class.forName(driverName); - - jdbcConnection = DriverManager.getConnection(url, user, password); - - sqlCompleter = createSqlCompleter(jdbcConnection); - - exceptionOnConnect = null; - logger.info("Successfully created psql connection"); - - } catch (ClassNotFoundException | SQLException e) { - logger.error("Cannot open connection", e); - exceptionOnConnect = e; - close(); - } - } - - private SqlCompleter createSqlCompleter(Connection jdbcConnection) { - - SqlCompleter completer = null; - try { - Set<String> keywordsCompletions = SqlCompleter.getSqlKeywordsCompletions(jdbcConnection); - Set<String> dataModelCompletions = - SqlCompleter.getDataModelMetadataCompletions(jdbcConnection); - SetView<String> allCompletions = Sets.union(keywordsCompletions, dataModelCompletions); - completer = new SqlCompleter(allCompletions, dataModelCompletions); - - } catch (IOException | SQLException e) { - logger.error("Cannot create SQL completer", e); - } - - return completer; - } - - @Override - public void close() { - - logger.info("Close psql connection!"); - - try { - if (getJdbcConnection() != null) { - getJdbcConnection().close(); - } - } catch (SQLException e) { - logger.error("Cannot close connection", e); - } finally { - exceptionOnConnect = null; - } - } - - private InterpreterResult executeSql(String sql) { - try { - - if (exceptionOnConnect != null) { - return new InterpreterResult(Code.ERROR, exceptionOnConnect.getMessage()); - } - - currentStatement = getJdbcConnection().createStatement(); - - currentStatement.setMaxRows(maxResult); - - StringBuilder msg = null; - boolean isTableType = false; - - if (containsIgnoreCase(sql, EXPLAIN_PREDICATE)) { - msg = new StringBuilder(); - } else { - msg = new StringBuilder(TABLE_MAGIC_TAG); - isTableType = true; - } - - ResultSet resultSet = null; - try { - - boolean isResultSetAvailable = currentStatement.execute(sql); - - if (isResultSetAvailable) { - resultSet = currentStatement.getResultSet(); - - ResultSetMetaData md = resultSet.getMetaData(); - - for (int i = 1; i < md.getColumnCount() + 1; i++) { - if (i > 1) { - msg.append(TAB); - } - msg.append(replaceReservedChars(isTableType, md.getColumnName(i))); - } - msg.append(NEWLINE); - - int displayRowCount = 0; - while (resultSet.next() && displayRowCount < getMaxResult()) { - for (int i = 1; i < md.getColumnCount() + 1; i++) { - msg.append(replaceReservedChars(isTableType, resultSet.getString(i))); - if (i != md.getColumnCount()) { - msg.append(TAB); - } - } - msg.append(NEWLINE); - displayRowCount++; - } - } else { - // Response contains either an update count or there are no results. - int updateCount = currentStatement.getUpdateCount(); - msg.append(UPDATE_COUNT_HEADER).append(NEWLINE); - msg.append(updateCount).append(NEWLINE); - - // In case of update event (e.g. isResultSetAvailable = false) update the completion - // meta-data. - if (sqlCompleter != null) { - sqlCompleter.updateDataModelMetaData(getJdbcConnection()); - } - } - } finally { - try { - if (resultSet != null) { - resultSet.close(); - } - currentStatement.close(); - } finally { - currentStatement = null; - } - } - - return new InterpreterResult(Code.SUCCESS, msg.toString()); - - } catch (SQLException ex) { - logger.error("Cannot run " + sql, ex); - return new InterpreterResult(Code.ERROR, ex.getMessage()); - } - } - - /** - * For %table response replace Tab and Newline characters from the content. - */ - private String replaceReservedChars(boolean isTableResponseType, String str) { - if (str == null) { - return EMPTY_COLUMN_VALUE; - } - return (!isTableResponseType) ? str : str.replace(TAB, WhITESPACE).replace(NEWLINE, WhITESPACE); - } - - @Override - public InterpreterResult interpret(String cmd, InterpreterContext contextInterpreter) { - logger.info("Run SQL command '{}'", cmd); - return executeSql(cmd); - } - - @Override - public void cancel(InterpreterContext context) { - - logger.info("Cancel current query statement."); - - if (currentStatement != null) { - try { - currentStatement.cancel(); - } catch (SQLException ex) { - logger.error("SQLException in PostgreSqlInterpreter while cancel ", ex); - } finally { - currentStatement = null; - } - } - } - - @Override - public FormType getFormType() { - return FormType.SIMPLE; - } - - @Override - public int getProgress(InterpreterContext context) { - return 0; - } - - @Override - public Scheduler getScheduler() { - return SchedulerFactory.singleton().createOrGetFIFOScheduler( - PostgreSqlInterpreter.class.getName() + this.hashCode()); - } - - @Override - public List<InterpreterCompletion> completion(String buf, int cursor) { - - List<CharSequence> candidates = new ArrayList<>(); - if (sqlCompleter != null && sqlCompleter.complete(buf, cursor, candidates) >= 0) { - List completion = Lists.transform(candidates, sequenceToStringTransformer); - return completion; - } else { - return NO_COMPLETION; - } - } - - public int getMaxResult() { - return maxResult; - } - - // Test only method - protected Connection getJdbcConnection() { - return jdbcConnection; - } -} http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9d90ccca/postgresql/src/main/java/org/apache/zeppelin/postgresql/SqlCompleter.java ---------------------------------------------------------------------- diff --git a/postgresql/src/main/java/org/apache/zeppelin/postgresql/SqlCompleter.java b/postgresql/src/main/java/org/apache/zeppelin/postgresql/SqlCompleter.java deleted file mode 100644 index 66a1287..0000000 --- a/postgresql/src/main/java/org/apache/zeppelin/postgresql/SqlCompleter.java +++ /dev/null @@ -1,250 +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 - * - * 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.postgresql; - -/* - * This source file is based on code taken from SQLLine 1.0.2 See SQLLine notice in LICENSE - */ -import static org.apache.commons.lang.StringUtils.isBlank; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.StringTokenizer; -import java.util.TreeSet; -import java.util.regex.Pattern; - -import jline.console.completer.ArgumentCompleter.ArgumentList; -import jline.console.completer.ArgumentCompleter.WhitespaceArgumentDelimiter; -import jline.console.completer.StringsCompleter; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.Joiner; -import com.google.common.collect.Sets; -import com.google.common.collect.Sets.SetView; - -/** - * SQL auto complete functionality for the PostgreSqlInterpreter. - */ -public class SqlCompleter extends StringsCompleter { - - private static Logger logger = LoggerFactory.getLogger(SqlCompleter.class); - - /** - * Delimiter that can split SQL statement in keyword list - */ - private WhitespaceArgumentDelimiter sqlDelimiter = new WhitespaceArgumentDelimiter() { - - private Pattern pattern = Pattern.compile("[\\.:;,]"); - - @Override - public boolean isDelimiterChar(CharSequence buffer, int pos) { - return pattern.matcher("" + buffer.charAt(pos)).matches() - || super.isDelimiterChar(buffer, pos); - } - }; - - private Set<String> modelCompletions = new HashSet<>(); - - public SqlCompleter(Set<String> allCompletions, Set<String> dataModelCompletions) { - super(allCompletions); - this.modelCompletions = dataModelCompletions; - } - - @Override - public int complete(String buffer, int cursor, List<CharSequence> candidates) { - - if (isBlank(buffer) || (cursor > buffer.length() + 1)) { - return -1; - } - - // The delimiter breaks the buffer into separate words (arguments), separated by the - // white spaces. - ArgumentList argumentList = sqlDelimiter.delimit(buffer, cursor); - String argument = argumentList.getCursorArgument(); - // cursor in the selected argument - int argumentPosition = argumentList.getArgumentPosition(); - - if (isBlank(argument)) { - int argumentsCount = argumentList.getArguments().length; - if (argumentsCount <= 0 || ((buffer.length() + 2) < cursor) - || sqlDelimiter.isDelimiterChar(buffer, cursor - 2)) { - return -1; - } - argument = argumentList.getArguments()[argumentsCount - 1]; - argumentPosition = argument.length(); - } - - int complete = super.complete(argument, argumentPosition, candidates); - - logger.debug("complete:" + complete + ", size:" + candidates.size()); - - return complete; - } - - public void updateDataModelMetaData(Connection connection) { - - try { - Set<String> newModelCompletions = getDataModelMetadataCompletions(connection); - logger.debug("New model metadata is:" + Joiner.on(',').join(newModelCompletions)); - - // Sets.difference(set1, set2) - returned set contains all elements that are contained by set1 - // and not contained by set2. set2 may also contain elements not present in set1; these are - // simply ignored. - SetView<String> removedCompletions = Sets.difference(modelCompletions, newModelCompletions); - logger.debug("Removed Model Completions: " + Joiner.on(',').join(removedCompletions)); - this.getStrings().removeAll(removedCompletions); - - SetView<String> newCompletions = Sets.difference(newModelCompletions, modelCompletions); - logger.debug("New Completions: " + Joiner.on(',').join(newCompletions)); - this.getStrings().addAll(newCompletions); - - modelCompletions = newModelCompletions; - - } catch (SQLException e) { - logger.error("Failed to update the metadata conmpletions", e); - } - } - - public static Set<String> getSqlKeywordsCompletions(Connection connection) throws IOException, - SQLException { - - // Add the default SQL completions - String keywords = - new BufferedReader(new InputStreamReader( - SqlCompleter.class.getResourceAsStream("/ansi.sql.keywords"))).readLine(); - - DatabaseMetaData metaData = connection.getMetaData(); - - // Add the driver specific SQL completions - String driverSpecificKeywords = - "/" + metaData.getDriverName().replace(" ", "-").toLowerCase() + "-sql.keywords"; - - logger.info("JDBC DriverName:" + driverSpecificKeywords); - - if (SqlCompleter.class.getResource(driverSpecificKeywords) != null) { - String driverKeywords = - new BufferedReader(new InputStreamReader( - SqlCompleter.class.getResourceAsStream(driverSpecificKeywords))).readLine(); - keywords += "," + driverKeywords.toUpperCase(); - } - - Set<String> completions = new TreeSet<>(); - - - // Add the keywords from the current JDBC connection - try { - keywords += "," + metaData.getSQLKeywords(); - } catch (Exception e) { - logger.debug("fail to get SQL key words from database metadata: " + e, e); - } - try { - keywords += "," + metaData.getStringFunctions(); - } catch (Exception e) { - logger.debug("fail to get string function names from database metadata: " + e, e); - } - try { - keywords += "," + metaData.getNumericFunctions(); - } catch (Exception e) { - logger.debug("fail to get numeric function names from database metadata: " + e, e); - } - try { - keywords += "," + metaData.getSystemFunctions(); - } catch (Exception e) { - logger.debug("fail to get system function names from database metadata: " + e, e); - } - try { - keywords += "," + metaData.getTimeDateFunctions(); - } catch (Exception e) { - logger.debug("fail to get time date function names from database metadata: " + e, e); - } - - // Also allow lower-case versions of all the keywords - keywords += "," + keywords.toLowerCase(); - - StringTokenizer tok = new StringTokenizer(keywords, ", "); - while (tok.hasMoreTokens()) { - completions.add(tok.nextToken()); - } - - return completions; - } - - public static Set<String> getDataModelMetadataCompletions(Connection connection) - throws SQLException { - Set<String> completions = new TreeSet<>(); - getColumnNames(connection.getMetaData(), completions); - getSchemaNames(connection.getMetaData(), completions); - return completions; - } - - private static void getColumnNames(DatabaseMetaData meta, Set<String> names) throws SQLException { - - try { - ResultSet columns = meta.getColumns(meta.getConnection().getCatalog(), null, "%", "%"); - try { - - while (columns.next()) { - // Add the following strings: (1) column name, (2) table name - String name = columns.getString("TABLE_NAME"); - if (!isBlank(name)) { - names.add(name); - names.add(columns.getString("COLUMN_NAME")); - // names.add(columns.getString("TABLE_NAME") + "." + columns.getString("COLUMN_NAME")); - } - } - } finally { - columns.close(); - } - - logger.debug(Joiner.on(',').join(names)); - } catch (Throwable t) { - logger.error("Failed to retrieve the column name", t); - } - } - - private static void getSchemaNames(DatabaseMetaData meta, Set<String> names) throws SQLException { - - try { - ResultSet schemas = meta.getSchemas(); - try { - while (schemas.next()) { - String schemaName = schemas.getString("TABLE_SCHEM"); - if (!isBlank(schemaName)) { - names.add(schemaName + "."); - } - } - } finally { - schemas.close(); - } - } catch (Throwable t) { - logger.error("Failed to retrieve the column name", t); - } - } - - // test purpose only - WhitespaceArgumentDelimiter getSqlDelimiter() { - return this.sqlDelimiter; - } -} http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9d90ccca/postgresql/src/main/resources/ansi.sql.keywords ---------------------------------------------------------------------- diff --git a/postgresql/src/main/resources/ansi.sql.keywords b/postgresql/src/main/resources/ansi.sql.keywords deleted file mode 100644 index 1f25a81..0000000 --- a/postgresql/src/main/resources/ansi.sql.keywords +++ /dev/null @@ -1 +0,0 @@ -ABSOLUTE,ACTION,ADD,ALL,ALLOCATE,ALTER,AND,ANY,ARE,AS,ASC,ASSERTION,AT,AUTHORIZATION,AVG,BEGIN,BETWEEN,BIT,BIT_LENGTH,BOTH,BY,CASCADE,CASCADED,CASE,CAST,CATALOG,CHAR,CHARACTER,CHAR_LENGTH,CHARACTER_LENGTH,CHECK,CLOSE,CLUSTER,COALESCE,COLLATE,COLLATION,COLUMN,COMMIT,CONNECT,CONNECTION,CONSTRAINT,CONSTRAINTS,CONTINUE,CONVERT,CORRESPONDING,COUNT,CREATE,CROSS,CURRENT,CURRENT_DATE,CURRENT_TIME,CURRENT_TIMESTAMP,CURRENT_USER,CURSOR,DATE,DAY,DEALLOCATE,DEC,DECIMAL,DECLARE,DEFAULT,DEFERRABLE,DEFERRED,DELETE,DESC,DESCRIBE,DESCRIPTOR,DIAGNOSTICS,DISCONNECT,DISTINCT,DOMAIN,DOUBLE,DROP,ELSE,END,END-EXEC,ESCAPE,EXCEPT,EXCEPTION,EXEC,EXECUTE,EXISTS,EXTERNAL,EXTRACT,FALSE,FETCH,FIRST,FLOAT,FOR,FOREIGN,FOUND,FROM,FULL,GET,GLOBAL,GO,GOTO,GRANT,GROUP,HAVING,HOUR,IDENTITY,IMMEDIATE,IN,INDICATOR,INITIALLY,INNER,INPUT,INSENSITIVE,INSERT,INT,INTEGER,INTERSECT,INTERVAL,INTO,IS,ISOLATION,JOIN,KEY,LANGUAGE,LAST,LEADING,LEFT,LEVEL,LIKE,LOCAL,LOWER,MATCH,MAX,MIN,MINUTE,MODULE,MONTH,NAMES,NATIONAL,NATURAL,NCHA R,NEXT,NO,NOT,NULL,NULLIF,NUMERIC,OCTET_LENGTH,OF,ON,ONLY,OPEN,OPTION,OR,ORDER,OUTER,OUTPUT,OVERLAPS,OVERWRITE,PAD,PARTIAL,PARTITION,POSITION,PRECISION,PREPARE,PRESERVE,PRIMARY,PRIOR,PRIVILEGES,PROCEDURE,PUBLIC,READ,REAL,REFERENCES,RELATIVE,RESTRICT,REVOKE,RIGHT,ROLLBACK,ROWS,SCHEMA,SCROLL,SECOND,SECTION,SELECT,SESSION,SESSION_USER,SET,SIZE,SMALLINT,SOME,SPACE,SQL,SQLCODE,SQLERROR,SQLSTATE,SUBSTRING,SUM,SYSTEM_USER,TABLE,TEMPORARY,THEN,TIME,TIMESTAMP,TIMEZONE_HOUR,TIMEZONE_MINUTE,TO,TRAILING,TRANSACTION,TRANSLATE,TRANSLATION,TRIM,TRUE,UNION,UNIQUE,UNKNOWN,UPDATE,UPPER,USAGE,USER,USING,VALUE,VALUES,VARCHAR,VARYING,VIEW,WHEN,WHENEVER,WHERE,WITH,WORK,WRITE,YEAR,ZONE,ADA,C,CATALOG_NAME,CHARACTER_SET_CATALOG,CHARACTER_SET_NAME,CHARACTER_SET_SCHEMA,CLASS_ORIGIN,COBOL,COLLATION_CATALOG,COLLATION_NAME,COLLATION_SCHEMA,COLUMN_NAME,COMMAND_FUNCTION,COMMITTED,CONDITION_NUMBER,CONNECTION_NAME,CONSTRAINT_CATALOG,CONSTRAINT_NAME,CONSTRAINT_SCHEMA,CURSOR_NAME,DATA,DATETIME_INTERVAL_CODE,DATETIME_I NTERVAL_PRECISION,DYNAMIC_FUNCTION,FORTRAN,LENGTH,MESSAGE_LENGTH,MESSAGE_OCTET_LENGTH,MESSAGE_TEXT,MORE,MUMPS,NAME,NULLABLE,NUMBER,PASCAL,PLI,REPEATABLE,RETURNED_LENGTH,RETURNED_OCTET_LENGTH,RETURNED_SQLSTATE,ROW_COUNT,SCALE,SCHEMA_NAME,SERIALIZABLE,SERVER_NAME,SUBCLASS_ORIGIN,TABLE_NAME,TYPE,UNCOMMITTED,UNNAMED,LIMIT http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9d90ccca/postgresql/src/main/resources/postgresql-native-driver-sql.keywords ---------------------------------------------------------------------- diff --git a/postgresql/src/main/resources/postgresql-native-driver-sql.keywords b/postgresql/src/main/resources/postgresql-native-driver-sql.keywords deleted file mode 100644 index a857cbd..0000000 --- a/postgresql/src/main/resources/postgresql-native-driver-sql.keywords +++ /dev/null @@ -1 +0,0 @@ -A,ABORT,ABS,ABSENT,ABSOLUTE,ACCESS,ACCORDING,ACTION,ADA,ADD,ADMIN,AFTER,AGGREGATE,ALL,ALLOCATE,ALSO,ALTER,ALWAYS,ANALYSE,ANALYZE,AND,ANY,ARE,ARRAY,ARRAY_AGG,ARRAY_MAX_CARDINALITY,AS,ASC,ASENSITIVE,ASSERTION,ASSIGNMENT,ASYMMETRIC,AT,ATOMIC,ATTRIBUTE,ATTRIBUTES,AUTHORIZATION,AVG,BACKWARD,BASE64,BEFORE,BEGIN,BEGIN_FRAME,BEGIN_PARTITION,BERNOULLI,BETWEEN,BIGINT,BINARY,BIT,BIT_LENGTH,BLOB,BLOCKED,BOM,BOOLEAN,BOTH,BREADTH,BY,C,CACHE,CALL,CALLED,CARDINALITY,CASCADE,CASCADED,CASE,CAST,CATALOG,CATALOG_NAME,CEIL,CEILING,CHAIN,CHAR,CHARACTER,CHARACTERISTICS,CHARACTERS,CHARACTER_LENGTH,CHARACTER_SET_CATALOG,CHARACTER_SET_NAME,CHARACTER_SET_SCHEMA,CHAR_LENGTH,CHECK,CHECKPOINT,CLASS,CLASS_ORIGIN,CLOB,CLOSE,CLUSTER,COALESCE,COBOL,COLLATE,COLLATION,COLLATION_CATALOG,COLLATION_NAME,COLLATION_SCHEMA,COLLECT,COLUMN,COLUMNS,COLUMN_NAME,COMMAND_FUNCTION,COMMAND_FUNCTION_CODE,COMMENT,COMMENTS,COMMIT,COMMITTED,CONCURRENTLY,CONDITION,CONDITION_NUMBER,CONFIGURATION,CONNECT,CONNECTION,CONNECTION_NAME,CONSTRA INT,CONSTRAINTS,CONSTRAINT_CATALOG,CONSTRAINT_NAME,CONSTRAINT_SCHEMA,CONSTRUCTOR,CONTAINS,CONTENT,CONTINUE,CONTROL,CONVERSION,CONVERT,COPY,CORR,CORRESPONDING,COST,COUNT,COVAR_POP,COVAR_SAMP,CREATE,CROSS,CSV,CUBE,CUME_DIST,CURRENT,CURRENT_CATALOG,CURRENT_DATE,CURRENT_DEFAULT_TRANSFORM_GROUP,CURRENT_PATH,CURRENT_ROLE,CURRENT_ROW,CURRENT_SCHEMA,CURRENT_TIME,CURRENT_TIMESTAMP,CURRENT_TRANSFORM_GROUP_FOR_TYPE,CURRENT_USER,CURSOR,CURSOR_NAME,CYCLE,DATA,DATABASE,DATALINK,DATE,DATETIME_INTERVAL_CODE,DATETIME_INTERVAL_PRECISION,DAY,DB,DEALLOCATE,DEC,DECIMAL,DECLARE,DEFAULT,DEFAULTS,DEFERRABLE,DEFERRED,DEFINED,DEFINER,DEGREE,DELETE,DELIMITER,DELIMITERS,DENSE_RANK,DEPTH,DEREF,DERIVED,DESC,DESCRIBE,DESCRIPTOR,DETERMINISTIC,DIAGNOSTICS,DICTIONARY,DISABLE,DISCARD,DISCONNECT,DISPATCH,DISTINCT,DLNEWCOPY,DLPREVIOUSCOPY,DLURLCOMPLETE,DLURLCOMPLETEONLY,DLURLCOMPLETEWRITE,DLURLPATH,DLURLPATHONLY,DLURLPATHWRITE,DLURLSCHEME,DLURLSERVER,DLVALUE,DO,DOCUMENT,DOMAIN,DOUBLE,DROP,DYNAMIC,DYNAMIC_FUNCTION,DYNAM IC_FUNCTION_CODE,EACH,ELEMENT,ELSE,EMPTY,ENABLE,ENCODING,ENCRYPTED,END,END-EXEC,END_FRAME,END_PARTITION,ENFORCED,ENUM,EQUALS,ESCAPE,EVENT,EVERY,EXCEPT,EXCEPTION,EXCLUDE,EXCLUDING,EXCLUSIVE,EXEC,EXECUTE,EXISTS,EXP,EXPLAIN,EXPRESSION,EXTENSION,EXTERNAL,EXTRACT,FALSE,FAMILY,FETCH,FILE,FILTER,FINAL,FIRST,FIRST_VALUE,FLAG,FLOAT,FLOOR,FOLLOWING,FOR,FORCE,FOREIGN,FORTRAN,FORWARD,FOUND,FRAME_ROW,FREE,FREEZE,FROM,FS,FULL,FUNCTION,FUNCTIONS,FUSION,G,GENERAL,GENERATED,GET,GLOBAL,GO,GOTO,GRANT,GRANTED,GREATEST,GROUP,GROUPING,GROUPS,HANDLER,HAVING,HEADER,HEX,HIERARCHY,HOLD,HOUR,ID,IDENTITY,IF,IGNORE,ILIKE,IMMEDIATE,IMMEDIATELY,IMMUTABLE,IMPLEMENTATION,IMPLICIT,IMPORT,IN,INCLUDING,INCREMENT,INDENT,INDEX,INDEXES,INDICATOR,INHERIT,INHERITS,INITIALLY,INLINE,INNER,INOUT,INPUT,INSENSITIVE,INSERT,INSTANCE,INSTANTIABLE,INSTEAD,INT,INTEGER,INTEGRITY,INTERSECT,INTERSECTION,INTERVAL,INTO,INVOKER,IS,ISNULL,ISOLATION,JOIN,K,KEY,KEY_MEMBER,KEY_TYPE,LABEL,LAG,LANGUAGE,LARGE,LAST,LAST_VALUE,LATERAL,LC_COLLATE,L C_CTYPE,LEAD,LEADING,LEAKPROOF,LEAST,LEFT,LENGTH,LEVEL,LIBRARY,LIKE,LIKE_REGEX,LIMIT,LINK,LISTEN,LN,LOAD,LOCAL,LOCALTIME,LOCALTIMESTAMP,LOCATION,LOCATOR,LOCK,LOWER,M,MAP,MAPPING,MATCH,MATCHED,MATERIALIZED,MAX,MAXVALUE,MAX_CARDINALITY,MEMBER,MERGE,MESSAGE_LENGTH,MESSAGE_OCTET_LENGTH,MESSAGE_TEXT,METHOD,MIN,MINUTE,MINVALUE,MOD,MODE,MODIFIES,MODULE,MONTH,MORE,MOVE,MULTISET,MUMPS,NAME,NAMES,NAMESPACE,NATIONAL,NATURAL,NCHAR,NCLOB,NESTING,NEW,NEXT,NFC,NFD,NFKC,NFKD,NIL,NO,NONE,NORMALIZE,NORMALIZED,NOT,NOTHING,NOTIFY,NOTNULL,NOWAIT,NTH_VALUE,NTILE,NULL,NULLABLE,NULLIF,NULLS,NUMBER,NUMERIC,OBJECT,OCCURRENCES_REGEX,OCTETS,OCTET_LENGTH,OF,OFF,OFFSET,OIDS,OLD,ON,ONLY,OPEN,OPERATOR,OPTION,OPTIONS,OR,ORDER,ORDERING,ORDINALITY,OTHERS,OUT,OUTER,OUTPUT,OVER,OVERLAPS,OVERLAY,OVERRIDING,OWNED,OWNER,P,PAD,PARAMETER,PARAMETER_MODE,PARAMETER_NAME,PARAMETER_ORDINAL_POSITION,PARAMETER_SPECIFIC_CATALOG,PARAMETER_SPECIFIC_NAME,PARAMETER_SPECIFIC_SCHEMA,PARSER,PARTIAL,PARTITION,PASCAL,PASSING,PASSTHROUGH,PAS SWORD,PATH,PERCENT,PERCENTILE_CONT,PERCENTILE_DISC,PERCENT_RANK,PERIOD,PERMISSION,PLACING,PLANS,PLI,PORTION,POSITION,POSITION_REGEX,POWER,PRECEDES,PRECEDING,PRECISION,PREPARE,PREPARED,PRESERVE,PRIMARY,PRIOR,PRIVILEGES,PROCEDURAL,PROCEDURE,PROGRAM,PUBLIC,QUOTE,RANGE,RANK,READ,READS,REAL,REASSIGN,RECHECK,RECOVERY,RECURSIVE,REF,REFERENCES,REFERENCING,REFRESH,REGR_AVGX,REGR_AVGY,REGR_COUNT,REGR_INTERCEPT,REGR_R2,REGR_SLOPE,REGR_SXX,REGR_SXY,REGR_SYY,REINDEX,RELATIVE,RELEASE,RENAME,REPEATABLE,REPLACE,REPLICA,REQUIRING,RESET,RESPECT,RESTART,RESTORE,RESTRICT,RESULT,RETURN,RETURNED_CARDINALITY,RETURNED_LENGTH,RETURNED_OCTET_LENGTH,RETURNED_SQLSTATE,RETURNING,RETURNS,REVOKE,RIGHT,ROLE,ROLLBACK,ROLLUP,ROUTINE,ROUTINE_CATALOG,ROUTINE_NAME,ROUTINE_SCHEMA,ROW,ROWS,ROW_COUNT,ROW_NUMBER,RULE,SAVEPOINT,SCALE,SCHEMA,SCHEMA_NAME,SCOPE,SCOPE_CATALOG,SCOPE_NAME,SCOPE_SCHEMA,SCROLL,SEARCH,SECOND,SECTION,SECURITY,SELECT,SELECTIVE,SELF,SENSITIVE,SEQUENCE,SEQUENCES,SERIALIZABLE,SERVER,SERVER_NAME,SESSION,S ESSION_USER,SET,SETOF,SETS,SHARE,SHOW,SIMILAR,SIMPLE,SIZE,SMALLINT,SNAPSHOT,SOME,SOURCE,SPACE,SPECIFIC,SPECIFICTYPE,SPECIFIC_NAME,SQL,SQLCODE,SQLERROR,SQLEXCEPTION,SQLSTATE,SQLWARNING,SQRT,STABLE,STANDALONE,START,STATE,STATEMENT,STATIC,STATISTICS,STDDEV_POP,STDDEV_SAMP,STDIN,STDOUT,STORAGE,STRICT,STRIP,STRUCTURE,STYLE,SUBCLASS_ORIGIN,SUBMULTISET,SUBSTRING,SUBSTRING_REGEX,SUCCEEDS,SUM,SYMMETRIC,SYSID,SYSTEM,SYSTEM_TIME,SYSTEM_USER,T,TABLE,TABLES,TABLESAMPLE,TABLESPACE,TABLE_NAME,TEMP,TEMPLATE,TEMPORARY,TEXT,THEN,TIES,TIME,TIMESTAMP,TIMEZONE_HOUR,TIMEZONE_MINUTE,TO,TOKEN,TOP_LEVEL_COUNT,TRAILING,TRANSACTION,TRANSACTIONS_COMMITTED,TRANSACTIONS_ROLLED_BACK,TRANSACTION_ACTIVE,TRANSFORM,TRANSFORMS,TRANSLATE,TRANSLATE_REGEX,TRANSLATION,TREAT,TRIGGER,TRIGGER_CATALOG,TRIGGER_NAME,TRIGGER_SCHEMA,TRIM,TRIM_ARRAY,TRUE,TRUNCATE,TRUSTED,TYPE,TYPES,UESCAPE,UNBOUNDED,UNCOMMITTED,UNDER,UNENCRYPTED,UNION,UNIQUE,UNKNOWN,UNLINK,UNLISTEN,UNLOGGED,UNNAMED,UNNEST,UNTIL,UNTYPED,UPDATE,UPPER,URI,USAGE,USER, USER_DEFINED_TYPE_CATALOG,USER_DEFINED_TYPE_CODE,USER_DEFINED_TYPE_NAME,USER_DEFINED_TYPE_SCHEMA,USING,VACUUM,VALID,VALIDATE,VALIDATOR,VALUE,VALUES,VALUE_OF,VARBINARY,VARCHAR,VARIADIC,VARYING,VAR_POP,VAR_SAMP,VERBOSE,VERSION,VERSIONING,VIEW,VIEWS,VOLATILE,WHEN,WHENEVER,WHERE,WHITESPACE,WIDTH_BUCKET,WINDOW,WITH,WITHIN,WITHOUT,WORK,WRAPPER,WRITE,XML,XMLAGG,XMLATTRIBUTES,XMLBINARY,XMLCAST,XMLCOMMENT,XMLCONCAT,XMLDECLARATION,XMLDOCUMENT,XMLELEMENT,XMLEXISTS,XMLFOREST,XMLITERATE,XMLNAMESPACES,XMLPARSE,XMLPI,XMLQUERY,XMLROOT,XMLSCHEMA,XMLSERIALIZE,XMLTABLE,XMLTEXT,XMLVALIDATE,YEAR,YES,ZONE http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9d90ccca/postgresql/src/test/java/org/apache/zeppelin/postgresql/PostgreSqlInterpreterTest.java ---------------------------------------------------------------------- diff --git a/postgresql/src/test/java/org/apache/zeppelin/postgresql/PostgreSqlInterpreterTest.java b/postgresql/src/test/java/org/apache/zeppelin/postgresql/PostgreSqlInterpreterTest.java deleted file mode 100644 index 7637981..0000000 --- a/postgresql/src/test/java/org/apache/zeppelin/postgresql/PostgreSqlInterpreterTest.java +++ /dev/null @@ -1,262 +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 - * - * 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.postgresql; - -import static org.apache.zeppelin.postgresql.PostgreSqlInterpreter.DEFAULT_JDBC_DRIVER_NAME; -import static org.apache.zeppelin.postgresql.PostgreSqlInterpreter.DEFAULT_JDBC_URL; -import static org.apache.zeppelin.postgresql.PostgreSqlInterpreter.DEFAULT_JDBC_USER_NAME; -import static org.apache.zeppelin.postgresql.PostgreSqlInterpreter.DEFAULT_JDBC_USER_PASSWORD; -import static org.apache.zeppelin.postgresql.PostgreSqlInterpreter.DEFAULT_MAX_RESULT; -import static org.apache.zeppelin.postgresql.PostgreSqlInterpreter.POSTGRESQL_SERVER_DRIVER_NAME; -import static org.apache.zeppelin.postgresql.PostgreSqlInterpreter.POSTGRESQL_SERVER_MAX_RESULT; -import static org.apache.zeppelin.postgresql.PostgreSqlInterpreter.POSTGRESQL_SERVER_PASSWORD; -import static org.apache.zeppelin.postgresql.PostgreSqlInterpreter.POSTGRESQL_SERVER_URL; -import static org.apache.zeppelin.postgresql.PostgreSqlInterpreter.POSTGRESQL_SERVER_USER; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.sql.SQLException; -import java.util.Properties; - -import org.apache.zeppelin.interpreter.InterpreterResult; -import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion; -import org.junit.Before; -import org.junit.Test; - -import com.mockrunner.jdbc.BasicJDBCTestCaseAdapter; -import com.mockrunner.jdbc.StatementResultSetHandler; -import com.mockrunner.mock.jdbc.MockConnection; -import com.mockrunner.mock.jdbc.MockResultSet; - -/** - * PostgreSQL interpreter unit tests - */ -public class PostgreSqlInterpreterTest extends BasicJDBCTestCaseAdapter { - - private PostgreSqlInterpreter psqlInterpreter = null; - private MockResultSet result = null; - - @Before - public void beforeTest() { - MockConnection connection = getJDBCMockObjectFactory().getMockConnection(); - - StatementResultSetHandler statementHandler = connection.getStatementResultSetHandler(); - result = statementHandler.createResultSet(); - statementHandler.prepareGlobalResultSet(result); - - Properties properties = new Properties(); - properties.put(POSTGRESQL_SERVER_DRIVER_NAME, DEFAULT_JDBC_DRIVER_NAME); - properties.put(POSTGRESQL_SERVER_URL, DEFAULT_JDBC_URL); - properties.put(POSTGRESQL_SERVER_USER, DEFAULT_JDBC_USER_NAME); - properties.put(POSTGRESQL_SERVER_PASSWORD, DEFAULT_JDBC_USER_PASSWORD); - properties.put(POSTGRESQL_SERVER_MAX_RESULT, DEFAULT_MAX_RESULT); - - psqlInterpreter = spy(new PostgreSqlInterpreter(properties)); - when(psqlInterpreter.getJdbcConnection()).thenReturn(connection); - } - - @Test - public void testOpenCommandIndempotency() throws SQLException { - // Ensure that an attempt to open new connection will clean any remaining connections - psqlInterpreter.open(); - psqlInterpreter.open(); - psqlInterpreter.open(); - - verify(psqlInterpreter, times(3)).open(); - verify(psqlInterpreter, times(3)).close(); - } - - @Test - public void testDefaultProperties() throws SQLException { - - PostgreSqlInterpreter psqlInterpreter = new PostgreSqlInterpreter(new Properties()); - - assertEquals(DEFAULT_JDBC_DRIVER_NAME, - psqlInterpreter.getProperty(POSTGRESQL_SERVER_DRIVER_NAME)); - assertEquals(DEFAULT_JDBC_URL, psqlInterpreter.getProperty(POSTGRESQL_SERVER_URL)); - assertEquals(DEFAULT_JDBC_USER_NAME, psqlInterpreter.getProperty(POSTGRESQL_SERVER_USER)); - assertEquals(DEFAULT_JDBC_USER_PASSWORD, - psqlInterpreter.getProperty(POSTGRESQL_SERVER_PASSWORD)); - assertEquals(DEFAULT_MAX_RESULT, psqlInterpreter.getProperty(POSTGRESQL_SERVER_MAX_RESULT)); - } - - @Test - public void testConnectionClose() throws SQLException { - - PostgreSqlInterpreter psqlInterpreter = spy(new PostgreSqlInterpreter(new Properties())); - - when(psqlInterpreter.getJdbcConnection()).thenReturn( - getJDBCMockObjectFactory().getMockConnection()); - - psqlInterpreter.close(); - - verifyAllResultSetsClosed(); - verifyAllStatementsClosed(); - verifyConnectionClosed(); - } - - @Test - public void testStatementCancel() throws SQLException { - - PostgreSqlInterpreter psqlInterpreter = spy(new PostgreSqlInterpreter(new Properties())); - - when(psqlInterpreter.getJdbcConnection()).thenReturn( - getJDBCMockObjectFactory().getMockConnection()); - - psqlInterpreter.cancel(null); - - verifyAllResultSetsClosed(); - verifyAllStatementsClosed(); - assertFalse("Cancel operation should not close the connection", psqlInterpreter - .getJdbcConnection().isClosed()); - } - - @Test - public void testNullColumnResult() throws SQLException { - - when(psqlInterpreter.getMaxResult()).thenReturn(1000); - - String sqlQuery = "select * from t"; - - result.addColumn("col1", new String[] {"val11", null}); - result.addColumn("col2", new String[] {null, "val22"}); - - InterpreterResult interpreterResult = psqlInterpreter.interpret(sqlQuery, null); - - assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code()); - assertEquals(InterpreterResult.Type.TABLE, interpreterResult.message().get(0).getType()); - assertEquals("col1\tcol2\nval11\t\n\tval22\n", interpreterResult.message().get(0).getData()); - - verifySQLStatementExecuted(sqlQuery); - verifyAllResultSetsClosed(); - verifyAllStatementsClosed(); - } - - @Test - public void testSelectQuery() throws SQLException { - - when(psqlInterpreter.getMaxResult()).thenReturn(1000); - - String sqlQuery = "select * from t"; - - result.addColumn("col1", new String[] {"val11", "val12"}); - result.addColumn("col2", new String[] {"val21", "val22"}); - - InterpreterResult interpreterResult = psqlInterpreter.interpret(sqlQuery, null); - - assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code()); - assertEquals(InterpreterResult.Type.TABLE, interpreterResult.message().get(0).getType()); - assertEquals("col1\tcol2\nval11\tval21\nval12\tval22\n", interpreterResult.message().get(0).getData()); - - verifySQLStatementExecuted(sqlQuery); - verifyAllResultSetsClosed(); - verifyAllStatementsClosed(); - } - - @Test - public void testSelectQueryMaxResult() throws SQLException { - - when(psqlInterpreter.getMaxResult()).thenReturn(1); - - String sqlQuery = "select * from t"; - - result.addColumn("col1", new String[] {"val11", "val12"}); - result.addColumn("col2", new String[] {"val21", "val22"}); - - InterpreterResult interpreterResult = psqlInterpreter.interpret(sqlQuery, null); - - assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code()); - assertEquals(InterpreterResult.Type.TABLE, interpreterResult.message().get(0).getType()); - assertEquals("col1\tcol2\nval11\tval21\n", interpreterResult.message().get(0).getData()); - - verifySQLStatementExecuted(sqlQuery); - verifyAllResultSetsClosed(); - verifyAllStatementsClosed(); - } - - @Test - public void testSelectQueryWithSpecialCharacters() throws SQLException { - - when(psqlInterpreter.getMaxResult()).thenReturn(1000); - - String sqlQuery = "select * from t"; - - result.addColumn("co\tl1", new String[] {"val11", "va\tl1\n2"}); - result.addColumn("co\nl2", new String[] {"v\nal21", "val\t22"}); - - InterpreterResult interpreterResult = psqlInterpreter.interpret(sqlQuery, null); - - assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code()); - assertEquals(InterpreterResult.Type.TABLE, interpreterResult.message().get(0).getType()); - assertEquals("co l1\tco l2\nval11\tv al21\nva l1 2\tval 22\n", interpreterResult.message().get(0).getData()); - - verifySQLStatementExecuted(sqlQuery); - verifyAllResultSetsClosed(); - verifyAllStatementsClosed(); - } - - @Test - public void testExplainQuery() throws SQLException { - - when(psqlInterpreter.getMaxResult()).thenReturn(1000); - - String sqlQuery = "explain select * from t"; - - result.addColumn("col1", new String[] {"val11", "val12"}); - - InterpreterResult interpreterResult = psqlInterpreter.interpret(sqlQuery, null); - - assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code()); - assertEquals(InterpreterResult.Type.TEXT, interpreterResult.message().get(0).getType()); - assertEquals("col1\nval11\nval12\n", interpreterResult.message().get(0).getData()); - - verifySQLStatementExecuted(sqlQuery); - verifyAllResultSetsClosed(); - verifyAllStatementsClosed(); - } - - @Test - public void testExplainQueryWithSpecialCharachters() throws SQLException { - - when(psqlInterpreter.getMaxResult()).thenReturn(1000); - - String sqlQuery = "explain select * from t"; - - result.addColumn("co\tl\n1", new String[] {"va\nl11", "va\tl\n12"}); - - InterpreterResult interpreterResult = psqlInterpreter.interpret(sqlQuery, null); - - assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code()); - assertEquals(InterpreterResult.Type.TEXT, interpreterResult.message().get(0).getType()); - assertEquals("co\tl\n1\nva\nl11\nva\tl\n12\n", interpreterResult.message().get(0).getData()); - - verifySQLStatementExecuted(sqlQuery); - verifyAllResultSetsClosed(); - verifyAllStatementsClosed(); - } - - @Test - public void testAutoCompletion() throws SQLException { - psqlInterpreter.open(); - assertEquals(1, psqlInterpreter.completion("SEL", 0).size()); - InterpreterCompletion selectCompletion = new InterpreterCompletion("SELECT ", "SELECT "); - assertEquals(selectCompletion, psqlInterpreter.completion("SEL", 0).iterator().next()); - assertEquals(0, psqlInterpreter.completion("SEL", 100).size()); - } -} http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9d90ccca/postgresql/src/test/java/org/apache/zeppelin/postgresql/SqlCompleterTest.java ---------------------------------------------------------------------- diff --git a/postgresql/src/test/java/org/apache/zeppelin/postgresql/SqlCompleterTest.java b/postgresql/src/test/java/org/apache/zeppelin/postgresql/SqlCompleterTest.java deleted file mode 100644 index 05d9487..0000000 --- a/postgresql/src/test/java/org/apache/zeppelin/postgresql/SqlCompleterTest.java +++ /dev/null @@ -1,197 +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 - * - * 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.postgresql; - -import static com.google.common.collect.Sets.newHashSet; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Set; - -import jline.console.completer.Completer; - -import org.junit.Before; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.Joiner; -import com.google.common.collect.Sets; -import com.mockrunner.jdbc.BasicJDBCTestCaseAdapter; - -public class SqlCompleterTest extends BasicJDBCTestCaseAdapter { - - private Logger logger = LoggerFactory.getLogger(SqlCompleterTest.class); - - private final static Set<String> EMPTY = new HashSet<>(); - - private CompleterTester tester; - - private SqlCompleter sqlCompleter; - - @Before - public void beforeTest() throws IOException, SQLException { - Set<String> keywordsCompletions = - SqlCompleter.getSqlKeywordsCompletions(getJDBCMockObjectFactory().getMockConnection()); - Set<String> dataModelCompletions = - SqlCompleter - .getDataModelMetadataCompletions(getJDBCMockObjectFactory().getMockConnection()); - - sqlCompleter = - new SqlCompleter(Sets.union(keywordsCompletions, dataModelCompletions), - dataModelCompletions); - tester = new CompleterTester(sqlCompleter); - } - - @Test - public void testAfterBufferEnd() { - String buffer = "ORDER"; - // Up to 2 white spaces after the buffer end, the completer still uses the last argument - tester.buffer(buffer).from(0).to(buffer.length() + 1).expect(newHashSet("ORDER ")).test(); - // 2 white spaces or more behind the buffer end the completer returns empty result - tester.buffer(buffer).from(buffer.length() + 2).to(buffer.length() + 5).expect(EMPTY).test(); - } - - @Test - public void testEdges() { - String buffer = " ORDER "; - tester.buffer(buffer).from(0).to(8).expect(newHashSet("ORDER ")).test(); - tester.buffer(buffer).from(9).to(15).expect(EMPTY).test(); - } - - @Test - public void testMultipleWords() { - String buffer = " SELE fro LIM"; - tester.buffer(buffer).from(0).to(6).expect(newHashSet("SELECT ")).test(); - tester.buffer(buffer).from(7).to(11).expect(newHashSet("from ")).test(); - tester.buffer(buffer).from(12).to(19).expect(newHashSet("LIMIT ")).test(); - tester.buffer(buffer).from(20).to(24).expect(EMPTY).test(); - } - - @Test - public void testMultiLineBuffer() { - String buffer = " \n SELE \n fro"; - tester.buffer(buffer).from(0).to(7).expect(newHashSet("SELECT ")).test(); - tester.buffer(buffer).from(8).to(14).expect(newHashSet("from ")).test(); - tester.buffer(buffer).from(15).to(17).expect(EMPTY).test(); - } - - @Test - public void testMultipleCompletionSuggestions() { - String buffer = " SU"; - tester.buffer(buffer).from(0).to(5).expect(newHashSet("SUBCLASS_ORIGIN", "SUM", "SUBSTRING")) - .test(); - tester.buffer(buffer).from(6).to(7).expect(EMPTY).test(); - } - - @Test - public void testDotDelimiter() { - String buffer = " order.select "; - tester.buffer(buffer).from(4).to(7).expect(newHashSet("order ")).test(); - tester.buffer(buffer).from(8).to(15).expect(newHashSet("select ")).test(); - tester.buffer(buffer).from(16).to(17).expect(EMPTY).test(); - } - - @Test - public void testSqlDelimiterCharacters() { - assertTrue(sqlCompleter.getSqlDelimiter().isDelimiterChar("r.", 1)); - assertTrue(sqlCompleter.getSqlDelimiter().isDelimiterChar("SS;", 2)); - assertTrue(sqlCompleter.getSqlDelimiter().isDelimiterChar(":", 0)); - assertTrue(sqlCompleter.getSqlDelimiter().isDelimiterChar("ttt,", 3)); - } - - public class CompleterTester { - - private Completer completer; - - private String buffer; - private int fromCursor; - private int toCursor; - private Set<String> expectedCompletions; - - public CompleterTester(Completer completer) { - this.completer = completer; - } - - public CompleterTester buffer(String buffer) { - this.buffer = buffer; - return this; - } - - public CompleterTester from(int fromCursor) { - this.fromCursor = fromCursor; - return this; - } - - public CompleterTester to(int toCursor) { - this.toCursor = toCursor; - return this; - } - - public CompleterTester expect(Set<String> expectedCompletions) { - this.expectedCompletions = expectedCompletions; - return this; - } - - public void test() { - for (int c = fromCursor; c <= toCursor; c++) { - expectedCompletions(buffer, c, expectedCompletions); - } - } - - private void expectedCompletions(String buffer, int cursor, Set<String> expected) { - - ArrayList<CharSequence> candidates = new ArrayList<>(); - - completer.complete(buffer, cursor, candidates); - - String explain = explain(buffer, cursor, candidates); - - logger.info(explain); - - assertEquals("Buffer [" + buffer.replace(" ", ".") + "] and Cursor[" + cursor + "] " - + explain, expected, newHashSet(candidates)); - } - - private String explain(String buffer, int cursor, ArrayList<CharSequence> candidates) { - StringBuffer sb = new StringBuffer(); - - for (int i = 0; i <= Math.max(cursor, buffer.length()); i++) { - if (i == cursor) { - sb.append("("); - } - if (i >= buffer.length()) { - sb.append("_"); - } else { - if (Character.isWhitespace(buffer.charAt(i))) { - sb.append("."); - } else { - sb.append(buffer.charAt(i)); - } - } - if (i == cursor) { - sb.append(")"); - } - } - sb.append(" >> [").append(Joiner.on(",").join(candidates)).append("]"); - - return sb.toString(); - } - } -} http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9d90ccca/zeppelin-zengine/src/main/java/org/apache/zeppelin/conf/ZeppelinConfiguration.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/conf/ZeppelinConfiguration.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/conf/ZeppelinConfiguration.java index c0cae07..259f948 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/conf/ZeppelinConfiguration.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/conf/ZeppelinConfiguration.java @@ -546,7 +546,6 @@ public class ZeppelinConfiguration extends XMLConfiguration { + "org.apache.zeppelin.livy.LivySparkRInterpreter," + "org.apache.zeppelin.alluxio.AlluxioInterpreter," + "org.apache.zeppelin.file.HDFSFileInterpreter," - + "org.apache.zeppelin.postgresql.PostgreSqlInterpreter," + "org.apache.zeppelin.pig.PigInterpreter," + "org.apache.zeppelin.pig.PigQueryInterpreter," + "org.apache.zeppelin.flink.FlinkInterpreter,"
