Skip to content
Closed
Changes from 1 commit
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
Next Next commit
array_contains function deals with Column type for the second parameter.
  • Loading branch information
Chongguang LIU authored and Chongguang LIU committed Jun 17, 2018
commit 27733f9ad56657925c176ae394114e0429aa9a0b
8 changes: 6 additions & 2 deletions sql/core/src/main/scala/org/apache/spark/sql/functions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3077,12 +3077,16 @@ object functions {
//////////////////////////////////////////////////////////////////////////////////////////////

/**
* Returns null if the array is null, true if the array contains `value`, and false otherwise.
* Returns null if the array is null, true if the array contains `value` or the content of
Copy link
Member

Choose a reason for hiding this comment

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

We need to update this comment? I think content of value is a little ambiguous.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey, thanks for the message. Do you want me to change the comment back? I see that you have started the test, is it too late?

Copy link
Member

Choose a reason for hiding this comment

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

you can fix now

* `value` if it is of type Column, and false otherwise.
* @group collection_funcs
* @since 1.5.0
*/
def array_contains(column: Column, value: Any): Column = withExpr {
ArrayContains(column.expr, Literal(value))
Copy link
Member

Choose a reason for hiding this comment

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

Other similar expressions are ArrayPosition, ElementAt, ArrayRemove.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I just found @maropu has pointed it out in #21581 (comment).

value match {
Copy link
Member

Choose a reason for hiding this comment

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

On second thoughts, we should use lit(), e.g., ArrayContains(column.expr, lit(value).expr)? WDYT? @viirya @maropu @HyukjinKwon

Copy link
Member

Choose a reason for hiding this comment

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

Yup, that's what I was thinking too from my glance.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I think so.

Copy link
Member

Choose a reason for hiding this comment

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

+1

Copy link
Member

Choose a reason for hiding this comment

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

@chongguang I mean, use just ArrayContains(column.expr, lit(value).expr) instead of value match { .... The lit() should handle literals and columns well.

case c: Column => ArrayContains(column.expr, c.expr)
case _ => ArrayContains(column.expr, Literal(value))
}
}

/**
Expand Down