pig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r1378625 - in /pig/trunk/contrib: CHANGES.txt piggybank/java/src/main/java/org/apache/pig/piggybank/storage/DBStorage.java piggybank/java/src/test/java/org/apache/pig/piggybank/test/storage/TestDBStorage.java
Date Wed, 29 Aug 2012 16:00:20 GMT
Author: gates
Date: Wed Aug 29 16:00:20 2012
New Revision: 1378625

URL: http://svn.apache.org/viewvc?rev=1378625&view=rev
Log:
PIG-2893 fix DBStorage compile issue

Modified:
    pig/trunk/contrib/CHANGES.txt
    pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/storage/DBStorage.java
    pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/storage/TestDBStorage.java

Modified: pig/trunk/contrib/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/trunk/contrib/CHANGES.txt?rev=1378625&r1=1378624&r2=1378625&view=diff
==============================================================================
--- pig/trunk/contrib/CHANGES.txt (original)
+++ pig/trunk/contrib/CHANGES.txt Wed Aug 29 16:00:20 2012
@@ -56,6 +56,8 @@ OPTIMIZATIONS
 
 BUG FIXES
 
+PIG-2893  fix DBStorage compile issue (thejas via gates)
+
 PIG-2195 AvroStorage fails to STORE when LOADing via PigStorage (billgraham via gates)
 
 PIG-1839 XMLLoader will always add an extra empty tuple even if no tags are

Modified: pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/storage/DBStorage.java
URL: http://svn.apache.org/viewvc/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/storage/DBStorage.java?rev=1378625&r1=1378624&r2=1378625&view=diff
==============================================================================
--- pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/storage/DBStorage.java
(original)
+++ pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/storage/DBStorage.java
Wed Aug 29 16:00:20 2012
@@ -118,7 +118,7 @@ public class DBStorage extends StoreFunc
             break;
 
           case DataType.DATETIME:
-            ps.setDate(sqlPos, ((DateTime) field).toDate());
+            ps.setDate(sqlPos, new Date(((DateTime) field).getMillis()));
             sqlPos++;
             break;
 

Modified: pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/storage/TestDBStorage.java
URL: http://svn.apache.org/viewvc/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/storage/TestDBStorage.java?rev=1378625&r1=1378624&r2=1378625&view=diff
==============================================================================
--- pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/storage/TestDBStorage.java
(original)
+++ pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/storage/TestDBStorage.java
Wed Aug 29 16:00:20 2012
@@ -29,6 +29,7 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
+import java.sql.Date;
 import java.util.List;
 
 import org.apache.pig.ExecType;
@@ -90,16 +91,16 @@ public class TestDBStorage extends TestC
 	private void createFile() throws IOException {
 		PrintWriter w = new PrintWriter(new FileWriter(INPUT_FILE));
 		w = new PrintWriter(new FileWriter(INPUT_FILE));
-		w.println("100\tapple\t1.0");
-		w.println("100\torange\t2.0");
-		w.println("100\tbanana\t1.1");
+		w.println("100\tapple\t1.0\t2008-01-01");
+		w.println("100\torange\t2.0\t2008-02-01");
+		w.println("100\tbanana\t1.1\t2008-03-01");
 		w.close();
 		Util.copyFromLocalToCluster(cluster, INPUT_FILE, INPUT_FILE);
 	}
 
 	private void createTable() throws IOException {
 		Connection con = null;
-		String sql = "create table ttt (id integer, name varchar(32), ratio double)";
+		String sql = "create table ttt (id integer, name varchar(32), ratio double, dt date)";
 		try {
 			con = DriverManager.getConnection(url, user, password);
 		} catch (SQLException sqe) {
@@ -148,12 +149,12 @@ public class TestDBStorage extends TestC
 	}
 
 	public void testWriteToDB() throws IOException {
-		String insertQuery = "insert into ttt (id, name, ratio) values (?,?,?)";
+		String insertQuery = "insert into ttt (id, name, ratio, dt) values (?,?,?,?)";
 		pigServer.setBatchOn();
 		String dbStore = "org.apache.pig.piggybank.storage.DBStorage('" + driver              
                                                                                         
              
 	            + "', '" + url + "', '" + insertQuery + "');";
 		pigServer.registerQuery("A = LOAD '" + INPUT_FILE
-				+ "' as (id:int, fruit:chararray, ratio:double);");
+				+ "' as (id:int, fruit:chararray, ratio:double, dt : datetime);");
 		pigServer.registerQuery("STORE A INTO 'dummy' USING " + dbStore);
 	  ExecJob job = pigServer.executeBatch().get(0);
 		try {
@@ -165,7 +166,7 @@ public class TestDBStorage extends TestC
 						ExecJob.JOB_STATUS.FAILED);
 		
 		Connection con = null;
-		String selectQuery = "select id, name, ratio from ttt order by name";
+		String selectQuery = "select id, name, ratio, dt from ttt order by name";
 		try {
 			con = DriverManager.getConnection(url, user, password);
 		} catch (SQLException sqe) {
@@ -179,11 +180,14 @@ public class TestDBStorage extends TestC
 			int expId = 100;
 			String[] expNames = { "apple", "banana", "orange" };
 			double[] expRatios = { 1.0, 1.1, 2.0 };
+                        Date []  expDates = {new Date(2008,01,01),new Date(2008,02,01),new
Date(2008,03,01)};
 			for (int i = 0; i < 3 && rs.next(); i++) {
 				assertEquals("Id mismatch", expId, rs.getInt(1));
 				assertEquals("Name mismatch", expNames[i], rs.getString(2));
 				assertEquals("Ratio mismatch", expRatios[i], rs.getDouble(3), 0.0001);
+				assertEquals("Date mismatch", expDates[i], rs.getDate(4));
 			}
+
 		} catch (SQLException sqe) {
 			throw new IOException(
 					"Unable to read data from database for verification", sqe);



Mime
View raw message