Github user maropu commented on a diff in the pull request:
https://github.com/apache/spark/pull/8374#discussion_r43359470
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/jdbc/JdbcDialects.scala ---
@@ -278,3 +285,59 @@ case object MsSqlServerDialect extends JdbcDialect {
} else None
}
}
+
+/**
+ * :: DeveloperApi ::
+* Default Oracle dialect, mapping string/boolean on write to valid Oracle
types.
+*/
+@DeveloperApi
+case object OracleDialect extends JdbcDialect {
+ override def canHandle(url: String): Boolean =
url.startsWith("jdbc:oracle")
+ override def getCatalystType(
+ sqlType: Int, typeName: String, size: Int, md: MetadataBuilder):
Option[DataType] = {
+ if (sqlType == Types.VARCHAR && typeName.equals("VARCHAR")) {
+ // Save varchar size to metadata
+ md.putLong("maxlength", size)
+ Some(LongType)
+ } else None
+ }
+
+ override def getJDBCType(dt: DataType, md: Metadata): Option[JdbcType] =
{
+ if (dt == StringType && md.contains("maxlength")) {
+ Some(JdbcType(s"VARCHAR(${md.getLong("maxlength")})",
java.sql.Types.VARCHAR))
+ } else if (dt == StringType ) {
--- End diff --
Nit: Remove the end single space in parenthesis.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]