You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2022/03/15 22:49:22 UTC

[GitHub] [pinot] Jackie-Jiang commented on a change in pull request #8357: Validate schema name before permissions to return proper message

Jackie-Jiang commented on a change in pull request #8357:
URL: https://github.com/apache/pinot/pull/8357#discussion_r827476107



##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotSchemaRestletResource.java
##########
@@ -251,14 +249,27 @@ public String validateSchema(FormDataMultiPart multiPart) {
       @ApiResponse(code = 500, message = "Internal error")
   })
   public String validateSchema(Schema schema) {
+    validateSchemaInternal(schema);
+    return schema.toPrettyJsonString();
+  }
+
+  private void validateSchemaName(Schema schema) {
+    if (StringUtils.isBlank(schema.getSchemaName())) {
+      throw new ControllerApplicationException(LOGGER,
+          "Invalid schema: " + schema.getSchemaName() + ". Reason: 'schemaName' should not be null",
+          Response.Status.BAD_REQUEST);
+    }
+  }
+
+  private void validateSchemaInternal(Schema schema) {
     try {
+      Preconditions.checkNotNull(schema.getSchemaName(), "'schemaName' should not be null");

Review comment:
       ```suggestion
     private void validateSchemaInternal(Schema schema) {
       validateSchemaName(Schema schema);
       try {
   ```

##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotSchemaRestletResource.java
##########
@@ -251,14 +249,27 @@ public String validateSchema(FormDataMultiPart multiPart) {
       @ApiResponse(code = 500, message = "Internal error")
   })
   public String validateSchema(Schema schema) {
+    validateSchemaInternal(schema);
+    return schema.toPrettyJsonString();
+  }
+
+  private void validateSchemaName(Schema schema) {

Review comment:
       (minor) Consider directly put `String schemaName` as parameter

##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotSchemaRestletResource.java
##########
@@ -251,14 +249,27 @@ public String validateSchema(FormDataMultiPart multiPart) {
       @ApiResponse(code = 500, message = "Internal error")
   })
   public String validateSchema(Schema schema) {
+    validateSchemaInternal(schema);
+    return schema.toPrettyJsonString();
+  }
+
+  private void validateSchemaName(Schema schema) {
+    if (StringUtils.isBlank(schema.getSchemaName())) {
+      throw new ControllerApplicationException(LOGGER,
+          "Invalid schema: " + schema.getSchemaName() + ". Reason: 'schemaName' should not be null",

Review comment:
       This exception message is not very readable as schema name is always blank. Consider changing it to `'schemaName' must be provided`




-- 
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-unsubscribe@pinot.apache.org

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



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