Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Add KLL Datasketch and Hive ColumnStatisticsObj as standard blo… #8202

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ private StandardBlobTypes() {}
*/
public static final String APACHE_DATASKETCHES_THETA_V1 = "apache-datasketches-theta-v1";

/**
* A serialized form of Hive column stats object. The full list of available stats are provided in
* the <a
* href="https://cwiki.apache.org/confluence/display/Hive/StatsDev#StatsDev-ColumnStatistics">Hive
* columns stats wiki </a>
*/
public static final String HIVE_COLUMN_STATS_OBJ = "hive-column-statistics-obj";

/**
* A serialized form of a KLL sketch produced by the <a
* href="https://datasketches.apache.org/">Apache DataSketches</a> library
*/
public static final String APACHE_DATASKETCHES_KLL_SKETCH = "apache-datasketches-kll-sketch";

/** A serialized deletion vector according to the Iceberg spec */
public static final String DV_V1 = "deletion-vector-v1";
}
17 changes: 17 additions & 0 deletions format/puffin-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,23 @@ for Puffin v1.
[roaring-bitmap-portable-serialization]: https://github.com/RoaringBitmap/RoaringFormatSpec?tab=readme-ov-file#extension-for-64-bit-implementations
[roaring-bitmap-general-layout]: https://github.com/RoaringBitmap/RoaringFormatSpec?tab=readme-ov-file#general-layout

#### `hive-column-statistics-obj` blob type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just FYI that adding changes to the Spec now requires a VOTE on the Dev mailing list in order to increase visibility for spec changes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should I start [DISCUSS] thread first or go ahead with [VOTE]?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can also start with a DISCUSS thread first in order to have a short discussion on the introduced changes


A serialized form of Hive ColumnStatsObject.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is what's referenced here the Thrift ColumnStatisticsObj in the Hive IDL? https://github.com/apache/hive/blob/ffb1165f59defa66b31b4fd9cb6367b71050071b/standalone-metastore/metastore-common/src/main/thrift/hive_metastore.thrift#L583

If so, I'd recommend correcting the name, and linking to the Thrift IDL, and explicitly calling out that this is Thrift-serialized.

I'm also wondering if we need to think about versioning. If this is based on the Thrift IDL, I am not sure if those are intended to be persisted. At the very least, I am concerned if Hive decides to introduce a backwards-incompatible field to this struct, some engines begin to serialize with this newly introduced backwards incompatible field, and other engines begin to attempt to deserialize it with an older IDL, then it will break in the Iceberg library.

Please let me know if I'm misunderstanding anything.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
In hive , we writes the statistics to HMS in addition to puffin files.
So the Thrift ColumnStatisticsObj is used to write the statistics to HMS.

hive-column-statistics-obj referred here is a serialized using the org.apache.commons.lang3.SerializationUtils and stored into puffin file.


The ColumnStatsObject supports Histograms, NDV, Min and Max values, Number of nulls, Number of trues, column name, type.
A full list of supported statistics is listed in the table here:
[ColumnStatistics](https://cwiki.apache.org/confluence/display/Hive/StatsDev#StatsDev-ColumnStatistics)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see much value in adding this.

NDV sketches are already supported using Theta sketches so this would duplicate the purpose of an existing sketch. Is there sufficient value to justify the difference? This doesn't provide enough context to tell.

In addition, the Iceberg manifest format already covers value count, lower bounds, upper bounds, number of nulls, and number of NaNs. The partition statistics files provide a way to aggregate those beyond the file level, and we use snapshot summaries for table-level stats. I'm not sure what value this would provide.

Copy link
Member

@deniskuzZ deniskuzZ Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @rdblue,
thanks for checking this PR!

The partition statistics files provide a way to aggregate those beyond the file level
Does iceberg provide build-in support to get an aggregated Column stats? I mean, is there some library/service that generates partition files with an aggregated column stats?
AFAIK we only do this for basic stats : #11216

If yes, could you please point me to the code where is that done? I had an impression that from colstats only NDV is calculated and stored in partition files.

How about:

  1. bitvectors - used to improve stats estimations for IN operator
  2. histogram - histogram statistics, which are particularly useful for skewed data and range predicates (KLL data sketches)
  3. numTrue/numFalse
  4. avgColLen

Wouldn't it make sense to store in a single puffin file an aggregated partition column stats object per table snapshot with all the values?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @rdblue,
I'm sorry, it seems we had pretty limited knowledge in that area and now I think we finally get your point.
I've drafted a small doc with the proposal and our intent: https://docs.google.com/document/d/11Rp-irqb4L4Qpdxr6l83bA4IRsfw3AAyR8wokNe1r80/edit?usp=sharing
Could you please take a quick look and suggest if that is a valid proposal.
Thank you!


#### `apache-datasketches-KLL-sketch` blob type

A serialized form of a "compact" KLL-sketch produced by the [Apache
DataSketches](https://datasketches.apache.org/) library.
Apache-Datasketches-KLL-sketch is an implementation of a very compact quantiles
sketch with lazy compaction scheme and nearly optimal accuracy per bit.

Histograms are derived from this sketch.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't much to go on. How is the sketch calculated? Does this support a single column or multiple columns?

Copy link
Member

@deniskuzZ deniskuzZ Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

per column: KllSketchUDF(columnName, columnStatsType)
more details: https://issues.apache.org/jira/browse/HIVE-26221


### Compression codecs

The data can also be uncompressed. If it is compressed the codec should be one of
Expand Down