Search in sources :

Example 66 with QueryResult

use of io.trino.tempto.query.QueryResult in project trino by trinodb.

the class TestIcebergSparkCompatibility method testTrinoWritingDataWithWriterDataPathSet.

@Test(groups = { ICEBERG, PROFILE_SPECIFIC_TESTS }, dataProvider = "storageFormatsWithSpecVersion")
public void testTrinoWritingDataWithWriterDataPathSet(StorageFormat storageFormat, int specVersion) {
    String baseTableName = "test_writer_data_path_" + storageFormat;
    String sparkTableName = sparkTableName(baseTableName);
    String trinoTableName = trinoTableName(baseTableName);
    String dataPath = "hdfs://hadoop-master:9000/user/hive/warehouse/test_writer_data_path_/obj-data";
    onSpark().executeQuery(format("CREATE TABLE %s (_string STRING, _bigint BIGINT) USING ICEBERG TBLPROPERTIES (" + "'write.data.path'='%s'," + "'write.format.default' = '%s'," + "'format-version' = %s)", sparkTableName, dataPath, storageFormat, specVersion));
    onTrino().executeQuery(format("INSERT INTO %s VALUES ('a_string', 1000000000000000)", trinoTableName));
    Row result = row("a_string", 1000000000000000L);
    assertThat(onSpark().executeQuery(format("SELECT _string, _bigint FROM %s", sparkTableName))).containsOnly(result);
    assertThat(onTrino().executeQuery(format("SELECT _string, _bigint FROM %s", trinoTableName))).containsOnly(result);
    QueryResult queryResult = onTrino().executeQuery(format("SELECT file_path FROM %s", trinoTableName("\"" + baseTableName + "$files\"")));
    assertThat(queryResult).hasRowsCount(1).hasColumnsCount(1);
    assertTrue(((String) queryResult.row(0).get(0)).contains(dataPath));
    assertQueryFailure(() -> onTrino().executeQuery("DROP TABLE " + trinoTableName)).hasMessageContaining("contains Iceberg path override properties and cannot be dropped from Trino");
    onSpark().executeQuery("DROP TABLE " + sparkTableName);
}
Also used : QueryResult(io.trino.tempto.query.QueryResult) Row(io.trino.tempto.assertions.QueryAssert.Row) Test(org.testng.annotations.Test) ProductTest(io.trino.tempto.ProductTest)

Example 67 with QueryResult

use of io.trino.tempto.query.QueryResult in project trino by trinodb.

the class TestIcebergSparkCompatibility method testMigratedDataWithAlteredSchema.

@Test(groups = { ICEBERG, PROFILE_SPECIFIC_TESTS }, dataProvider = "storageFormats")
public void testMigratedDataWithAlteredSchema(StorageFormat storageFormat) {
    String baseTableName = "test_migrated_data_with_altered_schema_" + randomTableSuffix();
    String defaultCatalogTableName = sparkDefaultCatalogTableName(baseTableName);
    String sparkTableDefinition = "" + "CREATE TABLE %s (\n" + "  doc_id STRING\n" + ", nested_struct STRUCT<id:INT, name:STRING, address:STRUCT<a:INT, b:STRING>>)\n" + " USING %s";
    onSpark().executeQuery(format(sparkTableDefinition, defaultCatalogTableName, storageFormat.name()));
    String insert = "" + "INSERT INTO TABLE %s SELECT" + "  'Doc213'" + ", named_struct('id', 1, 'name', 'P. Sherman', 'address', named_struct('a', 42, 'b', 'Wallaby Way'))";
    onSpark().executeQuery(format(insert, defaultCatalogTableName));
    onSpark().executeQuery(format("CALL system.migrate('%s')", defaultCatalogTableName));
    String sparkTableName = sparkTableName(baseTableName);
    onSpark().executeQuery("ALTER TABLE " + sparkTableName + " RENAME COLUMN nested_struct TO nested_struct_moved");
    String select = "SELECT" + " nested_struct_moved.name" + ", nested_struct_moved.address.a" + ", nested_struct_moved.address.b" + "  FROM ";
    Row row = row("P. Sherman", 42, "Wallaby Way");
    QueryResult sparkResult = onSpark().executeQuery(select + sparkTableName);
    assertThat(sparkResult).containsOnly(ImmutableList.of(row));
    String trinoTableName = trinoTableName(baseTableName);
    assertThat(onTrino().executeQuery(select + trinoTableName)).containsOnly(ImmutableList.of(row));
    // After removing the name mapping, columns from migrated files should be null since they are missing the Iceberg Field IDs
    onSpark().executeQuery(format("ALTER TABLE %s UNSET TBLPROPERTIES ('schema.name-mapping.default')", sparkTableName));
    assertThat(onTrino().executeQuery(select + trinoTableName)).containsOnly(row(null, null, null));
}
Also used : QueryResult(io.trino.tempto.query.QueryResult) Row(io.trino.tempto.assertions.QueryAssert.Row) Test(org.testng.annotations.Test) ProductTest(io.trino.tempto.ProductTest)

