Skip to content

Commit

Permalink
Updated build script to generate phoenix-csvupload.jar used exclusive…
Browse files Browse the repository at this point in the history
…ly for CSV upload.

Updated build script to generate files in lib directory.
Removed log4j warning by adding log4j props to generated jar
  • Loading branch information
mujtabachohan authored and jyates committed Jan 26, 2013
1 parent 0c2dcb5 commit c6ef10c
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 33 deletions.
2 changes: 1 addition & 1 deletion bin/pcsv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ if [ -z "$3" ]
usage;
fi

java -cp ../lib/phoenix-client.jar -Dlog4j.configuration=./log4j.properties phoenix.util.PhoenixRuntime CSV "$@"
java -cp ../lib/phoenix-csvload.jar:../lib/phoenix-client.jar phoenix.util.CSVUtil "$@"

3 changes: 1 addition & 2 deletions bin/psql.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,4 @@ if [ -z "$2" ]
usage;
fi

java -cp ../lib/phoenix-client.jar -Dlog4j.configuration=./log4j.properties phoenix.util.PhoenixRuntime SQL "$@"

java -jar ../lib/phoenix-client.jar "$@"
File renamed without changes.
23 changes: 19 additions & 4 deletions build/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,15 @@
</target>
<target name="jar" depends="compile" description="make deployable jars">
<buildnumber/>
<jar destfile="${devhome.dir}/build/phoenix.jar"
<jar destfile="${devhome.dir}/lib/phoenix.jar"
basedir="${devhome.dir}/java/classes"
includes="**/*.class">
<manifest>
<attribute name="Main-Class" value="phoenix.util.PhoenixRuntime"/>
<attribute name="Version" value="${phoenix-version-number}.${build.number}" />
</manifest>
</jar>
<jar destfile="${devhome.dir}/build/phoenix-client.jar"
<jar destfile="${devhome.dir}/lib/phoenix-client.jar"
basedir="${devhome.dir}/java/classes"
includes="**/*.class">
<manifest>
Expand All @@ -193,15 +193,30 @@
<zipfileset src="${hbase.lib}/zookeeper-3.4.3.jar" excludes="META-INF/*" />
<zipfileset src="${hbase.lib}/log4j-1.2.16.jar" excludes="META-INF/*" />
<zipfileset src="${lib.dir}/antlr-3.2.jar" excludes="META-INF/*" />
<fileset file="${devhome.dir}/build/.settings/log4j.properties" />
</jar>
<jar destfile="${devhome.dir}/lib/phoenix-csvload.jar"
basedir="${devhome.dir}/java/classes"
includes="**/CSVUtil.class">
<manifest>
<attribute name="Main-Class" value="phoenix.util.CSVUtil"/>
<attribute name="Version" value="${phoenix-version-number}.${build.number}" />
</manifest>
<zipfileset src="${lib.dir}/opencsv-2.3.jar" excludes="META-INF/*" />
<fileset file="${devhome.dir}/build/.settings/log4j.properties" />
</jar>
</target>
<target name="sourcejar" description="make phoenix source jar">
<jar destfile="${devhome.dir}/lib/phoenix-source.jar"
basedir="${src.dir}"
includes="**/*.java" />
</target>
<target name="testjar" description="make deployable test jars">
<jar destfile="${devhome.dir}/build/phoenix-test.jar">
<jar destfile="${devhome.dir}/lib/phoenix-test.jar">
<fileset dir="${utest.classes.dir}"/>
<fileset dir="${ftest.classes.dir}"/>
</jar>
<jar destfile="${devhome.dir}/build/phoenix-test-source.jar">
<jar destfile="${devhome.dir}/lib/phoenix-test-source.jar">
<fileset dir="${utest.src.dir}" includes="**/*.java"/>
<fileset dir="${ftest.src.dir}" includes="**/*.java"/>
</jar>
Expand Down
21 changes: 21 additions & 0 deletions java/src/phoenix/util/CSVUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.sql.*;

import phoenix.jdbc.PhoenixConnection;
import phoenix.jdbc.PhoenixProdEmbeddedDriver;
import phoenix.schema.PDataType;
import au.com.bytecode.opencsv.CSVReader;

Expand All @@ -50,6 +51,26 @@ public CSVUtil(PhoenixConnection conn, String tableName) {
this.tableName = tableName;
}

/**
* Main method for CSV Upsert. Usage: pcsv <connection-url> <tablename> <path-to-csv>
* @param args
*/
public static void main(String [] args) {
if (args.length !=3) {
System.err.println("Usage: pcsv <connection-url> <tablename> <path-to-csv>");
return;
}

try {
Class.forName(PhoenixProdEmbeddedDriver.class.getName());
PhoenixConnection conn = DriverManager.getConnection(args[0]).unwrap(PhoenixConnection.class);
new CSVUtil(conn, args[1]).upsert(args[2]);

} catch (Throwable t) {
t.printStackTrace();
}
}

/**
* Upserts data from CSV file. Data is batched up based on connection batch
* size. Column PDataType is read from metadata and is used to convert
Expand Down
40 changes: 14 additions & 26 deletions java/src/phoenix/util/PhoenixRuntime.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class PhoenixRuntime {
* increment timestamp value.
*/
public static void main(String [] args) {
if (args.length < 3) {
if (args.length < 2) {
System.err.println("Usage: psql <connection-url> <path-to-sql-script>... \n " +
" pcsv <connection-url> <tablename> <path-to-csv>");
return;
Expand All @@ -92,31 +92,19 @@ public static void main(String [] args) {
try {
Properties props = new Properties();
Class.forName(PhoenixProdEmbeddedDriver.class.getName());
PhoenixConnection conn = DriverManager.getConnection(args[1]).unwrap(PhoenixConnection.class);

// Upserts CSV file
if (args[0].equalsIgnoreCase("CSV")) {
if (args.length != 4) {
System.err.println("Error: CSV file not specified.");
return;
}
new CSVUtil(conn, args[2]).upsert(args[3]);
// Execute SQL script files
} else if (args[0].equalsIgnoreCase("SQL")) {
for (int i = 2; i < args.length; i++) {
PhoenixRuntime.executeStatements(conn, new FileReader(args[i]), Collections.emptyList());
Long scn = conn.getSCN();
// If specifying SCN, increment it between processing files to allow
// for later files to see earlier files tables.
if (scn != null) {
scn++;
props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, scn.toString());
conn.close();
conn = DriverManager.getConnection(args[1], props).unwrap(PhoenixConnection.class);
}
}
} else {
System.err.println("Error: First argument can only be CSV or SQL.");
PhoenixConnection conn = DriverManager.getConnection(args[0]).unwrap(PhoenixConnection.class);

for (int i = 1; i < args.length; i++) {
PhoenixRuntime.executeStatements(conn, new FileReader(args[i]), Collections.emptyList());
Long scn = conn.getSCN();
// If specifying SCN, increment it between processing files to allow
// for later files to see earlier files tables.
if (scn != null) {
scn++;
props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, scn.toString());
conn.close();
conn = DriverManager.getConnection(args[0], props).unwrap(PhoenixConnection.class);
}
}
} catch (Throwable t) {
t.printStackTrace();
Expand Down
Binary file modified lib/phoenix-client.jar
Binary file not shown.
Binary file added lib/phoenix-csvload.jar
Binary file not shown.
Binary file modified lib/phoenix.jar
Binary file not shown.

0 comments on commit c6ef10c

Please sign in to comment.