use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.
the class AbstractTestHiveClient method readTable.
private MaterializedResult readTable(Transaction transaction, ConnectorTableHandle tableHandle, List<ColumnHandle> columnHandles, ConnectorSession session, TupleDomain<ColumnHandle> tupleDomain, OptionalInt expectedSplitCount, Optional<HiveStorageFormat> expectedStorageFormat) throws Exception {
List<ConnectorTableLayoutResult> tableLayoutResults = transaction.getMetadata().getTableLayouts(session, tableHandle, new Constraint<>(tupleDomain, bindings -> true), Optional.empty());
ConnectorTableLayoutHandle layoutHandle = getOnlyElement(tableLayoutResults).getTableLayout().getHandle();
List<ConnectorSplit> splits = getAllSplits(splitManager.getSplits(transaction.getTransactionHandle(), session, layoutHandle));
if (expectedSplitCount.isPresent()) {
assertEquals(splits.size(), expectedSplitCount.getAsInt());
}
ImmutableList.Builder<MaterializedRow> allRows = ImmutableList.builder();
for (ConnectorSplit split : splits) {
try (ConnectorPageSource pageSource = pageSourceProvider.createPageSource(transaction.getTransactionHandle(), session, split, columnHandles)) {
if (expectedStorageFormat.isPresent()) {
assertPageSourceType(pageSource, expectedStorageFormat.get());
}
MaterializedResult result = materializeSourceDataStream(session, pageSource, getTypes(columnHandles));
allRows.addAll(result.getMaterializedRows());
}
}
return new MaterializedResult(allRows.build(), getTypes(columnHandles));
}
use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.
the class AbstractTestHiveClientS3 method testGetRecordsS3.
@Test
public void testGetRecordsS3() throws Exception {
try (Transaction transaction = newTransaction()) {
ConnectorMetadata metadata = transaction.getMetadata();
ConnectorSession session = newSession();
ConnectorTableHandle table = getTableHandle(metadata, tableS3);
List<ColumnHandle> columnHandles = ImmutableList.copyOf(metadata.getColumnHandles(session, table).values());
Map<String, Integer> columnIndex = indexColumns(columnHandles);
List<ConnectorTableLayoutResult> tableLayoutResults = metadata.getTableLayouts(session, table, new Constraint<>(TupleDomain.all(), bindings -> true), Optional.empty());
HiveTableLayoutHandle layoutHandle = (HiveTableLayoutHandle) getOnlyElement(tableLayoutResults).getTableLayout().getHandle();
assertEquals(layoutHandle.getPartitions().get().size(), 1);
ConnectorSplitSource splitSource = splitManager.getSplits(transaction.getTransactionHandle(), session, layoutHandle);
long sum = 0;
for (ConnectorSplit split : getAllSplits(splitSource)) {
try (ConnectorPageSource pageSource = pageSourceProvider.createPageSource(transaction.getTransactionHandle(), session, split, columnHandles)) {
MaterializedResult result = materializeSourceDataStream(session, pageSource, getTypes(columnHandles));
for (MaterializedRow row : result) {
sum += (Long) row.getField(columnIndex.get("t_bigint"));
}
}
}
assertEquals(sum, 78300);
}
}
use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.
the class TestRaptorIntegrationSmokeTest method testShardingByTemporalTimestampColumn.
@Test
public void testShardingByTemporalTimestampColumn() throws Exception {
// Make sure we have at least 2 different orderdate.
assertEquals(computeActual("SELECT count(DISTINCT orderdate) >= 2 FROM orders WHERE orderdate < date '1992-02-08'").getOnlyValue(), true);
assertUpdate("CREATE TABLE test_shard_temporal_timestamp(col1 BIGINT, col2 TIMESTAMP) WITH (temporal_column = 'col2')");
int rows = 20;
StringJoiner joiner = new StringJoiner(", ", "INSERT INTO test_shard_temporal_timestamp VALUES ", "");
for (int i = 0; i < rows; i++) {
joiner.add(format("(%s, TIMESTAMP '2016-08-08 01:00' + interval '%s' hour)", i, i * 4));
}
assertUpdate(joiner.toString(), format("VALUES(%s)", rows));
MaterializedResult results = computeActual("SELECT format_datetime(col2, 'yyyyMMdd'), \"$shard_uuid\" FROM test_shard_temporal_timestamp");
assertEquals(results.getRowCount(), rows);
// Each shard will only contain data of one date.
SetMultimap<String, String> shardDateMap = HashMultimap.create();
for (MaterializedRow row : results.getMaterializedRows()) {
shardDateMap.put((String) row.getField(1), (String) row.getField(0));
}
for (Collection<String> dates : shardDateMap.asMap().values()) {
assertEquals(dates.size(), 1);
}
// Ensure one shard can contain different timestamps from the same day
assertLessThan(shardDateMap.size(), rows);
}
use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.
the class DataTypeTest method execute.
public void execute(QueryRunner prestoExecutor, DataSetup dataSetup) {
List<Type> expectedTypes = inputs.stream().map(Input::getPrestoResultType).collect(toList());
List<Object> expectedResults = inputs.stream().map(Input::toPrestoQueryResult).collect(toList());
try (TestTable testTable = dataSetup.setupTestTable(unmodifiableList(inputs))) {
MaterializedResult materializedRows = prestoExecutor.execute("SELECT * from " + testTable.getName());
assertEquals(expectedTypes, materializedRows.getTypes());
MaterializedRow row = getOnlyElement(materializedRows);
assertEquals(expectedResults, row.getFields());
}
}
use of com.facebook.presto.testing.MaterializedRow in project presto by prestodb.
the class QueryAssertions method assertQuery.
public static void assertQuery(QueryRunner actualQueryRunner, Session session, @Language("SQL") String actual, H2QueryRunner h2QueryRunner, @Language("SQL") String expected, boolean ensureOrdering, boolean compareUpdate) {
long start = System.nanoTime();
MaterializedResult actualResults = null;
try {
actualResults = actualQueryRunner.execute(session, actual).toJdbcTypes();
} catch (RuntimeException ex) {
fail("Execution of 'actual' query failed: " + actual, ex);
}
Duration actualTime = nanosSince(start);
long expectedStart = System.nanoTime();
MaterializedResult expectedResults = null;
try {
expectedResults = h2QueryRunner.execute(session, expected, actualResults.getTypes());
} catch (RuntimeException ex) {
fail("Execution of 'expected' query failed: " + actual, ex);
}
log.info("FINISHED in presto: %s, h2: %s, total: %s", actualTime, nanosSince(expectedStart), nanosSince(start));
if (actualResults.getUpdateType().isPresent() || actualResults.getUpdateCount().isPresent()) {
if (!actualResults.getUpdateType().isPresent()) {
fail("update count present without update type for query: \n" + actual);
}
if (!compareUpdate) {
fail("update type should not be present (use assertUpdate) for query: \n" + actual);
}
}
List<MaterializedRow> actualRows = actualResults.getMaterializedRows();
List<MaterializedRow> expectedRows = expectedResults.getMaterializedRows();
if (compareUpdate) {
if (!actualResults.getUpdateType().isPresent()) {
fail("update type not present for query: \n" + actual);
}
if (!actualResults.getUpdateCount().isPresent()) {
fail("update count not present for query: \n" + actual);
}
assertEquals(actualRows.size(), 1, "For query: \n " + actual + "\n:");
assertEquals(expectedRows.size(), 1, "For query: \n " + actual + "\n:");
MaterializedRow row = expectedRows.get(0);
assertEquals(row.getFieldCount(), 1, "For query: \n " + actual + "\n:");
assertEquals(row.getField(0), actualResults.getUpdateCount().getAsLong(), "For query: \n " + actual + "\n:");
}
if (ensureOrdering) {
if (!actualRows.equals(expectedRows)) {
assertEquals(actualRows, expectedRows, "For query: \n " + actual + "\n:");
}
} else {
assertEqualsIgnoreOrder(actualRows, expectedRows, "For query: \n " + actual);
}
}
Aggregations