protected ASTNode analyzeCreateView(ASTNode ast, QB qb, PlannerContext plannerCtx) throws SemanticException {
    TableName qualTabName = getQualifiedTableName((ASTNode) ast.getChild(0));
    final String dbDotTable = qualTabName.getNotEmptyDbTable();
    List<FieldSchema> cols = null;
    boolean ifNotExists = false;
    boolean rewriteEnabled = true;
    String comment = null;
    ASTNode selectStmt = null;
    Map<String, String> tblProps = null;
    List<String> partColNames = null;
    List<String> sortColNames = null;
    List<String> distributeColNames = null;
    String location = null;
    RowFormatParams rowFormatParams = new RowFormatParams();
    StorageFormat storageFormat = new StorageFormat(conf);
    boolean partitionTransformSpecExists = false;

    LOG.info("Creating view " + dbDotTable + " position="
        + ast.getCharPositionInLine());
    int numCh = ast.getChildCount();

    // all the CREATE VIEW statements are DDLs (including MV)
    queryProperties.setQueryType(QueryProperties.QueryType.DDL);

    for (int num = 1; num < numCh; num++) {
      ASTNode child = (ASTNode) ast.getChild(num);
      if (storageFormat.fillStorageFormat(child)) {
        continue;
      }
      switch (child.getToken().getType()) {
      case HiveParser.TOK_IFNOTEXISTS:
        ifNotExists = true;
        break;
      case HiveParser.TOK_REWRITE_DISABLED:
        rewriteEnabled = false;
        break;
      case HiveParser.TOK_QUERY:
        // For CBO
        if (plannerCtx != null) {
          plannerCtx.setViewToken(child);
        }
        selectStmt = child;
        break;
      case HiveParser.TOK_TABCOLNAME:
        cols = getColumns(child);
        break;
      case HiveParser.TOK_TABLECOMMENT:
        comment = unescapeSQLString(child.getChild(0).getText());
        break;
      case HiveParser.TOK_TABLEPROPERTIES:
        tblProps = getProps((ASTNode) child.getChild(0));
        break;
      case HiveParser.TOK_VIEWPARTCOLS:
        partColNames = getColumnNames((ASTNode) child.getChild(0));
        break;
      case HiveParser.TOK_VIEWCLUSTERCOLS:
        assert distributeColNames == null && sortColNames == null;
        distributeColNames = getColumnNames((ASTNode) child.getChild(0));
        sortColNames = new ArrayList<>(distributeColNames);
        break;
      case HiveParser.TOK_VIEWDISTRIBUTECOLS:
        assert distributeColNames == null;
        distributeColNames = getColumnNames((ASTNode) child.getChild(0));
        break;
      case HiveParser.TOK_VIEWSORTCOLS:
        assert sortColNames == null;
        sortColNames = getColumnNames((ASTNode) child.getChild(0));
        break;
      case HiveParser.TOK_TABLEROWFORMAT:
        rowFormatParams.analyzeRowFormat(child);
        break;
      case HiveParser.TOK_TABLELOCATION:
        location = unescapeSQLString(child.getChild(0).getText());
        location = EximUtil.relativeToAbsolutePath(conf, location);
        inputs.add(toReadEntity(location));
        break;
      case HiveParser.TOK_TABLESERIALIZER:
        child = (ASTNode) child.getChild(0);
        storageFormat.setSerde(unescapeSQLString(child.getChild(0).getText()));
        if (child.getChildCount() == 2) {
          readProps((ASTNode) (child.getChild(1).getChild(0)),
              storageFormat.getSerdeProps());
        }
        break;
      case HiveParser.TOK_TABLEPARTCOLSBYSPEC:
        SessionStateUtil.addResourceOrThrow(conf, hive_metastoreConstants.PARTITION_TRANSFORM_SPEC,
                PartitionTransform.getPartitionTransformSpec(child));
        partitionTransformSpecExists = true;
        break;
      default:
        assert false;
      }
    }

    validateStorageFormat(storageFormat, tblProps, partitionTransformSpecExists);

    storageFormat.fillDefaultStorageFormat(false, true);

    if (!ifNotExists) {
      // Verify that the table does not already exist
      // dumpTable is only used to check the conflict for non-temporary tables
      try {
        Table dumpTable = db.newTable(dbDotTable);
        if (null != db.getTable(dumpTable.getDbName(), dumpTable.getTableName(), false) &&
            !ctx.isExplainSkipExecution()) {
          throw new SemanticException(ErrorMsg.TABLE_ALREADY_EXISTS.getMsg(dbDotTable));
        }
      } catch (HiveException e) {
        throw new SemanticException(e);
      }
    }
    if (partColNames != null && (distributeColNames != null || sortColNames != null)) {
      // Verify that partition columns and data organization columns are not overlapping
      Set<String> partColNamesSet = new HashSet<>(partColNames);
      if (distributeColNames != null) {
        for (String colName : distributeColNames) {
          if (partColNamesSet.contains(colName)) {
            throw new SemanticException("Same column cannot be present in partition and cluster/distribute clause. "
                + "Column name: " + colName);
          }
        }
      }
      if (sortColNames != null) {
        for (String colName : sortColNames) {
          if (partColNamesSet.contains(colName)) {
            throw new SemanticException("Same column cannot be present in partition and cluster/sort clause. "
                + "Column name: " + colName);
          }
        }
      }
    }

    unparseTranslator.enable();

    if (makeAcid()) {
      if (tblProps == null) {
        tblProps = new HashMap<>();
      }
      tblProps = convertToAcidByDefault(storageFormat, dbDotTable, null, tblProps);
    }
    if (tblProps == null) {
      tblProps = new HashMap<>();
    }
    tblProps.put(hive_metastoreConstants.TABLE_IS_CTAS, "true");

    createVwDesc = new CreateMaterializedViewDesc(
        dbDotTable, cols, comment, tblProps, partColNames, sortColNames, distributeColNames,
        ifNotExists, rewriteEnabled,
        storageFormat.getInputFormat(), storageFormat.getOutputFormat(),
        location, storageFormat.getSerde(), storageFormat.getStorageHandler(),
        storageFormat.getSerdeProps());
    addDbAndTabToOutputs(new String[] {qualTabName.getDb(), qualTabName.getTable()}, TableType.MATERIALIZED_VIEW,
        false, tblProps, storageFormat);
    queryState.setCommandType(HiveOperation.CREATE_MATERIALIZED_VIEW);
    qb.setViewDesc(createVwDesc);

    return selectStmt;
  }
Adds entities for create table/create view.
ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java