mirror of https://github.com/apache/druid.git
Merge branch 'master' of github.com:metamx/druid
This commit is contained in:
commit
4d68bf1114
|
@ -22,6 +22,8 @@ package com.metamx.druid.query.timeboundary;
|
|||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Functions;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Ordering;
|
||||
import com.metamx.common.guava.MergeSequence;
|
||||
|
@ -59,13 +61,29 @@ public class TimeBoundaryQueryQueryToolChest
|
|||
};
|
||||
|
||||
@Override
|
||||
public <T extends LogicalSegment> List<T> filterSegments(TimeBoundaryQuery query, List<T> input)
|
||||
public <T extends LogicalSegment> List<T> filterSegments(TimeBoundaryQuery query, List<T> segments)
|
||||
{
|
||||
if(input.size() <= 1) {
|
||||
return input;
|
||||
if (segments.size() <= 1) {
|
||||
return segments;
|
||||
}
|
||||
|
||||
return Lists.newArrayList(input.get(0), input.get(input.size() - 1));
|
||||
final T first = segments.get(0);
|
||||
final T second = segments.get(segments.size() - 1);
|
||||
|
||||
return Lists.newArrayList(
|
||||
Iterables.filter(
|
||||
segments,
|
||||
new Predicate<T>()
|
||||
{
|
||||
@Override
|
||||
public boolean apply(T input)
|
||||
{
|
||||
return input.getInterval().overlaps(first.getInterval()) || input.getInterval()
|
||||
.overlaps(second.getInterval());
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* Druid - a distributed column store.
|
||||
* Copyright (C) 2012 Metamarkets Group Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package com.metamx.druid.query.timeboundary;
|
||||
|
||||
import com.metamx.druid.LogicalSegment;
|
||||
import junit.framework.Assert;
|
||||
import org.joda.time.Interval;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class TimeBoundaryQueryQueryToolChestTest
|
||||
{
|
||||
@Test
|
||||
public void testFilterSegments() throws Exception
|
||||
{
|
||||
List<LogicalSegment> segments = new TimeBoundaryQueryQueryToolChest().filterSegments(
|
||||
null,
|
||||
Arrays.asList(
|
||||
new LogicalSegment()
|
||||
{
|
||||
@Override
|
||||
public Interval getInterval()
|
||||
{
|
||||
return new Interval("2013-01-01/P1D");
|
||||
}
|
||||
},
|
||||
new LogicalSegment()
|
||||
{
|
||||
@Override
|
||||
public Interval getInterval()
|
||||
{
|
||||
return new Interval("2013-01-01T01/PT1H");
|
||||
}
|
||||
},
|
||||
new LogicalSegment()
|
||||
{
|
||||
@Override
|
||||
public Interval getInterval()
|
||||
{
|
||||
return new Interval("2013-01-01T02/PT1H");
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
Assert.assertEquals(segments.size(), 3);
|
||||
|
||||
List<LogicalSegment> expected = Arrays.asList(
|
||||
new LogicalSegment()
|
||||
{
|
||||
@Override
|
||||
public Interval getInterval()
|
||||
{
|
||||
return new Interval("2013-01-01/P1D");
|
||||
}
|
||||
},
|
||||
new LogicalSegment()
|
||||
{
|
||||
@Override
|
||||
public Interval getInterval()
|
||||
{
|
||||
return new Interval("2013-01-01T01/PT1H");
|
||||
}
|
||||
},
|
||||
new LogicalSegment()
|
||||
{
|
||||
@Override
|
||||
public Interval getInterval()
|
||||
{
|
||||
return new Interval("2013-01-01T02/PT1H");
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
for (int i = 0; i < segments.size(); i++) {
|
||||
Assert.assertEquals(segments.get(i).getInterval(), expected.get(i).getInterval());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue