Search in sources :

Example 6 with TestingBlockEncodingSerde

use of io.trino.spi.block.TestingBlockEncodingSerde in project trino by trinodb.

the class TestFileSingleStreamSpiller method assertSpill.

private void assertSpill(boolean compression, boolean encryption) throws Exception {
    FileSingleStreamSpillerFactory spillerFactory = new FileSingleStreamSpillerFactory(// executor won't be closed, because we don't call destroy() on the spiller factory
    executor, new TestingBlockEncodingSerde(), new SpillerStats(), ImmutableList.of(spillPath.toPath()), 1.0, compression, encryption);
    LocalMemoryContext memoryContext = newSimpleAggregatedMemoryContext().newLocalMemoryContext("test");
    SingleStreamSpiller singleStreamSpiller = spillerFactory.create(TYPES, bytes -> {
    }, memoryContext);
    assertTrue(singleStreamSpiller instanceof FileSingleStreamSpiller);
    FileSingleStreamSpiller spiller = (FileSingleStreamSpiller) singleStreamSpiller;
    Page page = buildPage();
    // The spillers will reserve memory in their constructors
    assertEquals(memoryContext.getBytes(), 4096);
    spiller.spill(page).get();
    spiller.spill(Iterators.forArray(page, page, page)).get();
    assertEquals(listFiles(spillPath.toPath()).size(), 1);
    // Assert the spill codec flags match the expected configuration
    try (InputStream is = newInputStream(listFiles(spillPath.toPath()).get(0))) {
        Iterator<Slice> serializedPages = PagesSerdeUtil.readSerializedPages(is);
        assertTrue(serializedPages.hasNext(), "at least one page should be successfully read back");
        Slice serializedPage = serializedPages.next();
        assertEquals(isSerializedPageCompressed(serializedPage), compression);
        assertEquals(isSerializedPageEncrypted(serializedPage), encryption);
    }
    // The spillers release their memory reservations when they are closed, therefore at this point
    // they will have non-zero memory reservation.
    // assertEquals(memoryContext.getBytes(), 0);
    Iterator<Page> spilledPagesIterator = spiller.getSpilledPages();
    assertEquals(memoryContext.getBytes(), FileSingleStreamSpiller.BUFFER_SIZE);
    ImmutableList<Page> spilledPages = ImmutableList.copyOf(spilledPagesIterator);
    // The spillers release their memory reservations when they are closed, therefore at this point
    // they will have non-zero memory reservation.
    // assertEquals(memoryContext.getBytes(), 0);
    assertEquals(4, spilledPages.size());
    for (int i = 0; i < 4; ++i) {
        PageAssertions.assertPageEquals(TYPES, page, spilledPages.get(i));
    }
    spiller.close();
    assertEquals(listFiles(spillPath.toPath()).size(), 0);
    assertEquals(memoryContext.getBytes(), 0);
}
Also used : LocalMemoryContext(io.trino.memory.context.LocalMemoryContext) TestingBlockEncodingSerde(io.trino.spi.block.TestingBlockEncodingSerde) Files.newInputStream(java.nio.file.Files.newInputStream) InputStream(java.io.InputStream) Page(io.trino.spi.Page) Slice(io.airlift.slice.Slice)

Example 7 with TestingBlockEncodingSerde

use of io.trino.spi.block.TestingBlockEncodingSerde in project trino by trinodb.

the class TestGenericPartitioningSpiller method setUp.

@BeforeClass
public void setUp() throws Exception {
    tempDirectory = createTempDirectory(getClass().getSimpleName());
    FeaturesConfig featuresConfig = new FeaturesConfig();
    featuresConfig.setSpillerSpillPaths(tempDirectory.toString());
    featuresConfig.setSpillerThreads(8);
    featuresConfig.setSpillMaxUsedSpaceThreshold(1.0);
    SingleStreamSpillerFactory singleStreamSpillerFactory = new FileSingleStreamSpillerFactory(new TestingBlockEncodingSerde(), new SpillerStats(), featuresConfig, new NodeSpillConfig());
    factory = new GenericPartitioningSpillerFactory(singleStreamSpillerFactory);
    scheduledExecutor = newSingleThreadScheduledExecutor();
}
Also used : TestingBlockEncodingSerde(io.trino.spi.block.TestingBlockEncodingSerde) FeaturesConfig(io.trino.FeaturesConfig) BeforeClass(org.testng.annotations.BeforeClass)

