Skip to content

Commit

Permalink
opt between
Browse files Browse the repository at this point in the history
  • Loading branch information
englefly committed Nov 6, 2024
1 parent 800f5c6 commit 782cbe7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3495,10 +3495,16 @@ private Expression withPredicate(Expression valueExpression, PredicateContext ct
Expression outExpression;
switch (ctx.kind.getType()) {
case DorisParser.BETWEEN:
outExpression = new And(
new GreaterThanEqual(valueExpression, getExpression(ctx.lower)),
new LessThanEqual(valueExpression, getExpression(ctx.upper))
);
Expression lower = getExpression(ctx.lower);
Expression upper = getExpression(ctx.upper);
if (lower.equals(upper)) {
outExpression = new EqualTo(valueExpression, lower);
} else {
outExpression = new And(
new GreaterThanEqual(valueExpression, getExpression(ctx.lower)),
new LessThanEqual(valueExpression, getExpression(ctx.upper))
);
}
break;
case DorisParser.LIKE:
outExpression = new Like(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.apache.doris.nereids.parser;

import org.apache.doris.nereids.trees.expressions.And;
import org.apache.doris.nereids.trees.expressions.EqualTo;
import org.apache.doris.nereids.trees.expressions.Expression;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class BetweenTest {
private static final NereidsParser PARSER = new NereidsParser();

@Test
public void testBetween() {
String expression ="A between 1 and 1"; //
Expression result = PARSER.parseExpression(expression);
Assertions.assertInstanceOf(EqualTo.class, result);

expression = "A between 1 and 2";
result = PARSER.parseExpression(expression);
Assertions.assertInstanceOf(And.class, result);
}
}

0 comments on commit 782cbe7

Please sign in to comment.