Search in sources :

Example 6 with Pair

use of io.prestosql.spi.heuristicindex.Pair in project hetu-core by openlookeng.

the class TestBitmapIndex method testInteger.

@Test
public void testInteger() throws IOException {
    try (TempFolder folder = new TempFolder();
        BitmapIndex bitmapIndexWrite = new BitmapIndex();
        BitmapIndex bitmapIndexRead = new BitmapIndex()) {
        folder.create();
        File file = folder.newFile();
        String columnName = "column";
        List<Object> columnValues = ImmutableList.of(3, 1024, 12345, 3, 2048, 999);
        bitmapIndexWrite.setExpectedNumOfEntries(columnValues.size());
        bitmapIndexWrite.addValues(Collections.singletonList(new Pair<>(columnName, columnValues)));
        try (FileOutputStream os = new FileOutputStream(file);
            FileInputStream is = new FileInputStream(file)) {
            bitmapIndexWrite.serialize(os);
            bitmapIndexRead.deserialize(is);
        }
        assertEquals(iteratorToList(bitmapIndexRead.lookUp(Domain.create(ValueSet.ofRanges(equal(IntegerType.INTEGER, 3L)), false))), ImmutableList.of(0, 3));
        assertEquals(iteratorToList(bitmapIndexRead.lookUp(Domain.create(ValueSet.ofRanges(equal(IntegerType.INTEGER, 3L)), false))), ImmutableList.of(0, 3));
        assertEquals(iteratorToList(bitmapIndexRead.lookUp(Domain.create(ValueSet.ofRanges(equal(IntegerType.INTEGER, 2048L)), false))), ImmutableList.of(4));
        assertEquals(iteratorToList(bitmapIndexRead.lookUp(Domain.create(ValueSet.ofRanges(equal(IntegerType.INTEGER, 0L)), false))), ImmutableList.of());
    }
}
Also used : TempFolder(io.hetu.core.common.filesystem.TempFolder) FileOutputStream(java.io.FileOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) Pair(io.prestosql.spi.heuristicindex.Pair) Test(org.testng.annotations.Test)

Example 7 with Pair

use of io.prestosql.spi.heuristicindex.Pair in project hetu-core by openlookeng.

the class TestBitmapIndex method testMultiThread.

@Test
public void testMultiThread() throws IOException {
    try (TempFolder folder = new TempFolder();
        BitmapIndex bitmapIndexWrite = new BitmapIndex();
        BitmapIndex bitmapIndexRead = new BitmapIndex()) {
        folder.create();
        File file = folder.newFile();
        String columnName = "column";
        List<Object> columnValues = ImmutableList.of(3, 1024, 12345, 3, 2048, 999);
        bitmapIndexWrite.setExpectedNumOfEntries(columnValues.size());
        bitmapIndexWrite.addValues(Collections.singletonList(new Pair<>(columnName, columnValues)));
        try (FileOutputStream os = new FileOutputStream(file);
            FileInputStream is = new FileInputStream(file)) {
            bitmapIndexWrite.serialize(os);
            bitmapIndexRead.deserialize(is);
        }
        IntStream.range(1, 10).parallel().forEach(i -> {
            assertEquals(iteratorToList(bitmapIndexRead.lookUp(Domain.create(ValueSet.ofRanges(equal(IntegerType.INTEGER, 3L)), false))), ImmutableList.of(0, 3));
            assertEquals(iteratorToList(bitmapIndexRead.lookUp(Domain.create(ValueSet.ofRanges(equal(IntegerType.INTEGER, 2048L)), false))), ImmutableList.of(4));
            assertEquals(iteratorToList(bitmapIndexRead.lookUp(Domain.create(ValueSet.ofRanges(equal(IntegerType.INTEGER, 0L)), false))), ImmutableList.of());
        });
    }
}
Also used : TempFolder(io.hetu.core.common.filesystem.TempFolder) FileOutputStream(java.io.FileOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) Pair(io.prestosql.spi.heuristicindex.Pair) Test(org.testng.annotations.Test)

Example 8 with Pair

use of io.prestosql.spi.heuristicindex.Pair in project hetu-core by openlookeng.

the class TestBloomIndex method testDomainMatching.

@Test
public void testDomainMatching() throws IOException {
    try (TempFolder folder = new TempFolder();
        BloomIndex stringBloomIndex = new BloomIndex()) {
        folder.create();
        File testFile = folder.newFile();
        List<Object> testValues = ImmutableList.of("a", "ab", "测试", "\n", "%#!", ":dfs");
        stringBloomIndex.setExpectedNumOfEntries(testValues.size());
        stringBloomIndex.addValues(Collections.singletonList(new Pair<>("testColumn", testValues)));
        try (FileOutputStream fo = new FileOutputStream(testFile)) {
            stringBloomIndex.serialize(fo);
        }
        try (FileInputStream fi = new FileInputStream(testFile)) {
            stringBloomIndex.deserialize(fi);
        }
        ValueSet valueSet = mock(ValueSet.class);
        when(valueSet.isSingleValue()).thenReturn(true);
        when(valueSet.getType()).thenReturn(VARCHAR);
        when(valueSet.getSingleValue()).thenReturn("a");
        assertTrue(stringBloomIndex.matches(Domain.create(valueSet, false)));
        when(valueSet.getSingleValue()).thenReturn("%#!");
        assertTrue(stringBloomIndex.matches(Domain.create(valueSet, false)));
        when(valueSet.getSingleValue()).thenReturn("bb");
        assertFalse(stringBloomIndex.matches(Domain.create(valueSet, false)));
    }
}
Also used : TempFolder(io.hetu.core.common.filesystem.TempFolder) FileOutputStream(java.io.FileOutputStream) File(java.io.File) ValueSet(io.prestosql.spi.predicate.ValueSet) FileInputStream(java.io.FileInputStream) Pair(io.prestosql.spi.heuristicindex.Pair) Test(org.testng.annotations.Test)