Example 8 with TestingBlockEncodingSerde

use of io.trino.spi.block.TestingBlockEncodingSerde in project trino by trinodb.

the class TestBinaryFileSpiller method setUp.

@BeforeMethod
public void setUp() {
    spillerStats = new SpillerStats();
    FeaturesConfig featuresConfig = new FeaturesConfig();
    featuresConfig.setSpillerSpillPaths(spillPath.getAbsolutePath());
    featuresConfig.setSpillMaxUsedSpaceThreshold(1.0);
    NodeSpillConfig nodeSpillConfig = new NodeSpillConfig();
    BlockEncodingSerde blockEncodingSerde = new TestingBlockEncodingSerde();
    singleStreamSpillerFactory = new FileSingleStreamSpillerFactory(blockEncodingSerde, spillerStats, featuresConfig, nodeSpillConfig);
    factory = new GenericSpillerFactory(singleStreamSpillerFactory);
    PagesSerdeFactory pagesSerdeFactory = new PagesSerdeFactory(blockEncodingSerde, nodeSpillConfig.isSpillCompressionEnabled());
    pagesSerde = pagesSerdeFactory.createPagesSerde();
    memoryContext = newSimpleAggregatedMemoryContext();
}
Also used : PagesSerdeFactory(io.trino.execution.buffer.PagesSerdeFactory) TestingBlockEncodingSerde(io.trino.spi.block.TestingBlockEncodingSerde) FeaturesConfig(io.trino.FeaturesConfig) TestingBlockEncodingSerde(io.trino.spi.block.TestingBlockEncodingSerde) BlockEncodingSerde(io.trino.spi.block.BlockEncodingSerde) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 9 with TestingBlockEncodingSerde

use of io.trino.spi.block.TestingBlockEncodingSerde in project trino by trinodb.

the class TestSortedRangeSet method testJsonSerialization.

@Test
public void testJsonSerialization() throws Exception {
    TestingTypeManager typeManager = new TestingTypeManager();
    TestingBlockEncodingSerde blockEncodingSerde = new TestingBlockEncodingSerde();
    ObjectMapper mapper = new ObjectMapperProvider().get().registerModule(new SimpleModule().addDeserializer(Type.class, new TestingTypeDeserializer(typeManager)).addSerializer(Block.class, new TestingBlockJsonSerde.Serializer(blockEncodingSerde)).addDeserializer(Block.class, new TestingBlockJsonSerde.Deserializer(blockEncodingSerde)));
    SortedRangeSet set = SortedRangeSet.all(BIGINT);
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), SortedRangeSet.class));
    set = SortedRangeSet.none(DOUBLE);
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), SortedRangeSet.class));
    set = SortedRangeSet.of(VARCHAR, utf8Slice("abc"));
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), SortedRangeSet.class));
    set = SortedRangeSet.of(Range.equal(BOOLEAN, true), Range.equal(BOOLEAN, false));
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), SortedRangeSet.class));
}
Also used : Type(io.trino.spi.type.Type) DecimalType.createDecimalType(io.trino.spi.type.DecimalType.createDecimalType) VarcharType.createVarcharType(io.trino.spi.type.VarcharType.createVarcharType) TestingTypeDeserializer(io.trino.spi.type.TestingTypeDeserializer) TestingBlockEncodingSerde(io.trino.spi.block.TestingBlockEncodingSerde) TestingTypeDeserializer(io.trino.spi.type.TestingTypeDeserializer) Block(io.trino.spi.block.Block) TestingBlockJsonSerde(io.trino.spi.block.TestingBlockJsonSerde) TestingTypeManager(io.trino.spi.type.TestingTypeManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) Test(org.testng.annotations.Test)

Example 10 with TestingBlockEncodingSerde

use of io.trino.spi.block.TestingBlockEncodingSerde in project trino by trinodb.