Example 68 with QueryResult

use of io.trino.tempto.query.QueryResult in project trino by trinodb.

the class TestIcebergSparkCompatibility method testTrinoWritingDataWithObjectStorageLocationProvider.

@Test(groups = { ICEBERG, PROFILE_SPECIFIC_TESTS }, dataProvider = "storageFormatsWithSpecVersion")
public void testTrinoWritingDataWithObjectStorageLocationProvider(StorageFormat storageFormat, int specVersion) {
    String baseTableName = "test_object_storage_location_provider_" + storageFormat;
    String sparkTableName = sparkTableName(baseTableName);
    String trinoTableName = trinoTableName(baseTableName);
    String dataPath = "hdfs://hadoop-master:9000/user/hive/warehouse/test_object_storage_location_provider/obj-data";
    onSpark().executeQuery(format("CREATE TABLE %s (_string STRING, _bigint BIGINT) USING ICEBERG TBLPROPERTIES (" + "'write.object-storage.enabled'=true," + "'write.object-storage.path'='%s'," + "'write.format.default' = '%s'," + "'format-version' = %s)", sparkTableName, dataPath, storageFormat, specVersion));
    onTrino().executeQuery(format("INSERT INTO %s VALUES ('a_string', 1000000000000000)", trinoTableName));
    Row result = row("a_string", 1000000000000000L);
    assertThat(onSpark().executeQuery(format("SELECT _string, _bigint FROM %s", sparkTableName))).containsOnly(result);
    assertThat(onTrino().executeQuery(format("SELECT _string, _bigint FROM %s", trinoTableName))).containsOnly(result);
    QueryResult queryResult = onTrino().executeQuery(format("SELECT file_path FROM %s", trinoTableName("\"" + baseTableName + "$files\"")));
    assertThat(queryResult).hasRowsCount(1).hasColumnsCount(1);
    assertTrue(((String) queryResult.row(0).get(0)).contains(dataPath));
    // TODO: support path override in Iceberg table creation: https://github.com/trinodb/trino/issues/8861
    assertQueryFailure(() -> onTrino().executeQuery("DROP TABLE " + trinoTableName)).hasMessageContaining("contains Iceberg path override properties and cannot be dropped from Trino");
    onSpark().executeQuery("DROP TABLE " + sparkTableName);
}
Also used : QueryResult(io.trino.tempto.query.QueryResult) Row(io.trino.tempto.assertions.QueryAssert.Row) Test(org.testng.annotations.Test) ProductTest(io.trino.tempto.ProductTest)

Example 69 with QueryResult

use of io.trino.tempto.query.QueryResult in project trino by trinodb.

the class TestIcebergSparkCompatibility method testSparkReadingNestedTrinoData.

