@Override
  protected Filter visitBetweenPredicate(BetweenPredicate node, Void context) {
    Expression firstExpression = node.getValue();
    Expression secondExpression = node.getMin();
    Expression thirdExpression = node.getMax();

    if (firstExpression instanceof SymbolReference) {
      // firstExpression is TIMESTAMP
      long minValue = getLongValue(secondExpression);
      long maxValue = getLongValue(thirdExpression);

      if (minValue == maxValue) {
        return TimeFilterApi.eq(minValue);
      }
      return TimeFilterApi.between(minValue, maxValue);
    } else if (secondExpression instanceof SymbolReference) {
      // secondExpression is TIMESTAMP
      long value = getLongValue(firstExpression);
      long maxValue = getLongValue(thirdExpression);

      // cases:
      // 1 BETWEEN time AND 2 => time <= 1
      // 1 BETWEEN time AND 1 => time <= 1
      // 1 BETWEEN time AND 0 => FALSE
      // 1 NOT BETWEEN time AND 2 => time > 1
      // 1 NOT BETWEEN time AND 1 => time > 1
      // 1 NOT BETWEEN time AND 0 => TRUE
      checkArgument(
          value <= maxValue,
          String.format("Predicate [%s] should be simplified in previous step", node));
      return TimeFilterApi.ltEq(value);
    } else if (thirdExpression instanceof SymbolReference) {
      // thirdExpression is TIMESTAMP
      long value = getLongValue(firstExpression);
      long minValue = getLongValue(secondExpression);

      // cases:
      // 1 BETWEEN 2 AND time => FALSE
      // 1 BETWEEN 1 AND time => time >= 1
      // 1 BETWEEN 0 AND time => time >= 1
      // 1 NOT BETWEEN 2 AND time => TRUE
      // 1 NOT BETWEEN 1 AND time => time < 1
      // 1 NOT BETWEEN 0 AND time => time < 1
      checkArgument(
          value >= minValue,
          String.format("Predicate [%s] should be simplified in previous step", node));
      return TimeFilterApi.gtEq(value);
    } else {
      throw new IllegalStateException(
          "Three operand of between expression should have time column.");
    }
  }
The caller must make sure that the Expression only contains valid time predicate
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/predicate/ConvertPredicateToTimeFilterVisitor.java