diff --git a/build-package.sh b/build-package.sh index ed8f3a7..e766a9f 100755 --- a/build-package.sh +++ b/build-package.sh @@ -1,6 +1,6 @@ #This script builds the jar by calling build.sh in RImpala/java #and then builds the RImpala package -cd java +cd src/java ./build.sh -cd .. +cd ../.. R CMD build src diff --git a/java/README.md b/java/README.md deleted file mode 100755 index ecd89d0..0000000 --- a/java/README.md +++ /dev/null @@ -1,22 +0,0 @@ -###RImpala - JDBC connection jar - -This java project creates the JDBC connection jar for the RImpala package. -This project is based on the [Cloudera-Impala-JDBC-Example](https://github.com/onefoursix/Cloudera-Impala-JDBC-Example) - -Here are links to more information on Cloudera Impala: - -- [Cloudera Enterprise RTQ](http://www.cloudera.com/content/cloudera/en/products/cloudera-enterprise-core/cloudera-enterprise-RTQ.html) - -- [Cloudera Impala Documentation](http://www.cloudera.com/content/support/en/documentation/cloudera-impala/cloudera-impala-documentation-v1-latest.html) - -- [Cloudera Impala JDBC Documentation](http://www.cloudera.com/content/cloudera-content/cloudera-docs/Impala/latest/Installing-and-Using-Impala/ciiu_impala_jdbc.html) - -- [Impala-User Google Group](https://groups.google.com/a/cloudera.org/forum/?fromgroups#!forum/impala-user) - - - -####Dependencies -To build the project you must have Maven 2.x or higher installed. Maven info is [here](http://maven.apache.org). - -To run the project you must have access to a Hadoop cluster running Cloudera Impala with at least one populated table defined in the Hive Metastore. - diff --git a/java/pom.xml b/java/pom.xml deleted file mode 100755 index 17ab9ca..0000000 --- a/java/pom.xml +++ /dev/null @@ -1,159 +0,0 @@ - - - 4.0.0 - com.musigma.ird.bigdata - RImpala - 2.0 - jar - - - UTF-8 - UTF-8 - - - - - - commons-logging - commons-logging - 1.1.3 - - - - org.apache.hive - hive-jdbc - 0.12.0-cdh5.1.0 - - - - org.apache.hadoop - hadoop-common - 2.3.0-cdh5.1.0 - - - - org.apache.hive - hive-metastore - 0.12.0-cdh5.1.0 - - - - org.apache.hive - hive-service - 0.12.0-cdh5.1.0 - - - - org.apache.thrift - libfb303 - 0.9.0 - - - - org.apache.thrift - libthrift - 0.9.0.cloudera.2 - - - - log4j - log4j - 1.2.16 - - - - org.slf4j - slf4j-api - 1.7.5 - - - - org.slf4j - slf4j-log4j12 - 1.7.5 - - - - - - - - - - org.codehaus.mojo - exec-maven-plugin - 1.2.1 - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.3.2 - - 1.6 - 1.6 - - - - org.apache.maven.plugins - maven-jar-plugin - 2.4 - - ${basedir} - - - - maven-assembly-plugin - - - - com.musigma.ird.bigdata.RImpala - - - - jar-with-dependencies - - - - - - - - - - cdh.repo - https://repository.cloudera.com/artifactory/cloudera-repos - Cloudera Repositories - - false - - - - cdh.snapshots.repo - https://repository.cloudera.com/artifactory/libs-snapshot-local - Cloudera Snapshots Repository - - true - - - false - - - - central - http://repo1.maven.org/maven2/ - - true - - - false - - - - - diff --git a/java/src/main/java/com/musigma/ird/bigdata/RImpala.java b/java/src/main/java/com/musigma/ird/bigdata/RImpala.java deleted file mode 100755 index 33f6445..0000000 --- a/java/src/main/java/com/musigma/ird/bigdata/RImpala.java +++ /dev/null @@ -1,393 +0,0 @@ -package com.musigma.ird.bigdata; - -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; - -public class RImpala { - - - private static String CONNECTION_URL; - - private static final String JDBC_DRIVER_NAME = "org.apache.hive.jdbc.HiveDriver"; - - private static Connection con = null; - - public static void main(String[] args) { - - - } - - - public static boolean connect(String IP, String port, String principal) { - - CONNECTION_URL = "jdbc:hive2://" + IP + ':' + port + "/;" + principal; - - try { - Class.forName(JDBC_DRIVER_NAME); - con = DriverManager.getConnection(CONNECTION_URL); - con.setAutoCommit(false); - return true; - - } catch (SQLException e) { - // TODO Auto-generated catch block - System.out.println("Error: " + e.getMessage()); - return false; - - } catch (ClassNotFoundException e) { - // TODO Auto-generated catch block - System.out.println("Error: " + e.getMessage()); - return false; - } - - } - - public static boolean close() { - try { - con.close(); - return true; - - } catch (SQLException e) { - // TODO Auto-generated catch block - System.out.println("Error: " + e.getMessage()); - return false; - } - } - - public static boolean refresh(String table) throws ClassNotFoundException { - - try { - Statement stmt; - stmt = con.createStatement(); - String Q = "refresh " + table; - //stmt.execute("connect "+ IP+":21000;"); - stmt.execute(Q); - return true; - - } catch (SQLException e) { - // TODO Auto-generated catch block - System.out.println("Error: " + e.getMessage()); - return false; - - } - } - - public static boolean invalidate(String table) throws ClassNotFoundException { - - try { - Statement stmt; - stmt = con.createStatement(); - String Q = "invalidate metadata " + table; - //stmt.execute("connect "+ IP+":21000;"); - stmt.execute(Q); - return true; - - } catch (SQLException e) { - // TODO Auto-generated catch block - System.out.println("Error: " + e.getMessage()); - return false; - - } - } - - public static List < String[] > showtables() throws SQLException { - Statement stmt; - String Q = "show tables"; - ResultSet rs = null; - - try { - stmt = con.createStatement(); - rs = stmt.executeQuery(Q); - List < String[] > dynamicResult = new ArrayList < String[] > (); - - ResultSetMetaData metaData = rs.getMetaData(); - - int columnCount = metaData.getColumnCount(); - - String[] columnNames = new String[columnCount]; - - for (int j = 1; j <= columnCount; j++) { - columnNames[j - 1] = metaData.getColumnName(j); - - } - dynamicResult.add(columnNames); - - while (rs.next()) { - - String[] dynamicRow = new String[columnCount]; - - for (int i = 1; i <= columnCount; i++) { - - dynamicRow[i - 1] = rs.getObject(i).toString(); - } - dynamicResult.add(dynamicRow); - - - } - return dynamicResult; - - } catch (SQLException e) { - // TODO Auto-generated catch block - System.out.println("Error: " + e.getMessage()); - } catch (Exception e) { - //e.printStackTrace(); - - if (!con.isValid(2)) { - System.out.println("Connection has probably not been established"); - System.out.println("Please use rimpala.connect(IP= ,port= )"); - } - - System.out.println("Error: " + e.getMessage()); - - } finally { - - } - return null; - - } - - public static List < String[] > showdatabases() throws SQLException { - Statement stmt; - String Q = "show databases"; - ResultSet rs = null; - - try { - stmt = con.createStatement(); - rs = stmt.executeQuery(Q); - List < String[] > dynamicResult = new ArrayList < String[] > (); - - ResultSetMetaData metaData = rs.getMetaData(); - - int columnCount = metaData.getColumnCount(); - - String[] columnNames = new String[columnCount]; - - for (int j = 1; j <= columnCount; j++) { - columnNames[j - 1] = metaData.getColumnName(j); - - } - dynamicResult.add(columnNames); - - while (rs.next()) { - - String[] dynamicRow = new String[columnCount]; - - for (int i = 1; i <= columnCount; i++) { - - dynamicRow[i - 1] = rs.getObject(i).toString(); - } - dynamicResult.add(dynamicRow); - - - } - return dynamicResult; - - } catch (SQLException e) { - // TODO Auto-generated catch block - System.out.println("Error: " + e.getMessage()); - } catch (Exception e) { - //e.printStackTrace(); - - if (!con.isValid(2)) { - System.out.println("Connection has probably not been established"); - System.out.println("Please use rimpala.connect(IP= ,port= )"); - } - - System.out.println("Error: " + e.getMessage()); - - } finally { - - } - return null; - - } - - - - public static boolean usedatabase(String db) { - Statement stmt; - String Q = "use" + " " + db; - try { - stmt = con.createStatement(); - stmt.execute(Q); - System.out.println("Database changed to " + db); - return true; - } catch (SQLException e) { - // TODO Auto-generated catch block - System.out.println("Error: " + e.getMessage()); - return false; - } - } - - public static List < String[] > describe(String table) throws SQLException { - Statement stmt; - String Q = "describe" + " " + table; - ResultSet rs = null; - try { - stmt = con.createStatement(); - rs = stmt.executeQuery(Q); - - List < String[] > dynamicResult = new ArrayList < String[] > (); - - ResultSetMetaData metaData = rs.getMetaData(); - - int columnCount = metaData.getColumnCount(); - - String[] columnNames = new String[columnCount]; - - for (int j = 1; j <= columnCount; j++) { - columnNames[j - 1] = metaData.getColumnName(j); - - } - dynamicResult.add(columnNames); - - while (rs.next()) { - - String[] dynamicRow = new String[columnCount]; - - for (int i = 1; i <= columnCount; i++) { - - dynamicRow[i - 1] = rs.getObject(i).toString(); - } - dynamicResult.add(dynamicRow); - - - } - return dynamicResult; - } catch (SQLException e) { - // TODO Auto-generated catch block - System.out.println("Error: " + e.getMessage()); - } catch (Exception e) { - //e.printStackTrace(); - - if (!con.isValid(2)) { - System.out.println("Connection has probably not been established"); - System.out.println("Please use rimpala.connect(IP= ,port= )"); - } - - System.out.println("Error: " + e.getMessage()); - - } finally { - - } - return null; - - } - - public static List < String[] > query(String Q, String isDDL, String fetchSize) throws SQLException { - - ResultSet rs = null; - - - if ("true".equals(isDDL)) { - List < String[] > updateResult = new ArrayList < String[] > (); - - String[] Result_array = new String[1]; - - String Result; - - try { - Statement stmt = con.createStatement(); - - stmt.executeUpdate(Q); - - Result = "true"; - - Result_array[0] = Result; - - updateResult.add(Result_array); - - return updateResult; - - } catch (SQLException e) { - - System.out.println("Error: " + e.getMessage()); - - } catch (Exception e) { - - if (!con.isValid(2)) { - System.out.println("Connection has probably not been established"); - System.out.println("Please use rphoenix.connect(IP= ,port= )"); - } - - System.out.println("Error: " + e.getMessage()); - } finally {} - - return null; - } else { - try { - - Statement stmt = con.createStatement(); - - stmt.setFetchSize(Integer.parseInt(fetchSize)); - - rs = stmt.executeQuery(Q); - - List < String[] > dynamicResult = new ArrayList < String[] > (); - - ResultSetMetaData metaData = rs.getMetaData(); - - int columnCount = metaData.getColumnCount(); - - - //System.out.println("Number of Columns :"+columnCount); - - - String[] columnTypes = new String[columnCount]; - String[] columnNames = new String[columnCount]; - for (int j = 1; j <= columnCount; j++) { - - //System.out.print(metaData.getColumnName(j)+"\t"); - columnNames[j - 1] = metaData.getColumnName(j); - columnTypes[j - 1] = metaData.getColumnTypeName(j); - } - - dynamicResult.add(columnNames); - dynamicResult.add(columnTypes); - - - while (rs.next()) { - - String[] dynamicRow = new String[columnCount]; - - for (int i = 1; i <= columnCount; i++) { - - dynamicRow[i - 1] = rs.getObject(i).toString(); - } - dynamicResult.add(dynamicRow); - - - } - return dynamicResult; - - } catch (SQLException e) { - - System.out.println("Error: " + e.getMessage()); - - } catch (Exception e) { - //e.printStackTrace(); - - if (!con.isValid(2)) { - System.out.println("Connection has probably not been established"); - System.out.println("Please use rimpala.connect(IP= ,port= )"); - } - - System.out.println("Error: " + e.getMessage()); - - } finally { - - } - return null; - } - - - - } - - -} diff --git a/src/inst/java/RImpala-2.0.jar b/src/inst/java/RImpala-2.0.jar old mode 100755 new mode 100644 index 40e8319..2a63da5 Binary files a/src/inst/java/RImpala-2.0.jar and b/src/inst/java/RImpala-2.0.jar differ diff --git a/src/java/build.sh b/src/java/build.sh index 8862e80..9f1296e 100755 --- a/src/java/build.sh +++ b/src/java/build.sh @@ -1,2 +1,2 @@ -mvn clean install +mvn clean package mv RImpala-2.0.jar ../inst/java/RImpala-2.0.jar diff --git a/src/java/src/main/java/com/musigma/ird/bigdata/RImpala.java b/src/java/src/main/java/com/musigma/ird/bigdata/RImpala.java index 33f6445..9c9bd6a 100755 --- a/src/java/src/main/java/com/musigma/ird/bigdata/RImpala.java +++ b/src/java/src/main/java/com/musigma/ird/bigdata/RImpala.java @@ -356,8 +356,8 @@ public static List < String[] > query(String Q, String isDDL, String fetchSize) String[] dynamicRow = new String[columnCount]; for (int i = 1; i <= columnCount; i++) { - - dynamicRow[i - 1] = rs.getObject(i).toString(); + Object o = rs.getObject(i); + dynamicRow[i - 1] = o == null ? null : o.toString(); } dynamicResult.add(dynamicRow); diff --git a/src/java/target/classes/com/musigma/ird/bigdata/RImpala.class b/src/java/target/classes/com/musigma/ird/bigdata/RImpala.class new file mode 100644 index 0000000..ec6aa63 Binary files /dev/null and b/src/java/target/classes/com/musigma/ird/bigdata/RImpala.class differ diff --git a/java/src/main/resources/log4j.properties b/src/java/target/classes/log4j.properties old mode 100755 new mode 100644 similarity index 100% rename from java/src/main/resources/log4j.properties rename to src/java/target/classes/log4j.properties diff --git a/src/java/target/maven-archiver/pom.properties b/src/java/target/maven-archiver/pom.properties new file mode 100644 index 0000000..d9488f1 --- /dev/null +++ b/src/java/target/maven-archiver/pom.properties @@ -0,0 +1,5 @@ +#Generated by Maven +#Tue May 16 18:20:46 CEST 2017 +version=2.0 +groupId=com.musigma.ird.bigdata +artifactId=RImpala