-
Notifications
You must be signed in to change notification settings - Fork 10
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
feat: add support for utilising text indexes if exits for like operator in pinot based handlers #186
Merged
+148
−3
Merged
feat: add support for utilising text indexes if exits for like operator in pinot based handlers #186
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bd1dbbb
feat: add support for handling text indexes in pinot
kotharironak fe5f4f1
fixed spotless issues
kotharironak 8f50fae
rename the functions to match with its task
kotharironak 4ad57bf
removed temporary comments for test files
kotharironak d099e80
changed the test example to use dispalySpanName
kotharironak fe030cc
addressed comments
kotharironak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
import static org.hypertrace.core.query.service.QueryRequestUtil.getLogicalColumnName; | ||
import static org.hypertrace.core.query.service.QueryRequestUtil.isAttributeExpressionWithSubpath; | ||
import static org.hypertrace.core.query.service.QueryRequestUtil.isSimpleAttributeExpression; | ||
import static org.hypertrace.core.query.service.api.Expression.ValueCase.COLUMNIDENTIFIER; | ||
import static org.hypertrace.core.query.service.api.Expression.ValueCase.LITERAL; | ||
|
||
import com.google.common.base.Joiner; | ||
|
@@ -13,6 +12,7 @@ | |
import java.util.LinkedHashSet; | ||
import java.util.List; | ||
import java.util.Map.Entry; | ||
import java.util.Optional; | ||
import org.hypertrace.core.query.service.ExecutionContext; | ||
import org.hypertrace.core.query.service.api.Expression; | ||
import org.hypertrace.core.query.service.api.Filter; | ||
|
@@ -36,6 +36,7 @@ class QueryRequestToPinotSQLConverter { | |
|
||
private static final String QUESTION_MARK = "?"; | ||
private static final String REGEX_OPERATOR = "REGEXP_LIKE"; | ||
private static final String TEXT_MATCH_OPERATOR = "TEXT_MATCH"; | ||
private static final String MAP_VALUE = "mapValue"; | ||
private static final int MAP_KEY_INDEX = 0; | ||
private static final int MAP_VALUE_INDEX = 1; | ||
|
@@ -144,9 +145,15 @@ private String convertFilterToString( | |
} else { | ||
switch (filter.getOperator()) { | ||
case LIKE: | ||
// The like operation in PQL looks like `regexp_like(lhs, rhs)` | ||
/** | ||
* If the text index is not enabled on lhs expression, - the pql looks like | ||
* `regexp_like(lhs, rhs)` else - the pql looks like `text_match(lhs, rhs)` | ||
*/ | ||
operator = handleLikeOperatorConversion(filter.getLhs()); | ||
Expression rhs = | ||
handleValueConversionForLiteralExpression(filter.getLhs(), filter.getRhs()); | ||
rhs = postProcessValueConversionForLikeOperator(operator, rhs); | ||
|
||
builder.append(operator); | ||
builder.append("("); | ||
builder.append( | ||
|
@@ -276,6 +283,29 @@ private String convertOperatorToString(Operator operator) { | |
} | ||
} | ||
|
||
private String handleLikeOperatorConversion(Expression expression) { | ||
Optional<String> logicalColumnName = getLogicalColumnName(expression); | ||
if (logicalColumnName.isPresent() | ||
&& isSimpleAttributeExpression(expression) | ||
&& viewDefinition.hasTextIndex(logicalColumnName.get())) { | ||
return TEXT_MATCH_OPERATOR; | ||
} | ||
return REGEX_OPERATOR; | ||
} | ||
|
||
private Expression postProcessValueConversionForLikeOperator( | ||
String likeOperatorStr, Expression rhsExpression) { | ||
if (likeOperatorStr.equals(TEXT_MATCH_OPERATOR)) { | ||
String strValue = "/" + rhsExpression.getLiteral().getValue().getString() + "/"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this could be simplified a bit by just starting from the input.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
Value value = Value.newBuilder().setValueType(ValueType.STRING).setString(strValue).build(); | ||
|
||
return Expression.newBuilder() | ||
.setLiteral(LiteralConstant.newBuilder().setValue(value)) | ||
.build(); | ||
} | ||
return rhsExpression; | ||
} | ||
|
||
private String convertExpressionToString( | ||
Expression expression, Builder paramsBuilder, ExecutionContext executionContext) { | ||
switch (expression.getValueCase()) { | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: rather than taking multiple steps to calculate the RHS in the top level, could you do something like
and then have
handleValueConversionForLikeArgument
do the delegation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.