-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Update Iceberg table statistics on inserts #15441
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
Changes from all commits
3afebac
caa5ef3
114853e
c798729
047c1ed
adaffe6
b502bd9
87d7343
fb405ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * Licensed 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 io.trino.plugin.base.io; | ||
|
|
||
| import java.nio.ByteBuffer; | ||
|
|
||
| import static com.google.common.base.Preconditions.checkArgument; | ||
|
|
||
| public final class ByteBuffers | ||
| { | ||
| private ByteBuffers() {} | ||
|
|
||
| /** | ||
| * Gets the bytes the provided {@link ByteBuffer} wraps, without advancing buffer position. | ||
| * Throws when provided buffer does not directly wrap bytes. | ||
| */ | ||
| public static byte[] getWrappedBytes(ByteBuffer byteBuffer) | ||
| { | ||
| checkArgument(byteBuffer.hasArray(), "buffer does not have array"); | ||
| checkArgument(byteBuffer.arrayOffset() == 0, "buffer has non-zero array offset: %s", byteBuffer.arrayOffset()); | ||
| checkArgument(byteBuffer.position() == 0, "buffer has been repositioned to %s", byteBuffer.position()); | ||
| byte[] array = byteBuffer.array(); | ||
| checkArgument(byteBuffer.remaining() == array.length, "buffer has %s remaining bytes while array length is %s", byteBuffer.remaining(), array.length); | ||
| return array; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the bytes the provided {@link ByteBuffer} represents, without advancing buffer position. | ||
| * The returned byte array may be shared with the buffer. | ||
| */ | ||
| public static byte[] getBytes(ByteBuffer byteBuffer) | ||
| { | ||
| if (byteBuffer.hasArray() && byteBuffer.arrayOffset() == 0 && byteBuffer.position() == 0) { | ||
| byte[] array = byteBuffer.array(); | ||
| if (byteBuffer.remaining() == array.length) { | ||
| return array; | ||
| } | ||
| } | ||
|
|
||
| byte[] bytes = new byte[byteBuffer.remaining()]; | ||
| byteBuffer.asReadOnlyBuffer().get(bytes); | ||
| return bytes; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * Licensed 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 io.trino.plugin.base.io; | ||
|
|
||
| import org.testng.annotations.Test; | ||
|
|
||
| import java.nio.ByteBuffer; | ||
|
|
||
| import static io.trino.plugin.base.io.ByteBuffers.getWrappedBytes; | ||
| import static org.testng.Assert.assertEquals; | ||
|
|
||
| public class TestByteBuffers | ||
| { | ||
| @Test | ||
| public void testGetWrappedBytes() | ||
| { | ||
| ByteBuffer buffer = ByteBuffer.wrap(new byte[] {0, 1, 2, 3}); | ||
| assertEquals(getWrappedBytes(buffer), new byte[] {0, 1, 2, 3}, "getWrappedBytes"); | ||
|
|
||
| // Assert the buffer position hasn't changed | ||
| assertEquals(buffer.position(), 0, "position"); | ||
| assertEquals(getWrappedBytes(buffer), new byte[] {0, 1, 2, 3}, "getWrappedBytes again"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* | ||
| * Licensed 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 io.trino.plugin.iceberg; | ||
|
|
||
| import com.google.common.collect.ImmutableMap; | ||
| import org.apache.datasketches.theta.CompactSketch; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| public record CollectedStatistics(Map<Integer, CompactSketch> ndvSketches) | ||
| { | ||
| public CollectedStatistics | ||
| { | ||
| ndvSketches = ImmutableMap.copyOf(requireNonNull(ndvSketches, "ndvSketches is null")); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,7 @@ public class IcebergConfig | |
| public static final int FORMAT_VERSION_SUPPORT_MAX = 2; | ||
| public static final String EXTENDED_STATISTICS_CONFIG = "iceberg.extended-statistics.enabled"; | ||
| public static final String EXTENDED_STATISTICS_DESCRIPTION = "Enable collection (ANALYZE) and use of extended statistics."; | ||
| public static final String COLLECT_EXTENDED_STATISTICS_ON_WRITE_DESCRIPTION = "Collect extended statistics during writes"; | ||
| public static final String EXPIRE_SNAPSHOTS_MIN_RETENTION = "iceberg.expire_snapshots.min-retention"; | ||
| public static final String REMOVE_ORPHAN_FILES_MIN_RETENTION = "iceberg.remove_orphan_files.min-retention"; | ||
|
|
||
|
|
@@ -58,6 +59,7 @@ public class IcebergConfig | |
| private Duration dynamicFilteringWaitTimeout = new Duration(0, SECONDS); | ||
| private boolean tableStatisticsEnabled = true; | ||
| private boolean extendedStatisticsEnabled = true; | ||
| private boolean collectExtendedStatisticsOnWrite = true; | ||
| private boolean projectionPushdownEnabled = true; | ||
| private boolean registerTableProcedureEnabled; | ||
| private Optional<String> hiveCatalogName = Optional.empty(); | ||
|
|
@@ -202,6 +204,19 @@ public IcebergConfig setExtendedStatisticsEnabled(boolean extendedStatisticsEnab | |
| return this; | ||
| } | ||
|
|
||
| public boolean isCollectExtendedStatisticsOnWrite() | ||
| { | ||
| return collectExtendedStatisticsOnWrite; | ||
| } | ||
|
|
||
| @Config("iceberg.extended-statistics.collect-on-write") | ||
| @ConfigDescription(COLLECT_EXTENDED_STATISTICS_ON_WRITE_DESCRIPTION) | ||
| public IcebergConfig setCollectExtendedStatisticsOnWrite(boolean collectExtendedStatisticsOnWrite) | ||
|
||
| { | ||
| this.collectExtendedStatisticsOnWrite = collectExtendedStatisticsOnWrite; | ||
| return this; | ||
| } | ||
|
|
||
| public boolean isProjectionPushdownEnabled() | ||
| { | ||
| return projectionPushdownEnabled; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.