Skip to content

Commit

Permalink
add greaterthan and lessthan and other read functions to table class
Browse files Browse the repository at this point in the history
  • Loading branch information
firestar committed Dec 7, 2023
1 parent e6549d9 commit df16fb8
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 17 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = 'com.nucleodb'
version = '1.13.0'
version = '1.13.1'

repositories {
mavenCentral()
Expand Down
33 changes: 19 additions & 14 deletions src/main/java/com/nucleodb/library/database/index/IndexWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.collect.Queues;
import com.nucleodb.library.database.index.trie.Entry;
import com.nucleodb.library.database.tables.table.DataEntry;
import com.nucleodb.library.database.utils.exceptions.InvalidIndexTypeException;

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
Expand Down Expand Up @@ -90,33 +92,36 @@ public List<Object> getValues(Queue<String> pointer, Object start) throws JsonPr
}


public void add(T dataEntry) throws JsonProcessingException {
System.out.println("Add ERROR");
public void add(T dataEntry) throws JsonProcessingException, InvalidIndexTypeException {
throw new InvalidIndexTypeException("index selected does not implement add.");
}

public void delete(T dataEntry) {
System.out.println("Delete ERROR");
public void delete(T dataEntry) throws InvalidIndexTypeException {
throw new InvalidIndexTypeException("index selected does not implement delete.");
}

public void modify(T dataEntry) throws JsonProcessingException {
System.out.println("Modify ERROR");
public void modify(T dataEntry) throws JsonProcessingException, InvalidIndexTypeException {
throw new InvalidIndexTypeException("index selected does not implement modify.");
}

public Set<T> get(Object search){
return null;
public Set<T> get(Object search) throws InvalidIndexTypeException {
throw new InvalidIndexTypeException("index selected does not implement get.");
}

public Set<T> getNotEqual(Object notEqualVal) {
return null;
public Set<T> contains(Object searchObj) throws InvalidIndexTypeException {
throw new InvalidIndexTypeException("index selected does not implement contains.");
}

public String getIndexedKey() {
return indexedKeyStr;
}

public Set<T> contains(Object searchObj) {
return null;
public List<Entry> endsWith(String findString) throws InvalidIndexTypeException {
throw new InvalidIndexTypeException("index selected does not implement endsWith.");
}

public String getIndexedKey() {
return indexedKeyStr;
public List<Entry> startsWith(String findString) throws InvalidIndexTypeException {
throw new InvalidIndexTypeException("index selected does not implement startsWith.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ public List<Entry> partial(String findString) {
return objects.stream().distinct().collect(Collectors.toList());
}

@Override
public List<Entry> endsWith(String findString) {
LinkedList<Entry> objects = Lists.newLinkedList();
Root partialRoot = null;
Expand All @@ -226,6 +227,7 @@ public List<Entry> endsWith(String findString) {
return objects.stream().distinct().collect(Collectors.toList());
}

@Override
public List<Entry> startsWith(String findString) {
char[] charArray = findString.toCharArray();
Node tmp = this.root;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.collect.Queues;
import com.google.common.collect.Sets;
import com.nucleodb.library.database.index.TrieIndex;
import com.nucleodb.library.database.modifications.Create;
import com.nucleodb.library.database.modifications.Delete;
import com.nucleodb.library.database.modifications.Update;
Expand All @@ -20,6 +22,7 @@
import com.nucleodb.library.database.utils.exceptions.IncorrectDataEntryObjectException;
import com.nucleodb.library.database.index.IndexWrapper;
import com.nucleodb.library.database.index.TreeIndex;
import com.nucleodb.library.database.utils.exceptions.InvalidIndexTypeException;
import com.nucleodb.library.kafkaLedger.ConsumerHandler;
import com.nucleodb.library.kafkaLedger.ProducerHandler;
import org.apache.kafka.clients.admin.*;
Expand Down Expand Up @@ -120,6 +123,8 @@ public void loadSavedData() {
i.add(e);
} catch (JsonProcessingException ex) {
throw new RuntimeException(ex);
} catch (InvalidIndexTypeException ex) {
throw new RuntimeException(ex);
}
}
e.setTableName(this.config.getTable());
Expand Down Expand Up @@ -350,6 +355,23 @@ public Set<DataEntry> search(String key, Object searchObject, DataEntryProjectio
return new TreeSet<>();
}

public Set<DataEntry> startsWith(String key, String str, DataEntryProjection dataEntryProjection) throws InvalidIndexTypeException {
IndexWrapper<DataEntry> dataEntryIndexWrapper = this.indexes.get(key);
Stream<DataEntry> process = dataEntryProjection.process(dataEntryIndexWrapper.startsWith(str).stream().map(e-> (DataEntry) e.getData()));
if(dataEntryProjection.isWritable()) {
return process.map(de -> (DataEntry) de.copy(this.getConfig().getDataEntryClass())).collect(Collectors.toSet());
}
return process.collect(Collectors.toSet());
}
public Set<DataEntry> endsWith(String key, String str, DataEntryProjection dataEntryProjection) throws InvalidIndexTypeException {
IndexWrapper<DataEntry> dataEntryIndexWrapper = this.indexes.get(key);
Stream<DataEntry> process = dataEntryProjection.process(dataEntryIndexWrapper.endsWith(str).stream().map(e-> (DataEntry) e.getData()));
if(dataEntryProjection.isWritable()) {
return process.map(de -> (DataEntry) de.copy(this.getConfig().getDataEntryClass())).collect(Collectors.toSet());
}
return process.collect(Collectors.toSet());
}

public Set<DataEntry> get(String key, Object value, DataEntryProjection dataEntryProjection) {
if(dataEntryProjection==null){
dataEntryProjection = new DataEntryProjection();
Expand Down Expand Up @@ -637,7 +659,13 @@ public void modify(Modification mod, Object modification) {
entries.remove(de);
keyToEntry.remove(de.getKey());
dataEntries.remove(de);
this.indexes.values().forEach(i -> i.delete(de));
this.indexes.values().forEach(i -> {
try {
i.delete(de);
} catch (InvalidIndexTypeException e) {
throw new RuntimeException(e);
}
});
}
size--;
consumerResponse(de, d.getChangeUUID());
Expand Down Expand Up @@ -710,14 +738,22 @@ public void modify(Modification mod, Object modification) {
}
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
} catch (InvalidIndexTypeException e) {
throw new RuntimeException(e);
}
break;
case "move":
break;
case "remove":
synchronized (entries) {
IndexWrapper indexWrapper = this.indexes.get(op.getPath());
if (indexWrapper != null) indexWrapper.delete(de);
if (indexWrapper != null) {
try {
indexWrapper.delete(de);
} catch (InvalidIndexTypeException e) {
throw new RuntimeException(e);
}
}
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.nucleodb.library.database.utils.exceptions;

public class InvalidIndexTypeException extends Exception{
public InvalidIndexTypeException(String message) {
super(message);
}
}

0 comments on commit df16fb8

Please sign in to comment.