Skip to content
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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Conversation

inv-jishnu
Copy link
Contributor

@inv-jishnu inv-jishnu commented Dec 4, 2024

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

The following is a best-effort checklist. If any items in this checklist are not applicable to this PR or are dependent on other, unmerged PRs, please still mark the checkboxes after you have read and understood each item.

  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation to reflect the changes.
  • Any remaining open issues linked to this PR are documented and up-to-date (Jira, GitHub, etc.).
  • Tests (unit, integration, etc.) have been added for the changes.
  • My changes generate no new warnings.
  • Any dependent changes in other PRs have been merged and published.

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

@inv-jishnu inv-jishnu added the enhancement New feature or request label Dec 4, 2024
@inv-jishnu inv-jishnu marked this pull request as draft December 4, 2024 11:08
@ypeckstadt ypeckstadt marked this pull request as ready for review December 11, 2024 09:41
@ypeckstadt ypeckstadt self-assigned this Dec 11, 2024
Copy link
Contributor

@Torch3333 Torch3333 left a 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);
Copy link
Contributor

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);
    }

Copy link
Contributor Author

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.

Copy link
Contributor

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("/")) {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@feeblefakie feeblefakie self-requested a review December 12, 2024 06:49
Copy link
Collaborator

@brfrn169 brfrn169 left a 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);
Copy link
Collaborator

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:

Suggested change
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

Copy link
Contributor Author

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();
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Comment on lines 15 to 17
int N = collections[0].size();
for (Collection<?> a : collections) if (a.size() != N) return false;
return true;
Copy link
Collaborator

@brfrn169 brfrn169 Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;

Copy link
Contributor Author

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.

Comment on lines 15 to 17
for (Object value : values) {
if (value == null) {
throw new NullPointerException(DATA_LOADER_ERROR_METHOD_NULL_ARGUMENT.getMessage());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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());

Copy link
Contributor Author

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.

@inv-jishnu
Copy link
Contributor Author

@komamitsu san, @brfrn169 san,
I have updated the PR based on your feedback.
Please take a look at this again when you get a chance.
Thank you.

Copy link
Contributor

@komamitsu komamitsu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 👍

Copy link
Contributor

@feeblefakie feeblefakie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!

Comment on lines 9 to 24
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);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency:

Suggested change
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);
}
}

Copy link
Contributor Author

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.

@@ -1,4 +1,8 @@
subprojects {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Copy link
Contributor Author

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

@inv-jishnu inv-jishnu requested a review from brfrn169 December 16, 2024 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants