Copilot commented on code in PR #15902: URL: https://github.com/apache/pinot/pull/15902#discussion_r2108193660
########## pinot-spi/src/main/java/org/apache/pinot/spi/auth/TableAuthorizationResult.java: ########## @@ -16,51 +16,57 @@ * specific language governing permissions and limitations * under the License. */ + package org.apache.pinot.spi.auth; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; -/** - * Implementation of the AuthorizationResult interface that provides authorization results - * at the table level, including which tables failed authorization. - */ -public class TableAuthorizationResult implements AuthorizationResult { +public class TableAuthorizationResult implements MultiTableAuthResult { - private static final TableAuthorizationResult SUCCESS = new TableAuthorizationResult(Set.of()); + private static final TableAuthorizationResult SUCCESS = new TableAuthorizationResult(Map.of()); + + private final Map<String, Boolean> _authResult; private final Set<String> _failedTables; - public TableAuthorizationResult(Set<String> failedTables) { - _failedTables = failedTables; + public TableAuthorizationResult(Map<String, Boolean> authResult) { + _authResult = authResult; + _failedTables = + _authResult.entrySet().stream().filter(e -> !e.getValue()).map(Map.Entry::getKey).collect(Collectors.toSet()); } - /** - * Creates a TableAuthorizationResult with no failed tables. - * - * @return a TableAuthorizationResult with no failed tables. - */ - public static TableAuthorizationResult success() { - return SUCCESS; + public TableAuthorizationResult(Set<String> failedTables) { + Map<String, Boolean> authResult = new HashMap<>(); + for (String tableName : failedTables) { + authResult.put(tableName, false); + } + _authResult = authResult; + _failedTables = failedTables; } @Override public boolean hasAccess() { return _failedTables.isEmpty(); } + @Override + public Optional<Boolean> hasAccess(String tableName) { + return Optional.of(_authResult.get(tableName)); Review Comment: Using Optional.of() here may cause a NullPointerException if the tableName key is missing in _authResult. Consider using Optional.ofNullable(_authResult.get(tableName)) to safely handle missing keys. ```suggestion return Optional.ofNullable(_authResult.get(tableName)); ``` -- 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