Search in sources :

Example 1 with IntArrayBlock

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

the class TestSimplePagesHashStrategy method testHashRowWithMapType.

@Test
public void testHashRowWithMapType() {
    MapType mapType = new MapType(INTEGER, INTEGER, new TypeOperators());
    Block block = mapType.createBlockFromKeyValue(Optional.empty(), new int[] { 0, 1 }, new IntArrayBlock(1, Optional.empty(), new int[] { 1234 }), new IntArrayBlock(1, Optional.empty(), new int[] { 5678 }));
    SimplePagesHashStrategy strategy = createSimplePagesHashStrategy(mapType, ImmutableList.of(block));
    Page page = new Page(block);
    // This works because MapType is comparable.
    assertEquals(strategy.hashRow(0, page), 451258269207618863L);
}
Also used : IntArrayBlock(io.trino.spi.block.IntArrayBlock) IntArrayBlock(io.trino.spi.block.IntArrayBlock) Block(io.trino.spi.block.Block) Page(io.trino.spi.Page) MapType(io.trino.spi.type.MapType) BlockTypeOperators(io.trino.type.BlockTypeOperators) TypeOperators(io.trino.spi.type.TypeOperators) Test(org.testng.annotations.Test)

Example 2 with IntArrayBlock

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

the class TestDictionaryBlock method testNestedDictionarySizes.

@Test
public void testNestedDictionarySizes() {
    // fixed width block
    Block fixedWidthBlock = new IntArrayBlock(100, Optional.empty(), IntStream.range(0, 100).toArray());
    assertDictionarySizeMethods(fixedWidthBlock);
    assertDictionarySizeMethods(new DictionaryBlock(fixedWidthBlock, IntStream.range(0, 50).toArray()));
    assertDictionarySizeMethods(new DictionaryBlock(new DictionaryBlock(fixedWidthBlock, IntStream.range(0, 50).toArray()), IntStream.range(0, 10).toArray()));
    // variable width block
    Block variableWidthBlock = createSlicesBlock(createExpectedValues(100));
    assertDictionarySizeMethods(variableWidthBlock);
    assertDictionarySizeMethods(new DictionaryBlock(variableWidthBlock, IntStream.range(0, 50).toArray()));
    assertDictionarySizeMethods(new DictionaryBlock(new DictionaryBlock(variableWidthBlock, IntStream.range(0, 50).toArray()), IntStream.range(0, 10).toArray()));
}
Also used : IntArrayBlock(io.trino.spi.block.IntArrayBlock) DictionaryBlock(io.trino.spi.block.DictionaryBlock) BlockAssertions.createSlicesBlock(io.trino.block.BlockAssertions.createSlicesBlock) VariableWidthBlock(io.trino.spi.block.VariableWidthBlock) DictionaryBlock(io.trino.spi.block.DictionaryBlock) IntArrayBlock(io.trino.spi.block.IntArrayBlock) Block(io.trino.spi.block.Block) Test(org.testng.annotations.Test)

Example 3 with IntArrayBlock

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

the class TestSimplePagesHashStrategy method testCompareSortChannelPositionsWithMapType.

@Test
public void testCompareSortChannelPositionsWithMapType() {
    MapType mapType = new MapType(INTEGER, INTEGER, new TypeOperators());
    Block block = mapType.createBlockFromKeyValue(Optional.empty(), new int[] { 0, 1 }, new IntArrayBlock(1, Optional.empty(), new int[] { 1234 }), new IntArrayBlock(1, Optional.empty(), new int[] { 5678 }));
    SimplePagesHashStrategy strategy = createSimplePagesHashStrategy(mapType, ImmutableList.of(block));
    // This fails because MapType is not orderable.
    assertThatThrownBy(() -> strategy.compareSortChannelPositions(0, 0, 0, 0)).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("type is not orderable");
}
Also used : IntArrayBlock(io.trino.spi.block.IntArrayBlock) IntArrayBlock(io.trino.spi.block.IntArrayBlock) Block(io.trino.spi.block.Block) MapType(io.trino.spi.type.MapType) BlockTypeOperators(io.trino.type.BlockTypeOperators) TypeOperators(io.trino.spi.type.TypeOperators) Test(org.testng.annotations.Test)

