private String getSortOrderJson(ASTNode ast) {
    List<SortFieldDesc> sortFieldDescList = new ArrayList<>();
    SortFields sortFields = new SortFields(sortFieldDescList);
    for (int i = 0; i < ast.getChildCount(); i++) {
      ASTNode child = (ASTNode) ast.getChild(i);
      SortFieldDesc.SortDirection sortDirection = child.getToken()
          .getType() == HiveParser.TOK_TABSORTCOLNAMEDESC ? SortFieldDesc.SortDirection.DESC : SortFieldDesc.SortDirection.ASC;
      child = (ASTNode) child.getChild(0);
      String name = unescapeIdentifier(child.getChild(0).getText()).toLowerCase();
      NullOrdering nullOrder = NullOrdering.fromToken(child.getToken().getType());
      sortFieldDescList.add(new SortFieldDesc(name, sortDirection, nullOrder));
    }
    try {
      return JSON_OBJECT_MAPPER.writer().writeValueAsString(sortFields);
    } catch (JsonProcessingException e) {
      LOG.warn("Can not create write order json. ", e);      
      return null;
    }
  }
Append list of partition columns to Insert statement. If user specified partition spec, then
use it to get/set the value for partition column else use dynamic partition mode with no value.
Static partition mode:
INSERT INTO T PARTITION(partCol1=val1,partCol2...) SELECT col1, ... partCol1,partCol2...
Dynamic partition mode:
INSERT INTO T PARTITION(partCol1,partCol2...) SELECT col1, ... partCol1,partCol2...
ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java