Uploaded image for project: 'CarbonData'
  1. CarbonData
  2. CARBONDATA-1477

Wrong values shown when fetching date type values in hive

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Trivial
    • Resolution: Fixed
    • Affects Version/s: 1.2.0
    • Fix Version/s: 1.2.0
    • Component/s: hive-integration
    • Labels:
      None
    • Environment:
      hive1.2.1,spark2.1

      Description

      
      

      package org.apache.carbondata.hiveexample

      import java.io.File
      import java.sql.

      {DriverManager, ResultSet, Statement}

      import org.apache.spark.sql.SparkSession

      import org.apache.carbondata.common.logging.LogServiceFactory
      import org.apache.carbondata.hive.server.HiveEmbeddedServer2

      // scalastyle:off println
      object HiveExample {

      private val driverName: String = "org.apache.hive.jdbc.HiveDriver"

      def main(args: Array[String]) {
      val rootPath = new File(this.getClass.getResource("/").getPath
      + "../../../..").getCanonicalPath
      val store = s"$rootPath/integration/hive/target/store"
      val warehouse = s"$rootPath/integration/hive/target/warehouse"
      val metaStore_Db = s"$rootPath/integration/hive/target/carbon_metaStore_db"
      val logger = LogServiceFactory.getLogService(this.getClass.getCanonicalName)
      var resultId = ""
      var resultName = ""
      var resultSalary = ""

      import org.apache.spark.sql.CarbonSession._

      val carbonSession = SparkSession
      .builder()
      .master("local")
      .appName("HiveExample")
      .config("carbonSession.sql.warehouse.dir", warehouse).enableHiveSupport()
      .getOrCreateCarbonSession(
      store, metaStore_Db)

      carbonSession.sql("DROP TABLE IF EXISTS HIVE_CARBON_EXAMPLE ")
      carbonSession
      .sql(
      """CREATE TABLE IF NOT EXISTS HIVE_CARBON_EXAMPLE (ID int,NAME string,SALARY double,JOININGDATE date) STORED BY

      'CARBONDATA' """
      .stripMargin)

      carbonSession.sql(
      s"""

      LOAD DATA LOCAL INPATH '$rootPath/integration/hive/src/main/resources/data.csv' INTO
      TABLE
      HIVE_CARBON_EXAMPLE
      """)
      carbonSession.sql("SELECT * FROM HIVE_CARBON_EXAMPLE").show()

      carbonSession.stop()

      try

      { Class.forName(driverName) }

      catch

      { case classNotFoundException: ClassNotFoundException => classNotFoundException.printStackTrace() }

      val hiveEmbeddedServer2 = new HiveEmbeddedServer2()
      hiveEmbeddedServer2.start()
      val port = hiveEmbeddedServer2.getFreePort
      val connection = DriverManager.getConnection(s"jdbc:hive2://localhost:$port/default", "", "")
      val statement: Statement = connection.createStatement

      logger.info(s"============HIVE CLI IS STARTED ON PORT $port ==============")

      statement.execute("CREATE TABLE IF NOT EXISTS " + "HIVE_CARBON_EXAMPLE " +
      " (ID int, NAME string,SALARY double,JOININGDATE date)")
      statement
      .execute(
      "ALTER TABLE HIVE_CARBON_EXAMPLE SET FILEFORMAT INPUTFORMAT \"org.apache.carbondata." +
      "hive.MapredCarbonInputFormat\"OUTPUTFORMAT \"org.apache.carbondata.hive." +
      "MapredCarbonOutputFormat\"SERDE \"org.apache.carbondata.hive." +
      "CarbonHiveSerDe\" ")

      statement
      .execute(
      "ALTER TABLE HIVE_CARBON_EXAMPLE SET LOCATION " +
      s"'file:///$store/default/hive_carbon_example' ")

      val sql = "SELECT * FROM HIVE_CARBON_EXAMPLE"

      val resultSet: ResultSet = statement.executeQuery(sql)

      var rowsFetched = 0

      while (resultSet.next)

      { println("*********"+resultSet.getString("JOININGDATE")) }

      println(s"******Total Number Of Rows Fetched ****** $rowsFetched")

      logger.info("Fetching the Individual Columns ")

      hiveEmbeddedServer2.stop()
      System.exit(0)
      }

      }
      values that i get for date type is 1970-01-01 which was wrong

      1. data.csv
        0.1 kB
        anubhav tarar

        Issue Links

          Activity

          Hide
          chenliang613 Liang Chen added a comment -

          anubhav tarar can you provide data.csv file which you tested, let me reproduce it.

          Show
          chenliang613 Liang Chen added a comment - anubhav tarar can you provide data.csv file which you tested, let me reproduce it.
          Hide
          anubhavtarar anubhav tarar added a comment - - edited Reporter

          Liang Chen i attached the csv with this issue

          Show
          anubhavtarar anubhav tarar added a comment - - edited Reporter Liang Chen i attached the csv with this issue
          Hide
          anubhavtarar anubhav tarar added a comment - Reporter

          bug was values that i get for date type is 1970-01-01 which was wrong

          i just misedited the logs

          Show
          anubhavtarar anubhav tarar added a comment - Reporter bug was values that i get for date type is 1970-01-01 which was wrong i just misedited the logs

            People

            • Assignee:
              anubhavtarar anubhav tarar
              Reporter:
              anubhavtarar anubhav tarar
              Request participants:
              None
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 3h 20m
                3h 20m