接口 JdbcDialect

    • 字段详细资料

      • log

        static final org.slf4j.Logger log
    • 方法详细资料

      • dialectName

        String dialectName()
        Get the name of jdbc dialect.
        返回:
        the dialect name.
      • getRowConverter

        JdbcRowConverter getRowConverter()
        Get converter that convert jdbc object to seatunnel internal object.
        返回:
        a row converter for the database
      • getJdbcDialectTypeMapper

        JdbcDialectTypeMapper getJdbcDialectTypeMapper()
        get jdbc meta-information type to seatunnel data type mapper.
        返回:
        a type mapper for the database
      • hashModForField

        default String hashModForField​(String nativeType,
                                       String fieldName,
                                       int mod)
      • hashModForField

        default String hashModForField​(String fieldName,
                                       int mod)
      • quoteIdentifier

        default String quoteIdentifier​(String identifier)
        Quotes the identifier for table name or field name
      • quoteDatabaseIdentifier

        default String quoteDatabaseIdentifier​(String identifier)
        Quotes the identifier for database name or field name
      • tableIdentifier

        default String tableIdentifier​(String database,
                                       String tableName)
      • getInsertIntoStatement

        default String getInsertIntoStatement​(String database,
                                              String tableName,
                                              String[] fieldNames)
        Constructs the dialects insert statement for a single row. The returned string will be used as a PreparedStatement. Fields in the statement must be in the same order as the fieldNames parameter.
        
         INSERT INTO table_name (column_name [, ...]) VALUES (value [, ...])
         
        返回:
        the dialects INSERT INTO statement.
      • getUpdateStatement

        default String getUpdateStatement​(String database,
                                          String tableName,
                                          String[] fieldNames,
                                          String[] conditionFields,
                                          boolean isPrimaryKeyUpdated)
        Constructs the dialects update statement for a single row with the given condition. The returned string will be used as a PreparedStatement. Fields in the statement must be in the same order as the fieldNames parameter.
        
         UPDATE table_name SET col = val [, ...] WHERE cond [AND ...]
         
        返回:
        the dialects UPDATE statement.
      • getDeleteStatement

        default String getDeleteStatement​(String database,
                                          String tableName,
                                          String[] conditionFields)
        Constructs the dialects delete statement for a single row with the given condition. The returned string will be used as a PreparedStatement. Fields in the statement must be in the same order as the fieldNames parameter.
        
         DELETE FROM table_name WHERE cond [AND ...]
         
        返回:
        the dialects DELETE statement.
      • getRowExistsStatement

        default String getRowExistsStatement​(String database,
                                             String tableName,
                                             String[] conditionFields)
        Generates a query to determine if a row exists in the table. The returned string will be used as a PreparedStatement.
        
         SELECT 1 FROM table_name WHERE cond [AND ...]
         
        返回:
        the dialects QUERY statement.
      • getUpsertStatement

        Optional<String> getUpsertStatement​(String database,
                                            String tableName,
                                            String[] fieldNames,
                                            String[] uniqueKeyFields)
        Constructs the dialects upsert statement if supported; such as MySQL's DUPLICATE KEY UPDATE, or PostgreSQL's ON CONFLICT... DO UPDATE SET...

        If supported, the returned string will be used as a PreparedStatement. Fields in the statement must be in the same order as the fieldNames parameter.

        If the dialect does not support native upsert statements, the writer will fallback to SELECT ROW Exists + UPDATE/INSERT which may have poor performance.

        返回:
        the dialects UPSERT statement or Optional.empty().
      • creatPreparedStatement

        default PreparedStatement creatPreparedStatement​(Connection connection,
                                                         String queryTemplate,
                                                         int fetchSize)
                                                  throws SQLException
        Different dialects optimize their PreparedStatement
        返回:
        The logic about optimize PreparedStatement
        抛出:
        SQLException
      • extractTableName

        default String extractTableName​(org.apache.seatunnel.api.table.catalog.TablePath tablePath)
      • parse

        default org.apache.seatunnel.api.table.catalog.TablePath parse​(String tablePath)
      • tableIdentifier

        default String tableIdentifier​(org.apache.seatunnel.api.table.catalog.TablePath tablePath)
      • approximateRowCntStatement

        default Long approximateRowCntStatement​(Connection connection,
                                                JdbcSourceTable table)
                                         throws SQLException
        Approximate total number of entries in the lookup table.
        参数:
        connection - The JDBC connection object used to connect to the database.
        table - table info.
        返回:
        approximate row count statement.
        抛出:
        SQLException
      • sampleDataFromColumn

        default Object[] sampleDataFromColumn​(Connection connection,
                                              JdbcSourceTable table,
                                              String columnName,
                                              int samplingRate,
                                              int fetchSize)
                                       throws Exception
        Performs a sampling operation on the specified column of a table in a JDBC-connected database.
        参数:
        connection - The JDBC connection object used to connect to the database.
        table - The table in which the column resides.
        columnName - The name of the column to be sampled.
        samplingRate - samplingRate The inverse of the fraction of the data to be sampled from the column. For example, a value of 1000 would mean 1/1000 of the data will be sampled.
        返回:
        Returns a List of sampled data from the specified column.
        抛出:
        SQLException - If an SQL error occurs during the sampling operation.
        Exception
      • queryNextChunkMax

        default Object queryNextChunkMax​(Connection connection,
                                         JdbcSourceTable table,
                                         String columnName,
                                         int chunkSize,
                                         Object includedLowerBound)
                                  throws SQLException
        Query the maximum value of the next chunk, and the next chunk must be greater than or equal to includedLowerBound value [min_1, max_1), [min_2, max_2),... [min_n, null). Each time this method is called it will return max1, max2...
        参数:
        connection - JDBC connection.
        table - table info.
        columnName - column name.
        chunkSize - chunk size.
        includedLowerBound - the previous chunk end value.
        返回:
        next chunk end value.
        抛出:
        SQLException
      • convertType

        default String convertType​(String columnName,
                                   String columnType)
        Cast column type e.g. CAST(column AS type)
        参数:
        columnName -
        columnType -
        返回:
        the text of converted column type.
      • refreshTableSchemaBySchemaChangeEvent

        default void refreshTableSchemaBySchemaChangeEvent​(String sourceDialectName,
                                                           org.apache.seatunnel.api.table.event.AlterTableColumnEvent event,
                                                           JdbcConnectionProvider jdbcConnectionProvider,
                                                           org.apache.seatunnel.api.table.catalog.TablePath sinkTablePath)
        Refresh physical table schema by schema change event
        参数:
        sourceDialectName - source dialect name
        event - schema change event
        jdbcConnectionProvider - jdbc connection provider
        sinkTablePath - sink table path
      • generateAlterTableSql

        default String generateAlterTableSql​(String sourceDialectName,
                                             org.apache.seatunnel.api.table.event.AlterTableColumnEvent event,
                                             org.apache.seatunnel.api.table.catalog.TablePath sinkTablePath)
        generate alter table sql
        参数:
        sourceDialectName - source dialect name
        event - schema change event
        sinkTablePath - sink table path
        返回:
        alter table sql for sink table
      • buildAlterTableSql

        default String buildAlterTableSql​(String sourceDialectName,
                                          String sourceColumnType,
                                          String alterOperation,
                                          org.apache.seatunnel.api.table.catalog.Column newColumn,
                                          String tableName,
                                          String oldColumnName)
        build alter table sql
        参数:
        sourceDialectName - source dialect name
        sourceColumnType - source column type
        alterOperation - alter operation of ddl
        newColumn - new column after ddl
        tableName - table name of sink table
        oldColumnName - old column name before ddl
        返回:
        alter table sql for sink table after schema change
      • buildAlterTableBasicSql

        default String buildAlterTableBasicSql​(String alterOperation,
                                               String tableName)
        build the body of alter table sql
        参数:
        alterOperation - alter operation of ddl
        tableName - table name of sink table
        返回:
        basic sql of alter table for sink table
      • decorateWithColumnNameAndType

        default String decorateWithColumnNameAndType​(String sourceDialectName,
                                                     String sourceColumnType,
                                                     String basicSql,
                                                     String alterOperation,
                                                     org.apache.seatunnel.api.table.catalog.Column newColumn,
                                                     String oldColumnName,
                                                     String columnType)
        decorate the sql with column name and type
        参数:
        sourceDialectName - source dialect name
        sourceColumnType - source column type
        basicSql - basic sql of alter table for sink table
        alterOperation - alter operation of ddl
        newColumn - new column after ddl
        oldColumnName - old column name before ddl
        columnType - column type of new column
        返回:
        basic sql with column name and type of alter table for sink table
      • decorateWithNullable

        default String decorateWithNullable​(String basicSql,
                                            org.apache.seatunnel.api.table.converter.BasicTypeDefine typeBasicTypeDefine)
        decorate with nullable
        参数:
        basicSql - alter table sql for sink table
        typeBasicTypeDefine - type basic type define of new column
        返回:
        alter table sql with nullable for sink table
      • decorateWithDefaultValue

        default String decorateWithDefaultValue​(String basicSql,
                                                org.apache.seatunnel.api.table.converter.BasicTypeDefine typeBasicTypeDefine)
        decorate with default value
        参数:
        basicSql - alter table sql for sink table
        typeBasicTypeDefine - type basic type define of new column
        返回:
        alter table sql with default value for sink table
      • decorateWithComment

        default String decorateWithComment​(String basicSql,
                                           org.apache.seatunnel.api.table.converter.BasicTypeDefine typeBasicTypeDefine)
        decorate with comment
        参数:
        basicSql - alter table sql for sink table
        typeBasicTypeDefine - type basic type define of new column
        返回:
        alter table sql with comment for sink table
      • needsQuotesWithDefaultValue

        default boolean needsQuotesWithDefaultValue​(String sqlType)
        whether quotes with default value
        参数:
        sqlType - sql type of column
        返回:
        whether needs quotes with the type
      • isSpecialDefaultValue

        default boolean isSpecialDefaultValue​(Object defaultValue)
        whether is special default value e.g. current_timestamp
        参数:
        defaultValue - default value of column
        返回:
        whether is special default value e.g current_timestamp
      • quotesDefaultValue

        default String quotesDefaultValue​(Object defaultValue)
        quotes default value
        参数:
        defaultValue - default value of column
        返回:
        quoted default value