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
30 changes: 30 additions & 0 deletions core/trino-main/src/main/java/io/trino/testing/DataProviders.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@
*/
package io.trino.testing;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import org.testng.annotations.DataProvider;

import java.util.Arrays;
import java.util.stream.Collector;
import java.util.stream.Stream;

import static com.google.common.collect.ImmutableList.toImmutableList;
import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.mapping;
import static java.util.stream.Collectors.toList;
Expand All @@ -39,4 +44,29 @@ public static Object[][] trueFalse()
{
return new Object[][] {{true}, {false}};
}

/**
* @return Full cartesian product of arguments, i.e. cartesianProduct({{A, B}}, {{1,2}}) will produce {{A,1}, {A,2}, {B,1}, {B,2}}
*/
public static Object[][] cartesianProduct(Object[][]... args)
{
return Lists.cartesianProduct(Arrays.stream(args)
.map(ImmutableList::copyOf)
.collect(toImmutableList()))
.stream()
.map(list -> list.stream()
.flatMap(Stream::of)
.toArray(Object[]::new))
.toArray(Object[][]::new);
}

/**
* @return args concatenated together into a single Object[][]
*/
public static Object[][] concat(Object[][]... args)
{
return Arrays.stream(args)
.flatMap(Arrays::stream)
.toArray(Object[][]::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package io.trino.parquet.reader;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import io.airlift.slice.Slices;
import io.trino.parquet.DataPage;
import io.trino.parquet.DataPageV2;
Expand All @@ -34,7 +33,6 @@
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
Expand All @@ -45,10 +43,13 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier;
import java.util.stream.LongStream;
import java.util.stream.Stream;

import static com.google.common.collect.ImmutableList.toImmutableList;
import static io.trino.parquet.ParquetEncoding.PLAIN;
import static io.trino.spi.type.IntegerType.INTEGER;
import static io.trino.testing.DataProviders.cartesianProduct;
import static io.trino.testing.DataProviders.concat;
import static io.trino.testing.DataProviders.toDataProvider;
import static java.lang.Math.toIntExact;
import static java.util.Objects.requireNonNull;
import static org.apache.parquet.hadoop.metadata.CompressionCodecName.UNCOMPRESSED;
Expand Down Expand Up @@ -115,29 +116,33 @@ public void testReadFilteredPage(
@DataProvider
public Object[][] testRowRangesProvider()
{
Object[] columnReaders = ColumnReaderInput.values();
Object[] batchSkippers = BatchSkipper.values();
Object[] rowRanges = new Object[] {
Optional.empty(),
Optional.of(toRowRange(1024)),
Optional.of(toRowRange(956)),
Optional.of(toRowRanges(range(101, 900))),
Optional.of(toRowRanges(range(56, 89), range(120, 250), range(300, 455), range(600, 980)))
};
Object[] pageRowRanges = new Object[] {
ImmutableList.of(range(0, 1023)),
ImmutableList.of(range(0, 127), range(128, 1023)),
ImmutableList.of(range(0, 767), range(768, 1023)),
ImmutableList.of(range(0, 255), range(256, 511), range(512, 767), range(768, 1023)),
ImmutableList.of(range(0, 99), range(100, 199), range(200, 399), range(400, 599), range(600, 799), range(800, 999), range(1000, 1023))
};
Object[][] columnReaders = Stream.of(ColumnReaderInput.values())
.collect(toDataProvider());
Object[][] batchSkippers = Stream.of(BatchSkipper.values())
.collect(toDataProvider());
Object[][] rowRanges = Stream.of(
Optional.empty(),
Optional.of(toRowRange(1024)),
Optional.of(toRowRange(956)),
Optional.of(toRowRanges(range(101, 900))),
Optional.of(toRowRanges(range(56, 89), range(120, 250), range(300, 455), range(600, 980))))
.collect(toDataProvider());
Object[][] pageRowRanges = Stream.of(
ImmutableList.of(range(0, 1023)),
ImmutableList.of(range(0, 127), range(128, 1023)),
ImmutableList.of(range(0, 767), range(768, 1023)),
ImmutableList.of(range(0, 255), range(256, 511), range(512, 767), range(768, 1023)),
ImmutableList.of(range(0, 99), range(100, 199), range(200, 399), range(400, 599), range(600, 799), range(800, 999), range(1000, 1023)))
.collect(toDataProvider());
Object[][] rangesWithNoPageSkipped = cartesianProduct(columnReaders, batchSkippers, rowRanges, pageRowRanges);
Object[][] rangesWithPagesSkipped = cartesianProduct(
columnReaders,
batchSkippers,
new Object[] {Optional.of(toRowRanges(range(56, 80), range(120, 200), range(350, 455), range(600, 940)))},
new Object[] {ImmutableList.of(range(50, 100), range(120, 275), range(290, 455), range(590, 800), range(801, 1000))});
return combine(rangesWithNoPageSkipped, rangesWithPagesSkipped);
Stream.of(Optional.of(toRowRanges(range(56, 80), range(120, 200), range(350, 455), range(600, 940))))
.collect(toDataProvider()),
Stream.of(ImmutableList.of(range(50, 100), range(120, 275), range(290, 455), range(590, 800), range(801, 1000)))
.collect(toDataProvider()));
return concat(rangesWithNoPageSkipped, rangesWithPagesSkipped);
}

private enum ColumnReaderInput
Expand Down Expand Up @@ -282,27 +287,4 @@ private static int pagesRowCount(List<RowRange> pageRowRanges)
.mapToInt(range -> toIntExact(range.getEnd() - range.getStart() + 1))
.sum();
}

/**
* @return Full cartesian product of arguments, i.e cartesianProduct({A, B}, {1,2}) will produce {{A,1}, {A,2}, {B,1}, {B,2}}
*/
private static Object[][] cartesianProduct(Object[]... args)
{
return Lists.cartesianProduct(Arrays.stream(args)
.map(ImmutableList::copyOf)
.collect(toImmutableList()))
.stream()
.map(list -> list.toArray(Object[]::new))
.toArray(Object[][]::new);
}

/**
* @return args concatenated together into a single Object[][]
*/
private static Object[][] combine(Object[][]... args)
{
return Arrays.stream(args)
.flatMap(Arrays::stream)
.toArray(Object[][]::new);
}
}
Loading