Skip to content

Commit

Permalink
Support truncating table in Cassandra
Browse files Browse the repository at this point in the history
  • Loading branch information
ebyhr committed Mar 12, 2022
1 parent 6a70525 commit eed07af
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
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 @@ -324,6 +325,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

0 comments on commit eed07af

Please sign in to comment.