rdblue commented on code in PR #7880:
URL: https://github.com/apache/iceberg/pull/7880#discussion_r1315205881
##########
core/src/main/java/org/apache/iceberg/inmemory/InMemoryCatalog.java:
##########
@@ -337,4 +394,67 @@ protected String tableName() {
return tableIdentifier.toString();
}
}
+
+ private class InMemoryViewOperations extends BaseViewOperations {
+ private final FileIO fileIO;
+ private final TableIdentifier identifier;
+
+ InMemoryViewOperations(FileIO fileIO, TableIdentifier identifier) {
+ this.fileIO = fileIO;
+ this.identifier = identifier;
+ }
+
+ @Override
+ public void doRefresh() {
+ String latestLocation = views.get(identifier);
+ if (latestLocation == null) {
+ disableRefresh();
+ } else {
+ refreshFromMetadataLocation(latestLocation);
+ }
+ }
+
+ @Override
+ public void doCommit(ViewMetadata base, ViewMetadata metadata) {
+ String newLocation = writeNewMetadata(metadata, currentVersion() + 1);
+ String oldLocation = base == null ? null : currentMetadataLocation();
+
+ if (null == base && !namespaceExists(identifier.namespace())) {
+ throw new NoSuchNamespaceException(
+ "Cannot create view %s. Namespace does not exist: %s",
+ identifier, identifier.namespace());
+ }
+
+ if (tables.containsKey(identifier)) {
+ throw new AlreadyExistsException("Table with same name already exists:
%s", viewName());
+ }
+
+ views.compute(
+ identifier,
+ (k, existingLocation) -> {
+ if (!Objects.equal(existingLocation, oldLocation)) {
+ if (null == base) {
+ throw new AlreadyExistsException("View already exists: %s",
viewName());
+ }
+
+ throw new CommitFailedException(
+ "Cannot commit to view %s metadata location from %s to %s "
+ + "because it has been concurrently modified to %s",
+ identifier, oldLocation, newLocation, existingLocation);
+ }
+
+ return newLocation;
+ });
+ }
+
+ @Override
+ public FileIO io() {
+ return fileIO;
+ }
+
+ @Override
+ protected String viewName() {
+ return identifier.toString();
Review Comment:
Minor: looks like the behavior of `InMemoryCatalog` differs from other
catalogs here. The Hive catalog includes the catalog name in `tableName()`, but
both in memory tables and views use just `identifier.toString()` that doesn't
include the catalog name.
It would be nice to follow up with a fix that creates a string per
table/view operations that matches the behavior of other catalogs.
--
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]