values used in queries were added to the keys.csv

Due to a mistake in Tag which added all strings used
by Tag into the String dictionary, the dictionary
did contain all values that were used in queries.
This commit is contained in:
2019-02-09 08:28:23 +01:00
parent ea5884a5e6
commit 493971bcf3
13 changed files with 122 additions and 99 deletions

View File

@@ -175,6 +175,8 @@ public class DataStore implements AutoCloseable {
storageBasePath = storageDirectory(dataDirectory); storageBasePath = storageDirectory(dataDirectory);
Tags.STRING_COMPRESSOR = StringCompressor.create(keyCompressionFile(storageBasePath)); Tags.STRING_COMPRESSOR = StringCompressor.create(keyCompressionFile(storageBasePath));
Tags.STRING_COMPRESSOR.put(ALL_DOCS_KEY);
Tags.STRING_COMPRESSOR.put("");
TAG_ALL_DOCS = new Tag(ALL_DOCS_KEY, ""); // Tag(String, String) uses the StringCompressor internally, so it TAG_ALL_DOCS = new Tag(ALL_DOCS_KEY, ""); // Tag(String, String) uses the StringCompressor internally, so it
// must be initialized after the string compressor has been created // must be initialized after the string compressor has been created

View File

@@ -57,11 +57,11 @@ public class DataStoreTest {
dataStore = new DataStore(dataDirectory); dataStore = new DataStore(dataDirectory);
final Tags eagleTim = Tags.create("bird", "eagle", "name", "Tim"); final Tags eagleTim = Tags.createAndAddToDictionary("bird", "eagle", "name", "Tim");
final Tags pigeonJennifer = Tags.create("bird", "pigeon", "name", "Jennifer"); final Tags pigeonJennifer = Tags.createAndAddToDictionary("bird", "pigeon", "name", "Jennifer");
final Tags flamingoJennifer = Tags.create("bird", "flamingo", "name", "Jennifer"); final Tags flamingoJennifer = Tags.createAndAddToDictionary("bird", "flamingo", "name", "Jennifer");
final Tags labradorJenny = Tags.create("dog", "labrador", "name", "Jenny"); final Tags labradorJenny = Tags.createAndAddToDictionary("dog", "labrador", "name", "Jenny");
final Tags labradorTim = Tags.create("dog", "labrador", "name", "Tim"); final Tags labradorTim = Tags.createAndAddToDictionary("dog", "labrador", "name", "Tim");
tagsToBlockStorageRootBlockNumber = new HashMap<>(); tagsToBlockStorageRootBlockNumber = new HashMap<>();
tagsToBlockStorageRootBlockNumber.put(eagleTim, dataStore.createNewFile(eagleTim)); tagsToBlockStorageRootBlockNumber.put(eagleTim, dataStore.createNewFile(eagleTim));
@@ -105,8 +105,8 @@ public class DataStoreTest {
dataStore = new DataStore(dataDirectory); dataStore = new DataStore(dataDirectory);
tagsToBlockStorageRootBlockNumber = new LinkedHashMap<>(); tagsToBlockStorageRootBlockNumber = new LinkedHashMap<>();
final Tags pigeonJennifer = Tags.create("bird", "pigeon", "name", "Jennifer"); final Tags pigeonJennifer = Tags.createAndAddToDictionary("bird", "pigeon", "name", "Jennifer");
final Tags flamingoJennifer = Tags.create("bird", "flamingo", "name", "Jennifer"); final Tags flamingoJennifer = Tags.createAndAddToDictionary("bird", "flamingo", "name", "Jennifer");
tagsToBlockStorageRootBlockNumber.put(pigeonJennifer, dataStore.createNewFile(pigeonJennifer)); tagsToBlockStorageRootBlockNumber.put(pigeonJennifer, dataStore.createNewFile(pigeonJennifer));
tagsToBlockStorageRootBlockNumber.put(flamingoJennifer, dataStore.createNewFile(flamingoJennifer)); tagsToBlockStorageRootBlockNumber.put(flamingoJennifer, dataStore.createNewFile(flamingoJennifer));
@@ -118,7 +118,7 @@ public class DataStoreTest {
public void testBlockAlignment() throws IOException { public void testBlockAlignment() throws IOException {
dataStore = new DataStore(dataDirectory); dataStore = new DataStore(dataDirectory);
final Tags eagleTim = Tags.create("bird", "eagle", "name", "Tim"); final Tags eagleTim = Tags.createAndAddToDictionary("bird", "eagle", "name", "Tim");
final long eagleTimBlockOffset = dataStore.createNewFile(eagleTim); final long eagleTimBlockOffset = dataStore.createNewFile(eagleTim);
Assert.assertEquals(eagleTimBlockOffset % BSFile.BLOCK_SIZE, 0); Assert.assertEquals(eagleTimBlockOffset % BSFile.BLOCK_SIZE, 0);
} }
@@ -166,18 +166,18 @@ public class DataStoreTest {
dataStore = new DataStore(dataDirectory); dataStore = new DataStore(dataDirectory);
final List<Tags> tags = Arrays.asList( final List<Tags> tags = Arrays.asList(
Tags.create("type", "bird", "subtype", "eagle", "age", "three", "name", "Tim"), Tags.createAndAddToDictionary("type", "bird", "subtype", "eagle", "age", "three", "name", "Tim"),
Tags.create("type", "bird", "subtype", "pigeon", "age", "two", "name", "Jennifer"), Tags.createAndAddToDictionary("type", "bird", "subtype", "pigeon", "age", "two", "name", "Jennifer"),
Tags.create("type", "bird", "subtype", "flamingo", "age", "one", "name", "Jennifer"), Tags.createAndAddToDictionary("type", "bird", "subtype", "flamingo", "age", "one", "name", "Jennifer"),
Tags.create("type", "dog", "subtype", "labrador", "age", "three", "name", "Jenny"), Tags.createAndAddToDictionary("type", "dog", "subtype", "labrador", "age", "three", "name", "Jenny"),
Tags.create("type", "dog", "subtype", "labrador", "age", "three", "name", "Tim"), Tags.createAndAddToDictionary("type", "dog", "subtype", "labrador", "age", "three", "name", "Tim"),
Tags.create("type", "cat", "subtype", "tiger", "age", "one", "name", "Timothy"), Tags.createAndAddToDictionary("type", "cat", "subtype", "tiger", "age", "one", "name", "Timothy"),
Tags.create("type", "cat", "subtype", "tiger", "age", "two", "name", "Paul"), Tags.createAndAddToDictionary("type", "cat", "subtype", "tiger", "age", "two", "name", "Paul"),
Tags.create("type", "cat", "subtype", "lion", "age", "three", "name", "Jane"), Tags.createAndAddToDictionary("type", "cat", "subtype", "lion", "age", "three", "name", "Jane"),
Tags.create("type", "cat", "subtype", "lion", "age", "four", "name", "Sam"), Tags.createAndAddToDictionary("type", "cat", "subtype", "lion", "age", "four", "name", "Sam"),
Tags.create("type", "cat", "subtype", "lion", "age", "four", "name", "John")); Tags.createAndAddToDictionary("type", "cat", "subtype", "lion", "age", "four", "name", "John"));
tags.forEach(dataStore::createNewFile); tags.forEach(dataStore::createNewFile);
@@ -189,18 +189,21 @@ public class DataStoreTest {
try (DataStore dataStore = new DataStore(dir)) { try (DataStore dataStore = new DataStore(dir)) {
final List<Tags> tags = Arrays.asList( final List<Tags> tags = Arrays.asList(
Tags.create("type", "bird", "subtype", "eagle", "age", "three", "name", "Tim"), Tags.createAndAddToDictionary("type", "bird", "subtype", "eagle", "age", "three", "name", "Tim"),
Tags.create("type", "bird", "subtype", "pigeon", "age", "two", "name", "Jennifer"), Tags.createAndAddToDictionary("type", "bird", "subtype", "pigeon", "age", "two", "name",
Tags.create("type", "bird", "subtype", "flamingo", "age", "one", "name", "Jennifer"), "Jennifer"),
Tags.createAndAddToDictionary("type", "bird", "subtype", "flamingo", "age", "one", "name",
"Jennifer"),
Tags.create("type", "dog", "subtype", "labrador", "age", "three", "name", "Jenny"), Tags.createAndAddToDictionary("type", "dog", "subtype", "labrador", "age", "three", "name",
Tags.create("type", "dog", "subtype", "labrador", "age", "three", "name", "Tim"), "Jenny"),
Tags.createAndAddToDictionary("type", "dog", "subtype", "labrador", "age", "three", "name", "Tim"),
Tags.create("type", "cat", "subtype", "tiger", "age", "one", "name", "Timothy"), Tags.createAndAddToDictionary("type", "cat", "subtype", "tiger", "age", "one", "name", "Timothy"),
Tags.create("type", "cat", "subtype", "tiger", "age", "two", "name", "Paul"), Tags.createAndAddToDictionary("type", "cat", "subtype", "tiger", "age", "two", "name", "Paul"),
Tags.create("type", "cat", "subtype", "lion", "age", "three", "name", "Jane"), Tags.createAndAddToDictionary("type", "cat", "subtype", "lion", "age", "three", "name", "Jane"),
Tags.create("type", "cat", "subtype", "lion", "age", "four", "name", "Sam"), Tags.createAndAddToDictionary("type", "cat", "subtype", "lion", "age", "four", "name", "Sam"),
Tags.create("type", "cat", "subtype", "lion", "age", "four", "name", "John")); Tags.createAndAddToDictionary("type", "cat", "subtype", "lion", "age", "four", "name", "John"));
tags.forEach(dataStore::createNewFile); tags.forEach(dataStore::createNewFile);

View File

@@ -39,12 +39,12 @@ public class ProposerTest {
private void initDatabase() throws Exception { private void initDatabase() throws Exception {
dataStore = new DataStore(dataDirectory); dataStore = new DataStore(dataDirectory);
final Tags eagleTim = Tags.create("bird", "eagle", "name", "Tim"); final Tags eagleTim = Tags.createAndAddToDictionary("bird", "eagle", "name", "Tim");
final Tags eagleTimothy = Tags.create("bird", "eagle", "name", "Timothy"); final Tags eagleTimothy = Tags.createAndAddToDictionary("bird", "eagle", "name", "Timothy");
final Tags pigeonJennifer = Tags.create("bird", "pigeon", "name", "Jennifer"); final Tags pigeonJennifer = Tags.createAndAddToDictionary("bird", "pigeon", "name", "Jennifer");
final Tags flamingoJennifer = Tags.create("bird", "flamingo", "name", "Jennifer"); final Tags flamingoJennifer = Tags.createAndAddToDictionary("bird", "flamingo", "name", "Jennifer");
final Tags labradorJenny = Tags.create("dog", "labrador", "name", "Jenny"); final Tags labradorJenny = Tags.createAndAddToDictionary("dog", "labrador", "name", "Jenny");
final Tags labradorTim = Tags.create("dog", "labrador", "name", "Tim"); final Tags labradorTim = Tags.createAndAddToDictionary("dog", "labrador", "name", "Tim");
dataStore.createNewFile(eagleTim); dataStore.createNewFile(eagleTim);
dataStore.createNewFile(eagleTimothy); dataStore.createNewFile(eagleTimothy);

View File

@@ -36,9 +36,9 @@ public class QueryCompletionIndexTest {
Tags.STRING_COMPRESSOR = new StringCompressor(new UniqueStringIntegerPairs()); Tags.STRING_COMPRESSOR = new StringCompressor(new UniqueStringIntegerPairs());
final List<Tags> tags = Arrays.asList(// final List<Tags> tags = Arrays.asList(//
Tags.create("firstname", "John", "lastname", "Doe", "country", "Atlantis"), // A Tags.createAndAddToDictionary("firstname", "John", "lastname", "Doe", "country", "Atlantis"), // A
Tags.create("firstname", "Jane", "lastname", "Doe", "country", "ElDorado"), // B Tags.createAndAddToDictionary("firstname", "Jane", "lastname", "Doe", "country", "ElDorado"), // B
Tags.create("firstname", "John", "lastname", "Miller", "country", "Atlantis")// C Tags.createAndAddToDictionary("firstname", "John", "lastname", "Miller", "country", "Atlantis")// C
); );
try (QueryCompletionIndex index = new QueryCompletionIndex(dataDirectory)) { try (QueryCompletionIndex index = new QueryCompletionIndex(dataDirectory)) {

View File

@@ -11,8 +11,8 @@ public class Tag implements Comparable<Tag> {
} }
public Tag(final String key, final String value) { public Tag(final String key, final String value) {
this.key = key != null ? Tags.STRING_COMPRESSOR.put(key) : -1; this.key = key != null ? Tags.STRING_COMPRESSOR.getIfPresent(key) : -1;
this.value = value != null ? Tags.STRING_COMPRESSOR.put(value) : -1; this.value = value != null ? Tags.STRING_COMPRESSOR.getIfPresent(value) : -1;
} }
@Override @Override

View File

@@ -7,7 +7,6 @@ import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.Function; import java.util.function.Function;
import java.util.regex.Pattern;
import org.lucares.collections.IntList; import org.lucares.collections.IntList;
import org.lucares.collections.LongList; import org.lucares.collections.LongList;
@@ -56,30 +55,33 @@ public class Tags implements Comparable<Tags> {
return result; return result;
} }
public static Tags create(final String key, final String value) { public static Tags createAndAddToDictionary(final String key, final String value) {
return TagsBuilder.create().add(key, value).build(); return TagsBuilder.create().addAndAddToDictionary(key, value).build();
} }
public static Tags create(final String key1, final String value1, final String key2, final String value2) { public static Tags createAndAddToDictionary(final String key1, final String value1, final String key2,
final String value2) {
final Tags result = TagsBuilder.create().add(key1, value1).add(key2, value2).build(); final Tags result = TagsBuilder.create().addAndAddToDictionary(key1, value1).addAndAddToDictionary(key2, value2)
return result;
}
public static Tags create(final String key1, final String value1, final String key2, final String value2,
final String key3, final String value3) {
final Tags result = TagsBuilder.create().add(key1, value1).add(key2, value2).add(key3, value3).build();
return result;
}
public static Tags create(final String key1, final String value1, final String key2, final String value2,
final String key3, final String value3, final String key4, final String value4) {
final Tags result = TagsBuilder.create().add(key1, value1).add(key2, value2).add(key3, value3).add(key4, value4)
.build(); .build();
return result; return result;
} }
public static Tags createAndAddToDictionary(final String key1, final String value1, final String key2,
final String value2, final String key3, final String value3) {
final Tags result = TagsBuilder.create().addAndAddToDictionary(key1, value1).addAndAddToDictionary(key2, value2)
.addAndAddToDictionary(key3, value3).build();
return result;
}
public static Tags createAndAddToDictionary(final String key1, final String value1, final String key2,
final String value2, final String key3, final String value3, final String key4, final String value4) {
final Tags result = TagsBuilder.create().addAndAddToDictionary(key1, value1).addAndAddToDictionary(key2, value2)
.addAndAddToDictionary(key3, value3).addAndAddToDictionary(key4, value4).build();
return result;
}
public static Tags fromBytes(final byte[] bytes) { public static Tags fromBytes(final byte[] bytes) {
final List<Tag> result = new ArrayList<>(); final List<Tag> result = new ArrayList<>();
@@ -208,19 +210,6 @@ public class Tags implements Comparable<Tags> {
return String.join(",", tagsAsStrings); return String.join(",", tagsAsStrings);
} }
public static Tags fromCsv(final String line) {
final TagsBuilder tagsBuilder = new TagsBuilder();
final String[] tagsAsString = line.split(Pattern.quote(","));
for (final String tagAsString : tagsAsString) {
final String[] keyValue = tagAsString.split(Pattern.quote("="));
tagsBuilder.add(keyValue[0], keyValue[1]);
}
return tagsBuilder.build();
}
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
@@ -285,5 +274,4 @@ public class Tags implements Comparable<Tags> {
return result.toString(); return result.toString();
} }
} }

View File

@@ -17,6 +17,12 @@ public class TagsBuilder {
} }
public TagsBuilder add(final String key, final String value) { public TagsBuilder add(final String key, final String value) {
final int keyAsInt = Tags.STRING_COMPRESSOR.getIfPresent(key);
final int valueAsInt = Tags.STRING_COMPRESSOR.getIfPresent(value);
return add(keyAsInt, valueAsInt);
}
public TagsBuilder addAndAddToDictionary(final String key, final String value) {
final int keyAsInt = Tags.STRING_COMPRESSOR.put(key); final int keyAsInt = Tags.STRING_COMPRESSOR.put(key);
final int valueAsInt = Tags.STRING_COMPRESSOR.put(value); final int valueAsInt = Tags.STRING_COMPRESSOR.put(value);
return add(keyAsInt, valueAsInt); return add(keyAsInt, valueAsInt);

View File

@@ -82,11 +82,11 @@ public class MemoryScale {
} }
private static Object createTags1() { private static Object createTags1() {
return Tags.create("k1", "v1"); return Tags.createAndAddToDictionary("k1", "v1");
} }
private static Object createTags2() { private static Object createTags2() {
return Tags.create("k1", "v1", "k2", "v2"); return Tags.createAndAddToDictionary("k1", "v1", "k2", "v2");
} }
private static Object createTags6() { private static Object createTags6() {

View File

@@ -64,7 +64,9 @@ public class CsvToEntryTransformer implements LineToEntryTransformer {
break; break;
default: default:
if (!StringUtils.isBlank(columns[i])) { if (!StringUtils.isBlank(columns[i])) {
tagsBuilder.add(headers[i], columns[i]); final int key = Tags.STRING_COMPRESSOR.put(headers[i]);
final int value = Tags.STRING_COMPRESSOR.put(columns[i]);
tagsBuilder.add(key, value);
} }
break; break;
} }

View File

@@ -10,6 +10,7 @@ import java.util.regex.Pattern;
import org.lucares.pdb.api.Entries; import org.lucares.pdb.api.Entries;
import org.lucares.pdb.api.Entry; import org.lucares.pdb.api.Entry;
import org.lucares.pdb.api.Tags; import org.lucares.pdb.api.Tags;
import org.lucares.pdb.api.TagsBuilder;
import org.lucares.performance.db.PdbExport; import org.lucares.performance.db.PdbExport;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -104,7 +105,23 @@ public class CustomExportFormatToEntryTransformer {
final String[] tagsIdToSerializedTags = line.split(Pattern.quote(PdbExport.SEPARATOR_TAG_ID)); final String[] tagsIdToSerializedTags = line.split(Pattern.quote(PdbExport.SEPARATOR_TAG_ID));
final Long tagId = Long.parseLong(tagsIdToSerializedTags[0], 1, tagsIdToSerializedTags[0].length(), 10); final Long tagId = Long.parseLong(tagsIdToSerializedTags[0], 1, tagsIdToSerializedTags[0].length(), 10);
final Tags tags = Tags.fromCsv(tagsIdToSerializedTags[1]); final Tags tags = tagsFromCsv(tagsIdToSerializedTags[1]);
tagsDictionary.put(tagId, tags); tagsDictionary.put(tagId, tags);
} }
public static Tags tagsFromCsv(final String line) {
final TagsBuilder tagsBuilder = new TagsBuilder();
final String[] tagsAsString = line.split(Pattern.quote(","));
for (final String tagAsString : tagsAsString) {
final String[] keyValue = tagAsString.split(Pattern.quote("="));
final int key = Tags.STRING_COMPRESSOR.put(keyValue[0]);
final int value = Tags.STRING_COMPRESSOR.put(keyValue[1]);
tagsBuilder.add(key, value);
}
return tagsBuilder.build();
}
} }

View File

@@ -72,11 +72,16 @@ public class JsonToEntryTransformer implements LineToEntryTransformer {
// ignore: we only support key/value tags // ignore: we only support key/value tags
break; break;
default: default:
final int keyAsInt = Tags.STRING_COMPRESSOR.put(key);
final int valueAsInt;
if (value instanceof String) { if (value instanceof String) {
tags.add(key, (String) value); valueAsInt = Tags.STRING_COMPRESSOR.put((String) value);
} else if (value != null) { } else if (value != null) {
tags.add(key, String.valueOf(value)); valueAsInt = Tags.STRING_COMPRESSOR.put(String.valueOf(value));
} else {
continue;
} }
tags.add(keyAsInt, valueAsInt);
break; break;
} }
} }

View File

@@ -43,7 +43,7 @@ public class PerformanceDbTest {
try (PerformanceDb db = new PerformanceDb(dataDirectory)) { try (PerformanceDb db = new PerformanceDb(dataDirectory)) {
final long date = DateUtils.nowInUtc().toInstant().toEpochMilli(); final long date = DateUtils.nowInUtc().toInstant().toEpochMilli();
final long value = 1; final long value = 1;
final Tags tags = Tags.create("myKey", "myValue"); final Tags tags = Tags.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)); final Result result = db.get(Query.createQuery(tags));
@@ -63,7 +63,7 @@ public class PerformanceDbTest {
final long dayTwo = DateUtils.getDate(2016, 11, 2, 12, 34, 56).toInstant().toEpochMilli(); final long dayTwo = DateUtils.getDate(2016, 11, 2, 12, 34, 56).toInstant().toEpochMilli();
final long valueOne = 1; final long valueOne = 1;
final long valueTwo = 2; final long valueTwo = 2;
final Tags tags = Tags.create("myKey", "myValue"); final Tags tags = Tags.createAndAddToDictionary("myKey", "myValue");
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));
@@ -115,7 +115,7 @@ public class PerformanceDbTest {
final TimeRange timeRange = TimeRange.ofDay(DateUtils.getDate(year, month, day, 1, 1, 1)); final TimeRange timeRange = TimeRange.ofDay(DateUtils.getDate(year, month, day, 1, 1, 1));
final Tags tags = Tags.create("myKey", "one"); final Tags tags = Tags.createAndAddToDictionary("myKey", "one");
final List<Entry> entries = generateEntries(timeRange, numberOfEntries, 0, tags); final List<Entry> entries = generateEntries(timeRange, numberOfEntries, 0, tags);
printEntries(entries, ""); printEntries(entries, "");
@@ -156,7 +156,7 @@ public class PerformanceDbTest {
final int month = 1; final int month = 1;
final int day = 2; final int day = 2;
tags = Tags.create("myKey", "one"); tags = Tags.createAndAddToDictionary("myKey", "one");
final TimeRange timeRange = TimeRange.ofDay(DateUtils.getDate(year, month, day, 1, 1, 1)); final TimeRange timeRange = TimeRange.ofDay(DateUtils.getDate(year, month, day, 1, 1, 1));
final List<Entry> entries = generateEntries(timeRange, numberOfEntries, 0, tags); final List<Entry> entries = generateEntries(timeRange, numberOfEntries, 0, tags);
@@ -191,18 +191,18 @@ public class PerformanceDbTest {
final TimeRange timeRange = new TimeRange(from, to); final TimeRange timeRange = new TimeRange(from, to);
final long numberOfEntries = timeRange.duration().toHours(); final long numberOfEntries = timeRange.duration().toHours();
final Tags tagsCommon = Tags.create("commonKey", "commonValue"); final Tags tagsCommon = Tags.createAndAddToDictionary("commonKey", "commonValue");
final Tags tagsOne = Tags.create("myKey", "one", "commonKey", "commonValue"); final Tags tagsOne = Tags.createAndAddToDictionary("myKey", "one", "commonKey", "commonValue");
final List<Entry> entriesOne = generateEntries(timeRange, numberOfEntries, 1, tagsOne); final List<Entry> entriesOne = generateEntries(timeRange, numberOfEntries, 1, tagsOne);
db.putEntries(entriesOne); db.putEntries(entriesOne);
printEntries(entriesOne, "one"); printEntries(entriesOne, "one");
final Tags tagsTwo = Tags.create("myKey", "two", "commonKey", "commonValue"); final Tags tagsTwo = Tags.createAndAddToDictionary("myKey", "two", "commonKey", "commonValue");
final List<Entry> entriesTwo = generateEntries(timeRange, numberOfEntries, 2, tagsTwo); final List<Entry> entriesTwo = generateEntries(timeRange, numberOfEntries, 2, tagsTwo);
printEntries(entriesTwo, "two"); printEntries(entriesTwo, "two");
db.putEntries(entriesTwo); db.putEntries(entriesTwo);
final Tags tagsThree = Tags.create("myKey", "three", "commonKey", "commonValue"); final Tags tagsThree = Tags.createAndAddToDictionary("myKey", "three", "commonKey", "commonValue");
final List<Entry> entriesThree = generateEntries(timeRange, numberOfEntries, 3, tagsThree); final List<Entry> entriesThree = generateEntries(timeRange, numberOfEntries, 3, tagsThree);
printEntries(entriesThree, "three"); printEntries(entriesThree, "three");
db.putEntries(entriesThree); db.putEntries(entriesThree);
@@ -238,9 +238,9 @@ public class PerformanceDbTest {
final long numberOfEntries = timeRange.duration().toHours(); final long numberOfEntries = timeRange.duration().toHours();
final String key = "myKey"; final String key = "myKey";
final Tags tagsOne = Tags.create(key, "one", "commonKey", "commonValue"); final Tags tagsOne = Tags.createAndAddToDictionary(key, "one", "commonKey", "commonValue");
final Tags tagsTwo = Tags.create(key, "two", "commonKey", "commonValue"); final Tags tagsTwo = Tags.createAndAddToDictionary(key, "two", "commonKey", "commonValue");
final Tags tagsThree = Tags.create("commonKey", "commonValue"); final Tags tagsThree = Tags.createAndAddToDictionary("commonKey", "commonValue");
final LongList entriesOne = storeEntries(db, timeRange, numberOfEntries, tagsOne, 1); final LongList entriesOne = storeEntries(db, timeRange, numberOfEntries, tagsOne, 1);
final LongList entriesTwo = storeEntries(db, timeRange, numberOfEntries, tagsTwo, 2); final LongList entriesTwo = storeEntries(db, timeRange, numberOfEntries, tagsTwo, 2);
final LongList entriesThree = storeEntries(db, timeRange, numberOfEntries, tagsThree, 3); final LongList entriesThree = storeEntries(db, timeRange, numberOfEntries, tagsThree, 3);
@@ -252,9 +252,9 @@ public class PerformanceDbTest {
for (final GroupResult groupResult : groups) { for (final GroupResult groupResult : groups) {
final Tags groupedBy = groupResult.getGroupedBy(); final Tags groupedBy = groupResult.getGroupedBy();
if (groupedBy.equals(Tags.create(key, "one"))) { if (groupedBy.equals(Tags.createAndAddToDictionary(key, "one"))) {
Assert.assertEquals(groupResult.flatMap(), entriesOne); Assert.assertEquals(groupResult.flatMap(), entriesOne);
} else if (groupedBy.equals(Tags.create(key, "two"))) { } else if (groupedBy.equals(Tags.createAndAddToDictionary(key, "two"))) {
Assert.assertEquals(groupResult.flatMap(), entriesTwo); Assert.assertEquals(groupResult.flatMap(), entriesTwo);
} else if (groupedBy.isEmpty()) { } else if (groupedBy.isEmpty()) {
@@ -276,10 +276,10 @@ public class PerformanceDbTest {
final String key1 = "myKey1"; final String key1 = "myKey1";
final String key2 = "myKey2"; final String key2 = "myKey2";
final Tags tagsOne = Tags.create(key1, "one", key2, "aaa", "commonKey", "commonValue"); final Tags tagsOne = Tags.createAndAddToDictionary(key1, "one", key2, "aaa", "commonKey", "commonValue");
final Tags tagsTwoA = Tags.create(key1, "two", key2, "bbb", "commonKey", "commonValue"); final Tags tagsTwoA = Tags.createAndAddToDictionary(key1, "two", key2, "bbb", "commonKey", "commonValue");
final Tags tagsTwoB = Tags.create(key1, "two", key2, "bbb", "commonKey", "commonValue"); final Tags tagsTwoB = Tags.createAndAddToDictionary(key1, "two", key2, "bbb", "commonKey", "commonValue");
final Tags tagsThree = Tags.create(key1, "three", "commonKey", "commonValue"); final Tags tagsThree = Tags.createAndAddToDictionary(key1, "three", "commonKey", "commonValue");
final LongList entriesOne = storeEntries(db, timeRange, numberOfEntries, tagsOne, 1); final LongList entriesOne = storeEntries(db, timeRange, numberOfEntries, tagsOne, 1);
final LongList entriesTwo = storeEntries(db, timeRange, numberOfEntries, tagsTwoA, 2); final LongList entriesTwo = storeEntries(db, timeRange, numberOfEntries, tagsTwoA, 2);
@@ -293,9 +293,9 @@ public class PerformanceDbTest {
for (final GroupResult groupResult : groups) { for (final GroupResult groupResult : groups) {
final Tags groupedBy = groupResult.getGroupedBy(); final Tags groupedBy = groupResult.getGroupedBy();
if (groupedBy.equals(Tags.create(key1, "one", key2, "aaa"))) { if (groupedBy.equals(Tags.createAndAddToDictionary(key1, "one", key2, "aaa"))) {
Assert.assertEquals(groupResult.flatMap(), entriesOne); Assert.assertEquals(groupResult.flatMap(), entriesOne);
} else if (groupedBy.equals(Tags.create(key1, "two", key2, "bbb"))) { } else if (groupedBy.equals(Tags.createAndAddToDictionary(key1, "two", key2, "bbb"))) {
// there is no defined order of the entries. // there is no defined order of the entries.
// eventually we might return them in ascending order, but // eventually we might return them in ascending order, but
// that is not yet implemented // that is not yet implemented
@@ -305,7 +305,7 @@ public class PerformanceDbTest {
actualEntries.sort(); actualEntries.sort();
Assert.assertEquals(actualEntries, entriesTwo); Assert.assertEquals(actualEntries, entriesTwo);
} else if (groupedBy.equals(Tags.create(key1, "three"))) { } else if (groupedBy.equals(Tags.createAndAddToDictionary(key1, "three"))) {
Assert.assertEquals(groupResult.flatMap(), entriesThree); Assert.assertEquals(groupResult.flatMap(), entriesThree);
} else { } else {
Assert.fail("unexpected group: " + groupedBy); Assert.fail("unexpected group: " + groupedBy);

View File

@@ -36,7 +36,7 @@ public class TagsToFilesTest {
final TagsToFile tagsToFile = new TagsToFile(dataStore)) { final TagsToFile tagsToFile = new TagsToFile(dataStore)) {
final OffsetDateTime date = OffsetDateTime.now(ZoneOffset.UTC); final OffsetDateTime date = OffsetDateTime.now(ZoneOffset.UTC);
final Tags tags = Tags.create("myKey", "myValue"); final Tags tags = Tags.createAndAddToDictionary("myKey", "myValue");
final PdbWriter newFileForTags = tagsToFile.getWriter(date.toInstant().toEpochMilli(), tags); final PdbWriter newFileForTags = tagsToFile.getWriter(date.toInstant().toEpochMilli(), tags);
@@ -56,7 +56,7 @@ public class TagsToFilesTest {
final long dayB = DateUtils.getDate(2016, 1, 3, 1, 1, 1).toInstant().toEpochMilli(); final long dayB = DateUtils.getDate(2016, 1, 3, 1, 1, 1).toInstant().toEpochMilli();
final long dayC = DateUtils.getDate(2016, 1, 1, 1, 1, 1).toInstant().toEpochMilli(); final long dayC = DateUtils.getDate(2016, 1, 1, 1, 1, 1).toInstant().toEpochMilli();
final Tags tags = Tags.create("myKey", "myValue"); final Tags tags = Tags.createAndAddToDictionary("myKey", "myValue");
final PdbWriter writerForDayA = tagsToFile.getWriter(dayA, tags); final PdbWriter writerForDayA = tagsToFile.getWriter(dayA, tags);
writerForDayA.write(new Entry(dayA, 1, tags)); writerForDayA.write(new Entry(dayA, 1, tags));
@@ -78,7 +78,7 @@ public class TagsToFilesTest {
final long timestamp = DateUtils.getDate(2016, 1, 1, 13, 1, 1).toInstant().toEpochMilli(); final long timestamp = DateUtils.getDate(2016, 1, 1, 13, 1, 1).toInstant().toEpochMilli();
final Tags tags = Tags.create("myKey", "myValue"); final Tags tags = Tags.createAndAddToDictionary("myKey", "myValue");
final PdbWriter fileA = tagsToFile.getWriter(timestamp, tags); final PdbWriter fileA = tagsToFile.getWriter(timestamp, tags);
fileA.write(new Entry(timestamp, 1, tags)); fileA.write(new Entry(timestamp, 1, tags));