Search in sources :

Example 6 with TestingTypeManager

use of io.trino.spi.type.TestingTypeManager in project trino by trinodb.

the class TestIcebergSplitSource method testIncompleteDynamicFilterTimeout.

@Test(timeOut = 30_000)
public void testIncompleteDynamicFilterTimeout() throws Exception {
    long startMillis = System.currentTimeMillis();
    SchemaTableName schemaTableName = new SchemaTableName("tpch", "nation");
    IcebergTableHandle tableHandle = new IcebergTableHandle(schemaTableName.getSchemaName(), schemaTableName.getTableName(), TableType.DATA, Optional.empty(), TupleDomain.all(), TupleDomain.all(), ImmutableSet.of(), Optional.empty());
    Table nationTable = catalog.loadTable(SESSION, schemaTableName);
    IcebergSplitSource splitSource = new IcebergSplitSource(tableHandle, nationTable.newScan(), Optional.empty(), new DynamicFilter() {

        @Override
        public Set<ColumnHandle> getColumnsCovered() {
            return ImmutableSet.of();
        }

        @Override
        public CompletableFuture<?> isBlocked() {
            return CompletableFuture.runAsync(() -> {
                try {
                    TimeUnit.HOURS.sleep(1);
                } catch (InterruptedException e) {
                    throw new IllegalStateException(e);
                }
            });
        }

        @Override
        public boolean isComplete() {
            return false;
        }

        @Override
        public boolean isAwaitable() {
            return true;
        }

        @Override
        public TupleDomain<ColumnHandle> getCurrentPredicate() {
            return TupleDomain.all();
        }
    }, new Duration(2, SECONDS), alwaysTrue(), new TestingTypeManager(), false);
    ImmutableList.Builder<IcebergSplit> splits = ImmutableList.builder();
    while (!splitSource.isFinished()) {
        splitSource.getNextBatch(null, 100).get().getSplits().stream().map(IcebergSplit.class::cast).forEach(splits::add);
    }
    assertThat(splits.build().size()).isGreaterThan(0);
    assertTrue(splitSource.isFinished());
    assertThat(System.currentTimeMillis() - startMillis).as("IcebergSplitSource failed to wait for dynamicFilteringWaitTimeout").isGreaterThanOrEqualTo(2000);
}
Also used : Table(org.apache.iceberg.Table) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) ValueSet(io.trino.spi.predicate.ValueSet) DynamicFilter(io.trino.spi.connector.DynamicFilter) ImmutableList(com.google.common.collect.ImmutableList) Duration(io.airlift.units.Duration) SchemaTableName(io.trino.spi.connector.SchemaTableName) CompletableFuture(java.util.concurrent.CompletableFuture) TupleDomain(io.trino.spi.predicate.TupleDomain) TestingTypeManager(io.trino.spi.type.TestingTypeManager) Test(org.testng.annotations.Test)

Example 7 with TestingTypeManager

use of io.trino.spi.type.TestingTypeManager in project trino by trinodb.

the class TestIcebergV2 method updateTableToV2.

private Table updateTableToV2(String tableName) {
    IcebergTableOperationsProvider tableOperationsProvider = new FileMetastoreTableOperationsProvider(new HdfsFileIoProvider(hdfsEnvironment));
    TrinoCatalog catalog = new TrinoHiveCatalog(new CatalogName("hive"), CachingHiveMetastore.memoizeMetastore(metastore, 1000), hdfsEnvironment, new TestingTypeManager(), tableOperationsProvider, "test", false, false, false);
    BaseTable table = (BaseTable) loadIcebergTable(catalog, tableOperationsProvider, SESSION, new SchemaTableName("tpch", tableName));
    TableOperations operations = table.operations();
    TableMetadata currentMetadata = operations.current();
    operations.commit(currentMetadata, currentMetadata.upgradeToFormatVersion(2));
    return table;
}
Also used : TableMetadata(org.apache.iceberg.TableMetadata) BaseTable(org.apache.iceberg.BaseTable) TableOperations(org.apache.iceberg.TableOperations) FileMetastoreTableOperationsProvider(io.trino.plugin.iceberg.catalog.file.FileMetastoreTableOperationsProvider) TrinoHiveCatalog(io.trino.plugin.iceberg.catalog.hms.TrinoHiveCatalog) CatalogName(io.trino.plugin.base.CatalogName) IcebergTableOperationsProvider(io.trino.plugin.iceberg.catalog.IcebergTableOperationsProvider) SchemaTableName(io.trino.spi.connector.SchemaTableName) TrinoCatalog(io.trino.plugin.iceberg.catalog.TrinoCatalog) TestingTypeManager(io.trino.spi.type.TestingTypeManager)

