[AMBARI-24171] Fix issues in AMS aggregation and writes. (#1603)

* [AMBARI-24171] Fix issues in AMS aggregation and writes.

* [AMBARI-24171] Fix issues in AMS aggregation and writes - 2
6 files changed