use of io.trino.testing.MaterializedResult in project trino by trinodb.
the class BaseHiveConnectorTest method testTargetMaxFileSize.
protected void testTargetMaxFileSize(int expectedTableWriters) {
// We use TEXTFILE in this test because is has a very consistent and predictable size
@Language("SQL") String createTableSql = "CREATE TABLE test_max_file_size WITH (format = 'TEXTFILE') AS SELECT * FROM tpch.sf1.lineitem LIMIT 1000000";
@Language("SQL") String selectFileInfo = "SELECT distinct \"$path\", \"$file_size\" FROM test_max_file_size";
// verify the default behavior is one file per node
Session session = Session.builder(getSession()).setSystemProperty("task_writer_count", "1").build();
assertUpdate(session, createTableSql, 1000000);
assertThat(computeActual(selectFileInfo).getRowCount()).isEqualTo(expectedTableWriters);
assertUpdate("DROP TABLE test_max_file_size");
// Write table with small limit and verify we get multiple files per node near the expected size
// Writer writes chunks of rows that are about 1MB
DataSize maxSize = DataSize.of(1, Unit.MEGABYTE);
session = Session.builder(getSession()).setSystemProperty("task_writer_count", "1").setCatalogSessionProperty("hive", "target_max_file_size", maxSize.toString()).build();
assertUpdate(session, createTableSql, 1000000);
MaterializedResult result = computeActual(selectFileInfo);
assertThat(result.getRowCount()).isGreaterThan(expectedTableWriters);
for (MaterializedRow row : result) {
// allow up to a larger delta due to the very small max size and the relatively large writer chunk size
assertThat((Long) row.getField(1)).isLessThan(maxSize.toBytes() * 3);
}
assertUpdate("DROP TABLE test_max_file_size");
}
use of io.trino.testing.MaterializedResult in project trino by trinodb.
the class BaseHiveConnectorTest method testOrderByChar.
@Test
public void testOrderByChar() {
assertUpdate("CREATE TABLE char_order_by (c_char char(2))");
assertUpdate("INSERT INTO char_order_by (c_char) VALUES" + "(CAST('a' as CHAR(2)))," + "(CAST('a\0' as CHAR(2)))," + "(CAST('a ' as CHAR(2)))", 3);
MaterializedResult actual = computeActual(getSession(), "SELECT * FROM char_order_by ORDER BY c_char ASC");
assertUpdate("DROP TABLE char_order_by");
MaterializedResult expected = resultBuilder(getSession(), createCharType(2)).row("a\0").row("a ").row("a ").build();
assertEquals(actual, expected);
}
use of io.trino.testing.MaterializedResult in project trino by trinodb.
the class BaseHiveConnectorTest method doTestParquetTimestampPredicatePushdown.
private void doTestParquetTimestampPredicatePushdown(Session baseSession, HiveTimestampPrecision timestampPrecision, LocalDateTime value) {
Session session = withTimestampPrecision(baseSession, timestampPrecision);
String tableName = "test_parquet_timestamp_predicate_pushdown_" + randomTableSuffix();
assertUpdate("DROP TABLE IF EXISTS " + tableName);
assertUpdate("CREATE TABLE " + tableName + " (t TIMESTAMP) WITH (format = 'PARQUET')");
assertUpdate(session, format("INSERT INTO %s VALUES (%s)", tableName, formatTimestamp(value)), 1);
assertQuery(session, "SELECT * FROM " + tableName, format("VALUES (%s)", formatTimestamp(value)));
DistributedQueryRunner queryRunner = (DistributedQueryRunner) getQueryRunner();
ResultWithQueryId<MaterializedResult> queryResult = queryRunner.executeWithQueryId(session, format("SELECT * FROM %s WHERE t < %s", tableName, formatTimestamp(value)));
assertEquals(getQueryInfo(queryRunner, queryResult).getQueryStats().getProcessedInputDataSize().toBytes(), 0);
queryResult = queryRunner.executeWithQueryId(session, format("SELECT * FROM %s WHERE t > %s", tableName, formatTimestamp(value)));
assertEquals(getQueryInfo(queryRunner, queryResult).getQueryStats().getProcessedInputDataSize().toBytes(), 0);
assertQueryStats(session, format("SELECT * FROM %s WHERE t = %s", tableName, formatTimestamp(value)), queryStats -> {
assertThat(queryStats.getProcessedInputDataSize().toBytes()).isGreaterThan(0);
}, results -> {
});
}
use of io.trino.testing.MaterializedResult in project trino by trinodb.
the class TestHiveCreateExternalTable method testCreateExternalTableWithData.
@Test
public void testCreateExternalTableWithData() throws IOException {
Path tempDir = createTempDirectory(null);
Path tableLocation = tempDir.resolve("data");
@Language("SQL") String createTableSql = format("" + "CREATE TABLE test_create_external " + "WITH (external_location = '%s') AS " + "SELECT * FROM tpch.tiny.nation", tableLocation.toUri().toASCIIString());
assertUpdate(createTableSql, 25);
MaterializedResult expected = computeActual("SELECT * FROM tpch.tiny.nation");
MaterializedResult actual = computeActual("SELECT * FROM test_create_external");
assertEqualsIgnoreOrder(actual.getMaterializedRows(), expected.getMaterializedRows());
MaterializedResult result = computeActual("SELECT DISTINCT regexp_replace(\"$path\", '/[^/]*$', '/') FROM test_create_external");
String tablePath = (String) result.getOnlyValue();
assertThat(tablePath).startsWith(tableLocation.toFile().toURI().toString());
assertUpdate("DROP TABLE test_create_external");
deleteRecursively(tempDir, ALLOW_INSECURE);
}
use of io.trino.testing.MaterializedResult in project trino by trinodb.
the class TestHiveDistributedJoinQueries method testJoinWithEmptyBuildSide.
@Test
public void testJoinWithEmptyBuildSide() {
Session session = Session.builder(getSession()).setSystemProperty(JOIN_DISTRIBUTION_TYPE, BROADCAST.name()).build();
ResultWithQueryId<MaterializedResult> result = getDistributedQueryRunner().executeWithQueryId(session, "SELECT * FROM lineitem JOIN orders ON lineitem.orderkey = orders.orderkey AND orders.totalprice = 123.4567");
assertEquals(result.getResult().getRowCount(), 0);
OperatorStats probeStats = searchScanFilterAndProjectOperatorStats(result.getQueryId(), new QualifiedObjectName(HIVE_CATALOG, "tpch", "lineitem"));
// Probe-side is not scanned at all, due to dynamic filtering:
assertEquals(probeStats.getInputPositions(), 0L);
assertEquals(probeStats.getDynamicFilterSplitsProcessed(), probeStats.getTotalDrivers());
}
Aggregations