Example 9 with Pair

use of io.prestosql.spi.heuristicindex.Pair in project hetu-core by openlookeng.

the class TestBloomIndex method testLoad.

@Test
public void testLoad() throws IOException {
    try (TempFolder folder = new TempFolder();
        BloomIndex objectBloomIndex = new BloomIndex();
        BloomIndex readBloomIndex = new BloomIndex();
        BloomIndex intBloomIndex = new BloomIndex()) {
        folder.create();
        File testFile = folder.newFile();
        // Persist it using one object
        List<Object> testValues = ImmutableList.of("a", "ab", "测试", "\n", "%#!", ":dfs");
        objectBloomIndex.setExpectedNumOfEntries(testValues.size());
        objectBloomIndex.addValues(Collections.singletonList(new Pair<>("testColumn", testValues)));
        try (FileOutputStream fo = new FileOutputStream(testFile)) {
            objectBloomIndex.serialize(fo);
        }
        // Load it using another object
        try (FileInputStream fi = new FileInputStream(testFile)) {
            readBloomIndex.deserialize(fi);
        }
        // Check the result validity
        assertTrue(mightContain(readBloomIndex, VARCHAR, "a"));
        assertTrue(mightContain(readBloomIndex, VARCHAR, "ab"));
        assertTrue(mightContain(readBloomIndex, VARCHAR, "测试"));
        assertTrue(mightContain(readBloomIndex, VARCHAR, "\n"));
        assertTrue(mightContain(readBloomIndex, VARCHAR, "%#!"));
        assertTrue(mightContain(readBloomIndex, VARCHAR, ":dfs"));
        assertFalse(mightContain(readBloomIndex, VARCHAR, "random"));
        assertFalse(mightContain(readBloomIndex, VARCHAR, "abc"));
        // Load it using a weired object
        try (FileInputStream fi = new FileInputStream(testFile)) {
            intBloomIndex.deserialize(fi);
        }
        assertFalse(mightContain(intBloomIndex, BIGINT, 1));
        assertFalse(mightContain(intBloomIndex, BIGINT, 0));
        assertFalse(mightContain(intBloomIndex, BIGINT, 1000));
        assertFalse(mightContain(intBloomIndex, BIGINT, "a".hashCode()));
    }
}
Also used : TempFolder(io.hetu.core.common.filesystem.TempFolder) FileOutputStream(java.io.FileOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) Pair(io.prestosql.spi.heuristicindex.Pair) Test(org.testng.annotations.Test)

Example 10 with Pair

use of io.prestosql.spi.heuristicindex.Pair in project hetu-core by openlookeng.

the class TestIndexResources method getSplitAndMaterializedResult.

// Get the split count and MaterializedResult in one pair to return.
Pair<Integer, MaterializedResult> getSplitAndMaterializedResult(String testerQuery) {
    // Select the entry with specifics
    MaterializedResult queryResult = computeActual(testerQuery);
    String doublyQuotedQuery = testerQuery.replaceAll("'", "''");
    // Get queries executed and query ID to find the task with sum of splits
    String splits = "select sum(splits) from system.runtime.tasks where query_id in " + "(select query_id from system.runtime.queries " + "where query='" + doublyQuotedQuery + "' order by created desc limit 1)";
    MaterializedResult rows = computeActual(splits);
    assertEquals(rows.getRowCount(), 1);
    MaterializedRow materializedRow = rows.getMaterializedRows().get(0);
    int fieldCount = materializedRow.getFieldCount();
    assertEquals(fieldCount, 1, "Expected only one column, but got '%d', fiedlCount: " + fieldCount);
    Object value = materializedRow.getField(0);
    return new Pair<>((int) (long) value, queryResult);
}
Also used : MaterializedResult(io.prestosql.testing.MaterializedResult) MaterializedRow(io.prestosql.testing.MaterializedRow) Pair(io.prestosql.spi.heuristicindex.Pair)

Aggregations

Pair (io.prestosql.spi.heuristicindex.Pair)38 Test (org.testng.annotations.Test)25 File (java.io.File)24 FileOutputStream (java.io.FileOutputStream)24 FileInputStream (java.io.FileInputStream)23 ArrayList (java.util.ArrayList)22 RowExpression (io.prestosql.spi.relation.RowExpression)14 TempFolder (io.hetu.core.common.filesystem.TempFolder)12 List (java.util.List)10 IOException (java.io.IOException)9 CreateIndexMetadata (io.prestosql.spi.connector.CreateIndexMetadata)8 Map (java.util.Map)8 Properties (java.util.Properties)8 HashMap (java.util.HashMap)7 Iterator (java.util.Iterator)7 Collections (java.util.Collections)6 Index (io.prestosql.spi.heuristicindex.Index)5 Objects.requireNonNull (java.util.Objects.requireNonNull)5 Preconditions.checkState (com.google.common.base.Preconditions.checkState)4 HeuristicIndexerManager (io.prestosql.heuristicindex.HeuristicIndexerManager)4