@Override
  protected void doAlteration(Table table, Partition partition) throws HiveException {
    StorageDescriptor sd = getStorageDescriptor(table, partition);
    String serdeName = desc.getSerdeName();
    String oldSerdeName = sd.getSerdeInfo().getSerializationLib();

    // if orc table, restrict changing the serde as it can break schema evolution
    if (AlterTableUtils.isSchemaEvolutionEnabled(table, context.getConf()) &&
        oldSerdeName.equalsIgnoreCase(OrcSerde.class.getName()) &&
        !serdeName.equalsIgnoreCase(OrcSerde.class.getName())) {
      throw new HiveException(ErrorMsg.CANNOT_CHANGE_SERDE, OrcSerde.class.getSimpleName(),
          desc.getDbTableName());
    }

    sd.getSerdeInfo().setSerializationLib(serdeName);
    if (MapUtils.isNotEmpty(desc.getProps())) {
      sd.getSerdeInfo().getParameters().putAll(desc.getProps());
    }

    if (partition == null) {
      if (Table.shouldStoreFieldsInMetastore(context.getConf(), serdeName, table.getParameters())
          && !Table.hasMetastoreBasedSchema(context.getConf(), oldSerdeName)) {
        // If new SerDe needs to store fields in metastore, but the old serde doesn't, save
        // the fields so that new SerDe could operate. Note that this may fail if some fields
        // from old SerDe are too long to be stored in metastore, but there's nothing we can do.
        try {
          Deserializer oldSerde = HiveMetaStoreUtils.getDeserializer(context.getConf(), table.getTTable(), null,
              false, oldSerdeName);
          table.setFields(Hive.getFieldsFromDeserializer(table.getTableName(), oldSerde, context.getConf()));
        } catch (MetaException ex) {
          throw new HiveException(ex);
        }
      }
    }
  }
Operation process of setting the serde.
ql/src/java/org/apache/hadoop/hive/ql/ddl/table/storage/serde/AlterTableSetSerdeOperation.java