Your problem is that you could be charged with perjury or giving a false statement under oath. If you change your story in court the DA will impeach you with your original statement. The DA will argue to the jury that your original statement was true and that you only changed your testimony to help you friend. Most of the damage has been done based on the original statement.
You need to consult with an attorney because if your original statement was factually not true, you could plead the 5th Amendment against self incrimination at trial. The DA when then have to give you immunity for your testimony. Once you received immunity you could tell the truth without the fear of getting in trouble. Make sure you have an attorney when you do this because if you don't get the right type of immunity you could still be prosecuted.
This is a general discussion of legal principles by a California lawyer and does not create an attorney/client relationship. This is not intended to be legal advice in your specific case. It's impossible to give detailed, accurate advice based on a few sentences on a website. You should always seek advice from an attorney licensed in your jurisdiction who can give you an informed opinion after reviewing all of the relevant information in your case.
It is highly unlikely that you will be charged with perjury. As a potential victim of a sex crime California law gives you added protections. You should consult with an attorney to explore your options and examine the details. It is possible that you might be able to avoid testifying altogether rather than testifying that the allegations are not true.