You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by al...@apache.org on 2020/06/01 11:01:14 UTC

[zeppelin] branch master updated: [ZEPPELIN-4792] Help needs to be updated in Cassandra interpreter

This is an automated email from the ASF dual-hosted git repository.

alexott 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 def30ee  [ZEPPELIN-4792] Help needs to be updated in Cassandra interpreter
def30ee is described below

commit def30ee4b88b759ce6f607247829f556687454d6
Author: Alex Ott <al...@gmail.com>
AuthorDate: Sun May 31 13:52:44 2020 +0200

    [ZEPPELIN-4792] Help needs to be updated in Cassandra interpreter
    
    ### What is this PR for?
    
    When updating  for the new DataStax Java driver, I forgot to update template for a `HELP` command. This PR fixes this problem, and simplifies maintenance by reading driver version from the resource file generated during compilation, so HELP command will provide information based on the actual driver version used for building interpreter.
    
    ### What type of PR is it?
    Bug Fix
    
    ### What is the Jira issue?
    
    https://issues.apache.org/jira/browse/ZEPPELIN-4792
    
    ### How should this be tested?
    
    * https://travis-ci.org/github/alexott/zeppelin/builds/693123862 ()
    * Tested manually
    
    Author: Alex Ott <al...@gmail.com>
    
    Closes #3780 from alexott/ZEPPELIN-4792 and squashes the following commits:
    
    f62bc5c51 [Alex Ott] [ZEPPELIN-4792] Help needs to be updated in Cassandra interpreter
---
 cassandra/pom.xml                                  | 13 ++++-
 .../main/resources-filtered/driver-info.properties | 15 +++++
 cassandra/src/main/resources/scalate/helpMenu.ssp  | 23 +++++---
 .../apache/zeppelin/cassandra/DisplaySystem.scala  | 65 ++++++++++++++--------
 .../cassandra/CassandraInterpreterTest.java        |  2 +-
 cassandra/src/test/resources/scalate/Help.html     |  2 +-
 6 files changed, 87 insertions(+), 33 deletions(-)

diff --git a/cassandra/pom.xml b/cassandra/pom.xml
index 6d37359..9a93fd3 100644
--- a/cassandra/pom.xml
+++ b/cassandra/pom.xml
@@ -33,10 +33,9 @@
     <description>Zeppelin cassandra support</description>
 
     <properties>
-        <cassandra.driver.version>4.6.0</cassandra.driver.version>
+        <cassandra.driver.version>4.6.1</cassandra.driver.version>
         <snappy.version>1.1.7.3</snappy.version>
         <lz4.version>1.6.0</lz4.version>
-        <commons-lang.version>3.3.2</commons-lang.version>
         <scalate.version>1.7.1</scalate.version>
 
         <!-- test library versions -->
@@ -184,6 +183,16 @@
     </dependencies>
 
     <build>
+        <resources>
+            <resource>
+                <directory>src/main/resources-filtered</directory>
+                <filtering>true</filtering>
+            </resource>
+            <resource>
+                <directory>src/main/resources</directory>
+                <filtering>false</filtering>
+            </resource>
+        </resources>
         <plugins>
             <!-- Plugin to compile Scala code -->
             <plugin>
diff --git a/cassandra/src/main/resources-filtered/driver-info.properties b/cassandra/src/main/resources-filtered/driver-info.properties
new file mode 100644
index 0000000..db0d06d
--- /dev/null
+++ b/cassandra/src/main/resources-filtered/driver-info.properties
@@ -0,0 +1,15 @@
+# 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.
+driverVersion=${cassandra.driver.version}
diff --git a/cassandra/src/main/resources/scalate/helpMenu.ssp b/cassandra/src/main/resources/scalate/helpMenu.ssp
index c40c81a..f75eef6 100644
--- a/cassandra/src/main/resources/scalate/helpMenu.ssp
+++ b/cassandra/src/main/resources/scalate/helpMenu.ssp
@@ -30,6 +30,7 @@
 <%@ val sharedStatesId: UUID = Uuids.random() %>
 <%@ val changelogId: UUID = Uuids.random() %>
 <%@ val contactsId: UUID = Uuids.random() %>
