Skip to content

Commit

Permalink
Fix TimeFormatExtractionFn getCacheKey when tz, locale are not provid…
Browse files Browse the repository at this point in the history
…ed. (apache#4007)

* Fix TimeFormatExtractionFn getCacheKey when tz, locale are not provided.

* Remove unused import.

* Use defaults in cache key.
  • Loading branch information
gianm authored Mar 5, 2017
1 parent af5a4cc commit 337f387
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
6 changes: 3 additions & 3 deletions docs/content/querying/dimensionspecs.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ For a regular dimension, it assumes the string is formatted in
```json
{ "type" : "timeFormat",
"format" : <output_format> (optional),
"timeZone" : <time_zone> (optional),
"locale" : <locale> (optional),
"granularity" : <granularity> (optional) },
"timeZone" : <time_zone> (optional, default UTC),
"locale" : <locale> (optional, default current locale),
"granularity" : <granularity> (optional, default none) },
"asMillis" : <true or false> (optional) }
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ public boolean isAsMillis()
@Override
public byte[] getCacheKey()
{
final byte[] exprBytes = StringUtils.toUtf8(format + "\u0001" + tz.getID() + "\u0001" + locale.toLanguageTag());
final String tzId = (tz == null ? DateTimeZone.UTC : tz).getID();
final String localeTag = (locale == null ? Locale.getDefault() : locale).toLanguageTag();
final byte[] exprBytes = StringUtils.toUtf8(format + "\u0001" + tzId + "\u0001" + localeTag);
final byte[] granularityCacheKey = granularity.getCacheKey();
return ByteBuffer.allocate(4 + exprBytes.length + granularityCacheKey.length)
.put(ExtractionCacheHelper.CACHE_TYPE_ID_TIME_FORMAT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,16 @@ public void testCacheKey()
true
);

TimeFormatExtractionFn fn4 = new TimeFormatExtractionFn(
null,
null,
null,
null,
false
);

Assert.assertFalse(Arrays.equals(fn.getCacheKey(), fn2.getCacheKey()));
Assert.assertFalse(Arrays.equals(fn.getCacheKey(), fn4.getCacheKey()));
Assert.assertTrue(Arrays.equals(fn2.getCacheKey(), fn3.getCacheKey()));
}
}

0 comments on commit 337f387

Please sign in to comment.