mirror of https://github.com/apache/druid.git
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:
parent
af5a4cce3c
commit
337f3870d8
|
@ -229,9 +229,9 @@ For a regular dimension, it assumes the string is formatted in
|
||||||
```json
|
```json
|
||||||
{ "type" : "timeFormat",
|
{ "type" : "timeFormat",
|
||||||
"format" : <output_format> (optional),
|
"format" : <output_format> (optional),
|
||||||
"timeZone" : <time_zone> (optional),
|
"timeZone" : <time_zone> (optional, default UTC),
|
||||||
"locale" : <locale> (optional),
|
"locale" : <locale> (optional, default current locale),
|
||||||
"granularity" : <granularity> (optional) },
|
"granularity" : <granularity> (optional, default none) },
|
||||||
"asMillis" : <true or false> (optional) }
|
"asMillis" : <true or false> (optional) }
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,9 @@ public class TimeFormatExtractionFn implements ExtractionFn
|
||||||
@Override
|
@Override
|
||||||
public byte[] getCacheKey()
|
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();
|
final byte[] granularityCacheKey = granularity.getCacheKey();
|
||||||
return ByteBuffer.allocate(4 + exprBytes.length + granularityCacheKey.length)
|
return ByteBuffer.allocate(4 + exprBytes.length + granularityCacheKey.length)
|
||||||
.put(ExtractionCacheHelper.CACHE_TYPE_ID_TIME_FORMAT)
|
.put(ExtractionCacheHelper.CACHE_TYPE_ID_TIME_FORMAT)
|
||||||
|
|
|
@ -171,7 +171,16 @@ public class TimeFormatExtractionFnTest
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
|
TimeFormatExtractionFn fn4 = new TimeFormatExtractionFn(
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
Assert.assertFalse(Arrays.equals(fn.getCacheKey(), fn2.getCacheKey()));
|
Assert.assertFalse(Arrays.equals(fn.getCacheKey(), fn2.getCacheKey()));
|
||||||
|
Assert.assertFalse(Arrays.equals(fn.getCacheKey(), fn4.getCacheKey()));
|
||||||
Assert.assertTrue(Arrays.equals(fn2.getCacheKey(), fn3.getCacheKey()));
|
Assert.assertTrue(Arrays.equals(fn2.getCacheKey(), fn3.getCacheKey()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue