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