Class FacetCountingUtils

java.lang.Object
com.linkedin.venice.client.store.FacetCountingUtils

public class FacetCountingUtils extends Object
This class provides shared implementation for processing values and counting field occurrences that can be used by thin-client, fast-client, and server components.
  • Constructor Details

    • FacetCountingUtils

      public FacetCountingUtils()
  • Method Details

    • getValueToCount

      public static <T> Map<T,Integer> getValueToCount(Iterable<? extends org.apache.avro.generic.GenericRecord> records, String field, int topK)
      Get value counts for a single field with TopK filtering. This is the original logic from AvroComputeAggregationResponse.getValueToCount() moved to Utils.
      Parameters:
      records - Collection of GenericRecord results (supports both ComputeGenericRecord and server GenericRecord)
      field - The field name to count
      topK - Maximum number of top values to return
      Returns:
      Map of values to their counts, limited to topK entries
    • getBucketNameToCount

      public static Map<String,Integer> getBucketNameToCount(Iterable<? extends org.apache.avro.generic.GenericRecord> records, String fieldName, Map<String,Predicate> buckets)
      Get bucket counts for a single field with predicate-based bucketing. This is the original logic from AvroComputeAggregationResponse.getBucketNameToCount() moved to Utils.
      Parameters:
      records - Collection of GenericRecord results (supports both ComputeGenericRecord and server GenericRecord)
      fieldName - The field name to count
      buckets - Map of bucket names to their predicates
      Returns:
      Map of bucket names to their counts
    • convertToType

      public static <T> T convertToType(Object value, Class<T> targetType)
      Generic method to convert value to the target type for predicate evaluation. Supports Integer, Long, Float, and Double conversions.
    • validateFieldNames

      public static void validateFieldNames(String[] fieldNames, org.apache.avro.Schema valueSchema)
      Validate field names exist in schema (generic version for both clients).
      Parameters:
      fieldNames - Array of field names to validate
      valueSchema - The schema to validate against
      Throws:
      IllegalArgumentException - if validation fails