hadoop-mapreduce-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomwh...@apache.org
Subject svn commit: r938576 - in /hadoop/mapreduce/trunk: CHANGES.txt src/java/org/apache/hadoop/mapreduce/lib/db/OracleDBRecordReader.java src/java/org/apache/hadoop/mapreduce/lib/db/OracleDataDrivenDBRecordReader.java
Date Tue, 27 Apr 2010 17:33:35 GMT
Author: tomwhite
Date: Tue Apr 27 17:33:35 2010
New Revision: 938576

URL: http://svn.apache.org/viewvc?rev=938576&view=rev
Log:
MAPREDUCE-1728. Oracle timezone strings do not match Java. Contributed by Aaron Kimball.

Modified:
    hadoop/mapreduce/trunk/CHANGES.txt
    hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapreduce/lib/db/OracleDBRecordReader.java
    hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapreduce/lib/db/OracleDataDrivenDBRecordReader.java

Modified: hadoop/mapreduce/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/CHANGES.txt?rev=938576&r1=938575&r2=938576&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/CHANGES.txt (original)
+++ hadoop/mapreduce/trunk/CHANGES.txt Tue Apr 27 17:33:35 2010
@@ -599,6 +599,9 @@ Trunk (unreleased changes)
     MAPREDUCE-1397. NullPointerException observed during task failures.
     (Amareshwari Sriramadasu via vinodkv)
 
+    MAPREDUCE-1728. Oracle timezone strings do not match Java.
+    (Aaron Kimball via tomwhite)
+
 Release 0.21.0 - Unreleased
 
   INCOMPATIBLE CHANGES

Modified: hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapreduce/lib/db/OracleDBRecordReader.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapreduce/lib/db/OracleDBRecordReader.java?rev=938576&r1=938575&r2=938576&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapreduce/lib/db/OracleDBRecordReader.java
(original)
+++ hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapreduce/lib/db/OracleDBRecordReader.java
Tue Apr 27 17:33:35 2010
@@ -20,10 +20,7 @@ package org.apache.hadoop.mapreduce.lib.
 
 import java.io.IOException;
 import java.sql.Connection;
-import java.sql.ResultSet;
 import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.TimeZone;
 import java.lang.reflect.Method;
 
 import org.apache.hadoop.conf.Configuration;
@@ -35,13 +32,16 @@ import org.apache.commons.logging.LogFac
  */
 public class OracleDBRecordReader<T extends DBWritable> extends DBRecordReader<T>
{
 
+  /** Configuration key to set to a timezone string. */
+  public static final String SESSION_TIMEZONE_KEY = "oracle.sessionTimeZone";
+
   private static final Log LOG = LogFactory.getLog(OracleDBRecordReader.class);
 
   public OracleDBRecordReader(DBInputFormat.DBInputSplit split, 
       Class<T> inputClass, Configuration conf, Connection conn, DBConfiguration dbConfig,
       String cond, String [] fields, String table) throws SQLException {
     super(split, inputClass, conf, conn, dbConfig, cond, fields, table);
-    setSessionTimeZone(conn);
+    setSessionTimeZone(conf, conn);
   }
 
   /** Returns the query for selecting the records from an Oracle DB. */
@@ -96,10 +96,12 @@ public class OracleDBRecordReader<T exte
 
   /**
    * Set session time zone
-   * @param conn      Connection object
-   * @throws          SQLException instance
+   * @param conf The current configuration.
+   * We read the 'oracle.sessionTimeZone' property from here.
+   * @param conn The connection to alter the timezone properties of.
    */
-  public static void setSessionTimeZone(Connection conn) throws SQLException {
+  public static void setSessionTimeZone(Configuration conf,
+      Connection conn) throws SQLException {
     // need to use reflection to call the method setSessionTimeZone on
     // the OracleConnection class because oracle specific java libraries are
     // not accessible in this context.
@@ -114,18 +116,21 @@ public class OracleDBRecordReader<T exte
     }
 
     // Need to set the time zone in order for Java
-    // to correctly access the column "TIMESTAMP WITH LOCAL TIME ZONE"
-    String clientTimeZone = TimeZone.getDefault().getID();
+    // to correctly access the column "TIMESTAMP WITH LOCAL TIME ZONE".
+    // We can't easily get the correct Oracle-specific timezone string
+    // from Java; just let the user set the timezone in a property.
+    String clientTimeZone = conf.get(SESSION_TIMEZONE_KEY, "GMT");
     try {
       method.setAccessible(true);
       method.invoke(conn, clientTimeZone);
-      LOG.info("Time zone has been set");
+      LOG.info("Time zone has been set to " + clientTimeZone);
     } catch (Exception ex) {
       LOG.warn("Time zone " + clientTimeZone +
-               " could not be set on oracle database.");
-      LOG.info("Setting default time zone: UTC");
+               " could not be set on Oracle database.");
+      LOG.warn("Setting default time zone: GMT");
       try {
-        method.invoke(conn, "UTC");
+        // "GMT" timezone is guaranteed to exist.
+        method.invoke(conn, "GMT");
       } catch (Exception ex2) {
         LOG.error("Could not set time zone for oracle connection", ex2);
         // rethrow SQLException

Modified: hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapreduce/lib/db/OracleDataDrivenDBRecordReader.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapreduce/lib/db/OracleDataDrivenDBRecordReader.java?rev=938576&r1=938575&r2=938576&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapreduce/lib/db/OracleDataDrivenDBRecordReader.java
(original)
+++ hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapreduce/lib/db/OracleDataDrivenDBRecordReader.java
Tue Apr 27 17:33:35 2010
@@ -40,6 +40,6 @@ public class OracleDataDrivenDBRecordRea
         "ORACLE");
 
     // Must initialize the tz used by the connection for Oracle.
-    OracleDBRecordReader.setSessionTimeZone(conn);
+    OracleDBRecordReader.setSessionTimeZone(conf, conn);
   }
 }



Mime
View raw message