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

Reserved SQL words are not escaped by JDBC writer

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.0
    • Fix Version/s: 2.0.0
    • Component/s: SQL
    • Labels:
      None

      Description

      Here is a code (imports are omitted)
      object Main extends App {
      val sqlSession = SparkSession.builder().config(new SparkConf().
      setAppName("Sql Test").set("spark.app.id", "SQLTest").
      set("spark.master", "local[2]").
      set("spark.ui.enabled", "false")
      .setJars(Seq("/mysql/mysql-connector-java-5.1.38.jar" ))
      ).getOrCreate()

      import sqlSession.implicits._

      val localprops = new Properties
      localprops.put("user", "xxxx")
      localprops.put("password", "xxxx")

      val df = sqlSession.createDataset(Seq("a","b","c")).toDF("order")
      val writer = df.write
      .mode(SaveMode.Append)
      writer
      .jdbc("jdbc:mysql://localhost:3306/test3", s"jira_test", localprops)
      }

      End error is :
      com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order TEXT )' at line 1
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:422)

      Clearly the reserved word <order> has to be quoted

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                dongjoon Dongjoon Hyun
                Reporter:
                lev.numerify Lev
              • Votes:
                1 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: