Package io.delta.kernel.statistics
Class DataFileStatistics
Object
io.delta.kernel.statistics.DataFileStatistics
Encapsulates statistics for a data file in a Delta Lake table and provides methods to serialize
those stats to JSON with basic physical-type validation. Note that connectors (e.g. Spark, Flink)
are responsible for ensuring the correctness of collected stats, including any necessary string
truncation, prior to constructing this class.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Optional<DataFileStatistics> deserializeFromJson(String json, StructType physicalSchema) Utility method to deserialize statistics from a JSON string with full type information.booleanGet the maximum values of the columns in the data file.Get the minimum values of the columns in the data file.Get the number of nulls of columns in the data file.longGet the number of records in the data file.getNumRecords(String json) Utility method to extract only the numRecords field from a statistics JSON string.Get the tight bounds information for the data file.inthashCode()serializeAsJson(StructType physicalSchema) Serializes the statistics as a JSON string.toString()Returns a new DataFileStatistics instance with tightBounds set to false.
-
Field Details
-
TIMESTAMP_FORMATTER
-
EPOCH
-
-
Constructor Details
-
DataFileStatistics
public DataFileStatistics(long numRecords, Map<Column, Literal> minValues, Map<Column, Literal> maxValues, Map<Column, Long> nullCount, Optional<Boolean> tightBounds) Create a new instance ofDataFileStatistics. The minValues, maxValues, and nullCount are required fields. The tightBounds field is optional - pass Optional.empty() if not specified, Optional.of(true) or Optional.of(false) for explicit values.- Parameters:
numRecords- Number of records in the data file.minValues- Map of column to minimum value of it in the data file. If the data file has all nulls for the column, the value will be null or not present in the map.maxValues- Map of column to maximum value of it in the data file. If the data file has all nulls for the column, the value will be null or not present in the map.nullCount- Map of column to number of nulls in the data file.tightBounds- Optional boolean indicating if bounds are tight (accurate). Pass Optional.empty() if not specified.
-
-
Method Details
-
getNumRecords
Utility method to extract only the numRecords field from a statistics JSON string.- Parameters:
json- Data statistics JSON string to deserialize.- Returns:
- An
Optionalcontaining the numRecords value if present. - Throws:
KernelException- if JSON parsing fails
-
deserializeFromJson
public static Optional<DataFileStatistics> deserializeFromJson(String json, StructType physicalSchema) Utility method to deserialize statistics from a JSON string with full type information. This overloaded version uses the provided schema to correctly parse min/max values and null counts with their appropriate data types.- Parameters:
json- Data statistics JSON string to deserialize.physicalSchema- The physical schema providing type information for columns. Must match the schema used during serialization.- Returns:
- An
Optionalcontaining the deserializedDataFileStatisticsif present. - Throws:
KernelException- if JSON parsing fails or if values don't match expected types
-
getNumRecords
public long getNumRecords()Get the number of records in the data file.- Returns:
- Number of records in the data file.
-
getMinValues
Get the minimum values of the columns in the data file. The map may contain statistics for only a subset of columns in the data file.- Returns:
- Map of column to minimum value of it in the data file.
-
getMaxValues
Get the maximum values of the columns in the data file. The map may contain statistics for only a subset of columns in the data file.- Returns:
- Map of column to minimum value of it in the data file.
-
getNullCount
Get the number of nulls of columns in the data file. The map may contain statistics for only a subset of columns in the data file.- Returns:
- Map of column to number of nulls in the data file.
-
getTightBounds
Get the tight bounds information for the data file. Tight bounds indicate whether the values are guaranteed to be accurate bounds for the data.- Returns:
- The tight bounds boolean value.
-
withoutTightBounds
Returns a new DataFileStatistics instance with tightBounds set to false. This is useful when the statistics bounds are no longer guaranteed to be tight, such as after applying deletion vectors.- Returns:
- A new DataFileStatistics with tightBounds set to false
-
serializeAsJson
Serializes the statistics as a JSON string.Example: For nested column structures:
Input: minValues = { new Column(new String[]{"a", "b", "c"}) mapped to Literal.ofInt(10), new Column("d") mapped to Literal.ofString("value") } Output JSON: { "minValues": { "a": { "b": { "c": 10 } }, "d": "value" } }- Parameters:
physicalSchema- the optional physical schema. If provided, all min/max values and null counts will be included and validated against their physical types. If null, only numRecords will be serialized without validation.- Returns:
- a JSON representation of the statistics.
- Throws:
KernelException- if dataSchema is provided and there's a type mismatch between the Literal values and the expected types in the schema, or if an unsupported data type is found.
-
equals
-
hashCode
public int hashCode() -
toString
-