Class SourceStatisticsSerializer

java.lang.Object
org.elasticsearch.xpack.esql.datasources.SourceStatisticsSerializer

public final class SourceStatisticsSerializer extends Object
Serializes and deserializes SourceStatistics to/from a flat Map<String, Object> using well-known keys. This allows statistics to flow through the opaque sourceMetadata map in ExternalSourceExec without requiring new fields or serialization format changes.
  • Field Details

  • Method Details

    • embedStatistics

      public static Map<String,Object> embedStatistics(Map<String,Object> sourceMetadata, SourceStatistics statistics)
      Merges statistics entries into a new map that includes both the original sourceMetadata entries and the serialized statistics. Returns the original map if statistics are absent.
    • extractStatistics

      public static Optional<SourceStatistics> extractStatistics(Map<String,Object> sourceMetadata)
      Extracts statistics from the sourceMetadata map. Returns empty if no statistics keys are present.
    • extractRowCount

      public static OptionalLong extractRowCount(Map<String,Object> sourceMetadata)
      Extracts the row count directly from the sourceMetadata map without constructing a full SourceStatistics object.
    • extractColumnNullCount

      public static OptionalLong extractColumnNullCount(Map<String,Object> sourceMetadata, String columnName)
      Extracts the null count for a specific column directly from the sourceMetadata map.
    • extractColumnMin

      public static Optional<Object> extractColumnMin(Map<String,Object> sourceMetadata, String columnName)
      Extracts the min value for a specific column directly from the sourceMetadata map.
    • extractColumnMax

      public static Optional<Object> extractColumnMax(Map<String,Object> sourceMetadata, String columnName)
      Extracts the max value for a specific column directly from the sourceMetadata map.
    • columnNullCountKey

      public static String columnNullCountKey(String columnName)
      Returns the flat key used for a column's null count statistic.
    • columnMinKey

      public static String columnMinKey(String columnName)
      Returns the flat key used for a column's min statistic.
    • columnMaxKey

      public static String columnMaxKey(String columnName)
      Returns the flat key used for a column's max statistic.
    • resolveEffectiveMetadata

      public static Map<String,Object> resolveEffectiveMetadata(List<? extends ExternalSplit> splits, Map<String,Object> sourceMetadata)
      Resolves the effective metadata for a set of splits. For single-split queries returns the given sourceMetadata directly; for multi-split queries merges per-split statistics from each FileSplit. Returns null if any split is not a FileSplit or if mergeStatistics(java.util.List<java.util.Map<java.lang.String, java.lang.Object>>) cannot produce a valid merged result (e.g. missing or non-numeric row counts).
    • mergeStatistics

      public static Map<String,Object> mergeStatistics(List<Map<String,Object>> splitStats)