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

[SPARK-23927][SQL] Add "sequence" expression #21155

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ object FunctionRegistry {
expression[Reverse]("reverse"),
expression[Concat]("concat"),
expression[Flatten]("flatten"),
expression[Sequence]("sequence"),
expression[ArrayRepeat]("array_repeat"),
expression[ArrayRemove]("array_remove"),
expression[ArrayDistinct]("array_distinct"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,13 @@ object TypeCoercion {
case None => aj
}

case s @ Sequence(_, _, _, timeZoneId) if !haveSameType(s.coercibleChildren) =>
val types = s.coercibleChildren.map(_.dataType)
findWiderCommonType(types) match {
Copy link
Member

Choose a reason for hiding this comment

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

What if step is interval?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should use ExpectsInputTypes or ImplicitCastInputTypes instead of TypeCoercion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thank you. I've added a unit test and fixed coercion when the step is interval.
Regarding ImplicitCastInputTypes I tried it, but it isn't flexible enough for my case. To support actual type coercion for both integral and temporal sequences I had to resort to TypeCoercion. Please check the fixed version. Is there any better way how to do it?

case Some(widerDataType) => s.castChildrenTo(widerDataType)
case None => s
}

case m @ CreateMap(children) if m.keys.length == m.values.length &&
(!haveSameType(m.keys) || !haveSameType(m.values)) =>
val newKeys = if (haveSameType(m.keys)) {
Expand Down
Loading