/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.apache.pinot.tools.admin.command;

import java.util.Collections;
import org.apache.pinot.common.utils.CommonConstants;
import org.apache.pinot.common.utils.JsonUtils;
import org.apache.pinot.common.utils.NetUtil;
import org.apache.pinot.tools.Command;
import org.kohsuke.args4j.Option;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class PostQueryCommand extends AbstractBaseAdminCommand implements Command {
  private static final Logger LOGGER = LoggerFactory.getLogger(PostQueryCommand.class.getName());

  @Option(name = "-brokerHost", required = false, metaVar = "<String>", usage = "host name for controller.")
  private String _brokerHost;

  @Option(name = "-brokerPort", required = false, metaVar = "<int>", usage = "http port for broker.")
  private String _brokerPort = Integer.toString(CommonConstants.Helix.DEFAULT_BROKER_QUERY_PORT);

  @Option(name = "-query", required = true, metaVar = "<string>", usage = "Query string to perform.")
  private String _query;

  @Option(name = "-help", required = false, help = true, aliases = {"-h", "--h", "--help"}, usage = "Print this message.")
  private boolean _help = false;

  @Override
  public boolean getHelp() {
    return _help;
  }

  @Override
  public String getName() {
    return "PostQuery";
  }

  @Override
  public String toString() {
    return ("PostQuery -brokerHost " + _brokerHost + " -brokerPort " + _brokerPort + " -query " + _query);
  }

  @Override
  public void cleanup() {

  }

  @Override
  public String description() {
    return "Query the uploaded Pinot segments.";
  }

  public PostQueryCommand setBrokerHost(String host) {
    _brokerHost = host;
    return this;
  }

  public PostQueryCommand setBrokerPort(String port) {
    _brokerPort = port;
    return this;
  }

  public PostQueryCommand setQuery(String query) {
    _query = query;
    return this;
  }

  public String run()
      throws Exception {
    if (_brokerHost == null) {
      _brokerHost = NetUtil.getHostAddress();
    }
    LOGGER.info("Executing command: " + toString());

    String request = JsonUtils.objectToString(Collections.singletonMap("pql", _query));
    return sendPostRequest("http://" + _brokerHost + ":" + _brokerPort + "/query", request);
  }

  @Override
  public boolean execute()
      throws Exception {
    String result = run();
    LOGGER.info("Result: " + result);
    return true;
  }
}

@@ -933,16 +933,85 @@
 stants;%0A
+import org.apache.pinot.common.utils.CommonConstants.Broker.Request;%0A
 import o
@@ -1050,16 +1050,16 @@
 nUtils;%0A
-
 import o
@@ -1748,24 +1748,172 @@
 ERY_PORT);%0A%0A
+  @Option(name = %22-queryType%22, required = false, metaVar = %22%3Cstring%3E%22, usage = %22Query use sql or pql.%22)%0A  private String _queryType = Request.PQL;%0A%0A
   @Option(na
@@ -2445,16 +2445,46 @@
 Port + %22
+ -queryType %22 + _queryType + %22
  -query 
@@ -2837,32 +2837,141 @@
 turn this;%0A  %7D%0A%0A
+  public PostQueryCommand setQueryType(String queryType) %7B%0A    _queryType = queryType;%0A    return this;%0A  %7D%0A%0A
   public PostQue
@@ -3256,63 +3256,249 @@
 t = 
-JsonUtils.objectToString(Collections.singletonMap(%22pql%22
+null;%0A    if (_queryType.toLowerCase().equals(Request.SQL)) %7B%0A      request = JsonUtils.objectToString(Collections.singletonMap(Request.SQL, _query));%0A    %7D else %7B%0A      request = JsonUtils.objectToString(Collections.singletonMap(Request.PQL
 , _q
@@ -3501,24 +3501,31 @@
 , _query));%0A
+    %7D%0A%0A
     return s

Add sql query command (#4726)