Search in sources :

Example 21 with MaterializedResult

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");
}
Also used : Language(org.intellij.lang.annotations.Language) DataSize(io.airlift.units.DataSize) MaterializedResult(io.trino.testing.MaterializedResult) MaterializedRow(io.trino.testing.MaterializedRow) HiveQueryRunner.createBucketedSession(io.trino.plugin.hive.HiveQueryRunner.createBucketedSession) Session(io.trino.Session)

Example 22 with MaterializedResult

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);
}
Also used : MaterializedResult(io.trino.testing.MaterializedResult) Test(org.testng.annotations.Test) BaseConnectorTest(io.trino.testing.BaseConnectorTest)

Example 23 with MaterializedResult

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 -> {
    });
}
Also used : DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) MaterializedResult(io.trino.testing.MaterializedResult) HiveQueryRunner.createBucketedSession(io.trino.plugin.hive.HiveQueryRunner.createBucketedSession) Session(io.trino.Session)

Example 24 with MaterializedResult

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);
}
Also used : Path(java.nio.file.Path) Language(org.intellij.lang.annotations.Language) MaterializedResult(io.trino.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 25 with MaterializedResult

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());
}
Also used : OperatorStats(io.trino.operator.OperatorStats) MaterializedResult(io.trino.testing.MaterializedResult) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) Session(io.trino.Session) Test(org.testng.annotations.Test)

Aggregations

MaterializedResult (io.trino.testing.MaterializedResult)328 Test (org.testng.annotations.Test)248 Page (io.trino.spi.Page)103 BaseConnectorTest (io.trino.testing.BaseConnectorTest)64 MaterializedRow (io.trino.testing.MaterializedRow)63 Type (io.trino.spi.type.Type)61 RowPagesBuilder (io.trino.RowPagesBuilder)57 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)51 OperatorAssertion.toMaterializedResult (io.trino.operator.OperatorAssertion.toMaterializedResult)41 TaskContext (io.trino.operator.TaskContext)37 TestingTaskContext (io.trino.testing.TestingTaskContext)37 OperatorFactory (io.trino.operator.OperatorFactory)31 Language (org.intellij.lang.annotations.Language)31 ConnectorSession (io.trino.spi.connector.ConnectorSession)27 Session (io.trino.Session)24 ColumnHandle (io.trino.spi.connector.ColumnHandle)24 ConnectorMetadata (io.trino.spi.connector.ConnectorMetadata)24 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)23 ImmutableList (com.google.common.collect.ImmutableList)22 Constraint (io.trino.spi.connector.Constraint)20