Skip to content

Commit

Permalink
[ZEPPELIN-559] Cassandra interpreter v2
Browse files Browse the repository at this point in the history
### What is this PR for?
* Update the **Cassandra** interpreter to V2 to support new **schema commands** to describe **Cassandra** 3.x features:
    * User Defined Functions
    * User Defined Aggregates
    * Materialized Views
* Add support for single line comment using **double slashes** (//)
* Add **DESCRIBE TYPES**
* The Java driver version is bumped to **3.0.0-rc1**
* The contextual **HELP menu** is also updated and a _ChangeLog_ section is added.

### What type of PR is it?
[Improvement]

### Todos
* [x] - Add new PR to update official Cassandra interpreter with new features
* [x] - Test steps executed and confirmed working by the community
* [x] - Code review by the community (warning, **Scala** inside)

### Is there a relevant Jira issue?
**[ZEPPELIN-559]**
**[ZEPPELIN-575]** for doc

### How should this be tested?
1. Download and install locally **[Cassandra 3.1.1]**
2. Start **Cassandra**
3. Clone this pull request locally with:
    1. _git fetch origin pull/600/head:CassandraInterpreterV2_
    2. _git checkout CassandraInterpreterV2_
4. Build this version of Zeppelin with _mvn clean package -DskipTests_
5. Start **Zeppelin** and update the property _cassandra.hosts_ of the **Cassandra** interpreter (set it to _localhost_ or _127.0.0.1_ depending on your configuration)
6. In a paragraph, execute all the **CQL** statements given in this **[CassandraInterpreterV2TestData.cql]** by copy-pasting them
7. Start a new _%cassandra_ paragraph and execute **DESCRIBE FUNCTION test.maxOf;**. You should be able to see:
![image](https://cloud.githubusercontent.com/assets/1532977/12138932/edaf45d4-b45c-11e5-8724-104085d6e30d.png)
8. Start a new _%cassandra_ paragraph and execute **DESCRIBE AGGREGATE test.group_by;**. You should be able to see:
![image](https://cloud.githubusercontent.com/assets/1532977/12138970/2ecd784c-b45d-11e5-9076-a7b674439fa5.png)
9. Start a new _%cassandra_ paragraph and execute **DESCRIBE MATERIALIZED VIEW test.user_by_country;**. You should be able to see:
![image](https://cloud.githubusercontent.com/assets/1532977/12139025/a223a104-b45d-11e5-8331-b97323016fa3.png)
10. Start a new _%cassandra_ paragraph and execute **SELECT id,val1,val2,maxOf(val1,val2) FROM test.test_max;**. You should be able to see:
![image](https://cloud.githubusercontent.com/assets/1532977/12139046/c43febf8-b45d-11e5-9b96-290aff23730e.png)
11. Start a new _%cassandra_ paragraph and execute **SELECT group_by(category,sales_count) FROM test.items;**. You should be able to see:
![image](https://cloud.githubusercontent.com/assets/1532977/12139071/fb06b1e4-b45d-11e5-9077-6ec3275c1319.png)
12. Start a new _%cassandra_ paragraph and execute **SELECT * FROM test.user_by_country WHERE country='FR';**. You should be able to see:
![image](https://cloud.githubusercontent.com/assets/1532977/12139085/1671f3d0-b45e-11e5-9dc2-4bf6bd87e84e.png)

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

[ZEPPELIN-559]: https://issues.apache.org/jira/browse/ZEPPELIN-559
[ZEPPELIN-575]: https://issues.apache.org/jira/browse/ZEPPELIN-575
[Cassandra 3.1.1]: http://cassandra.apache.org/download/
[CassandraInterpreterV2TestData.cql]: https://gist.githubusercontent.com/doanduyhai/5d88aaf3820be28474d2/raw/e5b5d9c325a17a58c2f27bff454db999fd3a3a66/CassandraInterpreterV2TestData.cql

Author: DuyHai DOAN <doanduyhai@gmail.com>

Closes #600 from doanduyhai/CassandraInterpreter-V2 and squashes the following commits:

36e3bdb [DuyHai DOAN] Fix random test failure
a2d831b [DuyHai DOAN] Refactor after code review
41b8667 [DuyHai DOAN] Tune regular expression for FUNCTION creation pattern
138804c [DuyHai DOAN] Fix CSS style for UDF & MV in menu display
6509da5 [DuyHai DOAN] Fix failing tests
7a5ac39 [DuyHai DOAN] Update RegExp for UDF creation to fix multiple statements match
6ea9e55 [DuyHai DOAN] Update help menu and changelog
6b46076 [DuyHai DOAN] Add Support for UDF, UDA and Materialized Views
058161d [DuyHai DOAN] Upgrade Java driver version to 3.0.0-rc1
  • Loading branch information
doanduyhai authored and Felix Cheung committed Jan 24, 2016
1 parent 9308ee1 commit 11a45e2
Show file tree
Hide file tree
Showing 33 changed files with 2,122 additions and 3,121 deletions.
30 changes: 14 additions & 16 deletions cassandra/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,19 @@
<url>http://zeppelin.incubator.apache.org</url>

<properties>
<cassandra.driver.version>2.1.7.1</cassandra.driver.version>
<cassandra.driver.version>3.0.0-rc1</cassandra.driver.version>
<snappy.version>1.0.5.4</snappy.version>
<lz4.version>1.2.0</lz4.version>
<scala.version>2.11.7</scala.version>
<scala.binary.version>2.11</scala.binary.version>
<commons-lang.version>3.4</commons-lang.version>
<lz4.version>1.3.0</lz4.version>
<scala.version>2.10.4</scala.version>
<scala.binary.version>2.10</scala.binary.version>
<commons-lang.version>3.3.2</commons-lang.version>
<scalate.version>1.7.1</scalate.version>
<cassandra.guava.version>16.0.1</cassandra.guava.version>

<!--TEST-->
<scalatest.version>2.2.4</scalatest.version>
<junit.version>4.12</junit.version>
<achilles.version>3.2.2</achilles.version>
<achilles.version>3.2.4-Zeppelin</achilles.version>
<assertj.version>1.7.0</assertj.version>
<mockito.version>1.9.5</mockito.version>
</properties>
Expand All @@ -65,6 +66,12 @@
<version>${cassandra.driver.version}</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${cassandra.guava.version}</version>
</dependency>

<!-- Compression libraries for the cassandra-driver protocol. -->
<!-- Include both compression options to make to simplify deployment. -->

Expand Down Expand Up @@ -130,7 +137,7 @@

<dependency>
<groupId>info.archinnov</groupId>
<artifactId>achilles-junit</artifactId>
<artifactId>achilles-embedded</artifactId>
<version>${achilles.version}</version>
<scope>test</scope>
<exclusions>
Expand All @@ -145,13 +152,6 @@
</exclusions>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>16.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand All @@ -167,7 +167,6 @@
</dependency>
</dependencies>


<build>
<plugins>
<!-- Plugin to compile Scala code -->
Expand Down Expand Up @@ -293,7 +292,6 @@
</execution>
</executions>
</plugin>

</plugins>
</build>
</project>
81 changes: 81 additions & 0 deletions cassandra/src/main/resources/scalate/aggregateDetails.ssp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<%--
/*
* 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.
*/
--%>
#import(org.apache.zeppelin.cassandra.MetaDataHierarchy._)
<%@ val sameNameAggregateDetails: SameNameAggregateDetails %>
<%@ val withCaption: Boolean%>
<div class="row">
<div class="col-md-2"/>
<div class="col-md-8 col-offset-md-2">
#for (aggregate <- sameNameAggregateDetails.aggregates)
<div class="panel panel-default table-responsive table-bordered">
<table class="table">
#if(withCaption)
<caption><h4 class="text-success"><i class="glyphicon glyphicon-retweet"/>&nbsp;${aggregate.name}</h4></caption>
#end
<tbody>
<tr>
<td class="col-md-6"><strong>Keyspace</strong></td>
<td class="col-md-6 text-danger">${aggregate.keyspace}</td>
</tr>
<tr>
<td class="col-md-6"><strong>Arguments</strong></td>
<td class="col-md-6">${aggregate.arguments.toList.mkString(", ")}</td>
</tr>
<tr>
<td class="col-md-6"><strong>State Function</strong></td>
<td class="col-md-6">${aggregate.sFunc}</td>
</tr>
<tr>
<td class="col-md-6"><strong>State Type</strong></td>
<td class="col-md-6">${aggregate.sType}</td>
</tr>
#if(aggregate.finalFunc.isDefined)
<tr>
<td class="col-md-6"><strong>Final Function</strong></td>
<td class="col-md-6">${aggregate.finalFunc.get}</td>
</tr>
#end
#if(aggregate.initCond.isDefined)
<tr>
<td class="col-md-6"><strong>Initial State</strong></td>
<td class="col-md-6">${aggregate.initCond.get}</td>
</tr>
#end
<tr>
<td class="col-md-6"><strong>Return type</strong></td>
<td class="col-md-6">${aggregate.returnType}</td>
</tr>
</tbody>
</table>
<div class="panel-footer">
<a data-toggle="collapse" data-target="#${aggregate.uniqueId}_asCQL">
<strong>As CQL statement</strong>
<span class="caret"></span>
</a>
<br/><br/>
<div class="text-success collapse" id="${aggregate.uniqueId}_asCQL">
<pre class="well">${aggregate.asCQL}</pre>
</div>
</div>
</div>
<hr/>
#end
</div>
<div class="col-md-2"></div>
</div>
68 changes: 68 additions & 0 deletions cassandra/src/main/resources/scalate/allAggregates.ssp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<%--
/*
* 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.
*/
--%>

#import(org.apache.zeppelin.cassandra.MetaDataHierarchy._)
#import(java.util.UUID)
<%@ val allAggregates: Map[(UUID, String), List[AggregateSummary]] %>

<div class="container">

<div class="row">
<div class="panel-group" role="tablist" aria-multiselectable="true">
#for (((ksId,ksName), aggregates) <- allAggregates)
<div class="panel panel-default">
<div class="panel-heading" role="tab">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-target="#${ksId}" aria-expanded="false">
<span class="text-danger"><i class="glyphicon glyphicon-folder-open"/>&nbsp;&nbsp;${ksName}</span>
</a>
</h4>
</div>
<div id="${ksId}" class="panel-collapse collapse" role="tabpanel">
<div class="panel-body">
<div class="row">
<div class="col-md-2"/>
<div class="col-md-8 col-offset-md-2 table-responsive table-bordered">
<table class="table">
<thead>
<tr>
<th>Aggregate</th>
<th>Return Type</th>
</tr>
</thead>
<tbody>
#for (aggregate <- aggregates)
<tr class="text-success">
<td>${aggregate.name + aggregate.arguments.mkString("(", ", ", ")")}</td>
<td>${aggregate.returnType}</td>
</tr>
#end

</tbody>
</table>
</div>
<div class="col-md-2"/>
</div>
</div>
</div>
</div>
#end
</div>
</div>
</div>
68 changes: 68 additions & 0 deletions cassandra/src/main/resources/scalate/allFunctions.ssp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<%--
/*
* 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.
*/
--%>

#import(org.apache.zeppelin.cassandra.MetaDataHierarchy._)
#import(java.util.UUID)
<%@ val allFunctions: Map[(UUID, String), List[FunctionSummary]] %>

<div class="container">

<div class="row">
<div class="panel-group" role="tablist" aria-multiselectable="true">
#for (((ksId,ksName), functions) <- allFunctions)
<div class="panel panel-default">
<div class="panel-heading" role="tab">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-target="#${ksId}" aria-expanded="false">
<span class="text-danger"><i class="glyphicon glyphicon-folder-open"/>&nbsp;&nbsp;${ksName}</span>
</a>
</h4>
</div>
<div id="${ksId}" class="panel-collapse collapse" role="tabpanel">
<div class="panel-body">
<div class="row">
<div class="col-md-2"/>
<div class="col-md-8 col-offset-md-2 table-responsive table-bordered">
<table class="table">
<thead>
<tr>
<th>Function</th>
<th>Return Type</th>
</tr>
</thead>
<tbody>
#for (function <- functions)
<tr class="text-success">
<td>${function.name + function.arguments.mkString("(",", ", ")")}</td>
<td>${function.returnType}</td>
</tr>
#end

</tbody>
</table>
</div>
<div class="col-md-2"/>
</div>
</div>
</div>
</div>
#end
</div>
</div>
</div>
68 changes: 68 additions & 0 deletions cassandra/src/main/resources/scalate/allMaterializedViews.ssp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<%--
/*
* 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.
*/
--%>
#import(org.apache.zeppelin.cassandra.MetaDataHierarchy._)
#import(java.util.UUID)
<%@ val allMVs: Map[(UUID,String),List[MaterializedViewSummary]] %>
<div class="container">

<div class="row">
<div class="panel-group" role="tablist" aria-multiselectable="true">
#for (((ksId,ksName), mvs) <- allMVs)
<div class="panel panel-default">
<div class="panel-heading" role="tab">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-target="#${ksId}" aria-expanded="false">
<span class="text-danger"><i class="glyphicon glyphicon-folder-open"/>&nbsp;&nbsp;${ksName}</span>
</a>
</h4>
</div>
<div id="${ksId}" class="panel-collapse collapse" role="tabpanel">
<div class="panel-body">
<div class="row">
<div class="col-md-2"/>
<div class="col-md-8 col-offset-md-2 table-responsive table-bordered">
<table class="table">
<thead>
<tr><th>Materialized View</th></tr>
</thead>
<tbody>
#for (mv <- mvs)

<tr class="text-primary">
<td>
${mv.name}
&nbsp;<i class="glyphicon glyphicon-arrow-right"/>
&nbsp;<i class="glyphicon glyphicon-th-list"/>
&nbsp;${mv.baseTable}
</td>
</tr>
#end

</tbody>
</table>
</div>
<div class="col-md-2"/>
</div>
</div>
</div>
</div>
#end
</div>
</div>
</div>

0 comments on commit 11a45e2

Please sign in to comment.