-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Rewrites pull query WHERE clause to be in DNF and allow more ex…
…pressions (#6874) * feat: More generic where clause and key extraction
- Loading branch information
1 parent
fcac459
commit b8e0c99
Showing
20 changed files
with
1,404 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
ksqldb-engine/src/main/java/io/confluent/ksql/planner/plan/KeyConstraint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* | ||
* Copyright 2020 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (the "License"; you may not use | ||
* this file except in compliance with the License. You may obtain a copy of the | ||
* License at | ||
* | ||
* http://www.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.planner.plan; | ||
|
||
import io.confluent.ksql.GenericKey; | ||
import io.confluent.ksql.execution.streams.materialization.Locator.KsqlKey; | ||
import io.confluent.ksql.planner.plan.PullFilterNode.WindowBounds; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
/** | ||
* An instance of this class represents what we know about the use of keys in a given disjunct | ||
* from an expression. The key's value, operator associated with it, and window bounds are | ||
* available through the given methods. These are used as hints for the physical planning | ||
* layer about how to fetch the corresponding rows. | ||
*/ | ||
public class KeyConstraint implements LookupConstraint { | ||
|
||
private final ConstraintOperator operator; | ||
private final GenericKey key; | ||
private final Optional<WindowBounds> windowBounds; | ||
|
||
public KeyConstraint( | ||
final ConstraintOperator operator, | ||
final GenericKey key, | ||
final Optional<WindowBounds> windowBounds | ||
) { | ||
this.operator = operator; | ||
this.key = key; | ||
this.windowBounds = windowBounds; | ||
} | ||
|
||
public static KeyConstraint equal( | ||
final GenericKey key, | ||
final Optional<WindowBounds> windowBounds | ||
) { | ||
return new KeyConstraint(ConstraintOperator.EQUAL, key, windowBounds); | ||
} | ||
|
||
// The key value. | ||
public GenericKey getKey() { | ||
return key; | ||
} | ||
|
||
// The constraint operator associated with the value | ||
public ConstraintOperator getConstraintOperator() { | ||
return operator; | ||
} | ||
|
||
// Window bounds, if the query is for a windowed table. | ||
public Optional<WindowBounds> getWindowBounds() { | ||
return windowBounds; | ||
} | ||
|
||
public KeyConstraintKey getKsqlKey() { | ||
return new KeyConstraintKey(key, windowBounds); | ||
} | ||
|
||
// If the operator represents a range of keys | ||
public boolean isRangeOperator() { | ||
return operator != ConstraintOperator.EQUAL; | ||
} | ||
|
||
public enum ConstraintOperator { | ||
EQUAL, | ||
LESS_THAN, | ||
LESS_THAN_OR_EQUAL, | ||
GREATER_THAN, | ||
GREATER_THAN_OR_EQUAL | ||
} | ||
|
||
public static class KeyConstraintKey implements KsqlKey { | ||
|
||
private final GenericKey key; | ||
private final Optional<WindowBounds> windowBounds; | ||
|
||
public KeyConstraintKey(final GenericKey key, final Optional<WindowBounds> windowBounds) { | ||
this.key = key; | ||
this.windowBounds = windowBounds; | ||
} | ||
|
||
@Override | ||
public GenericKey getKey() { | ||
return key; | ||
} | ||
|
||
public Optional<WindowBounds> getWindowBounds() { | ||
return windowBounds; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(key, windowBounds); | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
|
||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
final KeyConstraintKey that = (KeyConstraintKey) o; | ||
return Objects.equals(this.key, that.key) | ||
&& Objects.equals(this.windowBounds, that.windowBounds); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return key.toString() + "-" + windowBounds.toString(); | ||
} | ||
} | ||
} |
Oops, something went wrong.