Uploaded image for project: 'Sqoop'
  1. Sqoop
  2. SQOOP-3039

Sqoop unable to export Time data "13:14:12.1234" into Time colum in RMDBS

    Details

    • Type: Bug
    • Status: Patch Available
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.4.6, 1.4.7
    • Fix Version/s: None
    • Component/s: tools
    • Labels:
      None

      Description

      To re-produce:

      Set up MySQL database with following schema:

      CREATE TABLE `test` (
        `a` time(2) DEFAULT NULL
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1
      

      Store the following data in HDFS:

      16:56:53.0999
      16:56:54.1
      16:56:53.0000
      16:56:54.1230
      

      run Sqoop export command to copy data from HDFS into MySQL:

      qoop export --connect jdbc:mysql://<mysql-host>/test --username root --password password --table test  -m 1 --driver com.mysql.jdbc.Driver  --export-dir /tmp/test
      

      Command will fail with the following error:

      java.lang.RuntimeException: Can't parse input data: '16:56:53.0999'
              at t5.__loadFromFields(t5.java:223)
              at t5.parse(t5.java:166)
              at org.apache.sqoop.mapreduce.TextExportMapper.map(TextExportMapper.java:89)
              at org.apache.sqoop.mapreduce.TextExportMapper.map(TextExportMapper.java:39)
              at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:145)
              at org.apache.sqoop.mapreduce.AutoProgressMapper.run(AutoProgressMapper.java:64)
              at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:784)
              at org.apache.hadoop.mapred.MapTask.run(MapTask.java:341)
              at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:163)
              at java.security.AccessController.doPrivileged(Native Method)
              at javax.security.auth.Subject.doAs(Subject.java:422)
              at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1628)
              at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:158)
      Caused by: java.lang.NumberFormatException: For input string: "53.0999"
              at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
              at java.lang.Integer.parseInt(Integer.java:580)
              at java.lang.Integer.parseInt(Integer.java:615)
              at java.sql.Time.valueOf(Time.java:108)
              at t5.__loadFromFields(t5.java:215)
              ... 12 more
      

      Looks like Sqoop uses java.sql.Time.valueOf function to convert "16:56:53.0999" to Time object, however, this function only accepts Time in "hh:mm:ss" format:

      https://docs.oracle.com/javase/7/docs/api/java/sql/Time.html#valueOf(java.lang.String)

        Attachments

        1. SQOOP-3039.2.patch
          14 kB
          Eric Lin
        2. SQOOP-3039.3.patch
          15 kB
          Eric Lin
        3. SQOOP-3039.3.patch
          16 kB
          Eric Lin
        4. SQOOP-3039.patch
          11 kB
          Eric Lin

          Issue Links

            Activity

              People

              • Assignee:
                ericlin Eric Lin
                Reporter:
                ericlin Eric Lin
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: