Skip to content

Commit 1ee4ea0

Browse files
committed
Remove metadata.
1 parent c0edad2 commit 1ee4ea0

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,11 @@ object JdbcUtils extends Logging {
301301
} else {
302302
rsmd.isNullable(i + 1) != ResultSetMetaData.columnNoNulls
303303
}
304-
val metadata = new MetadataBuilder()
305-
.putLong("scale", fieldScale)
304+
val metadata = new MetadataBuilder().putLong("scale", fieldScale)
306305
val columnType =
307306
dialect.getCatalystType(dataType, typeName, fieldSize, metadata).getOrElse(
308307
getCatalystType(dataType, fieldSize, fieldScale, isSigned))
309-
fields(i) = StructField(columnName, columnType, nullable, metadata.build())
308+
fields(i) = StructField(columnName, columnType, nullable)
310309
i = i + 1
311310
}
312311
new StructType(fields)
@@ -784,7 +783,7 @@ object JdbcUtils extends Logging {
784783
// This is resolved by names, use the custom filed dataType to replace the default dateType.
785784
val newSchema = tableSchema.map { col =>
786785
userSchema.find(f => nameEquality(f.name, col.name)) match {
787-
case Some(c) => col.copy(dataType = c.dataType, metadata = Metadata.empty)
786+
case Some(c) => col.copy(dataType = c.dataType)
788787
case None => col
789788
}
790789
}

sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtilsSuite.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,34 +34,34 @@ class JdbcUtilsSuite extends SparkFunSuite {
3434
assert(JdbcUtils.getCustomSchema(tableSchema, "", caseInsensitive) === tableSchema)
3535

3636
assert(JdbcUtils.getCustomSchema(tableSchema, "c1 DATE", caseInsensitive) ===
37-
StructType(Seq(StructField("C1", DateType, true), StructField("C2", IntegerType, false))))
37+
StructType(Seq(StructField("C1", DateType, false), StructField("C2", IntegerType, false))))
3838
assert(JdbcUtils.getCustomSchema(tableSchema, "c1 DATE", caseSensitive) ===
3939
StructType(Seq(StructField("C1", StringType, false), StructField("C2", IntegerType, false))))
4040

4141
assert(
4242
JdbcUtils.getCustomSchema(tableSchema, "c1 DATE, C2 STRING", caseInsensitive) ===
43-
StructType(Seq(StructField("C1", DateType, true), StructField("C2", StringType, true))))
43+
StructType(Seq(StructField("C1", DateType, false), StructField("C2", StringType, false))))
4444
assert(JdbcUtils.getCustomSchema(tableSchema, "c1 DATE, C2 STRING", caseSensitive) ===
45-
StructType(Seq(StructField("C1", StringType, false), StructField("C2", StringType, true))))
45+
StructType(Seq(StructField("C1", StringType, false), StructField("C2", StringType, false))))
4646

4747
// Throw AnalysisException
4848
val duplicate = intercept[AnalysisException]{
4949
JdbcUtils.getCustomSchema(tableSchema, "c1 DATE, c1 STRING", caseInsensitive) ===
50-
StructType(Seq(StructField("c1", DateType, true), StructField("c1", StringType, true)))
50+
StructType(Seq(StructField("c1", DateType, false), StructField("c1", StringType, false)))
5151
}
5252
assert(duplicate.getMessage.contains(
5353
"Found duplicate column(s) in the customSchema option value"))
5454

5555
// Throw ParseException
5656
val dataTypeNotSupported = intercept[ParseException]{
5757
JdbcUtils.getCustomSchema(tableSchema, "c3 DATEE, C2 STRING", caseInsensitive) ===
58-
StructType(Seq(StructField("c3", DateType, true), StructField("C2", StringType, true)))
58+
StructType(Seq(StructField("c3", DateType, false), StructField("C2", StringType, false)))
5959
}
6060
assert(dataTypeNotSupported.getMessage.contains("DataType datee is not supported"))
6161

6262
val mismatchedInput = intercept[ParseException]{
6363
JdbcUtils.getCustomSchema(tableSchema, "c3 DATE. C2 STRING", caseInsensitive) ===
64-
StructType(Seq(StructField("c3", DateType, true), StructField("C2", StringType, true)))
64+
StructType(Seq(StructField("c3", DateType, false), StructField("C2", StringType, false)))
6565
}
6666
assert(mismatchedInput.getMessage.contains("mismatched input '.' expecting"))
6767
}

0 commit comments

Comments
 (0)