use of io.trino.tpch.Nation in project trino by trinodb.
the class TestOrcPageSourceFactory method readFile.
private static List<Nation> readFile(Map<NationColumn, Integer> columns, OptionalLong nationKeyPredicate, Optional<AcidInfo> acidInfo, String filePath, long fileSize) {
TupleDomain<HiveColumnHandle> tupleDomain = TupleDomain.all();
if (nationKeyPredicate.isPresent()) {
tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of(toHiveColumnHandle(NATION_KEY, 0), Domain.singleValue(INTEGER, nationKeyPredicate.getAsLong())));
}
List<HiveColumnHandle> columnHandles = columns.entrySet().stream().map(entry -> toHiveColumnHandle(entry.getKey(), entry.getValue())).collect(toImmutableList());
List<String> columnNames = columnHandles.stream().map(HiveColumnHandle::getName).collect(toImmutableList());
Optional<ReaderPageSource> pageSourceWithProjections = PAGE_SOURCE_FACTORY.createPageSource(new JobConf(new Configuration(false)), SESSION, new Path(filePath), 0, fileSize, fileSize, createSchema(), columnHandles, tupleDomain, acidInfo, OptionalInt.empty(), false, NO_ACID_TRANSACTION);
checkArgument(pageSourceWithProjections.isPresent());
checkArgument(pageSourceWithProjections.get().getReaderColumns().isEmpty(), "projected columns not expected here");
ConnectorPageSource pageSource = pageSourceWithProjections.get().get();
int nationKeyColumn = columnNames.indexOf("n_nationkey");
int nameColumn = columnNames.indexOf("n_name");
int regionKeyColumn = columnNames.indexOf("n_regionkey");
int commentColumn = columnNames.indexOf("n_comment");
ImmutableList.Builder<Nation> rows = ImmutableList.builder();
while (!pageSource.isFinished()) {
Page page = pageSource.getNextPage();
if (page == null) {
continue;
}
page = page.getLoadedPage();
for (int position = 0; position < page.getPositionCount(); position++) {
long nationKey = -42;
if (nationKeyColumn >= 0) {
nationKey = BIGINT.getLong(page.getBlock(nationKeyColumn), position);
}
String name = "<not read>";
if (nameColumn >= 0) {
name = VARCHAR.getSlice(page.getBlock(nameColumn), position).toStringUtf8();
}
long regionKey = -42;
if (regionKeyColumn >= 0) {
regionKey = BIGINT.getLong(page.getBlock(regionKeyColumn), position);
}
String comment = "<not read>";
if (commentColumn >= 0) {
comment = VARCHAR.getSlice(page.getBlock(commentColumn), position).toStringUtf8();
}
rows.add(new Nation(position, nationKey, name, regionKey, comment));
}
}
return rows.build();
}
use of io.trino.tpch.Nation in project trino by trinodb.
the class TestOrcPageSourceFactory method assertEqualsByColumns.
private static void assertEqualsByColumns(Set<NationColumn> columns, List<Nation> actualRows, List<Nation> expectedRows) {
assertEquals(actualRows.size(), expectedRows.size(), "row count");
for (int i = 0; i < actualRows.size(); i++) {
Nation actual = actualRows.get(i);
Nation expected = expectedRows.get(i);
assertEquals(actual.getNationKey(), columns.contains(NATION_KEY) ? expected.getNationKey() : -42);
assertEquals(actual.getName(), columns.contains(NAME) ? expected.getName() : "<not read>");
assertEquals(actual.getRegionKey(), columns.contains(REGION_KEY) ? expected.getRegionKey() : -42);
assertEquals(actual.getComment(), columns.contains(COMMENT) ? expected.getComment() : "<not read>");
}
}
use of io.trino.tpch.Nation in project trino by trinodb.
the class TestOrcPageSourceFactory method testFullFileReadOriginalFilesTable.
@Test
public void testFullFileReadOriginalFilesTable() throws Exception {
File tableFile = new File(getResource("fullacidNationTableWithOriginalFiles/000000_0").toURI());
String tablePath = tableFile.getParent();
AcidInfo acidInfo = AcidInfo.builder(new Path(tablePath)).addDeleteDelta(new Path(tablePath, deleteDeltaSubdir(10000001, 10000001, 0))).addOriginalFile(new Path(tablePath, "000000_0"), 1780, 0).setOrcAcidVersionValidated(true).buildWithRequiredOriginalFiles(0);
List<Nation> expected = expectedResult(OptionalLong.empty(), nationKey -> nationKey == 24, 1);
List<Nation> result = readFile(ALL_COLUMNS, OptionalLong.empty(), Optional.of(acidInfo), tablePath + "/000000_0", 1780);
assertEquals(result.size(), expected.size());
int deletedRowKey = 24;
String deletedRowNameColumn = "UNITED STATES";
assertFalse(result.stream().anyMatch(acidNationRow -> acidNationRow.getName().equals(deletedRowNameColumn) && acidNationRow.getNationKey() == deletedRowKey), "Deleted row shouldn't be present in the result");
}
use of io.trino.tpch.Nation in project trino by trinodb.
the class TestOrcPageSourceFactory method testReadWithAcidVersionValidationHive3.
@Test
public void testReadWithAcidVersionValidationHive3() throws Exception {
File tableFile = new File(getResource("acid_version_validation/acid_version_hive_3/00000_0").toURI());
String tablePath = tableFile.getParent();
Optional<AcidInfo> acidInfo = AcidInfo.builder(new Path(tablePath)).setOrcAcidVersionValidated(false).build();
List<Nation> result = readFile(Map.of(), OptionalLong.empty(), acidInfo, tableFile.getPath(), 625);
assertEquals(result.size(), 1);
}
Aggregations