Example 8 with TestingTypeManager

use of io.trino.spi.type.TestingTypeManager in project trino by trinodb.

the class TestAvroSchemaConverter method testSimpleSchema.

@Test
public void testSimpleSchema() {
    Schema schema = Schema.create(Schema.Type.LONG);
    AvroSchemaConverter avroSchemaConverter = new AvroSchemaConverter(new TestingTypeManager(), IGNORE);
    List<Type> types = avroSchemaConverter.convertAvroSchema(schema);
    assertEquals(getOnlyElement(types), BIGINT);
}
Also used : Type(io.trino.spi.type.Type) RowType(io.trino.spi.type.RowType) MapType(io.trino.spi.type.MapType) ArrayType(io.trino.spi.type.ArrayType) Schema(org.apache.avro.Schema) TestingTypeManager(io.trino.spi.type.TestingTypeManager) Test(org.testng.annotations.Test)

Example 9 with TestingTypeManager

use of io.trino.spi.type.TestingTypeManager in project trino by trinodb.

the class TestAvroSchemaConverter method testNullableColumns.

@Test
public void testNullableColumns() {
    Schema schema = SchemaBuilder.record(RECORD_NAME).fields().name("bool_col").type().nullable().booleanType().noDefault().name("int_col").type().nullable().intType().noDefault().name("long_col").type().nullable().longType().noDefault().name("float_col").type().nullable().floatType().noDefault().name("double_col").type().nullable().doubleType().noDefault().name("string_col").type().nullable().stringType().noDefault().name("enum_col").type().nullable().enumeration("colors").symbols("blue", "red", "yellow").noDefault().name("bytes_col").type().nullable().bytesType().noDefault().name("fixed_col").type().nullable().fixed("fixed").size(5).noDefault().name("union_col").type().unionOf().nullType().and().floatType().and().doubleType().endUnion().noDefault().name("union_col2").type().unionOf().nullType().and().intType().and().longType().endUnion().noDefault().name("union_col3").type().unionOf().nullType().and().bytesType().and().type("fixed").endUnion().noDefault().name("union_col4").type().unionOf().nullType().and().type("colors").and().stringType().endUnion().noDefault().name("list_col").type().nullable().array().items().intType().noDefault().name("map_col").type().nullable().map().values().intType().noDefault().name("record_col").type().nullable().record("record_col").fields().name("nested_list").type().nullable().array().items().map().values().stringType().noDefault().name("nested_map").type().nullable().map().values().array().items().stringType().noDefault().endRecord().noDefault().endRecord();
    AvroSchemaConverter avroSchemaConverter = new AvroSchemaConverter(new TestingTypeManager(), IGNORE);
    List<Type> types = avroSchemaConverter.convertAvroSchema(schema);
    List<Type> expected = ImmutableList.<Type>builder().add(BOOLEAN).add(INTEGER).add(BIGINT).add(REAL).add(DOUBLE).add(VARCHAR).add(VARCHAR).add(VARBINARY).add(VARBINARY).add(DOUBLE).add(BIGINT).add(VARBINARY).add(VARCHAR).add(new ArrayType(INTEGER)).add(createType(INTEGER)).add(RowType.from(ImmutableList.<RowType.Field>builder().add(new RowType.Field(Optional.of("nested_list"), new ArrayType(createType(VARCHAR)))).add(new RowType.Field(Optional.of("nested_map"), createType(new ArrayType(VARCHAR)))).build())).build();
    assertEquals(types, expected);
}
Also used : ArrayType(io.trino.spi.type.ArrayType) Type(io.trino.spi.type.Type) RowType(io.trino.spi.type.RowType) MapType(io.trino.spi.type.MapType) ArrayType(io.trino.spi.type.ArrayType) Schema(org.apache.avro.Schema) RowType(io.trino.spi.type.RowType) TestingTypeManager(io.trino.spi.type.TestingTypeManager) Test(org.testng.annotations.Test)

