Search in sources :

Example 6 with TempFolder

use of io.hetu.core.common.filesystem.TempFolder in project hetu-core by openlookeng.

the class TestBitmapIndex method testString.

@Test
public void testString() 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("foo", "bar", "baz", "foo", "foo", "baz");
        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(createUnboundedVarcharType(), utf8Slice("foo"))), false))), ImmutableList.of(0, 3, 4));
        assertEquals(iteratorToList(bitmapIndexRead.lookUp(Domain.create(ValueSet.ofRanges(equal(createUnboundedVarcharType(), utf8Slice("bar"))), false))), ImmutableList.of(1));
        assertEquals(iteratorToList(bitmapIndexRead.lookUp(Domain.create(ValueSet.ofRanges(equal(createUnboundedVarcharType(), utf8Slice("notfound"))), 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 TempFolder

use of io.hetu.core.common.filesystem.TempFolder 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 8 with TempFolder

use of io.hetu.core.common.filesystem.TempFolder 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 9 with TempFolder

use of io.hetu.core.common.filesystem.TempFolder 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 10 with TempFolder

use of io.hetu.core.common.filesystem.TempFolder 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)

Aggregations

TempFolder (io.hetu.core.common.filesystem.TempFolder)28 File (java.io.File)18 Test (org.testng.annotations.Test)17 FileInputStream (java.io.FileInputStream)15 FileOutputStream (java.io.FileOutputStream)14 Pair (io.prestosql.spi.heuristicindex.Pair)12 HashMap (java.util.HashMap)5 HetuFileSystemClientPlugin (io.hetu.core.filesystem.HetuFileSystemClientPlugin)4 HetuMetastorePlugin (io.hetu.core.metastore.HetuMetastorePlugin)4 HetuFsMetastore (io.hetu.core.metastore.hetufilesystem.HetuFsMetastore)4 HetuFsMetastoreConfig (io.hetu.core.metastore.hetufilesystem.HetuFsMetastoreConfig)4 BeforeClass (org.testng.annotations.BeforeClass)4 HetuMetastore (io.prestosql.spi.metastore.HetuMetastore)3 InputStream (java.io.InputStream)3 Properties (java.util.Properties)3 HetuLocalFileSystemClient (io.hetu.core.filesystem.HetuLocalFileSystemClient)2 LocalConfig (io.hetu.core.filesystem.LocalConfig)2 JdbcHetuMetastore (io.hetu.core.metastore.jdbc.JdbcHetuMetastore)2 MemoryPlugin (io.prestosql.plugin.memory.MemoryPlugin)2 RowExpression (io.prestosql.spi.relation.RowExpression)2