Skip to content

Commit

Permalink
Support truncate table statement in BigQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
ebyhr committed Oct 10, 2022
1 parent e628403 commit 3cc0058
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/src/main/sphinx/connector/bigquery.rst
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ BigQuery database. In addition to the
the following features:

* :doc:`/sql/insert`
* :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 @@ -480,6 +480,21 @@ public void dropTable(ConnectorSession session, ConnectorTableHandle tableHandle
client.dropTable(tableId);
}

@Override
public void truncateTable(ConnectorSession session, ConnectorTableHandle tableHandle)
{
BigQueryTableHandle table = (BigQueryTableHandle) tableHandle;
BigQueryClient client = bigQueryClientFactory.createBigQueryClient(session);

RemoteTableName remoteTableName = table.asPlainTable().getRemoteTableName();
String sql = format(
"TRUNCATE TABLE %s.%s.%s",
quote(remoteTableName.getProjectId()),
quote(remoteTableName.getDatasetName()),
quote(remoteTableName.getTableName()));
client.executeUpdate(QueryJobConfiguration.of(sql));
}

@Override
public ConnectorInsertTableHandle beginInsert(ConnectorSession session, ConnectorTableHandle tableHandle, List<ColumnHandle> columns, RetryMode retryMode)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
case SUPPORTS_NOT_NULL_CONSTRAINT:
return false;

case SUPPORTS_TRUNCATE:
return true;

case SUPPORTS_NEGATIVE_DATE:
return false;

Expand Down

0 comments on commit 3cc0058

Please sign in to comment.