Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 152 additions & 0 deletions drill/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<?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.6.0-incubating-SNAPSHOT</version>
</parent>

<groupId>org.apache.zeppelin</groupId>
<artifactId>zeppelin-drill</artifactId>
<packaging>jar</packaging>
<version>0.6.0-incubating-SNAPSHOT</version>
<name>Zeppelin: Drill interpreter</name>
<url>http://www.apache.org</url>

<properties>
<drill.drill.version>1.1.0</drill.drill.version>
</properties>

<!-- MapR Technologies Maven Repository -->
<repositories>
<repository>
<id>mapr-releases</id>
<url>http://repository.mapr.com/maven/</url>
<snapshots><enabled>false</enabled></snapshots>
<releases><enabled>true</enabled></releases>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.apache.zeppelin</groupId>
<artifactId>zeppelin-interpreter</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-exec</artifactId>
<version>1.1</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>

<dependency>
<groupId>org.apache.drill.exec</groupId>
<artifactId>drill-jdbc</artifactId>
<version>${drill.drill.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>

<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<id>enforce</id>
<phase>none</phase>
</execution>
</executions>
</plugin>

<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/../../interpreter/drill</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/drill</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>
203 changes: 203 additions & 0 deletions drill/src/main/java/org/apache/zeppelin/drill/DrillInterpreter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
/**
* 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.drill;

import java.sql.*;
import java.util.List;
import java.util.Properties;

import org.apache.zeppelin.interpreter.*;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.zeppelin.interpreter.InterpreterResult.Code;
import org.apache.zeppelin.scheduler.Scheduler;
import org.apache.zeppelin.scheduler.SchedulerFactory;

/**
* Drill interpreter for Zeppelin.
*/
public class DrillInterpreter extends Interpreter {
Logger logger = LoggerFactory.getLogger(DrillInterpreter.class);
int commandTimeOut = 600000;

static final String DRILL_URL = "drill.drill.url";
static final String DRILL_USER = "drill.drill.user";
static final String DRILL_PASSWORD = "drill.drill.password";

static {
Interpreter.register(
"drill",
"drill",
DrillInterpreter.class.getName(),
new InterpreterPropertyBuilder()
.add(DRILL_URL, "jdbc:drill:", "The URL for Drill Instance.")
.add(DRILL_USER, "mapr", "The Drill user")
.add(DRILL_PASSWORD, "", "The password for the Drill user").build());
}

public DrillInterpreter(Properties property) {
super(property);
}

Connection jdbcConnection;
Exception exceptionOnConnect;

//Test only method
public Connection getJdbcConnection()
throws SQLException {
String url = getProperty(DRILL_URL);
String user = getProperty(DRILL_USER);
String password = getProperty(DRILL_PASSWORD);

return DriverManager.getConnection(url, user, password);
}

@Override
public void open() {
logger.info("Jdbc open connection called!");
try {
String driverName = "org.apache.drill.jdbc.Driver";
Class.forName(driverName);
} catch (ClassNotFoundException e) {
logger.error("Cannot load JDBC driver class", e);
exceptionOnConnect = e;
return;
}
try {
jdbcConnection = getJdbcConnection();
exceptionOnConnect = null;
logger.info("Successfully created JDBC connection");
}
catch (SQLException e) {
logger.error("Cannot open JDBC connection", e);
exceptionOnConnect = e;
}
}

@Override
public void close() {
try {
if (jdbcConnection != null) {
jdbcConnection.close();
}
}
catch (SQLException e) {
logger.error("Cannot close connection", e);
}
finally {
jdbcConnection = null;
exceptionOnConnect = null;
}
}

Statement currentStatement;
private InterpreterResult executeSql(String sql) {
try {
if (exceptionOnConnect != null) {
return new InterpreterResult(Code.ERROR, exceptionOnConnect.getMessage());
}
currentStatement = jdbcConnection.createStatement();
StringBuilder msg = null;
if (StringUtils.containsIgnoreCase(sql, "EXPLAIN ")) {
//return the explain as text, make this visual explain later
msg = new StringBuilder();
}
else {
msg = new StringBuilder("%table ");
}
ResultSet res = currentStatement.executeQuery(sql);
try {
ResultSetMetaData md = res.getMetaData();
for (int i = 1; i < md.getColumnCount() + 1; i++) {
if (i == 1) {
msg.append(md.getColumnName(i));
} else {
msg.append("\t" + md.getColumnName(i));
}
}
msg.append("\n");
while (res.next()) {
for (int i = 1; i < md.getColumnCount() + 1; i++) {
msg.append(res.getString(i) + "\t");
}
msg.append("\n");
}
}
finally {
try {
res.close();
currentStatement.close();
}
finally {
currentStatement = null;
}
}

InterpreterResult rett = new InterpreterResult(Code.SUCCESS, msg.toString());
return rett;
}
catch (SQLException ex) {
logger.error("Can not run " + sql, ex);
return new InterpreterResult(Code.ERROR, ex.getMessage());
}
}

@Override
public InterpreterResult interpret(String cmd, InterpreterContext contextInterpreter) {
logger.info("Run SQL command '" + cmd + "'");
return executeSql(cmd);
}

@Override
public void cancel(InterpreterContext context) {
if (currentStatement != null) {
try {
currentStatement.cancel();
}
catch (SQLException 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(
DrillInterpreter.class.getName() + this.hashCode());
}

@Override
public List<String> completion(String buf, int cursor) {
return null;
}

}
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
<module>hive</module>
<module>tajo</module>
<module>flink</module>
<module>drill</module>
<module>ignite</module>
<module>lens</module>
<module>zeppelin-web</module>
Expand All @@ -111,6 +112,17 @@
<MaxPermGen>512m</MaxPermGen>
</properties>

<!-- MapR Technologies Maven Repository -->
<repositories>
<repository>
<id>mapr-releases</id>
<url>http://repository.mapr.com/maven/</url>
<snapshots><enabled>false</enabled></snapshots>
<releases><enabled>true</enabled></releases>
</repository>
</repositories>


<dependencyManagement>
<dependencies>
<!-- Logging -->
Expand Down
Loading