Commit ce089e8
[SPARK-18123][SQL] Use db column names instead of RDD column ones during JDBC Writing
## What changes were proposed in this pull request?
Apache Spark supports the following cases **by quoting RDD column names** while saving through JDBC.
- Allow reserved keyword as a column name, e.g., 'order'.
- Allow mixed-case colume names like the following, e.g., `[a: int, A: int]`.
``` scala
scala> val df = sql("select 1 a, 1 A")
df: org.apache.spark.sql.DataFrame = [a: int, A: int]
...
scala> df.write.mode("overwrite").format("jdbc").options(option).save()
scala> df.write.mode("append").format("jdbc").options(option).save()
```
This PR aims to use **database column names** instead of RDD column ones in order to support the following additionally.
Note that this case succeeds with `MySQL`, but fails on `Postgres`/`Oracle` before.
``` scala
val df1 = sql("select 1 a")
val df2 = sql("select 1 A")
...
df1.write.mode("overwrite").format("jdbc").options(option).save()
df2.write.mode("append").format("jdbc").options(option).save()
```
## How was this patch tested?
Pass the Jenkins test with a new testcase.
Author: Dongjoon Hyun <[email protected]>
Author: gatorsmile <[email protected]>
Closes apache#15664 from dongjoon-hyun/SPARK-18123.1 parent 697858a commit ce089e8
File tree
3 files changed
+95
-25
lines changed- sql/core/src
- main/scala/org/apache/spark/sql/execution/datasources/jdbc
- test/scala/org/apache/spark/sql/jdbc
3 files changed
+95
-25
lines changedsql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcRelationProvider.scala
Lines changed: 7 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
| |||
67 | 68 | | |
68 | 69 | | |
69 | 70 | | |
70 | | - | |
| 71 | + | |
| 72 | + | |
71 | 73 | | |
72 | 74 | | |
73 | 75 | | |
74 | 76 | | |
75 | | - | |
| 77 | + | |
76 | 78 | | |
77 | 79 | | |
78 | 80 | | |
79 | | - | |
| 81 | + | |
| 82 | + | |
80 | 83 | | |
81 | 84 | | |
82 | 85 | | |
| |||
89 | 92 | | |
90 | 93 | | |
91 | 94 | | |
92 | | - | |
| 95 | + | |
93 | 96 | | |
94 | 97 | | |
95 | 98 | | |
| |||
Lines changed: 58 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
| 111 | + | |
112 | 112 | | |
113 | | - | |
114 | | - | |
115 | | - | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
116 | 139 | | |
117 | | - | |
118 | | - | |
| 140 | + | |
119 | 141 | | |
120 | 142 | | |
121 | 143 | | |
| |||
210 | 232 | | |
211 | 233 | | |
212 | 234 | | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
213 | 255 | | |
214 | 256 | | |
215 | 257 | | |
| |||
531 | 573 | | |
532 | 574 | | |
533 | 575 | | |
534 | | - | |
| 576 | + | |
535 | 577 | | |
536 | 578 | | |
537 | 579 | | |
| |||
568 | 610 | | |
569 | 611 | | |
570 | 612 | | |
571 | | - | |
572 | | - | |
573 | | - | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
574 | 616 | | |
575 | 617 | | |
576 | 618 | | |
| |||
657 | 699 | | |
658 | 700 | | |
659 | 701 | | |
| 702 | + | |
| 703 | + | |
660 | 704 | | |
661 | 705 | | |
662 | | - | |
663 | | - | |
664 | | - | |
665 | | - | |
666 | 706 | | |
667 | 707 | | |
668 | 708 | | |
669 | 709 | | |
| 710 | + | |
| 711 | + | |
670 | 712 | | |
671 | 713 | | |
672 | 714 | | |
| |||
675 | 717 | | |
676 | 718 | | |
677 | 719 | | |
678 | | - | |
| 720 | + | |
679 | 721 | | |
680 | 722 | | |
681 | 723 | | |
| |||
Lines changed: 30 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | | - | |
| 27 | + | |
29 | 28 | | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
99 | 103 | | |
100 | 104 | | |
101 | 105 | | |
| |||
165 | 169 | | |
166 | 170 | | |
167 | 171 | | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
168 | 192 | | |
169 | 193 | | |
170 | 194 | | |
| |||
177 | 201 | | |
178 | 202 | | |
179 | 203 | | |
180 | | - | |
| 204 | + | |
181 | 205 | | |
182 | 206 | | |
183 | 207 | | |
| |||
203 | 227 | | |
204 | 228 | | |
205 | 229 | | |
206 | | - | |
| 230 | + | |
207 | 231 | | |
208 | | - | |
| 232 | + | |
| 233 | + | |
209 | 234 | | |
210 | 235 | | |
211 | 236 | | |
| |||
0 commit comments