From edaba72c3315e2992b5c33f679710e31626d5583 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Sat, 18 Sep 2021 18:48:33 +0200 Subject: [PATCH] remove method to create a query based on tags was only used in tests --- .../main/java/org/lucares/pdb/api/Query.java | 22 ------------------- .../performance/db/PerformanceDbTest.java | 21 ++++++++++-------- 2 files changed, 12 insertions(+), 31 deletions(-) diff --git a/pdb-api/src/main/java/org/lucares/pdb/api/Query.java b/pdb-api/src/main/java/org/lucares/pdb/api/Query.java index 82ffbbc..9b489d5 100644 --- a/pdb-api/src/main/java/org/lucares/pdb/api/Query.java +++ b/pdb-api/src/main/java/org/lucares/pdb/api/Query.java @@ -1,8 +1,5 @@ package org.lucares.pdb.api; -import java.util.ArrayList; -import java.util.List; - public class Query { private final String query; @@ -42,25 +39,6 @@ public class Query { return new Query(query, dateRange); } - public static Query createQuery(final Tags tags, final DateTimeRange dateRange) { - - final List 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() { return query; } diff --git a/performanceDb/src/test/java/org/lucares/performance/db/PerformanceDbTest.java b/performanceDb/src/test/java/org/lucares/performance/db/PerformanceDbTest.java index b018ed1..bf53093 100644 --- a/performanceDb/src/test/java/org/lucares/performance/db/PerformanceDbTest.java +++ b/performanceDb/src/test/java/org/lucares/performance/db/PerformanceDbTest.java @@ -51,7 +51,7 @@ public class PerformanceDbTest { final Tags tags = Tags.STRING_COMPRESSOR.createAndAddToDictionary("myKey", "myValue"); 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(); Assertions.assertEquals(2, stream.size()); @@ -76,7 +76,7 @@ public class PerformanceDbTest { db.putEntry(new Entry(dayOne, valueOne, 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()); @@ -123,7 +123,7 @@ public class PerformanceDbTest { 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()); for (int i = 0; i < entries.size(); i++) { @@ -167,7 +167,7 @@ public class PerformanceDbTest { db.putEntries(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(toExpectedValues(expected), actualEntries); @@ -185,7 +185,6 @@ public class PerformanceDbTest { final DateTimeRange dateRange = new DateTimeRange(from, to); 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", "commonValue"); final List entriesOne = generateEntries(timeRange, numberOfEntries, 1, tagsOne); @@ -204,16 +203,20 @@ public class PerformanceDbTest { printEntries(entriesThree, "three"); 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); - 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); - 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); - 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 expectedAll = CollectionUtils.collate(entriesOne, CollectionUtils.collate(entriesTwo, entriesThree, EntryByDateComparator.INSTANCE), EntryByDateComparator.INSTANCE);