use of io.prestosql.testing.MaterializedRow in project hetu-core by openlookeng.
the class AbstractTestHive method testGetPartialRecords.
@Test
public void testGetPartialRecords() throws Exception {
try (Transaction transaction = newTransaction()) {
ConnectorMetadata metadata = transaction.getMetadata();
ConnectorSession session = newSession();
metadata.beginQuery(session);
ConnectorTableHandle tableHandle = getTableHandle(metadata, tablePartitionFormat);
List<ColumnHandle> columnHandles = ImmutableList.copyOf(metadata.getColumnHandles(session, tableHandle).values());
Map<String, Integer> columnIndex = indexColumns(columnHandles);
List<ConnectorSplit> splits = getAllSplits(tableHandle, transaction, session);
assertEquals(splits.size(), tablePartitionFormatPartitions.size());
for (ConnectorSplit split : splits) {
HiveSplit hiveSplit = HiveSplitWrapper.getOnlyHiveSplit(split);
List<HivePartitionKey> partitionKeys = hiveSplit.getPartitionKeys();
String ds = partitionKeys.get(0).getValue();
String fileFormat = partitionKeys.get(1).getValue();
HiveStorageFormat fileType = HiveStorageFormat.valueOf(fileFormat.toUpperCase(ENGLISH));
int dummyPartition = Integer.parseInt(partitionKeys.get(2).getValue());
long rowNumber = 0;
try (ConnectorPageSource pageSource = pageSourceProvider.createPageSource(transaction.getTransactionHandle(), session, split, tableHandle, columnHandles)) {
assertPageSourceType(pageSource, fileType);
MaterializedResult result = materializeSourceDataStream(session, pageSource, getTypes(columnHandles));
for (MaterializedRow row : result) {
rowNumber++;
assertEquals(row.getField(columnIndex.get("t_double")), 6.2 + rowNumber);
assertEquals(row.getField(columnIndex.get("ds")), ds);
assertEquals(row.getField(columnIndex.get("file_format")), fileFormat);
assertEquals(row.getField(columnIndex.get("dummy")), dummyPartition);
}
}
assertEquals(rowNumber, 100);
}
}
}
use of io.prestosql.testing.MaterializedRow in project hetu-core by openlookeng.
the class AbstractTestHive method testBucketedTableStringInt.
@Test
public void testBucketedTableStringInt() throws Exception {
try (Transaction transaction = newTransaction()) {
ConnectorMetadata metadata = transaction.getMetadata();
ConnectorSession session = newSession();
metadata.beginQuery(session);
ConnectorTableHandle tableHandle = getTableHandle(metadata, tableBucketedStringInt);
List<ColumnHandle> columnHandles = ImmutableList.copyOf(metadata.getColumnHandles(session, tableHandle).values());
Map<String, Integer> columnIndex = indexColumns(columnHandles);
assertTableIsBucketed(tableHandle, transaction, session);
String testString = "test";
Integer testInt = 13;
Short testSmallint = 12;
// Reverse the order of bindings as compared to bucketing order
ImmutableMap<ColumnHandle, NullableValue> bindings = ImmutableMap.<ColumnHandle, NullableValue>builder().put(columnHandles.get(columnIndex.get("t_int")), NullableValue.of(INTEGER, (long) testInt)).put(columnHandles.get(columnIndex.get("t_string")), NullableValue.of(createUnboundedVarcharType(), utf8Slice(testString))).put(columnHandles.get(columnIndex.get("t_smallint")), NullableValue.of(SMALLINT, (long) testSmallint)).build();
MaterializedResult result = readTable(transaction, tableHandle, columnHandles, session, TupleDomain.fromFixedValues(bindings), OptionalInt.of(1), Optional.empty());
boolean rowFound = false;
for (MaterializedRow row : result) {
if (testString.equals(row.getField(columnIndex.get("t_string"))) && testInt.equals(row.getField(columnIndex.get("t_int"))) && testSmallint.equals(row.getField(columnIndex.get("t_smallint")))) {
rowFound = true;
}
}
assertTrue(rowFound);
}
}
use of io.prestosql.testing.MaterializedRow in project hetu-core by openlookeng.
the class TestIndexResources method getSplitAndMaterializedResult.
// Get the split count and MaterializedResult in one pair to return.
Pair<Integer, MaterializedResult> getSplitAndMaterializedResult(String testerQuery) {
// Select the entry with specifics
MaterializedResult queryResult = computeActual(testerQuery);
String doublyQuotedQuery = testerQuery.replaceAll("'", "''");
// Get queries executed and query ID to find the task with sum of splits
String splits = "select sum(splits) from system.runtime.tasks where query_id in " + "(select query_id from system.runtime.queries " + "where query='" + doublyQuotedQuery + "' order by created desc limit 1)";
MaterializedResult rows = computeActual(splits);
assertEquals(rows.getRowCount(), 1);
MaterializedRow materializedRow = rows.getMaterializedRows().get(0);
int fieldCount = materializedRow.getFieldCount();
assertEquals(fieldCount, 1, "Expected only one column, but got '%d', fiedlCount: " + fieldCount);
Object value = materializedRow.getField(0);
return new Pair<>((int) (long) value, queryResult);
}
use of io.prestosql.testing.MaterializedRow in project hetu-core by openlookeng.
the class TestAtopSmoke method assertThatQueryReturnsValue.
private void assertThatQueryReturnsValue(@Language("SQL") String sql, Object expected) {
MaterializedResult rows = queryRunner.execute(sql);
MaterializedRow materializedRow = Iterables.getOnlyElement(rows);
int fieldCount = materializedRow.getFieldCount();
assertTrue(fieldCount == 1, format("Expected only one column, but got '%d'", fieldCount));
Object value = materializedRow.getField(0);
assertEquals(value, expected);
assertTrue(Iterables.getOnlyElement(rows).getFieldCount() == 1);
}
use of io.prestosql.testing.MaterializedRow in project hetu-core by openlookeng.
the class TestOrcDeleteDeltaPageSource method testReadingDeletedRows.
@Test
public void testReadingDeletedRows() {
OrcDeleteDeltaPageSourceFactory pageSourceFactory = new OrcDeleteDeltaPageSourceFactory("test", new JobConf(new Configuration(false)), HiveTestUtils.HDFS_ENVIRONMENT, new DataSize(1, MEGABYTE), new DataSize(8, MEGABYTE), new DataSize(8, MEGABYTE), new DataSize(16, MEGABYTE), new DataSize(8, MEGABYTE), true, false, new FileFormatDataSourceStats());
OrcDeleteDeltaPageSource pageSource = pageSourceFactory.createPageSource(new Path(DELETE_FILE.toURI()), DELETE_FILE.length(), DELETE_FILE.lastModified());
MaterializedResult materializedRows = MaterializedResult.materializeSourceDataStream(HiveTestUtils.SESSION, pageSource, ImmutableList.of(BIGINT, INTEGER, BIGINT));
assertEquals(materializedRows.getRowCount(), 1);
assertEquals(materializedRows.getMaterializedRows().get(0), new MaterializedRow(5, 2L, 536870912, 0L));
}
Aggregations