mcvsubbu commented on a change in pull request #4959: Add schemaFile as option 
in AddTableCommand
URL: https://github.com/apache/incubator-pinot/pull/4959#discussion_r363109752
 
 

 ##########
 File path: 
pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/AddTableCommand.java
 ##########
 @@ -102,33 +112,51 @@ public AddTableCommand setExecute(boolean exec) {
     return this;
   }
 
-  public boolean execute(JsonNode node)
+  public boolean sendTableCreationRequest(JsonNode node)
       throws IOException {
-    if (_controllerHost == null) {
-      _controllerHost = NetUtil.getHostAddress();
-    }
-    _controllerAddress = "http://"; + _controllerHost + ":" + _controllerPort;
+    String res = AbstractBaseAdminCommand
+        
.sendPostRequest(ControllerRequestURLBuilder.baseUrl(_controllerAddress).forTableCreate(),
 node.toString());
+    LOGGER.info(res);
+    return res.contains("succesfully added");
+  }
 
+  @Override
+  public boolean execute()
+      throws Exception {
     if (!_exec) {
       LOGGER.warn("Dry Running Command: " + toString());
       LOGGER.warn("Use the -exec option to actually execute the command.");
       return true;
     }
 
-    LOGGER.info("Executing command: " + toString());
-    String res = AbstractBaseAdminCommand
-        
.sendPostRequest(ControllerRequestURLBuilder.baseUrl(_controllerAddress).forTableCreate(),
 node.toString());
+    if (_controllerHost == null) {
+      _controllerHost = NetUtil.getHostAddress();
+    }
+    _controllerAddress = "http://"; + _controllerHost + ":" + _controllerPort;
 
-    LOGGER.info(res);
-    if (res.contains("succesfully added")) {
-      return true;
+    LOGGER.info("Executing command: " + toString());
+    // Backward compatible
+    if (_schemaFile != null) {
+      File schemaFile = new File(_schemaFile);
+      if (!schemaFile.exists()) {
+        throw new FileNotFoundException("schema file does not exist: " + 
_schemaFile);
+      }
+
+      Schema schema = Schema.fromFile(schemaFile);
+      try (FileUploadDownloadClient fileUploadDownloadClient = new 
FileUploadDownloadClient()) {
+        fileUploadDownloadClient.addSchema(
+            FileUploadDownloadClient.getUploadSchemaHttpURI(_controllerHost, 
Integer.parseInt(_controllerPort)),
+            schema.getSchemaName(), schemaFile);
+      } catch (Exception e) {
+        LOGGER.error("Got Exception to upload Pinot Schema: " + 
schema.getSchemaName(), e);
+        throw e;
+      }
+    }
+    File tableConfigFile = new File(_tableConfigFile);
+    if (!tableConfigFile.exists()) {
 
 Review comment:
   Maybe same technique can be used here and the file existence check avoided?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to