Interface JdbcDialect
-
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
AbstractDialect,DerbyDialect,MySqlDialect,OracleDialect,PostgresDialect,SqlServerDialect
@PublicEvolving public interface JdbcDialect extends Serializable
Represents a dialect of SQL implemented by a particular JDBC system. Dialects should be immutable and stateless.- See Also:
JdbcDialectFactory
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default StringappendDefaultUrlProperties(String url)Appends default JDBC properties to url for current dialect.default Optional<String>defaultDriverName()StringdialectName()Get the name of jdbc dialect.StringgetDeleteStatement(String tableName, String[] conditionFields)Constructs the dialects delete statement for a single row with the given condition.StringgetInsertIntoStatement(String tableName, String[] fieldNames)Generates a string that will be used as aPreparedStatementto insert a row into a database table.StringgetLimitClause(long limit)Get limit clause to limit the number of emitted row from the jdbc source.JdbcRowConvertergetRowConverter(org.apache.flink.table.types.logical.RowType rowType)Get converter that convert jdbc object and Flink internal object each other.StringgetRowExistsStatement(String tableName, String[] conditionFields)Generates a query to determine if a row exists in the table.StringgetSelectFromStatement(String tableName, String[] selectFields, String[] conditionFields)Constructs the dialects select statement for fields with given conditions.StringgetUpdateStatement(String tableName, String[] fieldNames, String[] conditionFields)Constructs the dialects update statement for a single row with the given condition.Optional<String>getUpsertStatement(String tableName, String[] fieldNames, String[] uniqueKeyFields)Constructs the dialects upsert statement if supported; such as MySQL'sDUPLICATE KEY UPDATE, or PostgreSQL'sON CONFLICT... DO UPDATE SET...StringquoteIdentifier(String identifier)Quotes the identifier.voidvalidate(org.apache.flink.table.types.logical.RowType rowType)Check if this dialect instance support a specific data type in table schema.
-
-
-
Method Detail
-
dialectName
String dialectName()
Get the name of jdbc dialect.- Returns:
- the dialect name.
-
getRowConverter
JdbcRowConverter getRowConverter(org.apache.flink.table.types.logical.RowType rowType)
Get converter that convert jdbc object and Flink internal object each other.- Parameters:
rowType- the given row type- Returns:
- a row converter for the database
-
getLimitClause
String getLimitClause(long limit)
Get limit clause to limit the number of emitted row from the jdbc source.- Parameters:
limit- number of row to emit. The value of the parameter should be non-negative.- Returns:
- the limit clause.
-
validate
void validate(org.apache.flink.table.types.logical.RowType rowType) throws org.apache.flink.table.api.ValidationExceptionCheck if this dialect instance support a specific data type in table schema.- Parameters:
rowType- the physical table datatype of a row in the database table.- Throws:
org.apache.flink.table.api.ValidationException- in case of the table schema contains unsupported type.
-
defaultDriverName
default Optional<String> defaultDriverName()
- Returns:
- the default driver class name, if user has not configured the driver class name, then this one will be used.
-
quoteIdentifier
String quoteIdentifier(String identifier)
Quotes the identifier.Used to put quotes around the identifier if the column name is a reserved keyword or contains characters requiring quotes (e.g., space).
- Returns:
- the quoted identifier.
-
getUpsertStatement
Optional<String> getUpsertStatement(String tableName, String[] fieldNames, String[] uniqueKeyFields)
Constructs the dialects upsert statement if supported; such as MySQL'sDUPLICATE KEY UPDATE, or PostgreSQL'sON CONFLICT... DO UPDATE SET... If supported, the returned string will be used as aPreparedStatement. Fields in the statement must be in the same order as thefieldNamesparameter.If the dialect does not support native upsert statements, the writer will fallback to
SELECT+UPDATE/INSERTwhich may have poor performance.- Returns:
- The upsert statement if supported, otherwise None.
-
getRowExistsStatement
String getRowExistsStatement(String tableName, String[] conditionFields)
Generates a query to determine if a row exists in the table. The returned string will be used as aPreparedStatement.By default, the dialect will fallback to a simple
SELECTquery.
-
getInsertIntoStatement
String getInsertIntoStatement(String tableName, String[] fieldNames)
Generates a string that will be used as aPreparedStatementto insert a row into a database table. Fields in the statement must be in the same order as thefieldNamesparameter.- Returns:
- the dialects
INSERT INTOstatement.
-
getUpdateStatement
String getUpdateStatement(String tableName, String[] fieldNames, String[] conditionFields)
Constructs the dialects update statement for a single row with the given condition. The returned string will be used as aPreparedStatement. Fields in the statement must be in the same order as thefieldNamesparameter.- Returns:
- A single row update statement.
-
getDeleteStatement
String getDeleteStatement(String tableName, String[] conditionFields)
Constructs the dialects delete statement for a single row with the given condition. The returned string will be used as aPreparedStatement. Fields in the statement must be in the same order as thefieldNamesparameter.- Returns:
- A single row delete statement.
-
getSelectFromStatement
String getSelectFromStatement(String tableName, String[] selectFields, String[] conditionFields)
Constructs the dialects select statement for fields with given conditions. The returned string will be used as aPreparedStatement. Fields in the statement must be in the same order as thefieldNamesparameter.- Returns:
- A select statement.
-
appendDefaultUrlProperties
default String appendDefaultUrlProperties(String url)
Appends default JDBC properties to url for current dialect. Some database dialects will set default JDBC properties for performance or optimization consideration, such as MySQL dialect uses 'rewriteBatchedStatements=true' to enable execute multiple MySQL statements in batch mode.- Returns:
- A JDBC url that has appended the default properties.
-
-