Example 4 with IntArrayBlock

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

the class TestSimplePagesHashStrategy method testRowEqualsRowWithIntegerType.

@Test
public void testRowEqualsRowWithIntegerType() {
    SimplePagesHashStrategy strategy = createSimplePagesHashStrategy(INTEGER, ImmutableList.of());
    Page leftPage = new Page(new IntArrayBlock(1, Optional.empty(), new int[] { 1234 }));
    Page rightPage1 = new Page(new IntArrayBlock(1, Optional.empty(), new int[] { 1234 }));
    Page rightPage2 = new Page(new IntArrayBlock(1, Optional.empty(), new int[] { 5678 }));
    // This works because IntegerType is comparable.
    assertTrue(strategy.rowEqualsRow(0, leftPage, 0, rightPage1));
    assertFalse(strategy.rowEqualsRow(0, leftPage, 0, rightPage2));
}
Also used : IntArrayBlock(io.trino.spi.block.IntArrayBlock) Page(io.trino.spi.Page) Test(org.testng.annotations.Test)

Example 5 with IntArrayBlock

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

the class TestSimplePagesHashStrategy method testRowEqualsRowWithMapType.

@Test
public void testRowEqualsRowWithMapType() {
    MapType mapType = new MapType(INTEGER, INTEGER, new TypeOperators());
    SimplePagesHashStrategy strategy = createSimplePagesHashStrategy(mapType, ImmutableList.of());
    Page leftPage = new Page(mapType.createBlockFromKeyValue(Optional.empty(), new int[] { 0, 1 }, new IntArrayBlock(1, Optional.empty(), new int[] { 1234 }), new IntArrayBlock(1, Optional.empty(), new int[] { 5678 })));
    Page rightPage1 = new Page(mapType.createBlockFromKeyValue(Optional.empty(), new int[] { 0, 1 }, new IntArrayBlock(1, Optional.empty(), new int[] { 1234 }), new IntArrayBlock(1, Optional.empty(), new int[] { 5678 })));
    Page rightPage2 = new Page(mapType.createBlockFromKeyValue(Optional.empty(), new int[] { 0, 1 }, new IntArrayBlock(1, Optional.empty(), new int[] { 1234 }), new IntArrayBlock(1, Optional.empty(), new int[] { 1234 })));
    // This works because MapType is comparable.
    assertTrue(strategy.rowEqualsRow(0, leftPage, 0, rightPage1));
    assertFalse(strategy.rowEqualsRow(0, leftPage, 0, rightPage2));
}
Also used : IntArrayBlock(io.trino.spi.block.IntArrayBlock) Page(io.trino.spi.Page) MapType(io.trino.spi.type.MapType) BlockTypeOperators(io.trino.type.BlockTypeOperators) TypeOperators(io.trino.spi.type.TypeOperators) Test(org.testng.annotations.Test)

Aggregations

IntArrayBlock (io.trino.spi.block.IntArrayBlock)9 Test (org.testng.annotations.Test)9 Block (io.trino.spi.block.Block)5 Page (io.trino.spi.Page)4 MapType (io.trino.spi.type.MapType)3 TypeOperators (io.trino.spi.type.TypeOperators)3 BlockTypeOperators (io.trino.type.BlockTypeOperators)3 BlockAssertions.createSlicesBlock (io.trino.block.BlockAssertions.createSlicesBlock)1 ResolvedFunction (io.trino.metadata.ResolvedFunction)1 DictionaryBlock (io.trino.spi.block.DictionaryBlock)1 VariableWidthBlock (io.trino.spi.block.VariableWidthBlock)1 ArrayType (io.trino.spi.type.ArrayType)1 CallExpression (io.trino.sql.relational.CallExpression)1 ConstantExpression (io.trino.sql.relational.ConstantExpression)1 RowExpression (io.trino.sql.relational.RowExpression)1