ebyhr commented on code in PR #15300:
URL: https://github.com/apache/iceberg/pull/15300#discussion_r2795802424
##########
bigquery/src/main/java/org/apache/iceberg/gcp/bigquery/BigQueryMetastoreClientImpl.java:
##########
@@ -527,6 +531,76 @@ public List<Tables> list(DatasetReference
datasetReference, boolean listAllTable
}
}
+ @Override
+ public void rename(TableReference fromTableReference, TableReference
toTableReference) {
+ try {
+ Table sourceTable = load(fromTableReference);
+
+ DatasetReference toDatasetReference =
+ new DatasetReference()
+ .setProjectId(toTableReference.getProjectId())
+ .setDatasetId(toTableReference.getDatasetId());
+ load(toDatasetReference);
+
+ Table renamedTable = new Table();
+ renamedTable.setTableReference(toTableReference);
+
renamedTable.setExternalCatalogTableOptions(sourceTable.getExternalCatalogTableOptions());
+
+ createNewTableDuringRename(toTableReference, renamedTable);
+ deleteOriginalTableDuringRename(fromTableReference, toTableReference);
Review Comment:
Does BigQuery preserve existing permissions even after drop & create?
##########
bigquery/src/main/java/org/apache/iceberg/gcp/bigquery/BigQueryMetastoreClientImpl.java:
##########
@@ -527,6 +531,76 @@ public List<Tables> list(DatasetReference
datasetReference, boolean listAllTable
}
}
+ @Override
+ public void rename(TableReference fromTableReference, TableReference
toTableReference) {
+ try {
+ Table sourceTable = load(fromTableReference);
+
+ DatasetReference toDatasetReference =
+ new DatasetReference()
+ .setProjectId(toTableReference.getProjectId())
+ .setDatasetId(toTableReference.getDatasetId());
+ load(toDatasetReference);
+
+ Table renamedTable = new Table();
+ renamedTable.setTableReference(toTableReference);
+
renamedTable.setExternalCatalogTableOptions(sourceTable.getExternalCatalogTableOptions());
Review Comment:
I've recently tested BigLake metastore, and noticed it requires that the
location must contain the table name. Does this BigQuery metastore have the
same requirement?
##########
bigquery/src/main/java/org/apache/iceberg/gcp/bigquery/BigQueryMetastoreClientImpl.java:
##########
@@ -527,6 +531,76 @@ public List<Tables> list(DatasetReference
datasetReference, boolean listAllTable
}
}
+ @Override
+ public void rename(TableReference fromTableReference, TableReference
toTableReference) {
+ try {
+ Table sourceTable = load(fromTableReference);
+
+ DatasetReference toDatasetReference =
+ new DatasetReference()
+ .setProjectId(toTableReference.getProjectId())
+ .setDatasetId(toTableReference.getDatasetId());
+ load(toDatasetReference);
+
+ Table renamedTable = new Table();
+ renamedTable.setTableReference(toTableReference);
+
renamedTable.setExternalCatalogTableOptions(sourceTable.getExternalCatalogTableOptions());
+
+ createNewTableDuringRename(toTableReference, renamedTable);
+ deleteOriginalTableDuringRename(fromTableReference, toTableReference);
+
+ } catch (Exception e) {
+ throw new RuntimeIOException(
+ "Failed to rename table from %s to %s: %s",
+ fromTableReference, toTableReference, e.getMessage());
+ }
+ }
+
+ private void createNewTableDuringRename(TableReference toTableReference,
Table renamedTable) {
+ try {
+ HttpResponse createResponse =
+ client
+ .tables()
+ .insert(
+ toTableReference.getProjectId(),
toTableReference.getDatasetId(), renamedTable)
+ .executeUnparsed();
+
+ convertExceptionIfUnsuccessful(createResponse);
+
+ } catch (Exception createException) {
+ throw new RuntimeIOException(
+ "Failed to create new table %s during rename: %s",
+ toTableReference, createException.getMessage());
+ }
+ }
+
+ private void deleteOriginalTableDuringRename(
+ TableReference fromTableReference, TableReference toTableReference) {
+ try {
+ delete(fromTableReference);
+ } catch (Exception deleteException) {
+ LOG.error("Failed to cleanup original table {}", fromTableReference,
deleteException);
+ cleanupNewlyCreatedTableDuringRename(toTableReference);
Review Comment:
This catch block seems unsafe. If an exception occurs on the client side
(e.g., a timeout) after the remote operation has actually succeeded, both
tables could end up being dropped, correct?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]