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

JDBCRDD does not correctly handle errors in getQueryOutputSchema

    XMLWordPrintableJSON

Details

    Description

      If there is an error executing statement.executeQuery(), it's possible that another error in one of the finally statements makes us not see the main error.

      def getQueryOutputSchema(
            query: String, options: JDBCOptions, dialect: JdbcDialect): StructType = {
          val conn: Connection = dialect.createConnectionFactory(options)(-1)
          try {
            val statement = conn.prepareStatement(query)
            try {
              statement.setQueryTimeout(options.queryTimeout)
              val rs = statement.executeQuery()
              try {
                JdbcUtils.getSchema(rs, dialect, alwaysNullable = true,
                  isTimestampNTZ = options.preferTimestampNTZ)
              } finally {
                rs.close()
              }
            } finally {
              statement.close()
            }
          } finally {
            conn.close()
          }
        } 

      Attachments

        Issue Links

          Activity

            People

              planga82 Pablo Langa Blanco
              planga82 Pablo Langa Blanco
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: