Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ public void testFromUnixTimeWithTimeZone()
assertThat(assertions.function("from_unixtime", "7200", "'Asia/Tokyo'"))
.matches("TIMESTAMP '1970-01-01 11:00:00.000 Asia/Tokyo'");

assertThat(assertions.function("from_unixtime", "7200", "'Europe/Moscow'"))
.matches("TIMESTAMP '1970-01-01 05:00:00.000 Europe/Moscow'");
assertThat(assertions.function("from_unixtime", "7200", "'Europe/Kiev'"))
.matches("TIMESTAMP '1970-01-01 05:00:00.000 Europe/Kiev'");

assertThat(assertions.function("from_unixtime", "7200", "'America/New_York'"))
.matches("TIMESTAMP '1969-12-31 21:00:00.000 America/New_York'");
Expand Down
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
Expand Up @@ -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";

Expand All @@ -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();
Expand Down Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

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

Could you also add information to the documentation ?

Copy link
Member Author

Choose a reason for hiding this comment

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

We also need to document iceberg.extended-statistics.enabled before we document iceberg.extended-statistics.collect-on-write. Let's follow-up

Note that Delta's delta.extended-statistics.collect-on-write isn't documented either, so you may want to document it.

{
this.collectExtendedStatisticsOnWrite = collectExtendedStatisticsOnWrite;
return this;
}

public boolean isProjectionPushdownEnabled()
{
return projectionPushdownEnabled;
Expand Down
Loading