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

make JdbcUtils methods makeGetter and makeSetter public to extend custom dialect support for complex types

    XMLWordPrintableJSON

Details

    • Wish
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 4.0.0
    • None
    • Spark Core, SQL
    • None

    Description

      Currently, in Apache Spark's JdbcUtils (across all versions, including Spark 4), there is no support for complex types like StructType, MapType, except for ArrayType. This limitation is evident in the private methods makeGetter and makeSetter.

      As Spark provides the ability to implement custom dialects, users cannot implement custom handling for these complex types because the methods are private and they encounter the following error:

       

      org.apache.spark.SparkSQLException: Unsupported type <complex_type>.

      The suggestion is to change the way these methods are called. Specifically, the getter/setter methods should be able to be provided by the `JdbcDialect`, rather than only being hardcoded in `JdbcUtils`.

      I suppose it can be done in one of two ways:

      1. Modify the makeGetter and makeSetter methods to delegate to the dialect

          
          class JdbcUtils {
            def makeGetter(args): Option[Getter] = {
              dialect.makeGetter(args).orElse {
                ...
              }
            }
          
            def makeSetter(args): Option[Setter] = {
              dialect.makeSetter(args).orElse {
                ...
              }
            }
          }
         

      2. Move the makeGetter/makeSetter methods out of JdbcUtils into JdbcDialect, allowing custom dialects to override them.

          
          abstract class JdbcDialect {
            def makeGetter(args): Option[Getter]
            def makeSetter(args): Option[Setter]
          }
          
          object JdbcUtils {
            def getGetter(args): Option[Getter] = {
              // logic to fetch getter from JdbcDialect
            }
          
            def getSetter(args): Option[Setter] = {
              // logic to fetch setter from JdbcDialect
            }
          }
         

      Attachments

        Activity

          People

            Unassigned Unassigned
            mvliksako1 Maksim Lixakov
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: