vrajat commented on code in PR #15515:
URL: https://github.com/apache/pinot/pull/15515#discussion_r2041899912


##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java:
##########
@@ -2205,6 +2206,91 @@ public PinotResourceManagerResponse 
toggleTableState(String tableNameWithType, S
     }
   }
 
+  public void addLogicalTable(LogicalTable logicalTable)
+      throws TableAlreadyExistsException {
+    String tableName = logicalTable.getTableName();
+    LOGGER.info("Adding logical table: {}", tableName);
+
+    validateLogicalTable(logicalTable);
+
+    // Check if the logical table name is already used
+    LogicalTable existingLogicalTable = 
ZKMetadataProvider.getLogicalTable(_propertyStore, tableName);
+    if (existingLogicalTable != null) {
+      throw new TableAlreadyExistsException("Logical table: " + tableName + " 
already exists");
+    }
+
+    // Check if the table name is already used by a physical table
+    
getAllTables().stream().map(TableNameBuilder::extractRawTableName).distinct().filter(tableName::equals)
+        .findFirst().ifPresent(tableNameWithType -> {
+          throw new TableAlreadyExistsException("Table name: " + tableName + " 
already exists");
+        });
+
+    ZKMetadataProvider.setLogicalTable(_propertyStore, logicalTable);
+    LOGGER.info("Added logical table: {}", tableName);
+  }
+
+  public void updateLogicalTable(LogicalTable logicalTable)
+      throws TableNotFoundException {
+    String tableName = logicalTable.getTableName();
+    LOGGER.info("Updating logical table: {}", tableName);
+
+    validateLogicalTable(logicalTable);
+
+    LogicalTable oldLogicalTable = 
ZKMetadataProvider.getLogicalTable(_propertyStore, tableName);
+    if (oldLogicalTable == null) {
+      throw new TableNotFoundException("Logical table: " + tableName + " does 
not exist");
+    }
+
+    ZKMetadataProvider.setLogicalTable(_propertyStore, logicalTable);
+    LOGGER.info("Updated logical table: {}", tableName);
+  }
+
+  public boolean deleteLogicalTable(String tableName) {
+    LOGGER.info("Deleting logical table: {}", tableName);
+    boolean result = false;
+    String propertyStorePath = 
ZKMetadataProvider.constructPropertyStorePathForLogical(tableName);
+    if (_propertyStore.exists(propertyStorePath, AccessOption.PERSISTENT)) {
+      result = _propertyStore.remove(propertyStorePath, 
AccessOption.PERSISTENT);
+    } else {
+      throw new ControllerApplicationException(LOGGER,
+          "Logical table: " + tableName + " does not exists.", 
Response.Status.NOT_FOUND);
+    }
+    LOGGER.info("Deleted logical table: {}", tableName);
+    return result;
+  }
+
+  public LogicalTable getLogicalTable(String tableName) {
+    return ZKMetadataProvider.getLogicalTable(_propertyStore, tableName);
+  }
+
+  public List<String> getAllLogicalTableNames() {
+    return 
ZKMetadataProvider.getAllLogicalTables(_propertyStore).stream().map(LogicalTable::getTableName)
+        .collect(Collectors.toList());
+  }
+
+  private void validateLogicalTable(LogicalTable logicalTable) {

Review Comment:
   One more validation required is that all the table names should be physical 
table names. 



-- 
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: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to