Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-10855] [SQL] Add a JDBC dialect for Apache Derby #8982

Closed
wants to merge 6 commits into from

Conversation

rick-ibm
Copy link
Contributor

@rick-ibm rick-ibm commented Oct 5, 2015

@marmbrus
@rxin

This patch adds a JdbcDialect class, which customizes the datatype mappings for Derby backends. The patch also adds unit tests for the new dialect, corresponding to the existing tests for other JDBC dialects.

JDBCSuite runs cleanly for me with this patch. So does JDBCWriteSuite, although it produces noise as described here: https://issues.apache.org/jira/browse/SPARK-10890

This patch is my original work, which I license to the ASF. I am a Derby contributor, so my ICLA is on file under SVN id "rhillegas": http://people.apache.org/committer-index.html

Touches the following files:


org.apache.spark.sql.jdbc.JdbcDialects

Adds a DerbyDialect.


org.apache.spark.sql.jdbc.JDBCSuite

Adds unit tests for the new DerbyDialect.

@JoshRosen
Copy link
Contributor

;Jenkins, this is ok to test

@SparkQA
Copy link

SparkQA commented Oct 5, 2015

Test build #43250 has finished for PR 8982 at commit 11fdb04.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@rick-ibm
Copy link
Contributor Author

rick-ibm commented Oct 6, 2015

Tests seem to have passed cleanly. Any comments? Suggestions for improvements? Thanks.

case object DerbyDialect extends JdbcDialect {
override def canHandle(url: String): Boolean = url.startsWith("jdbc:derby")
override def getCatalystType(
sqlType: Int, typeName: String, size: Int, md: MetadataBuilder): Option[DataType] = {
Copy link
Contributor

Choose a reason for hiding this comment

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

indent 4 space here

@SparkQA
Copy link

SparkQA commented Oct 9, 2015

Test build #43436 has finished for PR 8982 at commit f83d86c.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

override def canHandle(url: String): Boolean = url.startsWith("jdbc:derby")
override def getCatalystType(
sqlType: Int, typeName: String, size: Int, md: MetadataBuilder): Option[DataType] = {
if (sqlType == Types.REAL) Some(FloatType) else None
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have changed the original code so that it matches the pattern followed by the other getCatalystType() overloads: The code returns a Some(FloatType) rather than an Option(FloatType). I am new to programming in Scala, but the former expression is the pattern which I see all over the code. However, Reynold recommended the latter expression. If Option(FloatType) is the correct value to return, then we should probably change all of the other getCatalystType() overloads to return Option(...) rather than Some(...). I would appreciate your guidance on this point. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review comments, Reynold and Michael. Hopefully, my last commit (e6022ed) addresses your concerns:

o I adjusted the indentation of a method signature, per Reynold's advice.

o I simplified an "if" expression, also per Reynold's advice. However, I have a question about this change (see my comment above on the line in question).

Thanks,
-Rick

Copy link
Contributor

Choose a reason for hiding this comment

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

In this case (where you are clearly not passing null) they are equivalent.
Option will return None in the case of null, which is why I prefer using
that method of construction.
On Oct 9, 2015 9:28 AM, "Rick Hillegas" notifications@github.com wrote:

In sql/core/src/main/scala/org/apache/spark/sql/jdbc/JdbcDialects.scala
#8982 (comment):

@@ -287,3 +288,30 @@ case object MsSqlServerDialect extends JdbcDialect {
case _ => None
}
}
+
+/**

  • * :: DeveloperApi ::
  • * Default Apache Derby dialect, mapping real on read
  • * and string/byte/short/boolean/decimal on write.
  • */
    +@DeveloperAPI
    +case object DerbyDialect extends JdbcDialect {
  • override def canHandle(url: String): Boolean = url.startsWith("jdbc:derby")
  • override def getCatalystType(
  •  sqlType: Int, typeName: String, size: Int, md: MetadataBuilder): Option[DataType] = {
    
  • if (sqlType == Types.REAL) Some(FloatType) else None

I have changed the original code so that it matches the pattern followed
by the other getCatalystType() overloads: The code returns a
Some(FloatType) rather than an Option(FloatType). I am new to programming
in Scala, but the former expression is the pattern which I see all over the
code. However, Reynold recommended the latter expression. If
Option(FloatType) is the correct value to return, then we should probably
change all of the other getCatalystType() overloads to return Option(...)
rather than Some(...). I would appreciate your guidance on this point.
Thanks.


Reply to this email directly or view it on GitHub
https://github.com/apache/spark/pull/8982/files#r41649575.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the quick response, Michael. Should I adjust the other getCatalystType() overloads to follow the Option(...) pattern? I could do that as part of this pull-request or I could open another JIRA if you think that is worth doing. Thanks.

@SparkQA
Copy link

SparkQA commented Oct 9, 2015

Test build #43471 has finished for PR 8982 at commit 989ce9b.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@rick-ibm
Copy link
Contributor Author

rick-ibm commented Oct 9, 2015

My latest commit (d56897e) adjusts the Option usage per Reynold and Michael's advice. I believe that I have addressed all issues with this pull request. We can file a new JIRA if we want to harmonize the usage of Option in JdbcDialects.scala. Thanks.

@SparkQA
Copy link

SparkQA commented Oct 9, 2015

Test build #43478 has finished for PR 8982 at commit e6022ed.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Oct 9, 2015

Test build #43481 has finished for PR 8982 at commit d56897e.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@rxin
Copy link
Contributor

rxin commented Oct 9, 2015

Thanks - I've merged this.

@asfgit asfgit closed this in 12b7191 Oct 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants