jnaous commented on a change in pull request #9111: Add HashJoinSegment, a
virtual segment for joins.
URL: https://github.com/apache/druid/pull/9111#discussion_r365262336
##########
File path: core/src/main/java/org/apache/druid/common/config/NullHandling.java
##########
@@ -118,6 +118,27 @@ public static Double defaultDoubleValue()
return replaceWithDefault() ? ZERO_DOUBLE : null;
}
+ /**
+ * Returns the default value for an object of the provided class. Will be
null in SQL-compatible null handling mode.
+ * May be null or some non-null default value when not in SQL-compatible
null handling mode.
+ */
+ @Nullable
+ @SuppressWarnings("unchecked")
+ public static <T> T defaultValueForClass(final Class<T> clazz)
+ {
+ if (clazz == Float.class) {
+ return (T) defaultFloatValue();
+ } else if (clazz == Double.class) {
+ return (T) defaultDoubleValue();
+ } else if (clazz == Long.class) {
+ return (T) defaultLongValue();
+ } else if (clazz == String.class) {
+ return (T) defaultStringValue();
+ } else {
+ return null;
Review comment:
This else is problematic. What other classes do you expect? I prefer we're
explicit in this method, returning null for the supported classes, and
otherwise throwing an exception in the else case. If in the future we add a new
supported type, and forget to add the default value if case, we would hit the
exception instead of silently returning a null and causing issues. A unit test
should additionally be created based on the set of supported types. Ideally, we
should have our own typing system with an interface that has methods like
`getDefault()` so we avoid these issues. I friggin hate type checks in Java.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]