Skip to content

Conversation

@huaxingao
Copy link
Contributor

What changes were proposed in this pull request?

Add util methods to convert DS V2 Filter to V1 Filter.

Why are the changes needed?

Provide convenient methods to convert V2 to V1 Filters. These methods can be used by SupportsRuntimeFiltering and later be used by SupportsDelete

Does this PR introduce any user-facing change?

No. These are intended for internal use only

How was this patch tested?

new tests

@github-actions github-actions bot added the SQL label Jul 28, 2022
@huaxingao
Copy link
Contributor Author

The GA failure doesn't seem relevant.

@huaxingao
Copy link
Contributor Author

@cloud-fan Could you please take a look when you have time? Thanks!

Some(In(attribute, Array.empty[Any]))
}

case "=" | "<=>" | ">" | "<" | ">=" | "<=" if predicate.children().length == 2 &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Both case "=" | "<=>" | ">" | "<" | ">=" | "<=" and "STARTS_WITH" | "ENDS_WITH" | "CONTAINS" use condition

if predicate.children().length == 2 &&
  predicate.children()(0).isInstanceOf[NamedReference] &&
  predicate.children()(1).isInstanceOf[LiteralValue[_]]

Is it necessary to extract a function?


case "AND" =>
val and = predicate.asInstanceOf[V2And]
Some(And(toV1(and.left()).get, toV1(and.right()).get))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should return None if any of the children can't be converted to v1.

case "=" | "<=>" | ">" | "<" | ">=" | "<=" if isValidBinaryPredicate =>
val attribute = predicate.children()(0).toString
val value = predicate.children()(1).asInstanceOf[LiteralValue[_]]
predicate.name() match {
Copy link
Contributor

@cloud-fan cloud-fan Aug 1, 2022

Choose a reason for hiding this comment

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

nit:

val v1Value = CatalystTypeConverters.convertToScala(value.value, value.dataType)
val v1Filter = predicate.name() match {
  case "=" =>EqualTo(attribute, v1Value)
  ...
}
Some(v1Filter)


case "NOT" =>
val not = predicate.asInstanceOf[V2Not]
Some(Not(toV1(not.child()).get))
Copy link
Contributor

Choose a reason for hiding this comment

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

toV1(not.child()) may not always return Some

@huaxingao huaxingao closed this in 2ef7382 Aug 1, 2022
@huaxingao
Copy link
Contributor Author

Thanks for reviewing! Merged to master.

@huaxingao huaxingao deleted the toV1 branch August 1, 2022 18:24
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.

3 participants