private static List<ConstraintInfo> generateConstraintInfos(ASTNode child, List<String> columnNames,
      ASTNode typeChildForDefault, TokenRewriteStream tokenRewriteStream) throws SemanticException {
    // The ANTLR grammar looks like :
    // 1. KW_CONSTRAINT idfr=identifier KW_PRIMARY KW_KEY pkCols=columnParenthesesList
    //  constraintOptsCreate?
    // -> ^(TOK_PRIMARY_KEY $pkCols $idfr constraintOptsCreate?)
    // when the user specifies the constraint name.
    // 2.  KW_PRIMARY KW_KEY columnParenthesesList
    // constraintOptsCreate?
    // -> ^(TOK_PRIMARY_KEY columnParenthesesList constraintOptsCreate?)
    // when the user does not specify the constraint name.
    // Default values
    String constraintName = null;
    //by default if user hasn't provided any optional constraint properties
    // it will be considered ENABLE and NOVALIDATE and RELY=true
    boolean enable = true;
    boolean validate = false;
    boolean rely = true;
    String checkOrDefaultValue = null;
    int childType = child.getToken().getType();
    for (int i = 0; i < child.getChildCount(); i++) {
      ASTNode grandChild = (ASTNode) child.getChild(i);
      int type = grandChild.getToken().getType();
      if (type == HiveParser.TOK_CONSTRAINT_NAME) {
        constraintName = BaseSemanticAnalyzer.unescapeIdentifier(grandChild.getChild(0).getText().toLowerCase());
      } else if (type == HiveParser.TOK_ENABLE) {
        enable = true;
        // validate is false by default if we enable the constraint
        // TODO: A constraint like NOT NULL could be enabled using ALTER but VALIDATE remains
        //  false in such cases. Ideally VALIDATE should be set to true to validate existing data
        validate = false;
      } else if (type == HiveParser.TOK_DISABLE) {
        enable = false;
        // validate is false by default if we disable the constraint
        validate = false;
        rely = false;
      } else if (type == HiveParser.TOK_VALIDATE) {
        validate = true;
      } else if (type == HiveParser.TOK_NOVALIDATE) {
        validate = false;
      } else if (type == HiveParser.TOK_RELY) {
        rely = true;
      } else if (type == HiveParser.TOK_NORELY) {
        rely = false;
      } else if (childType == HiveParser.TOK_DEFAULT_VALUE) {
        // try to get default value only if this is DEFAULT constraint
        checkOrDefaultValue = getDefaultValue(grandChild, typeChildForDefault, tokenRewriteStream);
      } else if (childType == HiveParser.TOK_CHECK_CONSTRAINT) {
        UnparseTranslator unparseTranslator = HiveUtils.collectUnescapeIdentifierTranslations(grandChild);
        unparseTranslator.applyTranslations(tokenRewriteStream, CHECK_CONSTRAINT_PROGRAM);
        checkOrDefaultValue = tokenRewriteStream.toString(CHECK_CONSTRAINT_PROGRAM, grandChild.getTokenStartIndex(),
            grandChild.getTokenStopIndex());
      }
    }

    // metastore schema only allows maximum 255 for constraint name column
    if (constraintName != null && constraintName.length() > CONSTRAINT_MAX_LENGTH) {
      throw new SemanticException(ErrorMsg.INVALID_CSTR_SYNTAX.getMsg("Constraint name: " + constraintName +
          " exceeded maximum allowed length: " + CONSTRAINT_MAX_LENGTH));
    }

    // metastore schema only allows maximum 255 for constraint value column
    if (checkOrDefaultValue!= null && checkOrDefaultValue.length() > CONSTRAINT_MAX_LENGTH) {
      throw new SemanticException(ErrorMsg.INVALID_CSTR_SYNTAX.getMsg("Constraint value: " + checkOrDefaultValue +
          " exceeded maximum allowed length: " + CONSTRAINT_MAX_LENGTH));
    }

    // NOT NULL constraint could be enforced/enabled
    if (enable && childType != HiveParser.TOK_NOT_NULL && childType != HiveParser.TOK_DEFAULT_VALUE &&
        childType != HiveParser.TOK_CHECK_CONSTRAINT) {
      throw new SemanticException(ErrorMsg.INVALID_CSTR_SYNTAX.getMsg("ENABLE/ENFORCED feature not supported yet. " +
          "Please use DISABLE/NOT ENFORCED instead."));
    }
    if (validate) {
      throw new SemanticException(ErrorMsg.INVALID_CSTR_SYNTAX.getMsg("VALIDATE feature not supported yet. " +
          "Please use NOVALIDATE instead."));
    }

    List<ConstraintInfo> constraintInfos = new ArrayList<>();
    if (columnNames == null) {
      constraintInfos.add(new ConstraintInfo(null, constraintName, enable, validate, rely, checkOrDefaultValue));
    } else {
      for (String columnName : columnNames) {
        constraintInfos.add(new ConstraintInfo(columnName, constraintName, enable, validate, rely,
            checkOrDefaultValue));
      }
    }

    return constraintInfos;
  }
Get the constraint from the AST and populate the cstrInfos with the required information.
@param child  The node with the constraint token
@param columnNames The name of the columns for the primary key
@param typeChildForDefault type of column used for default value type check
ql/src/java/org/apache/hadoop/hive/ql/ddl/table/constraint/ConstraintsUtils.java