Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve custom schema.
  • Loading branch information
wangyum committed Jun 23, 2017
commit ffaee4280a9fb84d3aa5a6657423eb588c1c9609
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,9 @@ class OracleIntegrationSuite extends DockerJDBCIntegrationSuite with SharedSQLCo

// custom schema can read data
val schema = StructType(Seq(
StructField("ID", DecimalType(DecimalType.MAX_PRECISION, 0), true,
new MetadataBuilder().putString("name", "ID").build()),
StructField("N1", IntegerType, true, new MetadataBuilder().putString("name", "N1").build()),
StructField("N2", BooleanType, true, new MetadataBuilder().putString("name", "N2").build())))
StructField("ID", DecimalType(DecimalType.MAX_PRECISION, 0)),
StructField("N1", IntegerType, true),
StructField("N2", BooleanType, true)))

val dfRead = spark.read.schema(schema).jdbc(jdbcUrl, "custom_column_types", new Properties())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

val rows = dfRead.collect()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ object JDBCRDD extends Logging {
* @return A Catalyst schema corresponding to columns in the given order.
*/
private def pruneSchema(schema: StructType, columns: Array[String]): StructType = {
val fieldMap = Map(schema.fields.map(x => x.metadata.getString("name") -> x): _*)
new StructType(columns.map(name => fieldMap(name)))
val fieldMap = Map(schema.fields.map(x => x.name -> x): _*)
new StructType(columns.map(name => fieldMap(name)))
}

/**
Expand Down