use of io.prestosql.spi.heuristicindex.Pair in project hetu-core by openlookeng.
the class TestBTreeIndex method testLessThan.
@Test
public void testLessThan() throws IOException, IndexLookUpException {
BTreeIndex index = new BTreeIndex();
for (int i = 0; i < 100; i++) {
List<Pair> pairs = new ArrayList<>();
Long key = Long.valueOf(100 + i);
String value = "value" + i;
pairs.add(new Pair(key, value));
Pair pair = new Pair("dummyCol", pairs);
index.addKeyValues(Collections.singletonList(pair));
}
File file = getFile();
index.serialize(new FileOutputStream(file));
BTreeIndex readIndex = new BTreeIndex();
readIndex.deserialize(new FileInputStream(file));
RowExpression comparisonExpression = simplePredicate(OperatorType.LESS_THAN, "dummyCol", BIGINT, 120L);
Iterator<String> result = readIndex.lookUp(comparisonExpression);
assertNotNull(result, "Result shouldn't be null");
assertTrue(result.hasNext());
Object[] arr = IntStream.iterate(0, n -> n + 1).limit(20).mapToObj(i -> "value" + i).toArray();
Arrays.sort(arr);
for (int i = 0; i < 20; i++) {
assertEquals(arr[i], result.next());
}
assertFalse(result.hasNext());
index.close();
}
use of io.prestosql.spi.heuristicindex.Pair in project hetu-core by openlookeng.
the class TestBTreeIndex method testStringKey.
@Test
public void testStringKey() throws IOException {
BTreeIndex index = new BTreeIndex();
String value = "001:3,002:3,003:3,004:3,005:3,006:3,007:3,008:3,009:3,002:3,010:3,002:3,011:3,012:3,101:3,102:3,103:3,104:3,105:3,106:3,107:3,108:3,109:3,102:3,110:3,102:3,111:3,112:3";
List<Pair> pairs = new ArrayList<>();
pairs.add(new Pair("key1", value));
Pair pair = new Pair("dummyCol", pairs);
index.addKeyValues(Collections.singletonList(pair));
File file = getFile();
index.serialize(new FileOutputStream(file));
BTreeIndex readIndex = new BTreeIndex();
readIndex.deserialize(new FileInputStream(file));
RowExpression comparisonExpression = simplePredicate(OperatorType.EQUAL, "dummyCol", VARCHAR, "key1");
assertTrue(readIndex.matches(comparisonExpression), "Key should exists");
index.close();
}
use of io.prestosql.spi.heuristicindex.Pair in project hetu-core by openlookeng.
the class TestBTreeIndex method testIn.
@Test
public void testIn() throws IOException, IndexLookUpException {
BTreeIndex index = new BTreeIndex();
for (int i = 0; i < 20; i++) {
List<Pair> pairs = new ArrayList<>();
Long key = Long.valueOf(100 + i);
String value = "value" + i;
pairs.add(new Pair(key, value));
Pair pair = new Pair("dummyCol", pairs);
index.addKeyValues(Collections.singletonList(pair));
}
File file = getFile();
index.serialize(new FileOutputStream(file));
BTreeIndex readIndex = new BTreeIndex();
readIndex.deserialize(new FileInputStream(file));
RowExpression inPredicate = new SpecialForm(SpecialForm.Form.IN, BOOLEAN, new VariableReferenceExpression("dummyCol", VARCHAR), new ConstantExpression(111L, BIGINT), new ConstantExpression(115L, BIGINT), new ConstantExpression(118L, BIGINT), new ConstantExpression(150L, BIGINT));
Iterator<String> result = readIndex.lookUp(inPredicate);
assertNotNull(result, "Result shouldn't be null");
assertTrue(result.hasNext());
assertEquals("value11", result.next());
assertEquals("value15", result.next());
assertEquals("value18", result.next());
assertFalse(result.hasNext());
index.close();
}
use of io.prestosql.spi.heuristicindex.Pair in project hetu-core by openlookeng.
the class TestBTreeIndex method testGreaterThan.
@Test
public void testGreaterThan() throws IOException, IndexLookUpException {
BTreeIndex index = new BTreeIndex();
for (int i = 0; i < 25; i++) {
List<Pair> pairs = new ArrayList<>();
Long key = Long.valueOf(100 + i);
String value = "value" + i;
pairs.add(new Pair(key, value));
Pair pair = new Pair("dummyCol", pairs);
index.addKeyValues(Collections.singletonList(pair));
}
File file = getFile();
index.serialize(new FileOutputStream(file));
BTreeIndex readIndex = new BTreeIndex();
readIndex.deserialize(new FileInputStream(file));
RowExpression comparisonExpression = simplePredicate(OperatorType.GREATER_THAN, "dummyCol", BIGINT, 120L);
Iterator<String> result = readIndex.lookUp(comparisonExpression);
assertNotNull(result, "Result shouldn't be null");
System.out.println(result.hasNext());
for (int i = 21; i < 25; i++) {
Object data = result.next();
assertEquals("value" + i, data.toString());
}
assertFalse(result.hasNext());
index.close();
}
use of io.prestosql.spi.heuristicindex.Pair in project hetu-core by openlookeng.
the class TestMinMaxIndex method testMatches.
@Test
public void testMatches() throws IOException {
MinMaxIndex minMaxIndex = new MinMaxIndex();
List<Object> minmaxValues = ImmutableList.of(1L, 10L, 100L, 1000L);
minMaxIndex.addValues(Collections.singletonList(new Pair<>("testColumn", minmaxValues)));
RowExpression expression1 = simplePredicate(OperatorType.LESS_THAN, "testColumn", BIGINT, 0L);
RowExpression expression2 = simplePredicate(OperatorType.EQUAL, "testColumn", BIGINT, 1L);
RowExpression expression3 = simplePredicate(OperatorType.GREATER_THAN, "testColumn", BIGINT, 10L);
RowExpression expression4 = simplePredicate(OperatorType.GREATER_THAN, "testColumn", BIGINT, 1000L);
RowExpression expression5 = simplePredicate(OperatorType.LESS_THAN_OR_EQUAL, "testColumn", BIGINT, 1L);
assertFalse(minMaxIndex.matches(expression1));
assertTrue(minMaxIndex.matches(expression2));
assertTrue(minMaxIndex.matches(expression3));
assertFalse(minMaxIndex.matches(expression4));
assertTrue(minMaxIndex.matches(expression5));
}
Aggregations