Skip to content

Commit

Permalink
make the time filter and value filter process logic in tidy (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
Beyyes authored and MyXOF committed Jan 9, 2018
1 parent e2cc795 commit 8f1fdda
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import cn.edu.tsinghua.tsfile.timeseries.filter.definition.SingleSeriesFilterExpression;
import cn.edu.tsinghua.tsfile.timeseries.filter.definition.operators.*;
import cn.edu.tsinghua.tsfile.timeseries.filter.utils.DoubleInterval;
import cn.edu.tsinghua.tsfile.timeseries.filter.utils.FloatInterval;
import cn.edu.tsinghua.tsfile.timeseries.filter.utils.IntInterval;
import cn.edu.tsinghua.tsfile.timeseries.filter.utils.LongInterval;
import cn.edu.tsinghua.tsfile.timeseries.filter.utils.*;
import cn.edu.tsinghua.tsfile.timeseries.filter.verifier.FilterVerifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -22,14 +19,21 @@ public class SingleValueVisitor<V extends Comparable<V>> implements FilterVisito
private static final Logger LOG = LoggerFactory.getLogger(SingleValueVisitor.class);
private V value;
private FilterVerifier verifier;
private SingleSeriesFilterExpression ssFilter;
private SingleSeriesFilterExpression singleSeriesFilter;
private Interval interval;

public SingleValueVisitor() {
}

/**
* This method is only used for INT32,INT64,FLOAT,DOUBLE data type.
*
* @param filter
*/
public SingleValueVisitor(SingleSeriesFilterExpression filter) {
verifier = FilterVerifier.create(filter.getFilterSeries().getSeriesDataType());
this.ssFilter = filter;
this.singleSeriesFilter = filter;
interval = verifier.getInterval(singleSeriesFilter);
}

/**
Expand Down Expand Up @@ -59,7 +63,7 @@ private Boolean satisfy(V value, SingleSeriesFilterExpression filter) {
* @return is satisfied
*/
public boolean verify(int value) {
IntInterval val = (IntInterval) verifier.getInterval(ssFilter);
IntInterval val = (IntInterval) interval;
for (int i = 0; i < val.count; i += 2) {
if (val.v[i] < value && value < val.v[i + 1])
return true;
Expand All @@ -72,7 +76,7 @@ public boolean verify(int value) {
}

public boolean verify(long value) {
LongInterval val = (LongInterval) verifier.getInterval(ssFilter);
LongInterval val = (LongInterval) interval;
for (int i = 0; i < val.count; i += 2) {
if (val.v[i] < value && value < val.v[i + 1])
return true;
Expand All @@ -85,7 +89,7 @@ public boolean verify(long value) {
}

public boolean verify(float value) {
FloatInterval val = (FloatInterval) verifier.getInterval(ssFilter);
FloatInterval val = (FloatInterval) interval;
for (int i = 0; i < val.count; i += 2) {
if (val.v[i] < value && value < val.v[i + 1])
return true;
Expand All @@ -98,7 +102,7 @@ public boolean verify(float value) {
}

public boolean verify(double value) {
DoubleInterval val = (DoubleInterval) verifier.getInterval(ssFilter);
DoubleInterval val = (DoubleInterval) interval;
for (int i = 0; i < val.count; i += 2) {
if (val.v[i] < value && value < val.v[i + 1])
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,8 @@ public DynamicOneColumnData readOneColumnUseFilter(DynamicOneColumnData res, int
case BOOLEAN:
while (decoder.hasNext(page)) {
boolean v = decoder.readBoolean(page);
if ((valueFilter == null && timeFilter == null)
|| (valueFilter != null && timeFilter == null && valueVisitor.satisfyObject(v, valueFilter))
|| (valueFilter == null && timeFilter != null && timeVisitor.satisfyObject(timeValues[timeIdx], timeFilter))
|| (valueFilter != null && timeFilter != null && valueVisitor.satisfyObject(v, valueFilter)
&& timeVisitor.satisfyObject(timeValues[timeIdx], timeFilter))) {
if ((timeFilter == null || timeVisitor.satisfyObject(timeValues[timeIdx], timeFilter)) &&
(valueFilter == null || valueVisitor.satisfyObject(v, valueFilter))) {
res.putBoolean(v);
res.putTime(timeValues[timeIdx]);
}
Expand All @@ -335,11 +332,8 @@ public DynamicOneColumnData readOneColumnUseFilter(DynamicOneColumnData res, int
case INT32:
while (decoder.hasNext(page)) {
int v = decoder.readInt(page);
if ((valueFilter == null && timeFilter == null)
|| (valueFilter != null && timeFilter == null && valueVisitor.satisfyObject(v, valueFilter))
|| (valueFilter == null && timeFilter != null && timeVisitor.satisfyObject(timeValues[timeIdx], timeFilter))
|| (valueFilter != null && timeFilter != null && valueVisitor.satisfyObject(v, valueFilter)
&& timeVisitor.satisfyObject(timeValues[timeIdx], timeFilter))) {
if ((timeFilter == null || timeVisitor.satisfyObject(timeValues[timeIdx], timeFilter)) &&
(valueFilter == null || valueVisitor.satisfyObject(v, valueFilter))) {
res.putInt(v);
res.putTime(timeValues[timeIdx]);
}
Expand All @@ -349,11 +343,8 @@ public DynamicOneColumnData readOneColumnUseFilter(DynamicOneColumnData res, int
case INT64:
while (decoder.hasNext(page)) {
long v = decoder.readLong(page);
if ((valueFilter == null && timeFilter == null)
|| (valueFilter != null && timeFilter == null && valueVisitor.satisfyObject(v, valueFilter))
|| (valueFilter == null && timeFilter != null && timeVisitor.satisfyObject(timeValues[timeIdx], timeFilter))
|| (valueFilter != null && timeFilter != null && valueVisitor.satisfyObject(v, valueFilter)
&& timeVisitor.satisfyObject(timeValues[timeIdx], timeFilter))) {
if ((timeFilter == null || timeVisitor.satisfyObject(timeValues[timeIdx], timeFilter)) &&
(valueFilter == null || valueVisitor.satisfyObject(v, valueFilter))) {
res.putLong(v);
res.putTime(timeValues[timeIdx]);
}
Expand All @@ -363,11 +354,8 @@ public DynamicOneColumnData readOneColumnUseFilter(DynamicOneColumnData res, int
case FLOAT:
while (decoder.hasNext(page)) {
float v = decoder.readFloat(page);
if ((valueFilter == null && timeFilter == null)
|| (valueFilter != null && timeFilter == null && valueVisitor.satisfyObject(v, valueFilter))
|| (valueFilter == null && timeFilter != null && timeVisitor.satisfyObject(timeValues[timeIdx], timeFilter))
|| (valueFilter != null && timeFilter != null && valueVisitor.satisfyObject(v, valueFilter)
&& timeVisitor.satisfyObject(timeValues[timeIdx], timeFilter))) {
if ((timeFilter == null || timeVisitor.satisfyObject(timeValues[timeIdx], timeFilter)) &&
(valueFilter == null || valueVisitor.satisfyObject(v, valueFilter))) {
res.putFloat(v);
res.putTime(timeValues[timeIdx]);
}
Expand All @@ -377,11 +365,8 @@ public DynamicOneColumnData readOneColumnUseFilter(DynamicOneColumnData res, int
case DOUBLE:
while (decoder.hasNext(page)) {
double v = decoder.readDouble(page);
if ((valueFilter == null && timeFilter == null)
|| (valueFilter != null && timeFilter == null && valueVisitor.satisfyObject(v, valueFilter))
|| (valueFilter == null && timeFilter != null && timeVisitor.satisfyObject(timeValues[timeIdx], timeFilter))
|| (valueFilter != null && timeFilter != null && valueVisitor.satisfyObject(v, valueFilter)
&& timeVisitor.satisfyObject(timeValues[timeIdx], timeFilter))) {
if ((timeFilter == null || timeVisitor.satisfyObject(timeValues[timeIdx], timeFilter)) &&
(valueFilter == null || valueVisitor.satisfyObject(v, valueFilter))) {
res.putDouble(v);
res.putTime(timeValues[timeIdx]);
}
Expand All @@ -391,11 +376,8 @@ public DynamicOneColumnData readOneColumnUseFilter(DynamicOneColumnData res, int
case TEXT:
while (decoder.hasNext(page)) {
Binary v = decoder.readBinary(page);
if ((valueFilter == null && timeFilter == null)
|| (valueFilter != null && timeFilter == null && valueVisitor.satisfyObject(v, valueFilter))
|| (valueFilter == null && timeFilter != null && timeVisitor.satisfyObject(timeValues[timeIdx], timeFilter))
|| (valueFilter != null && timeFilter != null && valueVisitor.satisfyObject(v, valueFilter)
&& timeVisitor.satisfyObject(timeValues[timeIdx], timeFilter))) {
if ((timeFilter == null || timeVisitor.satisfyObject(timeValues[timeIdx], timeFilter)) &&
(valueFilter == null || valueVisitor.satisfyObject(v, valueFilter))) {
res.putBinary(v);
res.putTime(timeValues[timeIdx]);
}
Expand All @@ -405,11 +387,8 @@ public DynamicOneColumnData readOneColumnUseFilter(DynamicOneColumnData res, int
case ENUMS:
while (decoder.hasNext(page)) {
int v = decoder.readInt(page) - 1;
if ((valueFilter == null && timeFilter == null)
|| (valueFilter != null && timeFilter == null && valueVisitor.satisfyObject(enumValues.get(v), valueFilter))
|| (valueFilter == null && timeFilter != null && timeVisitor.satisfyObject(timeValues[timeIdx], timeFilter))
|| (valueFilter != null && timeFilter != null && valueVisitor.satisfyObject(enumValues.get(v), valueFilter)
&& timeVisitor.satisfyObject(timeValues[timeIdx], timeFilter))) {
if ((timeFilter == null || timeVisitor.satisfyObject(timeValues[timeIdx], timeFilter)) &&
(valueFilter == null || valueVisitor.satisfyObject(v, valueFilter))) {
res.putBinary(Binary.valueOf(enumValues.get(v)));
res.putTime(timeValues[timeIdx]);
}
Expand All @@ -429,8 +408,7 @@ public DynamicOneColumnData readOneColumnUseFilter(DynamicOneColumnData res, int
res.pageOffset += (lastAvailable - bis.available());
}

// Represents current Column has been read all.
// Prepare for next column in another RowGroup.
// Represents current Column has been read all, prepare for next column in another RowGroup.
if ((res.pageOffset - fileOffset) >= totalSize) {
res.plusRowGroupIndexAndInitPageOffset();
}
Expand Down

0 comments on commit 8f1fdda

Please sign in to comment.