All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openmetadata.service.dataInsight.PageViewsByEntitiesAggregator Maven / Gradle / Ivy

There is a newer version: 1.5.11
Show newest version
package org.openmetadata.service.dataInsight;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import org.openmetadata.schema.dataInsight.type.PageViewsByEntities;

public abstract class PageViewsByEntitiesAggregator
    implements DataInsightAggregatorInterface {
  private final A aggregations;

  protected PageViewsByEntitiesAggregator(A aggregations) {
    this.aggregations = aggregations;
  }

  @Override
  public List aggregate() throws ParseException {
    M timestampBuckets = getTimestampBuckets(this.aggregations);
    List data = new ArrayList<>();
    for (B timestampBucket : getBuckets(timestampBuckets)) {
      String dateTimeString = getKeyAsString(timestampBucket);
      Long timestamp = convertDatTimeStringToTimestamp(dateTimeString);
      M entityTypeBuckets = getEntityBuckets(timestampBucket);
      for (B entityTypeBucket : getBuckets(entityTypeBuckets)) {
        String entityType = getKeyAsString(entityTypeBucket);
        S sumPageViews = getSumAggregations(entityTypeBucket, "pageViews");

        data.add(
            new PageViewsByEntities()
                .withEntityType(entityType)
                .withTimestamp(timestamp)
                .withPageViews(getValue(sumPageViews)));
      }
    }
    return data;
  }

  protected abstract Double getValue(S key);

  protected abstract S getSumAggregations(B bucket, String key);

  protected abstract M getEntityBuckets(B bucket);

  protected abstract String getKeyAsString(B bucket);

  protected abstract List getBuckets(M multiBucketsAggregation);

  protected abstract M getTimestampBuckets(A aggregations);
}