@Test(groups = { ICEBERG, PROFILE_SPECIFIC_TESTS }, dataProvider = "storageFormats")
public void testSparkReadingNestedTrinoData(StorageFormat storageFormat) {
    String baseTableName = "test_spark_reading_nested_trino_data_" + storageFormat;
    String trinoTableName = trinoTableName(baseTableName);
    String sparkTableName = sparkTableName(baseTableName);
    onTrino().executeQuery(format("CREATE TABLE %s (\n" + "  doc_id VARCHAR\n" + ", nested_map MAP(VARCHAR, ARRAY(ROW(sname VARCHAR, snumber INT)))\n" + ", nested_array ARRAY(MAP(VARCHAR, ARRAY(ROW(mname VARCHAR, mnumber INT))))\n" + ", nested_struct ROW(name VARCHAR, complicated ARRAY(MAP(VARCHAR, ARRAY(ROW(mname VARCHAR, mnumber INT))))))" + "  WITH (format = '%s')", trinoTableName, storageFormat));
    onTrino().executeQuery(format("INSERT INTO %s SELECT" + "  'Doc213'" + ", map(array['s1'], array[array[row('ASName1', 201), row('ASName2', 202)]])" + ", array[map(array['m1'], array[array[row('MAS1Name1', 301), row('MAS1Name2', 302)]])" + "       ,map(array['m2'], array[array[row('MAS2Name1', 401), row('MAS2Name2', 402)]])]" + ", row('S1'" + "      ,array[map(array['m1'], array[array[row('SAMA1Name1', 301), row('SAMA1Name2', 302)]])" + "            ,map(array['m2'], array[array[row('SAMA2Name1', 401), row('SAMA2Name2', 402)]])])", trinoTableName));
    Row row = row("Doc213", "ASName2", 201, "MAS2Name1", 302, "SAMA1Name1", 402);
    assertThat(onTrino().executeQuery("SELECT" + "  doc_id" + ", nested_map['s1'][2].sname" + ", nested_map['s1'][1].snumber" + ", nested_array[2]['m2'][1].mname" + ", nested_array[1]['m1'][2].mnumber" + ", nested_struct.complicated[1]['m1'][1].mname" + ", nested_struct.complicated[2]['m2'][2].mnumber" + "  FROM " + trinoTableName)).containsOnly(row);
    QueryResult sparkResult = onSpark().executeQuery("SELECT" + "  doc_id" + ", nested_map['s1'][1].sname" + ", nested_map['s1'][0].snumber" + ", nested_array[1]['m2'][0].mname" + ", nested_array[0]['m1'][1].mnumber" + ", nested_struct.complicated[0]['m1'][0].mname" + ", nested_struct.complicated[1]['m2'][1].mnumber" + "  FROM " + sparkTableName);
    assertThat(sparkResult).containsOnly(row);
    onTrino().executeQuery("DROP TABLE " + trinoTableName);
}
Also used : QueryResult(io.trino.tempto.query.QueryResult) Row(io.trino.tempto.assertions.QueryAssert.Row) Test(org.testng.annotations.Test) ProductTest(io.trino.tempto.ProductTest)

Example 70 with QueryResult

use of io.trino.tempto.query.QueryResult in project trino by trinodb.

the class TestHiveStorageFormats method assertResultEqualForLineitemTable.

/**
 * Run the given query on the given table and the TPCH {@code lineitem} table
 * (in the schema {@code TPCH_SCHEMA}, asserting that the results are equal.
 */
