@Override
  public int execute() throws HiveException {
    // Get the existing table
    Table oldTable = context.getDb().getTable(desc.getLikeTableName());
    Table tbl;
    if (oldTable.getTableType() == TableType.VIRTUAL_VIEW || oldTable.getTableType() == TableType.MATERIALIZED_VIEW) {
      tbl = createViewLikeTable(oldTable);
    } else {
      Map<String, String> originalProperties = new HashMap<>();
      // Get the storage handler without caching, since the storage handler can get changed when copying the
      // properties of the target table and
      if (oldTable.getStorageHandlerWithoutCaching() != null) {
        originalProperties = new HashMap<>(oldTable.getStorageHandlerWithoutCaching().getNativeProperties(oldTable));
      }
      tbl = createTableLikeTable(oldTable, originalProperties);
    }

    // If location is specified - ensure that it is a full qualified name
    if (CreateTableOperation.doesTableNeedLocation(tbl)) {
      CreateTableOperation.makeLocationQualified(tbl, context.getConf());
    }

    if (desc.getLocation() == null && !tbl.isPartitioned() &&
        context.getConf().getBoolVar(HiveConf.ConfVars.HIVE_STATS_AUTOGATHER)) {
      StatsSetupConst.setStatsStateForCreateTable(tbl.getTTable().getParameters(),
          MetaStoreUtils.getColumnNames(tbl.getCols()), StatsSetupConst.TRUE);
    }

    // create the table
    context.getDb().createTable(tbl, desc.getIfNotExists());
    DDLUtils.addIfAbsentByName(new WriteEntity(tbl, WriteEntity.WriteType.DDL_NO_LOCK), context);
    return 0;
  }
Operation process of creating a table like an existing one.
ql/src/java/org/apache/hadoop/hive/ql/ddl/table/create/like/CreateTableLikeOperation.java