Skip to content

Simplify bounds/range vs selectors/equality logic in SQL planning.#14619

Merged
gianm merged 2 commits intoapache:masterfrom
gianm:adjust-new-filters-logic
Jul 20, 2023
Merged

Simplify bounds/range vs selectors/equality logic in SQL planning.#14619
gianm merged 2 commits intoapache:masterfrom
gianm:adjust-new-filters-logic

Conversation

@gianm
Copy link
Copy Markdown
Contributor

@gianm gianm commented Jul 19, 2023

  1. Consolidate duplicate code related to Expressions#buildTimeFloorFilter.

  2. Cleaner logic in Expressions#toSimpleLeafFilter: choose bounds vs range
    filter based solely on plannerContext.isUseBoundsAndSelectors, not also
    considering rhs kind. Use parsed rhs in both paths (except for numerics
    in the bound path).

  3. Fix ArrayContains, ArrayOverlap to avoid equality filters when there is
    an extractionFn present. Fixes a bug introduced in remove extractionFn from equality, null, and range filters #14612.

1) Consolidate duplicate code related to Expressions#buildTimeFloorFilter.

2) Cleaner logic in Expressions#toSimpleLeafFilter: choose bounds vs range
   filter based solely on plannerContext.isUseBoundsAndSelectors, not also
   considering rhs kind. Use parsed rhs in both paths (except for numerics
   in the bound path).

3) Fix ArrayContains, ArrayOverlap to avoid equality filters when there is
   an extractionFn present. Fixes a bug introduced in apache#14612.
@gianm gianm added this to the 27.0 milestone Jul 19, 2023
Copy link
Copy Markdown
Member

@clintropolis clintropolis left a comment

Choose a reason for hiding this comment

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

thanks for fixing 🤘

stringVal = String.valueOf(RexLiteral.value(rhs));
} else {
// Don't know how to filter on this kind of literal.
stringVal = String.valueOf(rhsParsed.getLiteralValue());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i wonder if we might want to check for ARRAY or COMPLEX types, since stringifying them and putting them in the filter isn't probably the right thing (it previously was impossible here because of the check for RexLiteral), could move

        final ColumnType matchValueType = Calcites.getColumnTypeForRelDataType(rhs.getType());

outside of the range filter case and check matchValueType.isPrimitive() to be safe.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is it OK to filter on ARRAY or COMPLEX inside the range filter case? Or should we require primitive across the board?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

totally cool for the range case since they include the ColumnType for the match value and know how to handle stuff, so just the bounds path needs guarded to not do weird stuff

@gianm gianm merged commit c2e6758 into apache:master Jul 20, 2023
@gianm gianm deleted the adjust-new-filters-logic branch July 20, 2023 05:40
gianm added a commit to gianm/druid that referenced this pull request Jul 20, 2023
…pache#14619)

* Simplify bounds/range vs selectors/equality logic in SQL planning.

1) Consolidate duplicate code related to Expressions#buildTimeFloorFilter.

2) Cleaner logic in Expressions#toSimpleLeafFilter: choose bounds vs range
   filter based solely on plannerContext.isUseBoundsAndSelectors, not also
   considering rhs kind. Use parsed rhs in both paths (except for numerics
   in the bound path).

3) Fix ArrayContains, ArrayOverlap to avoid equality filters when there is
   an extractionFn present. Fixes a bug introduced in apache#14612.

* Avoid sending nonprimitives down the bound path.
abhishekagarwal87 pushed a commit that referenced this pull request Jul 21, 2023
…14619) (#14624)

* Simplify bounds/range vs selectors/equality logic in SQL planning.

1) Consolidate duplicate code related to Expressions#buildTimeFloorFilter.

2) Cleaner logic in Expressions#toSimpleLeafFilter: choose bounds vs range
   filter based solely on plannerContext.isUseBoundsAndSelectors, not also
   considering rhs kind. Use parsed rhs in both paths (except for numerics
   in the bound path).

3) Fix ArrayContains, ArrayOverlap to avoid equality filters when there is
   an extractionFn present. Fixes a bug introduced in #14612.

* Avoid sending nonprimitives down the bound path.
sergioferragut pushed a commit to sergioferragut/druid that referenced this pull request Jul 21, 2023
…pache#14619)

* Simplify bounds/range vs selectors/equality logic in SQL planning.

1) Consolidate duplicate code related to Expressions#buildTimeFloorFilter.

2) Cleaner logic in Expressions#toSimpleLeafFilter: choose bounds vs range
   filter based solely on plannerContext.isUseBoundsAndSelectors, not also
   considering rhs kind. Use parsed rhs in both paths (except for numerics
   in the bound path).

3) Fix ArrayContains, ArrayOverlap to avoid equality filters when there is
   an extractionFn present. Fixes a bug introduced in apache#14612.

* Avoid sending nonprimitives down the bound path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants