remove method to create a query based on tags
was only used in tests
This commit is contained in:
@@ -1,8 +1,5 @@
|
|||||||
package org.lucares.pdb.api;
|
package org.lucares.pdb.api;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Query {
|
public class Query {
|
||||||
private final String query;
|
private final String query;
|
||||||
|
|
||||||
@@ -42,25 +39,6 @@ public class Query {
|
|||||||
return new Query(query, dateRange);
|
return new Query(query, dateRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Query createQuery(final Tags tags, final DateTimeRange dateRange) {
|
|
||||||
|
|
||||||
final List<String> terms = new ArrayList<>();
|
|
||||||
|
|
||||||
for (final String key : tags.getKeys()) {
|
|
||||||
final String value = tags.getValue(key);
|
|
||||||
|
|
||||||
final StringBuilder term = new StringBuilder();
|
|
||||||
term.append(key);
|
|
||||||
term.append("=");
|
|
||||||
term.append(value);
|
|
||||||
term.append(" ");
|
|
||||||
|
|
||||||
terms.add(term.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Query(String.join(" and ", terms), dateRange);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getQuery() {
|
public String getQuery() {
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class PerformanceDbTest {
|
|||||||
final Tags tags = Tags.STRING_COMPRESSOR.createAndAddToDictionary("myKey", "myValue");
|
final Tags tags = Tags.STRING_COMPRESSOR.createAndAddToDictionary("myKey", "myValue");
|
||||||
db.putEntry(new Entry(date, value, tags));
|
db.putEntry(new Entry(date, value, tags));
|
||||||
|
|
||||||
final Result result = db.get(Query.createQuery(tags, DateTimeRange.ofDay(nowInUtc)));
|
final Result result = db.get(Query.createQuery("myKey=myValue", DateTimeRange.ofDay(nowInUtc)));
|
||||||
final LongList stream = result.singleGroup().flatMap();
|
final LongList stream = result.singleGroup().flatMap();
|
||||||
|
|
||||||
Assertions.assertEquals(2, stream.size());
|
Assertions.assertEquals(2, stream.size());
|
||||||
@@ -76,7 +76,7 @@ public class PerformanceDbTest {
|
|||||||
db.putEntry(new Entry(dayOne, valueOne, tags));
|
db.putEntry(new Entry(dayOne, valueOne, tags));
|
||||||
db.putEntry(new Entry(dayTwo, valueTwo, tags));
|
db.putEntry(new Entry(dayTwo, valueTwo, tags));
|
||||||
|
|
||||||
final LongList stream = db.get(Query.createQuery(tags, dateRange)).singleGroup().flatMap();
|
final LongList stream = db.get(Query.createQuery("myKey=myValue", dateRange)).singleGroup().flatMap();
|
||||||
|
|
||||||
Assertions.assertEquals(4, stream.size());
|
Assertions.assertEquals(4, stream.size());
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ public class PerformanceDbTest {
|
|||||||
|
|
||||||
db.putEntries(entries);
|
db.putEntries(entries);
|
||||||
|
|
||||||
final LongList actualEntries = db.get(Query.createQuery(tags, timeRange)).singleGroup().flatMap();
|
final LongList actualEntries = db.get(Query.createQuery("myKey=one", timeRange)).singleGroup().flatMap();
|
||||||
Assertions.assertEquals(entries.size() * 2, actualEntries.size());
|
Assertions.assertEquals(entries.size() * 2, actualEntries.size());
|
||||||
|
|
||||||
for (int i = 0; i < entries.size(); i++) {
|
for (int i = 0; i < entries.size(); i++) {
|
||||||
@@ -167,7 +167,7 @@ public class PerformanceDbTest {
|
|||||||
db.putEntries(entries);
|
db.putEntries(entries);
|
||||||
expected.addAll(entries);
|
expected.addAll(entries);
|
||||||
|
|
||||||
final LongList actualEntries = db.get(Query.createQuery(tags, timeRange)).singleGroup().flatMap();
|
final LongList actualEntries = db.get(Query.createQuery("myKey=one", timeRange)).singleGroup().flatMap();
|
||||||
Assertions.assertEquals(expected.size() * 2, actualEntries.size());
|
Assertions.assertEquals(expected.size() * 2, actualEntries.size());
|
||||||
|
|
||||||
Assertions.assertEquals(toExpectedValues(expected), actualEntries);
|
Assertions.assertEquals(toExpectedValues(expected), actualEntries);
|
||||||
@@ -185,7 +185,6 @@ public class PerformanceDbTest {
|
|||||||
final DateTimeRange dateRange = new DateTimeRange(from, to);
|
final DateTimeRange dateRange = new DateTimeRange(from, to);
|
||||||
final long numberOfEntries = timeRange.duration().toHours();
|
final long numberOfEntries = timeRange.duration().toHours();
|
||||||
|
|
||||||
final Tags tagsCommon = Tags.STRING_COMPRESSOR.createAndAddToDictionary("commonKey", "commonValue");
|
|
||||||
final Tags tagsOne = Tags.STRING_COMPRESSOR.createAndAddToDictionary("myKey", "one", "commonKey",
|
final Tags tagsOne = Tags.STRING_COMPRESSOR.createAndAddToDictionary("myKey", "one", "commonKey",
|
||||||
"commonValue");
|
"commonValue");
|
||||||
final List<Entry> entriesOne = generateEntries(timeRange, numberOfEntries, 1, tagsOne);
|
final List<Entry> entriesOne = generateEntries(timeRange, numberOfEntries, 1, tagsOne);
|
||||||
@@ -204,16 +203,20 @@ public class PerformanceDbTest {
|
|||||||
printEntries(entriesThree, "three");
|
printEntries(entriesThree, "three");
|
||||||
db.putEntries(entriesThree);
|
db.putEntries(entriesThree);
|
||||||
|
|
||||||
final LongList actualEntriesOne = db.get(Query.createQuery(tagsOne, dateRange)).singleGroup().flatMap();
|
final LongList actualEntriesOne = db
|
||||||
|
.get(Query.createQuery("myKey=one and commonKey=commonValue", dateRange)).singleGroup().flatMap();
|
||||||
Assertions.assertEquals(toExpectedValues(entriesOne), actualEntriesOne);
|
Assertions.assertEquals(toExpectedValues(entriesOne), actualEntriesOne);
|
||||||
|
|
||||||
final LongList actualEntriesTwo = db.get(Query.createQuery(tagsTwo, dateRange)).singleGroup().flatMap();
|
final LongList actualEntriesTwo = db
|
||||||
|
.get(Query.createQuery("myKey=two and commonKey=commonValue", dateRange)).singleGroup().flatMap();
|
||||||
Assertions.assertEquals(toExpectedValues(entriesTwo), actualEntriesTwo);
|
Assertions.assertEquals(toExpectedValues(entriesTwo), actualEntriesTwo);
|
||||||
|
|
||||||
final LongList actualEntriesThree = db.get(Query.createQuery(tagsThree, dateRange)).singleGroup().flatMap();
|
final LongList actualEntriesThree = db
|
||||||
|
.get(Query.createQuery("myKey=three and commonKey=commonValue", dateRange)).singleGroup().flatMap();
|
||||||
Assertions.assertEquals(toExpectedValues(entriesThree), actualEntriesThree);
|
Assertions.assertEquals(toExpectedValues(entriesThree), actualEntriesThree);
|
||||||
|
|
||||||
final LongList actualEntriesAll = db.get(Query.createQuery(tagsCommon, dateRange)).singleGroup().flatMap();
|
final LongList actualEntriesAll = db.get(Query.createQuery("commonKey=commonValue", dateRange))
|
||||||
|
.singleGroup().flatMap();
|
||||||
final List<Entry> expectedAll = CollectionUtils.collate(entriesOne,
|
final List<Entry> expectedAll = CollectionUtils.collate(entriesOne,
|
||||||
CollectionUtils.collate(entriesTwo, entriesThree, EntryByDateComparator.INSTANCE),
|
CollectionUtils.collate(entriesTwo, entriesThree, EntryByDateComparator.INSTANCE),
|
||||||
EntryByDateComparator.INSTANCE);
|
EntryByDateComparator.INSTANCE);
|
||||||
|
|||||||
Reference in New Issue
Block a user