-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[IOTDB-6]Value filter query optimization #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a677f89
a402c4e
2ecafd4
2eab632
b051265
0020386
fb19e6e
a990d0b
ff2acca
a16bbe2
a447205
0395440
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,17 +16,18 @@ | |
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.iotdb.db.query.reader.mem; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Iterator; | ||
| import org.apache.iotdb.db.engine.memtable.TimeValuePairSorter; | ||
| import org.apache.iotdb.db.query.reader.IReader; | ||
| import org.apache.iotdb.db.query.reader.merge.EngineReaderByTimeStamp; | ||
| import org.apache.iotdb.db.utils.TimeValuePair; | ||
| import org.apache.iotdb.db.utils.TsPrimitiveType; | ||
| import org.apache.iotdb.tsfile.read.common.BatchData; | ||
|
|
||
| public class MemChunkReaderByTimestamp implements EngineReaderByTimeStamp { | ||
| public class MemChunkReaderByTimestamp implements EngineReaderByTimeStamp, IReader { | ||
|
|
||
| private Iterator<TimeValuePair> timeValuePairIterator; | ||
| private boolean hasCachedTimeValuePair; | ||
|
|
@@ -65,15 +66,16 @@ public void close() { | |
| } | ||
|
|
||
| // TODO consider change timeValuePairIterator to List structure, and use binary search instead of | ||
| // sequential search | ||
| @Override | ||
| public TsPrimitiveType getValueInTimestamp(long timestamp) throws IOException { | ||
| /** | ||
| * sequential search | ||
| */ | ||
| @Override public Object getValueInTimestamp(long timestamp) throws IOException { | ||
| while (hasNext()) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove |
||
| TimeValuePair timeValuePair = next(); | ||
| long time = timeValuePair.getTimestamp(); | ||
| if (time == timestamp) { | ||
| return timeValuePair.getValue(); | ||
| } else if (time > timestamp) { | ||
| long currentMemTime = timeValuePair.getTimestamp(); | ||
| if (currentMemTime == timestamp) { | ||
| return timeValuePair.getValue().getValue(); | ||
| } else if (currentMemTime > timestamp) { | ||
| hasCachedTimeValuePair = true; | ||
| cachedTimeValuePair = timeValuePair; | ||
| break; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,44 +16,61 @@ | |
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.iotdb.db.query.reader.merge; | ||
|
|
||
| import java.io.IOException; | ||
| import org.apache.iotdb.db.utils.TimeValuePair; | ||
| import org.apache.iotdb.db.utils.TsPrimitiveType; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * TODO the process of PriorityMergeReaderByTimestamp can be optimized. | ||
| * <p> | ||
| * Usage: Get value in timestamp by sorting time-value pair in multiple readers with time and | ||
| * priority. (1) merge multiple chunk group readers in the unsequence file (2)merge sequence reader, | ||
| * unsequence reader and mem reader | ||
| * </p> | ||
| */ | ||
| public class PriorityMergeReaderByTimestamp extends PriorityMergeReader implements | ||
| EngineReaderByTimeStamp { | ||
| public class PriorityMergeReaderByTimestamp implements EngineReaderByTimeStamp { | ||
|
|
||
| private List<EngineReaderByTimeStamp> readerList = new ArrayList<>(); | ||
| private List<Integer> priorityList = new ArrayList<>(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this unused variable |
||
|
|
||
| private boolean hasCachedTimeValuePair; | ||
| private TimeValuePair cachedTimeValuePair; | ||
| /** | ||
| * This function doesn't sort reader by priority. So you have to call this function in order of | ||
| * reader priority from small to large. | ||
| */ | ||
| public void addReaderWithPriority(EngineReaderByTimeStamp reader, int priority) { | ||
| readerList.add(reader); | ||
| priorityList.add(priority); | ||
| } | ||
|
|
||
| @Override | ||
| public TsPrimitiveType getValueInTimestamp(long timestamp) throws IOException { | ||
|
|
||
| if (hasCachedTimeValuePair) { | ||
| if (cachedTimeValuePair.getTimestamp() == timestamp) { | ||
| hasCachedTimeValuePair = false; | ||
| return cachedTimeValuePair.getValue(); | ||
| } else if (cachedTimeValuePair.getTimestamp() > timestamp) { | ||
| return null; | ||
| public Object getValueInTimestamp(long timestamp) throws IOException { | ||
| Object value = null; | ||
| for (int i = readerList.size() - 1; i >= 0; i--) { | ||
| value = readerList.get(i).getValueInTimestamp(timestamp); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just return value, |
||
| if (value != null) { | ||
| return value; | ||
| } | ||
| } | ||
| return value; | ||
| } | ||
|
|
||
| while (hasNext()) { | ||
| cachedTimeValuePair = next(); | ||
| if (cachedTimeValuePair.getTimestamp() == timestamp) { | ||
| hasCachedTimeValuePair = false; | ||
| return cachedTimeValuePair.getValue(); | ||
| } else if (cachedTimeValuePair.getTimestamp() > timestamp) { | ||
| hasCachedTimeValuePair = true; | ||
| return null; | ||
| } | ||
| @Override | ||
| public void close() throws IOException { | ||
| for (EngineReaderByTimeStamp reader : readerList) { | ||
| reader.close(); | ||
| } | ||
| } | ||
|
|
||
| return null; | ||
| @Override | ||
| public boolean hasNext() throws IOException { | ||
| for (int i = readerList.size() - 1; i >= 0; i--) { | ||
| if (readerList.get(i).hasNext()) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a null Field variable