You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 12 Next »

Status

Current state: Under Discussion

Discussion thread: https://lists.apache.org/thread/m4r3wrd7p96wdst3nz3ncqzog6kf51cf

JIRAhere (<- link to https://issues.apache.org/jira/browse/FLINK-XXXX)

Released: <Flink Version>

Please keep the discussion on the mailing list rather than commenting on the wiki (wiki discussions get unwieldy fast).

Motivation

The TRUNCATE TABLE statement is a SQL command that allows users to quickly and efficiently delete all rows from a table without dropping the table itself.  This statement is commonly used in data warehouse, where large data sets are frequently loaded and unloaded from tables. It can improve performance by reducing the amount of time and resources required to delete large amounts of data.

Also, the TRUNCATE TABLE statement can help simlify and streamling data management tasks by eliminating the need for complex queries or data manipulation operations.

Considering the TRUNCATE TABLE statment is useful and widely-used, this FLIP is aimed to support TRUNCATE TABLE  statment in Flink. This FLIP will bring Flink the TRUNCATE TABLE  syntax and an interface with which the coresponding connectors can implement their own  logic for truncating table.

Public Interfaces

Syntax

We propose add the following syntax for TRUNCATE TABLE statement.

TRUNCATE TABLE table_name

It only supports trucate table, if it's a view or temporary table, it should throw TableException with message Truncate a view/temporary table is not support .

Public interfaces Changes

We propose add a inerface for TRUNCATE TABLE statment. The connectors can implement this interface to custom their logic for truncating table.

/**
 * Enables to delete all existing data in a {@link DynamicTableSink} table using {@code TRUNCATE
 * TABLE} statement.
 *
 * <p>For {@code TRUNCATE TABLE} statement, if the corresponding {@link DynamicTableSink} have
 * implemented this interface, then the method {@link #truncateTable()} will be invoked in execution
 * phase. Otherwise, Flink will throw exception directly.
 */
@PublicEvolving
public interface SupportsTruncate {

    /**
     * Execute truncating table.
     *
     * @return true if truncate the table successfully otherwise false
     */
    boolean executeTruncation();
}

Proposed Changes

1: Add a parse rule in parserImpls.ftl to match TRUNCATE TABLE  statement and convert it to SqlTruncateTable 

2: Create a SqlTruncateTableConveter  to TruncateTableOperation, and register SqlTruncateTableConveter to SqlNodeConverters.

3: TruncateTableOperation  should implement ExecutableOperation, and in method #execute(Context ctx), it will  get the DynamicTableSink  of the table which should implement SupportsTruncate   and then call method SupportsTruncate#executeTruncation  directly to truncate the table.

Compatibility, Deprecation, and Migration Plan

No any compatibility issue.

Test Plan

It'll be covered by UT & IT.

Rejected Alternatives

If there are alternative ways of accomplishing the same thing, what were they? The purpose of this section is to motivate why the design is the way it is and not some other way.

  • No labels