Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Syntax

We propose add the following syntax for TRUNCATE TABLE statement.

Code Block
languagesql
TRUNCATE TABLE table_name

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



Public interfaces Changes

We propose add a inerface for TRUNCATE TABLE statment

Code Block
languagejava
/**
 * 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 {

    /**
     * TruncateExecute thetruncating table by removing all rows.
     *
     * @return true if truncate the table successfully otherwise false
     */
    boolean truncateTableexecuteTruncation();
}


Proposed Changes

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

...

3: In method TableEnvironmentImpl#executeInternal, if the operation is  instance of TruncateTableOperation,  get the DynamicTableSink  of the table which should implement SupportsTruncate   and then call method SupportsTruncate#truncateTable SupportsTruncate#executeTruncation  directly to truncate the table.

...