Example 10 with TestingTypeManager

use of io.trino.spi.type.TestingTypeManager in project trino by trinodb.

the class TestAvroSchemaConverter method testEmptyFieldStrategyForEmptySchema.

@Test
public void testEmptyFieldStrategyForEmptySchema() {
    Schema schema = SchemaBuilder.record(RECORD_NAME).fields().name("my_record").type().record("nested_record").fields().endRecord().noDefault().name("my_array").type().array().items().type("nested_record").noDefault().name("my_map").type().map().values().type("nested_record").noDefault().endRecord();
    assertThatThrownBy(() -> new AvroSchemaConverter(new TestingTypeManager(), IGNORE).convertAvroSchema(schema)).isInstanceOf(IllegalStateException.class).hasMessage("Schema has no valid fields: '%s'", schema);
    assertThatThrownBy(() -> new AvroSchemaConverter(new TestingTypeManager(), FAIL).convertAvroSchema(schema)).isInstanceOf(IllegalStateException.class).hasMessage("Struct type has no valid fields for schema: '%s'", SchemaBuilder.record("nested_record").fields().endRecord());
    List<Type> typesForAddDummyStrategy = ImmutableList.<Type>builder().add(RowType.from(ImmutableList.<RowType.Field>builder().add(new RowType.Field(Optional.of(DUMMY_FIELD_NAME), BOOLEAN)).build())).add(new ArrayType(RowType.from(ImmutableList.<RowType.Field>builder().add(new RowType.Field(Optional.of(DUMMY_FIELD_NAME), BOOLEAN)).build()))).add(createType(RowType.from(ImmutableList.<RowType.Field>builder().add(new RowType.Field(Optional.of(DUMMY_FIELD_NAME), BOOLEAN)).build()))).build();
    assertEquals(new AvroSchemaConverter(new TestingTypeManager(), ADD_DUMMY).convertAvroSchema(schema), typesForAddDummyStrategy);
}
Also used : ArrayType(io.trino.spi.type.ArrayType) Type(io.trino.spi.type.Type) RowType(io.trino.spi.type.RowType) MapType(io.trino.spi.type.MapType) ArrayType(io.trino.spi.type.ArrayType) Schema(org.apache.avro.Schema) RowType(io.trino.spi.type.RowType) TestingTypeManager(io.trino.spi.type.TestingTypeManager) Test(org.testng.annotations.Test)

Aggregations

TestingTypeManager (io.trino.spi.type.TestingTypeManager)21 Type (io.trino.spi.type.Type)14 Test (org.testng.annotations.Test)14 ObjectMapperProvider (io.airlift.json.ObjectMapperProvider)8 ArrayType (io.trino.spi.type.ArrayType)7 MapType (io.trino.spi.type.MapType)6 RowType (io.trino.spi.type.RowType)6 TestingTypeDeserializer (io.trino.spi.type.TestingTypeDeserializer)6 Schema (org.apache.avro.Schema)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)5 Block (io.trino.spi.block.Block)5 CatalogName (io.trino.plugin.base.CatalogName)4 FileMetastoreTableOperationsProvider (io.trino.plugin.iceberg.catalog.file.FileMetastoreTableOperationsProvider)4 TrinoHiveCatalog (io.trino.plugin.iceberg.catalog.hms.TrinoHiveCatalog)4 TestingBlockEncodingSerde (io.trino.spi.block.TestingBlockEncodingSerde)4 TestingBlockJsonSerde (io.trino.spi.block.TestingBlockJsonSerde)4 JsonCodecFactory (io.airlift.json.JsonCodecFactory)3 HdfsConfig (io.trino.plugin.hive.HdfsConfig)3 HdfsConfiguration (io.trino.plugin.hive.HdfsConfiguration)3