Skip to content

Commit 1f5c4cf

Browse files
authored
Rewrite PinotQuery based on expression hints at instance/segment level (#8451)
* Rewrite PinotQuery based on expression hints at segment level * Address comments
1 parent 370d86c commit 1f5c4cf

File tree

16 files changed

+411
-83
lines changed

16 files changed

+411
-83
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.pinot.common.request.context.predicate;
20+
21+
import org.apache.pinot.common.request.context.ExpressionContext;
22+
23+
24+
/**
25+
* Abstract predicate with left-hand side expression
26+
*/
27+
public abstract class BasePredicate implements Predicate {
28+
29+
protected ExpressionContext _lhs;
30+
31+
public BasePredicate(ExpressionContext lhs) {
32+
_lhs = lhs;
33+
}
34+
35+
@Override
36+
public ExpressionContext getLhs() {
37+
return _lhs;
38+
}
39+
40+
@Override
41+
public void setLhs(ExpressionContext lhs) {
42+
_lhs = lhs;
43+
}
44+
}

pinot-common/src/main/java/org/apache/pinot/common/request/context/predicate/EqPredicate.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@
2525
/**
2626
* Predicate for EQ.
2727
*/
28-
public class EqPredicate implements Predicate {
29-
private final ExpressionContext _lhs;
28+
public class EqPredicate extends BasePredicate {
3029
private final String _value;
3130

3231
public EqPredicate(ExpressionContext lhs, String value) {
33-
_lhs = lhs;
32+
super(lhs);
3433
_value = value;
3534
}
3635

@@ -39,10 +38,6 @@ public Type getType() {
3938
return Type.EQ;
4039
}
4140

42-
@Override
43-
public ExpressionContext getLhs() {
44-
return _lhs;
45-
}
4641

4742
public String getValue() {
4843
return _value;

pinot-common/src/main/java/org/apache/pinot/common/request/context/predicate/InPredicate.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@
2626
/**
2727
* Predicate for IN.
2828
*/
29-
public class InPredicate implements Predicate {
30-
private final ExpressionContext _lhs;
29+
public class InPredicate extends BasePredicate {
3130
private final List<String> _values;
3231

3332
public InPredicate(ExpressionContext lhs, List<String> values) {
34-
_lhs = lhs;
33+
super(lhs);
3534
_values = values;
3635
}
3736

@@ -40,11 +39,6 @@ public Type getType() {
4039
return Type.IN;
4140
}
4241

43-
@Override
44-
public ExpressionContext getLhs() {
45-
return _lhs;
46-
}
47-
4842
public List<String> getValues() {
4943
return _values;
5044
}

pinot-common/src/main/java/org/apache/pinot/common/request/context/predicate/IsNotNullPredicate.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,17 @@
2525
/**
2626
* Predicate for IS_NOT_NULL.
2727
*/
28-
public class IsNotNullPredicate implements Predicate {
29-
private final ExpressionContext _lhs;
28+
public class IsNotNullPredicate extends BasePredicate {
3029

3130
public IsNotNullPredicate(ExpressionContext lhs) {
32-
_lhs = lhs;
31+
super(lhs);
3332
}
3433

3534
@Override
3635
public Type getType() {
3736
return Type.IS_NOT_NULL;
3837
}
3938

40-
@Override
41-
public ExpressionContext getLhs() {
42-
return _lhs;
43-
}
44-
4539
@Override
4640
public boolean equals(Object o) {
4741
if (this == o) {

pinot-common/src/main/java/org/apache/pinot/common/request/context/predicate/IsNullPredicate.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,17 @@
2525
/**
2626
* Predicate for IS_NULL.
2727
*/
28-
public class IsNullPredicate implements Predicate {
29-
private final ExpressionContext _lhs;
28+
public class IsNullPredicate extends BasePredicate {
3029

3130
public IsNullPredicate(ExpressionContext lhs) {
32-
_lhs = lhs;
31+
super(lhs);
3332
}
3433

3534
@Override
3635
public Type getType() {
3736
return Type.IS_NULL;
3837
}
3938

40-
@Override
41-
public ExpressionContext getLhs() {
42-
return _lhs;
43-
}
44-
4539
@Override
4640
public boolean equals(Object o) {
4741
if (this == o) {

pinot-common/src/main/java/org/apache/pinot/common/request/context/predicate/JsonMatchPredicate.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@
2525
/**
2626
* Predicate for JSON_MATCH.
2727
*/
28-
public class JsonMatchPredicate implements Predicate {
29-
private final ExpressionContext _lhs;
28+
public class JsonMatchPredicate extends BasePredicate {
3029
private final String _value;
3130

3231
public JsonMatchPredicate(ExpressionContext lhs, String value) {
33-
_lhs = lhs;
32+
super(lhs);
3433
_value = value;
3534
}
3635

@@ -39,11 +38,6 @@ public Type getType() {
3938
return Type.JSON_MATCH;
4039
}
4140

42-
@Override
43-
public ExpressionContext getLhs() {
44-
return _lhs;
45-
}
46-
4741
public String getValue() {
4842
return _value;
4943
}

pinot-common/src/main/java/org/apache/pinot/common/request/context/predicate/NotEqPredicate.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@
2525
/**
2626
* Predicate for NOT_EQ.
2727
*/
28-
public class NotEqPredicate implements Predicate {
29-
private final ExpressionContext _lhs;
28+
public class NotEqPredicate extends BasePredicate {
3029
private final String _value;
3130

3231
public NotEqPredicate(ExpressionContext lhs, String value) {
33-
_lhs = lhs;
32+
super(lhs);
3433
_value = value;
3534
}
3635

@@ -39,11 +38,6 @@ public Type getType() {
3938
return Type.NOT_EQ;
4039
}
4140

42-
@Override
43-
public ExpressionContext getLhs() {
44-
return _lhs;
45-
}
46-
4741
public String getValue() {
4842
return _value;
4943
}

pinot-common/src/main/java/org/apache/pinot/common/request/context/predicate/NotInPredicate.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@
2626
/**
2727
* Predicate for NOT_IN.
2828
*/
29-
public class NotInPredicate implements Predicate {
30-
private final ExpressionContext _lhs;
29+
public class NotInPredicate extends BasePredicate {
3130
private final List<String> _values;
3231

3332
public NotInPredicate(ExpressionContext lhs, List<String> values) {
34-
_lhs = lhs;
33+
super(lhs);
3534
_values = values;
3635
}
3736

@@ -40,11 +39,6 @@ public Type getType() {
4039
return Type.NOT_IN;
4140
}
4241

43-
@Override
44-
public ExpressionContext getLhs() {
45-
return _lhs;
46-
}
47-
4842
public List<String> getValues() {
4943
return _values;
5044
}

pinot-common/src/main/java/org/apache/pinot/common/request/context/predicate/Predicate.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,9 @@ public boolean isExclusive() {
5454
* Returns the left-hand side expression of the predicate.
5555
*/
5656
ExpressionContext getLhs();
57+
58+
/**
59+
* Sets the left-hand side expression of the predicate.
60+
*/
61+
void setLhs(ExpressionContext lhs);
5762
}

pinot-common/src/main/java/org/apache/pinot/common/request/context/predicate/RangePredicate.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* Predicate for RANGE.
2929
* <p>Pinot uses RANGE to represent '>', '>=', '<', '<=', BETWEEN so that intersection of multiple ranges can be merged.
3030
*/
31-
public class RangePredicate implements Predicate {
31+
public class RangePredicate extends BasePredicate {
3232
public static final char DELIMITER = Range.DELIMITER;
3333
public static final char LOWER_EXCLUSIVE = Range.LOWER_EXCLUSIVE;
3434
public static final char LOWER_INCLUSIVE = Range.LOWER_INCLUSIVE;
@@ -39,7 +39,6 @@ public class RangePredicate implements Predicate {
3939
// For backward-compatibility
4040
private static final String LEGACY_DELIMITER = "\t\t";
4141

42-
private final ExpressionContext _lhs;
4342
private final boolean _lowerInclusive;
4443
private final String _lowerBound;
4544
private final boolean _upperInclusive;
@@ -56,7 +55,7 @@ public class RangePredicate implements Predicate {
5655
* </ul>
5756
*/
5857
public RangePredicate(ExpressionContext lhs, String range) {
59-
_lhs = lhs;
58+
super(lhs);
6059
String[] split = StringUtils.split(range, DELIMITER);
6160
if (split.length != 2) {
6261
split = StringUtils.split(range, LEGACY_DELIMITER);
@@ -72,7 +71,7 @@ public RangePredicate(ExpressionContext lhs, String range) {
7271

7372
public RangePredicate(ExpressionContext lhs, boolean lowerInclusive, String lowerBound, boolean upperInclusive,
7473
String upperBound) {
75-
_lhs = lhs;
74+
super(lhs);
7675
_lowerInclusive = lowerInclusive;
7776
_lowerBound = lowerBound;
7877
_upperInclusive = upperInclusive;
@@ -84,11 +83,6 @@ public Type getType() {
8483
return Type.RANGE;
8584
}
8685

87-
@Override
88-
public ExpressionContext getLhs() {
89-
return _lhs;
90-
}
91-
9286
public boolean isLowerInclusive() {
9387
return _lowerInclusive;
9488
}

0 commit comments

Comments
 (0)