org.apache.spark.sql.jdbc
Class JdbcDialect

Object
  extended by org.apache.spark.sql.jdbc.JdbcDialect
Direct Known Subclasses:
AggregatedDialect, MySQLDialect, NoopDialect, PostgresDialect

public abstract class JdbcDialect
extends Object

:: 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.


Constructor Summary
JdbcDialect()
           
 
Method Summary
abstract  boolean canHandle(String url)
          Check if this dialect instance can handle a certain jdbc url.
 scala.Option<DataType> getCatalystType(int sqlType, String typeName, int size, MetadataBuilder md)
          Get the custom datatype mapping for the given jdbc meta information.
 scala.Option<JdbcType> getJDBCType(DataType dt)
          Retrieve the jdbc / sql type for a given datatype.
 String quoteIdentifier(String colName)
          Quotes the identifier.
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JdbcDialect

public JdbcDialect()
Method Detail

canHandle

public abstract boolean canHandle(String url)
Check if this dialect instance can handle a certain jdbc url.

Parameters:
url - the jdbc url.
Returns:
True if the dialect can be applied on the given jdbc url.
Throws:
NullPointerException - if the url is null.

getCatalystType

public scala.Option<DataType> getCatalystType(int sqlType,
                                              String typeName,
                                              int size,
                                              MetadataBuilder md)
Get the custom datatype mapping for the given jdbc meta information.

Parameters:
sqlType - The sql type (see java.sql.Types)
typeName - The sql type name (e.g. "BIGINT UNSIGNED")
size - The size of the type.
md - Result metadata associated with this type.
Returns:
The actual DataType (subclasses of DataType) or null if the default type mapping should be used.

getJDBCType

public scala.Option<JdbcType> getJDBCType(DataType dt)
Retrieve the jdbc / sql type for a given datatype.

Parameters:
dt - The datatype (e.g. StringType)
Returns:
The new JdbcType if there is an override for this DataType

quoteIdentifier

public String quoteIdentifier(String colName)
Quotes the identifier. This is used to put quotes around the identifier in case the column name is a reserved keyword, or in case it contains characters that require quotes (e.g. space).

Parameters:
colName - (undocumented)
Returns:
(undocumented)