+<%@ val driverVersion: String %>
 
 <br/>
 <br/>
@@ -103,17 +104,17 @@
             <ul class="dropdown-menu">
                 <li>
                     <a role="button">
-                        <span class="text-info">Version <strong>3.0</strong></span>
+                        <span class="text-info">Version <strong>4.0</strong></span>
                     </a>
                 </li>
                 <li>
                     <a role="button">
-                        <span class="text-info">Java Driver Version <strong>3.0.1</strong></span>
+                        <span class="text-info">Java Driver Version <strong>${driverVersion}</strong></span>
                     </a>
                 </li>
                 <li>
                     <a role="button">
-                        <span class="text-info">Author <strong>@doanduyhai</strong></span>
+                        <span class="text-info">Author <strong>@doanduyhai, @alexott</strong></span>
                     </a>
                 </li>
             </ul>
@@ -257,7 +258,7 @@
                     <h3>II Comments</h3>
                     <p>
                         It is possible to add comments between statements. Single line comments start with the
-                        <strong>hash</strong> sign (#) or <strong>double slashes</strong> (//). Multi-line comments are enclosed between
+                        <strong>hash</strong> sign (<code>#</code>), <strong>double minus</strong> (<code>--</code>), or <strong>double slashes</strong> (<code>//</code>). Multi-line comments are enclosed between
                         <strong>&sol;&ast;&ast;</strong> and <strong>&ast;&ast;&sol;</strong>. Ex:
 
                         <br/>
@@ -266,11 +267,12 @@
                             <div class="col-md-8 col-md-offset-2">
                                 <pre>
 
-    #Single line comment style 1
+    # Single line comment style 1
     INSERT INTO users(login,name) VALUES('jdoe','John DOE');
 
-    //Single line comment style 2
+    -- Single line comment style 2
 
+    // Single line comment style 3
 
     /**
      Multi line
@@ -998,6 +1000,13 @@
         </div>        
         <div id="${changelogId}" class="panel-collapse collapse" role="tabpanel">
             <div class="panel-body">
+                <strong>4.0</strong>&nbsp;:
+                <br/>
+                <ul>
+                    <li>Migrate to DataStax Java driver 4.x that supports both Cassandra and DSE.  This contains breaking changes, like, removal of <code>@retryPolicy</code></li>
+                    <li>Fix schema disagreement that could arise when executing multiple DDL statements</li>
+                    <li>Added support for <code>--</code> comment style</li>
+                </ul>
                 <strong>3.0</strong>&nbsp;:
                 <br/>
                 <ul>
@@ -1037,7 +1046,7 @@
         </div>        
         <div id="${contactsId}" class="panel-collapse collapse" role="tabpanel">
             <div class="panel-body">
-                If you encounter a bug for this interpreter, please create a <a href="https://issues.apache.org/jira/browse/ZEPPELIN-382?jql=project%20%3D%20ZEPPELIN" target="_blank"><strong>JIRA</strong></a> ticket and ping me on Twitter at <a href="https://twitter.com/doanduyhai" target="_blank"><strong>@doanduyhai</strong></a>
+                If you encounter a bug for this interpreter, please create a <a href="https://issues.apache.org/jira/browse/ZEPPELIN" target="_blank"><strong>JIRA</strong></a> ticket.</a>
             </div>
         </div>            
     </div>    
diff --git a/cassandra/src/main/scala/org/apache/zeppelin/cassandra/DisplaySystem.scala b/cassandra/src/main/scala/org/apache/zeppelin/cassandra/DisplaySystem.scala
index 382bd46..18137d3 100644
--- a/cassandra/src/main/scala/org/apache/zeppelin/cassandra/DisplaySystem.scala
+++ b/cassandra/src/main/scala/org/apache/zeppelin/cassandra/DisplaySystem.scala
@@ -16,7 +16,8 @@
  */
 package org.apache.zeppelin.cassandra
 
-import java.util.UUID
+import java.io.InputStream
+import java.util.{Properties, UUID}
 
 import org.apache.zeppelin.cassandra.MetaDataHierarchy._
 import org.fusesource.scalate.TemplateEngine
@@ -42,32 +43,38 @@ object DisplaySystem {
 
   val engine = new TemplateEngine
 
-  val CLUSTER_DETAILS_TEMPLATE = "scalate/clusterDetails.ssp"
-  val KEYSPACE_DETAILS_TEMPLATE = "scalate/keyspaceDetails.ssp"
+  val CLUSTER_DETAILS_TEMPLATE: String = "scalate/clusterDetails.ssp"
+  val KEYSPACE_DETAILS_TEMPLATE: String = "scalate/keyspaceDetails.ssp"
 
-  val TABLE_DETAILS_TEMPLATE = "scalate/tableDetails.ssp"
-  val ALL_TABLES_TEMPLATE = "scalate/allTables.ssp"
+  val TABLE_DETAILS_TEMPLATE: String = "scalate/tableDetails.ssp"
+  val ALL_TABLES_TEMPLATE: String = "scalate/allTables.ssp"
 
-  val UDT_DETAILS_TEMPLATE = "scalate/udtDetails.ssp"
-  val ALL_UDTS_TEMPLATE = "scalate/allUDTs.ssp"
+  val UDT_DETAILS_TEMPLATE: String = "scalate/udtDetails.ssp"
+  val ALL_UDTS_TEMPLATE: String = "scalate/allUDTs.ssp"
 
-  val FUNCTION_DETAILS_TEMPLATE = "scalate/functionDetails.ssp"
-  val ALL_FUNCTIONS_TEMPLATE = "scalate/allFunctions.ssp"
+  val FUNCTION_DETAILS_TEMPLATE: String = "scalate/functionDetails.ssp"
+  val ALL_FUNCTIONS_TEMPLATE: String = "scalate/allFunctions.ssp"
 
-  val AGGREGATE_DETAILS_TEMPLATE = "scalate/aggregateDetails.ssp"
-  val ALL_AGGREGATES_TEMPLATE = "scalate/allAggregates.ssp"
+  val AGGREGATE_DETAILS_TEMPLATE: String = "scalate/aggregateDetails.ssp"
+  val ALL_AGGREGATES_TEMPLATE: String = "scalate/allAggregates.ssp"
 
-  val MATERIALIZED_VIEW_DETAILS_TEMPLATE = "scalate/materializedViewDetails.ssp"
-  val ALL_MATERIALIZED_VIEWS_TEMPLATE = "scalate/allMaterializedViews.ssp"
+  val MATERIALIZED_VIEW_DETAILS_TEMPLATE: String = "scalate/materializedViewDetails.ssp"
+  val ALL_MATERIALIZED_VIEWS_TEMPLATE: String = "scalate/allMaterializedViews.ssp"
 
-  val MENU_TEMPLATE = "scalate/menu.ssp"
-  val CLUSTER_DROPDOWN_TEMPLATE = "scalate/dropDownMenuForCluster.ssp"
+  val MENU_TEMPLATE: String = "scalate/menu.ssp"
+  val CLUSTER_DROPDOWN_TEMPLATE: String = "scalate/dropDownMenuForCluster.ssp"
 
-  val KEYSPACE_DROPDOWN_TEMPLATE = "scalate/dropDownMenuForKeyspace.ssp"
-  val CLUSTER_CONTENT_TEMPLATE = "scalate/clusterContent.ssp"
-  val KEYSPACE_CONTENT_TEMPLATE = "scalate/keyspaceContent.ssp"
+  val KEYSPACE_DROPDOWN_TEMPLATE: String = "scalate/dropDownMenuForKeyspace.ssp"
+  val CLUSTER_CONTENT_TEMPLATE: String = "scalate/clusterContent.ssp"
+  val KEYSPACE_CONTENT_TEMPLATE: String = "scalate/keyspaceContent.ssp"
+
+  val NO_RESULT_TEMPLATE: String = "scalate/noResult.ssp"
+  val NO_RESULT_WITH_EXECINFO_TEMPLATE: String = "scalate/noResultWithExecutionInfo.ssp"
+
+  val HELP_TEMPLATE = "scalate/helpMenu.ssp"
+
+  val DEFAULT_CLUSTER_NAME: String = "Test Cluster"
 
-  val DEFAULT_CLUSTER_NAME = "Test Cluster"
   def clusterName(meta: Metadata): String = {
     if (meta != null) {
       meta.getClusterName.orElse(DEFAULT_CLUSTER_NAME)
@@ -384,14 +391,28 @@ object DisplaySystem {
 
   object HelpDisplay {
 
+    lazy val driverProperties: Properties = {
+      val properties = new Properties()
+      try {
+        val is = getClass.getClassLoader.getResourceAsStream("driver-info.properties")
+        properties.load(is)
+        is.close()
+      } catch {
+        case x: Exception => println(s"Exception: ${x.getMessage}")
+      }
+      properties
+    }
+
     def formatHelp(): String = {
-      engine.layout("/scalate/helpMenu.ssp")
+      engine.layout(HELP_TEMPLATE,
+        Map[String, String]("driverVersion" ->
+          driverProperties.getProperty("driverVersion", "Unknown")))
     }
   }
 
   object NoResultDisplay {
 
-    val formatNoResult: String = engine.layout("/scalate/noResult.ssp")
+    val formatNoResult: String = engine.layout(NO_RESULT_TEMPLATE)
 
     def nodeToString(node: Node): String = {
       node.getEndPoint.toString
@@ -403,7 +424,7 @@ object DisplaySystem {
         .toSet + queriedHosts).mkString(", ")
       val schemaInAgreement = Option(execInfo.isSchemaInAgreement).map(_.toString).getOrElse("N/A")
 
-      engine.layout("/scalate/noResultWithExecutionInfo.ssp",
+      engine.layout(NO_RESULT_WITH_EXECINFO_TEMPLATE,
         Map[String, Any]("query" -> lastQuery,
           "triedHosts" -> triedHosts, "queriedHosts" -> queriedHosts,
           "schemaInAgreement" -> schemaInAgreement))
diff --git a/cassandra/src/test/java/org/apache/zeppelin/cassandra/CassandraInterpreterTest.java b/cassandra/src/test/java/org/apache/zeppelin/cassandra/CassandraInterpreterTest.java
index 8b40210..8dac12f 100644
--- a/cassandra/src/test/java/org/apache/zeppelin/cassandra/CassandraInterpreterTest.java
+++ b/cassandra/src/test/java/org/apache/zeppelin/cassandra/CassandraInterpreterTest.java
@@ -759,7 +759,7 @@ public class CassandraInterpreterTest { //extends AbstractCassandraUnit4CQLTestC
 
     //Then
     assertThat(actual.code()).isEqualTo(Code.SUCCESS);
-    assertThat(reformatHtml(actual.message().get(0).getData())).isEqualTo(expected);
+    assertThat(reformatHtml(actual.message().get(0).getData())).contains(expected);
   }
 
   private static String reformatHtml(String rawHtml) {
diff --git a/cassandra/src/test/resources/scalate/Help.html b/cassandra/src/test/resources/scalate/Help.html
index ce702ab..95c461b 100644
--- a/cassandra/src/test/resources/scalate/Help.html
+++ b/cassandra/src/test/resources/scalate/Help.html
@@ -1 +1 @@
-<br/><br/><nav class="navbar navbar-default"><ul class="nav navbar-nav"><li role="presentation" class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="text-info"><i class="glyphicon glyphicon-book"/>&nbsp;<strong>Please select ...</strong></span><span class="text-info caret"></span><ul class="dropdown-menu"><li class="dropdown-header"><span class="text-info">Topics</span></li><li><a role="button" data-toggl [...]
\ No newline at end of file
+<div class="container"><div class="panel panel-default"><div class="panel-heading" role="tab"><h4 class="panel-title"><a role="button" data-toggle="collapse"  aria-expanded="false"><span class="text-info"><strong>Basic Commands</strong></span></a></h4></div><div  class="panel-collapse collapse in" role="tabpanel"><div class="panel-body"><div class="panel panel-default"><div class="panel-body"><h3>I CQL Statements</h3><p>This interpreter is compatible with any CQL statement supported by C [...]