Search in sources :

Example 26 with Pair

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();
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) ArrayList(java.util.ArrayList) VARCHAR(io.prestosql.spi.type.VarcharType.VARCHAR) OperatorType(io.prestosql.spi.function.OperatorType) BOOLEAN(io.prestosql.spi.type.BooleanType.BOOLEAN) SpecialForm(io.prestosql.spi.relation.SpecialForm) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) Assert.assertFalse(org.testng.Assert.assertFalse) Iterator(java.util.Iterator) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) FileInputStream(java.io.FileInputStream) UUID(java.util.UUID) Assert.assertNotNull(org.testng.Assert.assertNotNull) Pair(io.prestosql.spi.heuristicindex.Pair) File(java.io.File) List(java.util.List) HeuristicIndexTestUtils.simplePredicate(io.hetu.core.HeuristicIndexTestUtils.simplePredicate) RowExpression(io.prestosql.spi.relation.RowExpression) Assert.assertTrue(org.testng.Assert.assertTrue) IndexLookUpException(io.prestosql.spi.heuristicindex.IndexLookUpException) Index(io.prestosql.spi.heuristicindex.Index) Collections(java.util.Collections) ArrayList(java.util.ArrayList) RowExpression(io.prestosql.spi.relation.RowExpression) FileInputStream(java.io.FileInputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) Pair(io.prestosql.spi.heuristicindex.Pair) Test(org.testng.annotations.Test)

Example 27 with Pair

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();
}
Also used : FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) RowExpression(io.prestosql.spi.relation.RowExpression) File(java.io.File) FileInputStream(java.io.FileInputStream) Pair(io.prestosql.spi.heuristicindex.Pair) Test(org.testng.annotations.Test)

Example 28 with Pair

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();
}
Also used : ConstantExpression(io.prestosql.spi.relation.ConstantExpression) ArrayList(java.util.ArrayList) RowExpression(io.prestosql.spi.relation.RowExpression) FileInputStream(java.io.FileInputStream) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) FileOutputStream(java.io.FileOutputStream) File(java.io.File) SpecialForm(io.prestosql.spi.relation.SpecialForm) Pair(io.prestosql.spi.heuristicindex.Pair) Test(org.testng.annotations.Test)

Example 29 with Pair

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();
}
Also used : ArrayList(java.util.ArrayList) RowExpression(io.prestosql.spi.relation.RowExpression) FileInputStream(java.io.FileInputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) Pair(io.prestosql.spi.heuristicindex.Pair) Test(org.testng.annotations.Test)

Example 30 with Pair

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));
}
Also used : RowExpression(io.prestosql.spi.relation.RowExpression) Pair(io.prestosql.spi.heuristicindex.Pair) Test(org.testng.annotations.Test)

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