Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
65 changes: 65 additions & 0 deletions api/src/main/java/org/apache/iceberg/PartitionStatistics.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.iceberg;

/** Interface for partition statistics returned from a {@link PartitionStatisticsScan}. */
public interface PartitionStatistics extends StructLike {

/** Returns the partition of these partition statistics */
StructLike partition();

/** Returns the spec ID of the partition of these partition statistics */
Integer specId();

/** Returns the number of data records in the partition */
Long dataRecordCount();

/** Returns the number of data files in the partition */
Integer dataFileCount();

/** Returns the total size of data files in bytes in the partition */
Long totalDataFileSizeInBytes();

/**
* Returns the number of positional delete records in the partition. Also includes dv record count
* as per spec
*/
Long positionDeleteRecordCount();

/** Returns the number of positional delete files in the partition */
Integer positionDeleteFileCount();

/** Returns the number of equality delete records in the partition */
Long equalityDeleteRecordCount();

/** Returns the number of equality delete files in the partition */
Integer equalityDeleteFileCount();

/** Returns the total number of records in the partition */
Long totalRecords();

/** Returns the timestamp in milliseconds when the partition was last updated */
Long lastUpdatedAt();

/** Returns the ID of the snapshot that last updated this partition */
Long lastUpdatedSnapshotId();

/** Returns the number of delete vectors in the partition */
Integer dvCount();
}
59 changes: 59 additions & 0 deletions api/src/main/java/org/apache/iceberg/PartitionStatisticsScan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.iceberg;

import org.apache.iceberg.expressions.Expression;
import org.apache.iceberg.io.CloseableIterable;

/** API for configuring partition statistics scan. */
public interface PartitionStatisticsScan {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe at lease a oneliner javadoc

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done


/**
* Create a new scan from this scan's configuration that will use the given snapshot by ID.
*
* @param snapshotId a snapshot ID
* @return a new scan based on this with the given snapshot ID
* @throws IllegalArgumentException if the snapshot cannot be found
*/
PartitionStatisticsScan useSnapshot(long snapshotId);

/**
* Create a new scan from the results of this, where partitions are filtered by the {@link
* Expression}.
*
* @param filter a filter expression
* @return a new scan based on this with results filtered by the expression
*/
PartitionStatisticsScan filter(Expression filter);

/**
* Create a new scan from this with the schema as its projection.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe describe what will happen with the PartitionStatistics attributes which are not part of the schema.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank for pointing this out! My initial plan was to always query the 'traditional' partition stats and allow projection for the column-based once when we introduce them later. But it makes sense to project also the existing ones, and then the current design with PartitionStatistics isn't suitable for that. Let me wrap my head around this and come back with a different design that can tackle this too.

*
* @param schema a projection schema
Copy link
Contributor

Choose a reason for hiding this comment

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

How does the user create the Schema?

I would prefer something like the DataFile where the possible columns are available as constants, and the type is available as well. Maybe copy/move/deprecate the schema from the old place.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're right. Let me add this to the possible follow-up steps in my comment at the top

* @return a new scan based on this with the given projection
*/
PartitionStatisticsScan project(Schema schema);

/**
* Scans a partition statistics file belonging to a particular snapshot
*
* @return an Iterable of partition statistics
*/
CloseableIterable<PartitionStatistics> scan();
}
12 changes: 12 additions & 0 deletions api/src/main/java/org/apache/iceberg/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ default IncrementalChangelogScan newIncrementalChangelogScan() {
throw new UnsupportedOperationException("Incremental changelog scan is not supported");
}

/**
* Create a new {@link PartitionStatisticsScan} for this table.
*
* <p>Once a partition statistics scan is created, it can be refined to project columns and filter
* data.
*
* @return a partition statistics scan for this table
*/
default PartitionStatisticsScan newPartitionStatisticsScan() {
throw new UnsupportedOperationException("Partition statistics scan is not supported");
}

/**
* Return the {@link Schema schema} for this table.
*
Expand Down
Loading