Package org.apache.spark.sql.jdbc
Class MySQLDialect
Object
org.apache.spark.sql.jdbc.JdbcDialect
org.apache.spark.sql.jdbc.MySQLDialect
- All Implemented Interfaces:
Serializable,org.apache.spark.internal.Logging,org.apache.spark.sql.catalyst.SQLConfHelper,NoLegacyJDBCError,scala.Equals,scala.Product
public class MySQLDialect
extends JdbcDialect
implements org.apache.spark.sql.catalyst.SQLConfHelper, NoLegacyJDBCError, scala.Product, Serializable
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassclassNested classes/interfaces inherited from interface org.apache.spark.internal.Logging
org.apache.spark.internal.Logging.LogStringContext, org.apache.spark.internal.Logging.SparkShellLoggingFilter -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract static Rapply()booleanCheck if this dialect instance can handle a certain jdbc url.classifyException(Throwable e, String condition, scala.collection.immutable.Map<String, String> messageParameters, String description, boolean isRuntime) Gets a dialect exception, classifies it and wraps it byAnalysisException.scala.Option<String>compileExpression(Expression expr) Converts V2 expression to String representing a SQL expression.createIndex(String indexName, Identifier tableIdent, NamedReference[] columns, Map<NamedReference, Map<String, String>> columnsProperties, Map<String, String> properties) Build a create index SQL statement.dropIndex(String indexName, Identifier tableIdent) Build a drop index SQL statement.dropSchema(String schema, boolean cascade) scala.Option<DataType>getCatalystType(int sqlType, String typeName, int size, MetadataBuilder md) Get the custom datatype mapping for the given jdbc meta information.getJdbcSQLQueryBuilder(org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions options) Returns the SQL builder for the SELECT statement.scala.Option<JdbcType>getJDBCType(DataType dt) Retrieve the jdbc / sql type for a given datatype.getRenameColumnQuery(String tableName, String columnName, String newName, int dbMajorVersion) getSchemaCommentQuery(String schema, String comment) getTableCommentQuery(String table, String comment) getUpdateColumnNullabilityQuery(String tableName, String columnName, boolean isNullable) getUpdateColumnTypeQuery(String tableName, String columnName, String newDataType) booleanindexExists(Connection conn, String indexName, Identifier tableIdent, org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions options) Checks whether an index existsscala.Option<Object>Return Some[true] iffTRUNCATE TABLEcauses cascading default.booleanbooleanisSupportedFunction(String funcName) Returns whether the database supports function.booleanisSyntaxErrorBestEffort(SQLException exception) Attempts to determine if the given SQLException is a SQL syntax error.listIndexes(Connection conn, Identifier tableIdent, org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions options) Lists all the indexes in this table.String[][]listSchemas(Connection conn, org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions options) Lists all the schemas in this table.quoteIdentifier(String colName) Quotes the identifier.removeSchemaCommentQuery(String schema) booleanschemasExists(Connection conn, org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions options, String schema) Check schema exists or not.booleanbooleanReturns ture if dialect supports LIMIT clause.booleanReturns ture if dialect supports OFFSET clause.static StringtoString()Methods inherited from class org.apache.spark.sql.jdbc.JdbcDialect
alterTable, beforeFetch, classifyException, compileAggregate, compileValue, convertJavaDateToDate, convertJavaTimestampToTimestamp, convertJavaTimestampToTimestampNTZ, convertTimestampNTZToJavaTimestamp, createConnectionFactory, createSchema, createTable, dropTable, functions, getAddColumnQuery, getDayTimeIntervalAsMicros, getDeleteColumnQuery, getFullyQualifiedQuotedTableName, getLimitClause, getOffsetClause, getSchemaQuery, getTableExistsQuery, getTableSample, getTruncateQuery, getTruncateQuery, getYearMonthIntervalAsMonths, insertIntoTable, renameTable, renameTable, supportsTableSample, updateExtraColumnMetaMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface scala.Equals
canEqual, equalsMethods inherited from interface org.apache.spark.internal.Logging
initializeForcefully, initializeLogIfNecessary, initializeLogIfNecessary, initializeLogIfNecessary$default$2, isTraceEnabled, log, logBasedOnLevel, logDebug, logDebug, logDebug, logDebug, logError, logError, logError, logError, logInfo, logInfo, logInfo, logInfo, logName, LogStringContext, logTrace, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, logWarning, org$apache$spark$internal$Logging$$log_, org$apache$spark$internal$Logging$$log__$eq, withLogContextMethods inherited from interface scala.Product
productArity, productElement, productElementName, productElementNames, productIterator, productPrefixMethods inherited from interface org.apache.spark.sql.catalyst.SQLConfHelper
conf, withSQLConf
-
Constructor Details
-
MySQLDialect
public MySQLDialect()
-
-
Method Details
-
apply
public abstract static R apply() -
toString
-
canHandle
Description copied from class:JdbcDialectCheck if this dialect instance can handle a certain jdbc url.- Specified by:
canHandlein classJdbcDialect- Parameters:
url- the jdbc url.- Returns:
- True if the dialect can be applied on the given jdbc url.
-
isSupportedFunction
Description copied from class:JdbcDialectReturns whether the database supports function.- Overrides:
isSupportedFunctionin classJdbcDialect- Parameters:
funcName- Upper-cased function name- Returns:
- True if the database supports function.
-
isObjectNotFoundException
- Overrides:
isObjectNotFoundExceptionin classJdbcDialect
-
compileExpression
Description copied from class:JdbcDialectConverts V2 expression to String representing a SQL expression.- Overrides:
compileExpressionin classJdbcDialect- Parameters:
expr- The V2 expression to be converted.- Returns:
- Converted value.
-
getCatalystType
public scala.Option<DataType> getCatalystType(int sqlType, String typeName, int size, MetadataBuilder md) Description copied from class:JdbcDialectGet the custom datatype mapping for the given jdbc meta information.Guidelines for mapping database defined timestamps to Spark SQL timestamps:
-
TIMESTAMP WITHOUT TIME ZONE if preferTimestampNTZ ->
TimestampNTZType -
TIMESTAMP WITHOUT TIME ZONE if !preferTimestampNTZ ->
TimestampType(LTZ) - TIMESTAMP WITH TIME ZONE ->
TimestampType(LTZ) - TIMESTAMP WITH LOCAL TIME ZONE ->
TimestampType(LTZ) -
If the TIMESTAMP cannot be distinguished by
sqlTypeandtypeName, preferTimestampNTZ is respected for now, but we may need to add another option in the future if necessary.
- Overrides:
getCatalystTypein classJdbcDialect- Parameters:
sqlType- Refers toTypesconstants, or other constants defined by the target database, e.g.-101is Oracle's TIMESTAMP WITH TIME ZONE type. This value is returned byResultSetMetaData.getColumnType(int).typeName- The column type name used by the database (e.g. "BIGINT UNSIGNED"). This is sometimes used to determine the target data type whensqlTypeis not sufficient if multiple database types are conflated into a single id. This value is returned byResultSetMetaData.getColumnTypeName(int).size- The size of the type, e.g. the maximum precision for numeric types, length for character string, etc. This value is returned byResultSetMetaData.getPrecision(int).md- Result metadata associated with this type. This contains additional information fromResultSetMetaDataor user specified options.-
isTimestampNTZ: Whether read a TIMESTAMP WITHOUT TIME ZONE value asTimestampNTZTypeor not. This is configured byJDBCOptions.preferTimestampNTZ. -
scale: The length of fractional partResultSetMetaData.getScale(int)
-
- Returns:
- An option the actual DataType (subclasses of
DataType) or None if the default type mapping should be used.
-
TIMESTAMP WITHOUT TIME ZONE if preferTimestampNTZ ->
-
quoteIdentifier
Description copied from class:JdbcDialectQuotes 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).- Overrides:
quoteIdentifierin classJdbcDialect- Parameters:
colName- (undocumented)- Returns:
- (undocumented)
-
schemasExists
public boolean schemasExists(Connection conn, org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions options, String schema) Description copied from class:JdbcDialectCheck schema exists or not.- Overrides:
schemasExistsin classJdbcDialect- Parameters:
conn- (undocumented)options- (undocumented)schema- (undocumented)- Returns:
- (undocumented)
-
listSchemas
public String[][] listSchemas(Connection conn, org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions options) Description copied from class:JdbcDialectLists all the schemas in this table.- Overrides:
listSchemasin classJdbcDialect- Parameters:
conn- (undocumented)options- (undocumented)- Returns:
- (undocumented)
-
isCascadingTruncateTable
Description copied from class:JdbcDialectReturn Some[true] iffTRUNCATE TABLEcauses cascading default. Some[true] : TRUNCATE TABLE causes cascading. Some[false] : TRUNCATE TABLE does not cause cascading. None: The behavior of TRUNCATE TABLE is unknown (default).- Overrides:
isCascadingTruncateTablein classJdbcDialect- Returns:
- (undocumented)
-
isSyntaxErrorBestEffort
Description copied from class:JdbcDialectAttempts to determine if the given SQLException is a SQL syntax error.This check is best-effort: it may not detect all syntax errors across all JDBC dialects. However, if this method returns true, the exception is guaranteed to be a syntax error.
This is used to decide whether to wrap the exception in a more appropriate Spark exception.
- Overrides:
isSyntaxErrorBestEffortin classJdbcDialect- Parameters:
exception- (undocumented)- Returns:
- true if the exception is confidently identified as a syntax error; false otherwise.
-
getUpdateColumnTypeQuery
- Overrides:
getUpdateColumnTypeQueryin classJdbcDialect
-
getRenameColumnQuery
public String getRenameColumnQuery(String tableName, String columnName, String newName, int dbMajorVersion) - Overrides:
getRenameColumnQueryin classJdbcDialect
-
getUpdateColumnNullabilityQuery
public String getUpdateColumnNullabilityQuery(String tableName, String columnName, boolean isNullable) - Overrides:
getUpdateColumnNullabilityQueryin classJdbcDialect
-
getTableCommentQuery
- Overrides:
getTableCommentQueryin classJdbcDialect
-
getJDBCType
Description copied from class:JdbcDialectRetrieve the jdbc / sql type for a given datatype.- Overrides:
getJDBCTypein classJdbcDialect- Parameters:
dt- The datatype (e.g.StringType)- Returns:
- The new JdbcType if there is an override for this DataType
-
getSchemaCommentQuery
- Overrides:
getSchemaCommentQueryin classJdbcDialect
-
removeSchemaCommentQuery
- Overrides:
removeSchemaCommentQueryin classJdbcDialect
-
createIndex
public String createIndex(String indexName, Identifier tableIdent, NamedReference[] columns, Map<NamedReference, Map<String, String>> columnsProperties, Map<String, String> properties) Description copied from class:JdbcDialectBuild a create index SQL statement.- Overrides:
createIndexin classJdbcDialect- Parameters:
indexName- the name of the index to be createdtableIdent- the table on which index to be createdcolumns- the columns on which index to be createdcolumnsProperties- the properties of the columns on which index to be createdproperties- the properties of the index to be created- Returns:
- the SQL statement to use for creating the index.
-
indexExists
public boolean indexExists(Connection conn, String indexName, Identifier tableIdent, org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions options) Description copied from class:JdbcDialectChecks whether an index exists- Overrides:
indexExistsin classJdbcDialect- Parameters:
conn- (undocumented)indexName- the name of the indextableIdent- the table on which index to be checkedoptions- JDBCOptions of the table- Returns:
- true if the index with
indexNameexists in the table withtableName, false otherwise
-
dropIndex
Description copied from class:JdbcDialectBuild a drop index SQL statement.- Overrides:
dropIndexin classJdbcDialect- Parameters:
indexName- the name of the index to be dropped.tableIdent- the table on which index to be dropped.- Returns:
- the SQL statement to use for dropping the index.
-
listIndexes
public TableIndex[] listIndexes(Connection conn, Identifier tableIdent, org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions options) Description copied from class:JdbcDialectLists all the indexes in this table.- Overrides:
listIndexesin classJdbcDialect- Parameters:
conn- (undocumented)tableIdent- (undocumented)options- (undocumented)- Returns:
- (undocumented)
-
classifyException
public Throwable classifyException(Throwable e, String condition, scala.collection.immutable.Map<String, String> messageParameters, String description, boolean isRuntime) Description copied from class:JdbcDialectGets a dialect exception, classifies it and wraps it byAnalysisException.- Specified by:
classifyExceptionin interfaceNoLegacyJDBCError- Overrides:
classifyExceptionin classJdbcDialect- Parameters:
e- The dialect specific exception.condition- The error condition assigned in the case of an unclassifiedemessageParameters- The message parameters oferrorClassdescription- The error descriptionisRuntime- Whether the exception is a runtime exception or not.- Returns:
SparkThrowable + Throwableor its sub-class.
-
dropSchema
- Overrides:
dropSchemain classJdbcDialect
-
getJdbcSQLQueryBuilder
public JdbcSQLQueryBuilder getJdbcSQLQueryBuilder(org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions options) Description copied from class:JdbcDialectReturns the SQL builder for the SELECT statement.- Overrides:
getJdbcSQLQueryBuilderin classJdbcDialect- Parameters:
options- (undocumented)- Returns:
- (undocumented)
-
supportsLimit
public boolean supportsLimit()Description copied from class:JdbcDialectReturns ture if dialect supports LIMIT clause.Note: Some build-in dialect supports LIMIT clause with some trick, please see:
OracleDialect.OracleSQLQueryBuilderandMsSqlServerDialect.MsSqlServerSQLQueryBuilder.- Overrides:
supportsLimitin classJdbcDialect- Returns:
- (undocumented)
-
supportsOffset
public boolean supportsOffset()Description copied from class:JdbcDialectReturns ture if dialect supports OFFSET clause.Note: Some build-in dialect supports OFFSET clause with some trick, please see:
OracleDialect.OracleSQLQueryBuilderandMySQLDialect.MySQLSQLQueryBuilder.- Overrides:
supportsOffsetin classJdbcDialect- Returns:
- (undocumented)
-
supportsHint
public boolean supportsHint()- Overrides:
supportsHintin classJdbcDialect
-