-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Util classes for data loader #2388
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
* @return formatted double as a string | ||
*/ | ||
public static String convertToNonScientific(Double doubleValue) { | ||
return createFormatter().format(doubleValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this method is frequently called, I think the DecimalFormat should be reused.
DecimalFormat DECIMAL_FORMAT = createFormatter();
...
public static String convertToNonScientific(Double doubleValue) {
return DECIMAL_FORMAT.format(doubleValue);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@komamitsu san, I had added this change but had to revert back based on Suzuki-san's comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, it's used by multiple threads, right. Understood. Using ThreadLocal is might be an option, though.
return ""; | ||
} | ||
|
||
if (!path.endsWith("/")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[minor] If this tool could be used on Windows environment, java.io.File#separatorChar
should be used instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the code to use the java.io.File#separatorChar
.
Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left several comments. Please take a look when you have time.
|
||
public class DebugUtil { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(DebugUtil.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use lower camel case for the logger:
private static final Logger LOGGER = LoggerFactory.getLogger(DebugUtil.class); | |
private static final Logger logger = LoggerFactory.getLogger(DebugUtil.class); |
According to the Google Java Style Guide, loggers are not considered constants: https://google.github.io/styleguide/javaguide.html#s5.2.4-constant-names
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the name to logger
.
Thank you.
/** Utils for decimal handling */ | ||
public class DecimalUtil { | ||
|
||
private static final DecimalFormat DECIMAL_FORMAT = createFormatter(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DecimalFormat
isn't thread-safe:
https://www.baeldung.com/java-decimalformat#thread-safety
We should not share the same instance between threads.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brfrn169 san,
I had changed this based on an earlier comment. I have reverted this back.
int N = collections[0].size(); | ||
for (Collection<?> a : collections) if (a.size() != N) return false; | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int N = collections[0].size(); | |
for (Collection<?> a : collections) if (a.size() != N) return false; | |
return true; | |
int n = collections[0].size(); | |
for (Collection<?> c : collections) { | |
if (c.size() != n) { | |
return false; | |
} | |
} | |
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the change as suggested.
Thank you.
for (Object value : values) { | ||
if (value == null) { | ||
throw new NullPointerException(DATA_LOADER_ERROR_METHOD_NULL_ARGUMENT.getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (Object value : values) { | |
if (value == null) { | |
throw new NullPointerException(DATA_LOADER_ERROR_METHOD_NULL_ARGUMENT.getMessage()); | |
for (Object value : values) { | |
if (value == null) { | |
throw new NullPointerException(DATA_LOADER_ERROR_METHOD_NULL_ARGUMENT.buildMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the change as suggested.
Thank you.
@komamitsu san, @brfrn169 san, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you!
public class RuntimeUtilTest { | ||
|
||
@Test | ||
public void checkNotNull_HasNullValues_ShouldThrowException() { | ||
assertThatThrownBy(() -> RuntimeUtil.checkNotNull(null, null)) | ||
.isExactlyInstanceOf(NullPointerException.class) | ||
.hasMessage(DATA_LOADER_ERROR_METHOD_NULL_ARGUMENT.buildMessage()); | ||
} | ||
|
||
@Test | ||
public void checkNotNull_HasNoNullValues_ShouldNotThrowException() { | ||
String string = "1"; | ||
Object object = new Object(); | ||
RuntimeUtil.checkNotNull(string, object); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency:
public class RuntimeUtilTest { | |
@Test | |
public void checkNotNull_HasNullValues_ShouldThrowException() { | |
assertThatThrownBy(() -> RuntimeUtil.checkNotNull(null, null)) | |
.isExactlyInstanceOf(NullPointerException.class) | |
.hasMessage(DATA_LOADER_ERROR_METHOD_NULL_ARGUMENT.buildMessage()); | |
} | |
@Test | |
public void checkNotNull_HasNoNullValues_ShouldNotThrowException() { | |
String string = "1"; | |
Object object = new Object(); | |
RuntimeUtil.checkNotNull(string, object); | |
} | |
} | |
class RuntimeUtilTest { | |
@Test | |
void checkNotNull_HasNullValues_ShouldThrowException() { | |
assertThatThrownBy(() -> RuntimeUtil.checkNotNull(null, null)) | |
.isExactlyInstanceOf(NullPointerException.class) | |
.hasMessage(DATA_LOADER_ERROR_METHOD_NULL_ARGUMENT.buildMessage()); | |
} | |
@Test | |
void checkNotNull_HasNoNullValues_ShouldNotThrowException() { | |
String string = "1"; | |
Object object = new Object(); | |
RuntimeUtil.checkNotNull(string, object); | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you.
I have updated it as suggested to make it consistent.
data-loader/build.gradle
Outdated
@@ -1,4 +1,8 @@ | |||
subprojects { | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed the empty line.
Thank you
Description
Added util classes for data loader
Related issues and/or PRs
NA
Changes made
Added a few util classes used in data loader.
Also includes a helper file for unit test and an file with error messages.
Checklist
Additional notes (optional)
This PR is part of the on-going process of merging all ScalarDB Data Loader code into the main repository.
Release notes
NA