Fix TimeFormatExtractionFn getCacheKey when tz, locale are not provided. (#4007)

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

* Remove unused import.

* Use defaults in cache key.
This commit is contained in:
Gian Merlino 2017-03-04 17:41:59 -08:00 committed by GitHub
parent af5a4cce3c
commit 337f3870d8
3 changed files with 15 additions and 4 deletions

View File

@ -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) }
```

View File

@ -106,7 +106,9 @@ public class TimeFormatExtractionFn implements ExtractionFn
@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)

View File

@ -171,7 +171,16 @@ public class TimeFormatExtractionFnTest
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()));
}
}