the class TestTupleDomain method testJsonSerialization.

@Test
public void testJsonSerialization() throws Exception {
    TestingTypeManager typeManager = new TestingTypeManager();
    TestingBlockEncodingSerde blockEncodingSerde = new TestingBlockEncodingSerde();
    ObjectMapper mapper = new ObjectMapperProvider().get().registerModule(new SimpleModule().addDeserializer(ColumnHandle.class, new JsonDeserializer<>() {

        @Override
        public ColumnHandle deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
            return new ObjectMapperProvider().get().readValue(jsonParser, TestingColumnHandle.class);
        }
    }).addDeserializer(Type.class, new TestingTypeDeserializer(typeManager)).addSerializer(Block.class, new TestingBlockJsonSerde.Serializer(blockEncodingSerde)).addDeserializer(Block.class, new TestingBlockJsonSerde.Deserializer(blockEncodingSerde)));
    TupleDomain<ColumnHandle> tupleDomain = TupleDomain.all();
    assertEquals(tupleDomain, mapper.readValue(mapper.writeValueAsString(tupleDomain), new TypeReference<TupleDomain<ColumnHandle>>() {
    }));
    tupleDomain = TupleDomain.none();
    assertEquals(tupleDomain, mapper.readValue(mapper.writeValueAsString(tupleDomain), new TypeReference<TupleDomain<ColumnHandle>>() {
    }));
    tupleDomain = TupleDomain.fromFixedValues(ImmutableMap.of(A, NullableValue.of(BIGINT, 1L), B, NullableValue.asNull(VARCHAR)));
    assertEquals(tupleDomain, mapper.readValue(mapper.writeValueAsString(tupleDomain), new TypeReference<TupleDomain<ColumnHandle>>() {
    }));
}
Also used : TestingColumnHandle(io.trino.spi.connector.TestingColumnHandle) ColumnHandle(io.trino.spi.connector.ColumnHandle) TestingBlockEncodingSerde(io.trino.spi.block.TestingBlockEncodingSerde) IOException(java.io.IOException) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) TestingColumnHandle(io.trino.spi.connector.TestingColumnHandle) Type(io.trino.spi.type.Type) TestingTypeDeserializer(io.trino.spi.type.TestingTypeDeserializer) TestingTypeDeserializer(io.trino.spi.type.TestingTypeDeserializer) JsonDeserializer(com.fasterxml.jackson.databind.JsonDeserializer) DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) Block(io.trino.spi.block.Block) TestingBlockJsonSerde(io.trino.spi.block.TestingBlockJsonSerde) TypeReference(com.fasterxml.jackson.core.type.TypeReference) TestingTypeManager(io.trino.spi.type.TestingTypeManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) JsonParser(com.fasterxml.jackson.core.JsonParser) Test(org.testng.annotations.Test)

Aggregations

TestingBlockEncodingSerde (io.trino.spi.block.TestingBlockEncodingSerde)10 Test (org.testng.annotations.Test)6 Block (io.trino.spi.block.Block)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)4 ObjectMapperProvider (io.airlift.json.ObjectMapperProvider)4 TestingBlockJsonSerde (io.trino.spi.block.TestingBlockJsonSerde)4 TestingTypeDeserializer (io.trino.spi.type.TestingTypeDeserializer)4 TestingTypeManager (io.trino.spi.type.TestingTypeManager)4 Type (io.trino.spi.type.Type)4 PagesSerdeFactory (io.trino.execution.buffer.PagesSerdeFactory)3 FeaturesConfig (io.trino.FeaturesConfig)2 PartitionedOutputBuffer (io.trino.execution.buffer.PartitionedOutputBuffer)2 TaskExecutor (io.trino.execution.executor.TaskExecutor)2 DriverFactory (io.trino.operator.DriverFactory)2 TaskContext (io.trino.operator.TaskContext)2 TaskOutputOperatorFactory (io.trino.operator.output.TaskOutputOperator.TaskOutputOperatorFactory)2 Page (io.trino.spi.Page)2 LocalExecutionPlan (io.trino.sql.planner.LocalExecutionPlanner.LocalExecutionPlan)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2