Search in sources :

Example 26 with MaterializedResult

use of io.trino.testing.MaterializedResult in project trino by trinodb.

the class BaseHiveConnectorTest method assertOneNotNullResult.

private void assertOneNotNullResult(Session session, @Language("SQL") String query) {
    MaterializedResult results = getQueryRunner().execute(session, query).toTestTypes();
    assertEquals(results.getRowCount(), 1);
    assertEquals(results.getMaterializedRows().get(0).getFieldCount(), 1);
    assertNotNull(results.getMaterializedRows().get(0).getField(0));
}
Also used : MaterializedResult(io.trino.testing.MaterializedResult)

Example 27 with MaterializedResult

use of io.trino.testing.MaterializedResult in project trino by trinodb.

the class BaseHiveConnectorTest method testSortedWritingTempStaging.

@Test
public void testSortedWritingTempStaging() {
    String tableName = "test_sorted_writing";
    @Language("SQL") String createTableSql = format("" + "CREATE TABLE %s " + "WITH (" + "   bucket_count = 7," + "   bucketed_by = ARRAY['shipmode']," + "   sorted_by = ARRAY['shipmode']" + ") AS " + "SELECT * FROM tpch.tiny.lineitem", tableName);
    Session session = Session.builder(getSession()).setCatalogSessionProperty("hive", "sorted_writing_enabled", "true").setCatalogSessionProperty("hive", "temporary_staging_directory_enabled", "true").setCatalogSessionProperty("hive", "temporary_staging_directory_path", "/tmp/custom/temporary-${USER}").build();
    assertUpdate(session, createTableSql, 60175L);
    MaterializedResult expected = computeActual("SELECT * FROM tpch.tiny.lineitem");
    MaterializedResult actual = computeActual("SELECT * FROM " + tableName);
    assertEqualsIgnoreOrder(actual.getMaterializedRows(), expected.getMaterializedRows());
    assertUpdate("DROP TABLE " + tableName);
}
Also used : Language(org.intellij.lang.annotations.Language) MaterializedResult(io.trino.testing.MaterializedResult) HiveQueryRunner.createBucketedSession(io.trino.plugin.hive.HiveQueryRunner.createBucketedSession) Session(io.trino.Session) Test(org.testng.annotations.Test) BaseConnectorTest(io.trino.testing.BaseConnectorTest)

Example 28 with MaterializedResult

use of io.trino.testing.MaterializedResult in project trino by trinodb.

the class BaseHiveConnectorTest method testCreateAvroTableWithSchemaUrl.

@Test
public void testCreateAvroTableWithSchemaUrl() throws Exception {
    String tableName = "test_create_avro_table_with_schema_url";
    File schemaFile = createAvroSchemaFile();
    String createTableSql = getAvroCreateTableSql(tableName, schemaFile.getAbsolutePath());
    String expectedShowCreateTable = getAvroCreateTableSql(tableName, schemaFile.toURI().toString());
    assertUpdate(createTableSql);
    try {
        MaterializedResult actual = computeActual("SHOW CREATE TABLE " + tableName);
        assertEquals(actual.getOnlyValue(), expectedShowCreateTable);
    } finally {
        assertUpdate("DROP TABLE " + tableName);
        verify(schemaFile.delete(), "cannot delete temporary file: %s", schemaFile);
    }
}
Also used : MaterializedResult(io.trino.testing.MaterializedResult) FileAssert.assertFile(org.testng.FileAssert.assertFile) File(java.io.File) Test(org.testng.annotations.Test) BaseConnectorTest(io.trino.testing.BaseConnectorTest)

Example 29 with MaterializedResult

use of io.trino.testing.MaterializedResult in project trino by trinodb.

the class BaseHiveConnectorTest method testShowColumnsPartitionKey.