private static void assertResultEqualForLineitemTable(String query, String tableName) {
    QueryResult expected = onTrino().executeQuery(format(query, "tpch." + TPCH_SCHEMA + ".lineitem"));
    List<Row> expectedRows = expected.rows().stream().map(columns -> row(columns.toArray())).collect(toImmutableList());
    QueryResult actual = onTrino().executeQuery(format(query, tableName));
    assertThat(actual).hasColumns(expected.getColumnTypes()).containsExactlyInOrder(expectedRows);
}
Also used : STORAGE_FORMATS_DETAILED(io.trino.tests.product.TestGroups.STORAGE_FORMATS_DETAILED) Arrays(java.util.Arrays) Connection(java.sql.Connection) HMS_ONLY(io.trino.tests.product.TestGroups.HMS_ONLY) Inject(com.google.inject.Inject) Test(org.testng.annotations.Test) QueryResult(io.trino.tempto.query.QueryResult) Matcher(java.util.regex.Matcher) ERROR_COMMITTING_WRITE_TO_HIVE_MATCH(io.trino.tests.product.hive.HiveProductTest.ERROR_COMMITTING_WRITE_TO_HIVE_MATCH) Maps.immutableEntry(com.google.common.collect.Maps.immutableEntry) Map(java.util.Map) Assertions(org.assertj.core.api.Assertions) Splitter(com.google.common.base.Splitter) ENGLISH(java.util.Locale.ENGLISH) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Collections.nCopies(java.util.Collections.nCopies) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) QueryAssert.assertThat(io.trino.tempto.assertions.QueryAssert.assertThat) ERROR_COMMITTING_WRITE_TO_HIVE_ISSUE(io.trino.tests.product.hive.HiveProductTest.ERROR_COMMITTING_WRITE_TO_HIVE_ISSUE) Set(java.util.Set) HiveTimestampPrecision(io.trino.plugin.hive.HiveTimestampPrecision) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Collectors.joining(java.util.stream.Collectors.joining) DataSize(io.airlift.units.DataSize) ParquetWriter(org.apache.parquet.hadoop.ParquetWriter) List(java.util.List) Stream(java.util.stream.Stream) InputStream.nullInputStream(java.io.InputStream.nullInputStream) JdbcDriverUtils(io.trino.tests.product.utils.JdbcDriverUtils) Pattern(java.util.regex.Pattern) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) SoftAssertions(org.assertj.core.api.SoftAssertions) DataProvider(org.testng.annotations.DataProvider) NANOSECONDS(io.trino.plugin.hive.HiveTimestampPrecision.NANOSECONDS) JdbcDriverUtils.setSessionProperty(io.trino.tests.product.utils.JdbcDriverUtils.setSessionProperty) QueryExecutors.onHive(io.trino.tests.product.utils.QueryExecutors.onHive) TemporaryHiveTable.randomTableSuffix(io.trino.tests.product.hive.util.TemporaryHiveTable.randomTableSuffix) JDBCType(java.sql.JDBCType) SQLException(java.sql.SQLException) Lists(com.google.common.collect.Lists) Verify.verify(com.google.common.base.Verify.verify) HdfsClient(io.trino.tempto.hadoop.hdfs.HdfsClient) Objects.requireNonNull(java.util.Objects.requireNonNull) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Named(javax.inject.Named) Row.row(io.trino.tempto.assertions.QueryAssert.Row.row) Row(io.trino.tempto.assertions.QueryAssert.Row) Flaky(io.trino.testng.services.Flaky) Comparator.comparingInt(java.util.Comparator.comparingInt) Iterator(java.util.Iterator) ProductTest(io.trino.tempto.ProductTest) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) QueryExecutors.onTrino(io.trino.tests.product.utils.QueryExecutors.onTrino) QueryExecutionException(io.trino.tempto.query.QueryExecutionException) MICROSECONDS(io.trino.plugin.hive.HiveTimestampPrecision.MICROSECONDS) QueryExecutor.param(io.trino.tempto.query.QueryExecutor.param) Collectors.toList(java.util.stream.Collectors.toList) QueryParam(io.trino.tempto.query.QueryExecutor.QueryParam) MILLISECONDS(io.trino.plugin.hive.HiveTimestampPrecision.MILLISECONDS) STORAGE_FORMATS(io.trino.tests.product.TestGroups.STORAGE_FORMATS) QueryResult(io.trino.tempto.query.QueryResult) Row(io.trino.tempto.assertions.QueryAssert.Row)

Aggregations

QueryResult (io.trino.tempto.query.QueryResult)84 Test (org.testng.annotations.Test)75 ProductTest (io.trino.tempto.ProductTest)61 Requires (io.trino.tempto.Requires)16 Row (io.trino.tempto.assertions.QueryAssert.Row)8 BigDecimal (java.math.BigDecimal)8 Duration (io.airlift.units.Duration)7 Flaky (io.trino.testng.services.Flaky)6 Statement (java.sql.Statement)6 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)4 QueryExecutionException (io.trino.tempto.query.QueryExecutionException)4 PreparedStatement (java.sql.PreparedStatement)4 ImmutableList (com.google.common.collect.ImmutableList)3 Row.row (io.trino.tempto.assertions.QueryAssert.Row.row)3 QueryAssert.assertThat (io.trino.tempto.assertions.QueryAssert.assertThat)3 List (java.util.List)3 Inject (com.google.inject.Inject)2 HiveTimestampPrecision (io.trino.plugin.hive.HiveTimestampPrecision)2 HMS_ONLY (io.trino.tests.product.TestGroups.HMS_ONLY)2 STORAGE_FORMATS (io.trino.tests.product.TestGroups.STORAGE_FORMATS)2