Skip to content

Commit

Permalink
Remove metadata.
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyum committed Sep 14, 2017
1 parent c0edad2 commit 1ee4ea0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,11 @@ object JdbcUtils extends Logging {
} else {
rsmd.isNullable(i + 1) != ResultSetMetaData.columnNoNulls
}
val metadata = new MetadataBuilder()
.putLong("scale", fieldScale)
val metadata = new MetadataBuilder().putLong("scale", fieldScale)
val columnType =
dialect.getCatalystType(dataType, typeName, fieldSize, metadata).getOrElse(
getCatalystType(dataType, fieldSize, fieldScale, isSigned))
fields(i) = StructField(columnName, columnType, nullable, metadata.build())
fields(i) = StructField(columnName, columnType, nullable)
i = i + 1
}
new StructType(fields)
Expand Down Expand Up @@ -784,7 +783,7 @@ object JdbcUtils extends Logging {
// This is resolved by names, use the custom filed dataType to replace the default dateType.
val newSchema = tableSchema.map { col =>
userSchema.find(f => nameEquality(f.name, col.name)) match {
case Some(c) => col.copy(dataType = c.dataType, metadata = Metadata.empty)
case Some(c) => col.copy(dataType = c.dataType)
case None => col
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,34 @@ class JdbcUtilsSuite extends SparkFunSuite {
assert(JdbcUtils.getCustomSchema(tableSchema, "", caseInsensitive) === tableSchema)

assert(JdbcUtils.getCustomSchema(tableSchema, "c1 DATE", caseInsensitive) ===
StructType(Seq(StructField("C1", DateType, true), StructField("C2", IntegerType, false))))
StructType(Seq(StructField("C1", DateType, false), StructField("C2", IntegerType, false))))
assert(JdbcUtils.getCustomSchema(tableSchema, "c1 DATE", caseSensitive) ===
StructType(Seq(StructField("C1", StringType, false), StructField("C2", IntegerType, false))))

assert(
JdbcUtils.getCustomSchema(tableSchema, "c1 DATE, C2 STRING", caseInsensitive) ===
StructType(Seq(StructField("C1", DateType, true), StructField("C2", StringType, true))))
StructType(Seq(StructField("C1", DateType, false), StructField("C2", StringType, false))))
assert(JdbcUtils.getCustomSchema(tableSchema, "c1 DATE, C2 STRING", caseSensitive) ===
StructType(Seq(StructField("C1", StringType, false), StructField("C2", StringType, true))))
StructType(Seq(StructField("C1", StringType, false), StructField("C2", StringType, false))))

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

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

val mismatchedInput = intercept[ParseException]{
JdbcUtils.getCustomSchema(tableSchema, "c3 DATE. C2 STRING", caseInsensitive) ===
StructType(Seq(StructField("c3", DateType, true), StructField("C2", StringType, true)))
StructType(Seq(StructField("c3", DateType, false), StructField("C2", StringType, false)))
}
assert(mismatchedInput.getMessage.contains("mismatched input '.' expecting"))
}
Expand Down

0 comments on commit 1ee4ea0

Please sign in to comment.