@Test
public void testShowColumnsPartitionKey() {
    assertUpdate("" + "CREATE TABLE test_show_columns_partition_key\n" + "(grape bigint, orange bigint, pear varchar(65535), mango integer, lychee smallint, kiwi tinyint, apple varchar, pineapple varchar(65535))\n" + "WITH (partitioned_by = ARRAY['apple', 'pineapple'])");
    MaterializedResult actual = computeActual("SHOW COLUMNS FROM test_show_columns_partition_key");
    Type unboundedVarchar = canonicalizeType(VARCHAR);
    MaterializedResult expected = resultBuilder(getSession(), unboundedVarchar, unboundedVarchar, unboundedVarchar, unboundedVarchar).row("grape", canonicalizeType(BIGINT).toString(), "", "").row("orange", canonicalizeType(BIGINT).toString(), "", "").row("pear", canonicalizeType(createVarcharType(65535)).toString(), "", "").row("mango", canonicalizeType(INTEGER).toString(), "", "").row("lychee", canonicalizeType(SMALLINT).toString(), "", "").row("kiwi", canonicalizeType(TINYINT).toString(), "", "").row("apple", canonicalizeType(VARCHAR).toString(), "partition key", "").row("pineapple", canonicalizeType(createVarcharType(65535)).toString(), "partition key", "").build();
    assertEquals(actual, expected);
}
Also used : DateType(io.trino.spi.type.DateType) CharType.createCharType(io.trino.spi.type.CharType.createCharType) TimestampType(io.trino.spi.type.TimestampType) HiveType.toHiveType(io.trino.plugin.hive.HiveType.toHiveType) DecimalType.createDecimalType(io.trino.spi.type.DecimalType.createDecimalType) VarcharType.createVarcharType(io.trino.spi.type.VarcharType.createVarcharType) Type(io.trino.spi.type.Type) VarcharType.createUnboundedVarcharType(io.trino.spi.type.VarcharType.createUnboundedVarcharType) VarcharType(io.trino.spi.type.VarcharType) MaterializedResult(io.trino.testing.MaterializedResult) Test(org.testng.annotations.Test) BaseConnectorTest(io.trino.testing.BaseConnectorTest)

Example 30 with MaterializedResult

use of io.trino.testing.MaterializedResult in project trino by trinodb.

the class BaseHiveConnectorTest method testFileSizeHiddenColumn.

@Test
public void testFileSizeHiddenColumn() {
    @Language("SQL") String createTable = "CREATE TABLE test_file_size " + "WITH (" + "partitioned_by = ARRAY['col1']" + ") AS " + "SELECT * FROM (VALUES " + "(0, 0), (3, 0), (6, 0), " + "(1, 1), (4, 1), (7, 1), " + "(2, 2), (5, 2) " + " ) t(col0, col1) ";
    assertUpdate(createTable, 8);
    assertTrue(getQueryRunner().tableExists(getSession(), "test_file_size"));
    TableMetadata tableMetadata = getTableMetadata(catalog, TPCH_SCHEMA, "test_file_size");
    List<String> columnNames = ImmutableList.of("col0", "col1", PATH_COLUMN_NAME, FILE_SIZE_COLUMN_NAME, FILE_MODIFIED_TIME_COLUMN_NAME, PARTITION_COLUMN_NAME);
    List<ColumnMetadata> columnMetadatas = tableMetadata.getColumns();
    assertEquals(columnMetadatas.size(), columnNames.size());
    for (int i = 0; i < columnMetadatas.size(); i++) {
        ColumnMetadata columnMetadata = columnMetadatas.get(i);
        assertEquals(columnMetadata.getName(), columnNames.get(i));
        if (columnMetadata.getName().equals(FILE_SIZE_COLUMN_NAME)) {
            assertTrue(columnMetadata.isHidden());
        }
    }
    assertEquals(getPartitions("test_file_size").size(), 3);
    MaterializedResult results = computeActual(format("SELECT *, \"%s\" FROM test_file_size", FILE_SIZE_COLUMN_NAME));
    Map<Integer, Long> fileSizeMap = new HashMap<>();
    for (int i = 0; i < results.getRowCount(); i++) {
        MaterializedRow row = results.getMaterializedRows().get(i);
        int col0 = (int) row.getField(0);
        int col1 = (int) row.getField(1);
        long fileSize = (Long) row.getField(2);
        assertTrue(fileSize > 0);
        assertEquals(col0 % 3, col1);
        if (fileSizeMap.containsKey(col1)) {
            assertEquals(fileSizeMap.get(col1).longValue(), fileSize);
        } else {
            fileSizeMap.put(col1, fileSize);
        }
    }
    assertEquals(fileSizeMap.size(), 3);
    assertUpdate("DROP TABLE test_file_size");
}
Also used : TableMetadata(io.trino.metadata.TableMetadata) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ColumnConstraint(io.trino.sql.planner.planprinter.IoPlanPrinter.ColumnConstraint) Constraint(io.trino.spi.connector.Constraint) Language(org.intellij.lang.annotations.Language) MaterializedResult(io.trino.testing.MaterializedResult) MaterializedRow(io.trino.testing.MaterializedRow) Test(org.testng.annotations.Test) BaseConnectorTest(io.trino.testing.BaseConnectorTest)

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