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

Java: Support struct scalar [skip ci] #8327

Merged
merged 8 commits into from
May 26, 2021

Conversation

sperlingxx
Copy link
Contributor

@sperlingxx sperlingxx commented May 24, 2021

Current PR is to support struct scalar in Java package, which is required by spark-rapids (issue link). In detail, current PR introduces three new features:

  1. create struct scalar through Java API
  2. get children of struct scalar through Java API
  3. create struct column from (struct) scalar through Java API

@sperlingxx sperlingxx requested a review from a team as a code owner May 24, 2021 12:41
@github-actions github-actions bot added the Java Affects Java cuDF API. label May 24, 2021
@sperlingxx sperlingxx added feature request New feature or request non-breaking Non-breaking change labels May 24, 2021
Signed-off-by: sperlingxx <[email protected]>
Signed-off-by: sperlingxx <[email protected]>
java/src/main/java/ai/rapids/cudf/Scalar.java Outdated Show resolved Hide resolved
java/src/main/java/ai/rapids/cudf/Scalar.java Outdated Show resolved Hide resolved
java/src/main/java/ai/rapids/cudf/Scalar.java Outdated Show resolved Hide resolved
java/src/main/java/ai/rapids/cudf/Scalar.java Outdated Show resolved Hide resolved
java/src/main/native/src/ScalarJni.cpp Outdated Show resolved Hide resolved
@sperlingxx sperlingxx changed the title Java: Support creating struct scalar [skip ci] Java: Support struct scalar [skip ci] May 25, 2021
@sperlingxx
Copy link
Contributor Author

sperlingxx commented May 25, 2021

Hi @revans2 @jlowe @firestarman, thanks for review!

I updated this PR, adding the support of ColumnVector.fromScalar on StructType (since #8310 merged).

@firestarman
Copy link
Contributor

LGTM

}
return new Scalar(DType.STRUCT, makeStructScalar(childHandles, false));
} finally {
IllegalStateException closeException = null;
Copy link
Member

Choose a reason for hiding this comment

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

This won't do what we want. If an exception is thrown from the try block then this finally block will still clobber that exception if any close() call fails. It needs something like this:

  RuntimeException error = null;
  try {
    ...
  } catch (RuntimeException e) {
    error = e;
  } catch (Exception e) {
    error = new RuntimeException(e);
  } finally {
    for (ColumnVector child : children) {
      if (child != null) {
        try {
          child.close();
        } catch (Exception e) {
          if (error != null) {
            error.addSuppressed(e);
          } else {
            error = new RuntimeException(e);
          }
        }
      }
    }
    if (error != null) {
      throw error;
    }
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Thanks for the demo code!

java/src/main/java/ai/rapids/cudf/Scalar.java Show resolved Hide resolved
// make sure the close process is exception-free
try {
child.close();
} catch (Exception ignore) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This has the same problem as up above we need to not just eat the exceptions but add them to the suppression list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Signed-off-by: sperlingxx <[email protected]>
@sperlingxx
Copy link
Contributor Author

@gpucibot merge

@rapids-bot rapids-bot bot merged commit 2383193 into rapidsai:branch-21.06 May 26, 2021
@sperlingxx sperlingxx deleted the struct_scalar_jni branch May 26, 2021 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request Java Affects Java cuDF API. non-breaking Non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants