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 in support for DateAddInterval #1841

Merged
merged 3 commits into from
Mar 5, 2021
Merged

Conversation

nartal1
Copy link
Collaborator

@nartal1 nartal1 commented Mar 2, 2021

This fixes #1612
Signed-off-by: Niranjan Artal nartal@nvidia.com

Signed-off-by: Niranjan Artal <nartal@nvidia.com>
@nartal1 nartal1 added the feature request New feature or request label Mar 2, 2021
@nartal1 nartal1 added this to the Mar 1 - Mar 12 milestone Mar 2, 2021
@nartal1 nartal1 self-assigned this Mar 2, 2021
willNotWorkOnGpu("interval months isn't supported")
}
}
if (ZoneId.of(a.timeZoneId.get).normalized() != GpuOverrides.UTC_TIMEZONE_ID) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

typically it's an anti-pattern to call get on an option, especially unconditionally that trips on Nones.
we can do:

a.timeZoneId.foreach {
  case zoneId if ZoneId.of(zoneId).normalized() != GpuOverrides.UTC_TIMEZONE_ID =>
     willNotWorkOnGpu(s"Only UTC zone id is supported. Actual zone id: $zoneId")
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it will be simpler to read

if (a.timeZoneId.nonEmpty && ZoneId.of(a.timeZoneId.get).normalized() != GpuOverrides.UTC_TIMEZONE_ID) {
...
}

I am also not sure what the performance impact will be but its not a big deal as its not huge

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks @razajafri . I have incorporated @gerashegalov suggestion here. Let me know if it's okay.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you also fix it in TimeAdd and other places where we might be doing this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, Do you want me to fix it in this PR or as a follow on ? I can put up another PR with just those fixes for other expressions.

"as an argument only")
}
} finally {
if (lhs.isInstanceOf[AutoCloseable]) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use withResourceIfAllowed

// This is to calculate when subtraction is performed. Need to take into account the
// interval( which are less than days). Convert it into days which needs to be
// subtracted along with intvl.days(if provided).
(intvl.microseconds.abs / (24 * 60 * 60 * 1000 * 1000.0)).ceil.toInt * -1
Copy link
Collaborator

Choose a reason for hiding this comment

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

it would be more readable to convert the numerator .toDouble instead of sneaking in a double as the last factor in the denominator.

Can we compute/define the number of microseconds in a day 24 * 60 * 60 * 1000 * 1000 only once, and reuse the constant. Instead of using our own let us use TimeUnit.DAYS.toMicros(1)

willNotWorkOnGpu("interval months isn't supported")
}
}
if (ZoneId.of(a.timeZoneId.get).normalized() != GpuOverrides.UTC_TIMEZONE_ID) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it will be simpler to read

if (a.timeZoneId.nonEmpty && ZoneId.of(a.timeZoneId.get).normalized() != GpuOverrides.UTC_TIMEZONE_ID) {
...
}

I am also not sure what the performance impact will be but its not a big deal as its not huge

Signed-off-by: Niranjan Artal <nartal@nvidia.com>
@nartal1
Copy link
Collaborator Author

nartal1 commented Mar 2, 2021

build

gerashegalov
gerashegalov previously approved these changes Mar 3, 2021
revans2
revans2 previously approved these changes Mar 3, 2021
Copy link
Collaborator

@revans2 revans2 left a comment

Choose a reason for hiding this comment

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

Code looks fine, just curious why we didn't use a DURATION_MICROSECONDS scalar value? This is probably more efficient so we should keep it. But I would like to understand if you tried it and there were issues, or you didn't even try it.

}
val daysToAdd = intvl.days + microSecToDays
if (daysToAdd != 0) {
withResource(Scalar.fromInt(daysToAdd)) { us_s =>
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: have you tried to use DURATION_DAYS instead, It might avoid all of the casting to INT32. If you cannot do that, then we could use logicalCastTo instead of castTo when going to an INT32 to avoid a small amount of extra data movement. This is fine as is though.

Copy link
Collaborator Author

@nartal1 nartal1 Mar 3, 2021

Choose a reason for hiding this comment

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

I hadn't tried DURATION_DAYS earlier but I am getting below exception:

  : ai.rapids.cudf.CudfException: NVRTC error: NVRTC_ERROR_COMPILATION
	at ai.rapids.cudf.ColumnView.binaryOpVS(Native Method)
	at ai.rapids.cudf.ColumnView.binaryOp(ColumnView.java:907)
	at ai.rapids.cudf.ColumnView.binaryOp(ColumnView.java:897)

Have updated the code to use logicalCastTo instead of castTo . Please take another look.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you try to clean your cudf jit cache and try again? If you still at least check with cudf if that is expected. I don't think it is and we might need to file a bug with them.

Signed-off-by: Niranjan Artal <nartal@nvidia.com>
@nartal1 nartal1 dismissed stale reviews from revans2 and gerashegalov via 6a9c761 March 3, 2021 23:46
@nartal1
Copy link
Collaborator Author

nartal1 commented Mar 3, 2021

build

@nartal1
Copy link
Collaborator Author

nartal1 commented Mar 4, 2021

@revans2 Could you please take another look. I think I have addressed the review comment.

@nartal1 nartal1 merged commit 6e57e27 into NVIDIA:branch-0.5 Mar 5, 2021
nartal1 added a commit to nartal1/spark-rapids that referenced this pull request Jun 9, 2021
Signed-off-by: Niranjan Artal <nartal@nvidia.com>
nartal1 added a commit to nartal1/spark-rapids that referenced this pull request Jun 9, 2021
Signed-off-by: Niranjan Artal <nartal@nvidia.com>
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEA] DateAdd Interval Support
4 participants