Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-36513

Using openGauss ( like postgres) as Spark Datasource, Spark thorws cast errors

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Invalid
    • 3.3.0
    • None
    • Java API, SQL
    • None
    • Spark 3.3.0

      Scala 2.12

    Description

      Hi, I'm trying to use openGauss as the Spark Datasource and implementing some datasource interfaces. I would like to know if there is any solution. Thank you!

       

      But when I try to get the column which is VARCHAR type, I got an error like this:

      When I use getInt() or getDouble() for other type, the code  is working fine.

      And here is some code:

       

      object OpenGaussTable {
        /*Table products*/
        val schema: StructType = new StructType().add("name", StringType)
      
      }
      ...
      
      class OpenGaussPartitionReader(connectionProperties: ConnectionProperties) extends PartitionReader[InternalRow] {
        private val connection = DriverManager.getConnection(
          connectionProperties.url, connectionProperties.user, connectionProperties.password
        )
        private val statement = connection.createStatement()
        private val resultSet = statement.executeQuery(s"select * from ${connectionProperties.tableName}")
      
        override def next(): Boolean = resultSet.next()
      
        override def get(): InternalRow = InternalRow(resultSet.getString(1))
      
        override def close(): Unit = connection.close()
      }

       

      the complete code address:

      https://pastebin.ubuntu.com/p/vCBssjhc2r/

      https://pastebin.ubuntu.com/p/jCcDbb79NG/

       

      Attachments

        1. image-2021-08-14-22-47-56-474.png
          137 kB
          Xiansen Chen

        Activity

          People

            Unassigned Unassigned
            Cerdore Xiansen Chen
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: