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

[Kernel][Expressions] Add IS NOT DISTINCT FROM support #2830

Closed
wants to merge 4 commits into from

Conversation

zzl-7
Copy link
Contributor

@zzl-7 zzl-7 commented Mar 31, 2024

Which Delta project/connector is this regarding?

  • Spark
  • Standalone
  • Flink
  • Kernel
  • Other (fill in here)

Description

Adding support for <=> null safe equal

Resolves #2538

How was this patch tested?

Added unit test for <=>

Does this PR introduce any user-facing changes?

Copy link
Collaborator

@vkorukanti vkorukanti left a comment

Choose a reason for hiding this comment

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

Thank you @zzl-7 for the PR. This looks great.

I think solving the issue #2541 first will make this PR easy. I added some details on the issue #2541 on how to fix it. Let me know if you are interested in working on it. Once #2541 is resolved, this PR should have minimal changes.

@Override
ExpressionTransformResult visitNullSafeComparator(Predicate predicate) {
switch (predicate.getName()) {
case "<=>":
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add the new operator to the Java doc of Predicate.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Wondering if we should just use IS NOT DISTINCT FROM which seems like is in the ANSI SQL.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vkorukanti isIS NOT DISTINCT FROM currently supported? I can't seem to find it in the source code

@@ -156,6 +157,19 @@ ExpressionTransformResult visitComparator(Predicate predicate) {
}
}

@Override
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this be combined into the visitComparator above? That way we can avoid an additional method on this visitor.

Copy link
Contributor Author

@zzl-7 zzl-7 Jun 7, 2024

Choose a reason for hiding this comment

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

fixed in #3230

Comment on lines +465 to +467
int numRows = argResults.rowCount;
boolean[] result = new boolean[numRows];
int[] compareResult = compareNullSafe(argResults.leftResult, argResults.rightResult);
Copy link
Collaborator

Choose a reason for hiding this comment

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

we want to get away from this model to lazy compute model (#2541)

this can be rewritten as

// Create a comparator
// Basically this comparator is based on the data type.
Comparator comparator = ...

return new ColumnVector() {
   public getDataType() { return BooleanType.BOOLEAN;}

   public getSize() { argResults.leftResult.getSize(); }

   public isNullAt(int rowId) {
       boolean isLeftNull = argResults.leftResult.isNullAt(rowId);
       boolean isRightNull = argResults.rightResult.isNullAt(rowId);
       return (isLeftNull && !isRightNull) || (!isLeftNull && isRightNull);
   }

  public getBoolean(int rowId) {
      // check both are null. if yes return true.
      compartor.compare(leftResult, rightResult, rowId)
   }

}

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 am a bit confused on

   public isNullAt(int rowId) {
       boolean isLeftNull = argResults.leftResult.isNullAt(rowId);
       boolean isRightNull = argResults.rightResult.isNullAt(rowId);
       return (isLeftNull && !isRightNull) || (!isLeftNull && isRightNull);
   }

Shouldn't isNullAt always return false based on https://spark.apache.org/docs/latest/sql-ref-null-semantics.html#comparison-operators-
because <=> can never return null?

@vkorukanti vkorukanti added this to the 3.2.0 milestone Apr 1, 2024
@zzl-7
Copy link
Contributor Author

zzl-7 commented Apr 2, 2024

Hi @vkorukanti Thanks for the code review, let me take a look at #2541 , might have a few question incoming, but let me dig the code first to see the scope
Thanks

@vkorukanti
Copy link
Collaborator

Hi @zzl-7, thank you for fixing the #2541. Are you interested in updating this PR?

@zzl-7
Copy link
Contributor Author

zzl-7 commented Jun 1, 2024

@vkorukanti yes, let me revisit this PR again, thanks :)

@zzl-7
Copy link
Contributor Author

zzl-7 commented Jun 7, 2024

Hi @vkorukanti I added all the fix in another PR
#3230
can you take a look?
thanks :)

@vkorukanti
Copy link
Collaborator

cc @raveeram-db

@vkorukanti vkorukanti changed the title Add <=> support [Kernel][Expressions] Add IS NOT DISTINCT FROM support Aug 15, 2024
@vkorukanti
Copy link
Collaborator

closing this PR in favor of #3230

@vkorukanti vkorukanti closed this Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Kernel][Data skipping] Support data skipping for <=> and NOT(<=>) using IS NOT DISTINCT FROM expression
2 participants