spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rtreffer <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-6888][SQL] Make the jdbc driver handlin...
Date Thu, 07 May 2015 13:26:06 GMT
Github user rtreffer commented on a diff in the pull request:

    https://github.com/apache/spark/pull/5555#discussion_r29850737
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/jdbc/JdbcDialects.scala ---
    @@ -0,0 +1,205 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.jdbc
    +
    +import org.apache.spark.sql.types._
    +import org.apache.spark.annotation.DeveloperApi
    +
    +import java.sql.Types
    +
    +
    +/**
    + * :: DeveloperApi ::
    + * Encapsulates everything (extensions, workarounds, quirks) to handle the
    + * SQL dialect of a certain database or jdbc driver.
    + * Lots of databases define types that aren't explicitly supported
    + * by the JDBC spec.  Some JDBC drivers also report inaccurate
    + * information---for instance, BIT(n>1) being reported as a BIT type is quite
    + * common, even though BIT in JDBC is meant for single-bit values.  Also, there
    + * does not appear to be a standard name for an unbounded string or binary
    + * type; we use BLOB and CLOB by default but override with database-specific
    + * alternatives when these are absent or do not behave correctly.
    + *
    + * Currently, the only thing done by the dialect is type mapping.
    + * `getCatalystType` is used when reading from a JDBC table and `getJDBCType`
    + * is used when writing to a JDBC table.  If `getCatalystType` returns `null`,
    + * the default type handling is used for the given JDBC type.  Similarly,
    + * if `getJDBCType` returns `(null, None)`, the default type handling is used
    + * for the given Catalyst type.
    + */
    +@DeveloperApi
    +abstract class JdbcDialect {
    +  /**
    +   * Check if this dialect instance can handle a certain jdbc url.
    +   * @param url the jdbc url.
    +   * @return True if the dialect can be applied on the given jdbc url.
    +   * @throws NullPointerException if the url is null.
    +   */
    +  def canHandle(url : String): Boolean
    +
    +  /**
    +   * Get the custom datatype mapping for the given jdbc meta information.
    +   * @param sqlType The sql type (see java.sql.Types)
    +   * @param typeName The sql type name (e.g. "BIGINT UNSIGNED")
    +   * @param size The size of the type.
    +   * @param md Result metadata associated with this type.
    +   * @return The actual DataType (subclasses of [[org.apache.spark.sql.types.DataType]])
    +   *         or null if the default type mapping should be used.
    +   */
    +  def getCatalystType(sqlType: Int, typeName: String, size: Int, md: MetadataBuilder):
DataType =
    +    null
    +
    +  /**
    +   * Retrieve the jdbc / sql type for a give datatype.
    +   * @param dt The datatype (e.g. [[org.apache.spark.sql.types.StringType]])
    +   * @return A tuple of sql type name and sql type, or {{{(null, None)}}} for no change.
    +   */
    +  def getJDBCType(dt: DataType): (String, Option[Int]) = (null, None)
    --- End diff --
    
    Sounds like a good idea. It would also clarify the magic getJDBCType(...)._1 and getJDBCType(...)._2
in jdbc.scala


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message