virajjasani commented on code in PR #2255:
URL: https://github.com/apache/phoenix/pull/2255#discussion_r2274717180
##########
phoenix-core-client/src/main/java/org/apache/phoenix/compile/WhereCompiler.java:
##########
@@ -294,6 +325,152 @@ protected ColumnRef resolveColumn(ColumnParseNode node)
throws SQLException {
}
}
+ private static final class ScanBoundaryExtractingCompiler extends
WhereExpressionCompiler {
+
+ private byte[] scanStartKey;
+ private byte[] scanEndKey;
+ private boolean hasTotalSegments = false;
+ private Integer totalSegmentsValue;
+
+ private ScanBoundaryExtractingCompiler(StatementContext context) {
+ super(context);
+ }
+
+ @Override
+ public Expression visitLeave(ComparisonParseNode node, List<Expression>
children)
+ throws SQLException {
+ boolean hasScanFunctionWithEquals = false;
+ if (node.getFilterOp() == CompareOperator.EQUAL && children.size() == 2)
{
+ Expression lhs = children.get(0);
+ Expression rhs = children.get(1);
+
+ if (lhs instanceof ScanStartKeyFunction && rhs instanceof
LiteralExpression) {
+ scanStartKey = extractBytes((LiteralExpression) rhs);
+ hasScanFunctionWithEquals = true;
+ } else if (rhs instanceof ScanStartKeyFunction && lhs instanceof
LiteralExpression) {
+ scanStartKey = extractBytes((LiteralExpression) lhs);
+ hasScanFunctionWithEquals = true;
+ }
+
+ if (lhs instanceof ScanEndKeyFunction && rhs instanceof
LiteralExpression) {
+ scanEndKey = extractBytes((LiteralExpression) rhs);
+ hasScanFunctionWithEquals = true;
+ } else if (rhs instanceof ScanEndKeyFunction && lhs instanceof
LiteralExpression) {
+ scanEndKey = extractBytes((LiteralExpression) lhs);
+ hasScanFunctionWithEquals = true;
+ }
+
+ if (lhs instanceof TotalSegmentsFunction && rhs instanceof
LiteralExpression) {
+ hasTotalSegments = true;
+ totalSegmentsValue = getTotalSegmentsVal((LiteralExpression) rhs);
+ } else if (rhs instanceof TotalSegmentsFunction && lhs instanceof
LiteralExpression) {
+ hasTotalSegments = true;
+ totalSegmentsValue = getTotalSegmentsVal((LiteralExpression) lhs);
+ }
+ }
+ if (hasScanFunctionWithEquals) {
+ Expression expression = super.visitLeave(node, children);
+ if (
+ expression instanceof LiteralExpression &&
LiteralExpression.isBooleanNull(expression)
+ ) {
+ return LiteralExpression.newConstant(true, PBoolean.INSTANCE,
Determinism.ALWAYS);
+ }
+ return expression;
+ }
+ return super.visitLeave(node, children);
+ }
+
+ private byte[] extractBytes(LiteralExpression literal) {
+ ImmutableBytesWritable ptr = new ImmutableBytesWritable();
+ if (literal.evaluate(null, ptr)) {
+ return ptr.copyBytes();
+ }
+ return null;
+ }
+
+ private Integer getTotalSegmentsVal(LiteralExpression literal) throws
SQLException {
+ ImmutableBytesWritable ptr = new ImmutableBytesWritable();
+ if (literal.evaluate(null, ptr)) {
+ Integer value = (Integer) PInteger.INSTANCE.toObject(ptr);
+ if (value != null && value <= 0) {
+ throw new
SQLExceptionInfo.Builder(SQLExceptionCode.INVALID_TOTAL_SEGMENTS_VALUE).build()
Review Comment:
Yes, we do in `testTotalSegmentsWithInvalidValues()`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]