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

Assert for non-empty nulls #13071

Merged
merged 20 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
</dependencies>

<properties>
<argLine>-da:ai.rapids.cudf.AssertEmptyNulls</argLine>
razajafri marked this conversation as resolved.
Show resolved Hide resolved
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
Expand Down
43 changes: 43 additions & 0 deletions java/src/main/java/ai/rapids/cudf/AssertEmptyNulls.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
*
* Copyright (c) 2023, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package ai.rapids.cudf;

/**
* This class is a Helper class to assert there are no non-empty nulls in a ColumnView
*
* The reason for the existence of this class is so that we can turn the asserts on/off when needed
* by passing "-da:ai.rapids.cudf.AssertEmptyNulls". We need that behavior because we have tests
* that explicitly test with ColumnViews that contain non-empty nulls but more importantly, there
revans2 marked this conversation as resolved.
Show resolved Hide resolved
* could be cases where an external system may not have a requirement of nulls being empty, so for
* us to work with those systems, we can turn off this assert in the field.
*/
public class AssertEmptyNulls {
// This is the recommended way to check at runtime that assertions are enabled.
// https://docs.oracle.com/javase/8/docs/technotes/guides/language/assert.html
private static boolean assertNullsAreEmpty = false;
static {
assert assertNullsAreEmpty = true ; // Intentional side effect
}

public static void assertNullsAreEmpty(ColumnView cv) {
revans2 marked this conversation as resolved.
Show resolved Hide resolved
if (cv.type.isNestedType() || cv.type.hasOffsets() && assertNullsAreEmpty) {
assert !cv.hasNonEmptyNulls() : "Column has non-empty nulls";
ttnghia marked this conversation as resolved.
Show resolved Hide resolved
razajafri marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
2 changes: 2 additions & 0 deletions java/src/main/java/ai/rapids/cudf/ColumnView.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class ColumnView implements AutoCloseable, BinaryOperable {
this.rows = ColumnView.getNativeRowCount(viewHandle);
this.nullCount = ColumnView.getNativeNullCount(viewHandle);
this.offHeap = null;
AssertEmptyNulls.assertNullsAreEmpty(this);
}


Expand All @@ -67,6 +68,7 @@ protected ColumnView(ColumnVector.OffHeapState state) {
type = DType.fromNative(ColumnView.getNativeTypeId(viewHandle), ColumnView.getNativeTypeScale(viewHandle));
rows = ColumnView.getNativeRowCount(viewHandle);
nullCount = ColumnView.getNativeNullCount(viewHandle);
AssertEmptyNulls.assertNullsAreEmpty(this);
}

/**
Expand Down