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());
}
}
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());
}
}
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());
});
}
}
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)));
}
}
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()));
}
}
Aggregations