Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support truncating table in Cassandra #11425

Merged
merged 1 commit into from
Mar 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/main/sphinx/connector/cassandra.rst
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ statements, the connector supports the following features:

* :doc:`/sql/insert`
* :doc:`/sql/delete` see :ref:`sql-delete-limitation`
* :doc:`/sql/truncate`
* :doc:`/sql/create-table`
* :doc:`/sql/create-table-as`
* :doc:`/sql/drop-table`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.util.OptionalLong;
import java.util.stream.Collectors;

import static com.datastax.driver.core.querybuilder.QueryBuilder.truncate;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.MoreCollectors.toOptional;
Expand Down Expand Up @@ -319,6 +320,13 @@ public Optional<ConnectorOutputMetadata> finishCreateTable(ConnectorSession sess
return Optional.empty();
}

@Override
public void truncateTable(ConnectorSession session, ConnectorTableHandle tableHandle)
{
CassandraTableHandle table = (CassandraTableHandle) tableHandle;
cassandraSession.execute(truncate(table.getSchemaName(), table.getTableName()));
}

@Override
public ConnectorInsertTableHandle beginInsert(ConnectorSession session, ConnectorTableHandle tableHandle)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ public class TestCassandraConnectorTest
protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
{
switch (connectorBehavior) {
case SUPPORTS_TRUNCATE:
return true;

case SUPPORTS_CREATE_SCHEMA:
return false;

Expand Down