Java Code Examples for org.apache.calcite.sql.SqlKind#IS_TRUE

The following examples show how to use org.apache.calcite.sql.SqlKind#IS_TRUE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RexSimplify.java    From Bats with Apache License 2.0 5 votes vote down vote up
private RexNode simplifyIs(RexCall call, RexUnknownAs unknownAs) {
    final SqlKind kind = call.getKind();
    final RexNode a = call.getOperands().get(0);

    // UnknownAs.FALSE corresponds to x IS TRUE evaluation
    // UnknownAs.TRUE to x IS NOT FALSE
    // Note that both UnknownAs.TRUE and UnknownAs.FALSE only changes the meaning of Unknown
    // (1) if we are already in UnknownAs.FALSE mode; x IS TRUE can be simiplified to x
    // (2) similarily in UnknownAs.TRUE mode ; x IS NOT FALSE can be simplified to x
    // (3) x IS FALSE could be rewritten to (NOT x) IS TRUE and from there the 1. rule applies
    // (4) x IS NOT TRUE can be rewritten to (NOT x) IS NOT FALSE and from there the 2. rule applies
    if (kind == SqlKind.IS_TRUE && unknownAs == RexUnknownAs.FALSE) {
        return simplify(a, unknownAs);
    }
    if (kind == SqlKind.IS_FALSE && unknownAs == RexUnknownAs.FALSE) {
        return simplify(rexBuilder.makeCall(SqlStdOperatorTable.NOT, a), unknownAs);
    }
    if (kind == SqlKind.IS_NOT_FALSE && unknownAs == RexUnknownAs.TRUE) {
        return simplify(a, unknownAs);
    }
    if (kind == SqlKind.IS_NOT_TRUE && unknownAs == RexUnknownAs.TRUE) {
        return simplify(rexBuilder.makeCall(SqlStdOperatorTable.NOT, a), unknownAs);
    }
    final RexNode pred = simplifyIsPredicate(kind, a);
    if (pred != null) {
        return pred;
    }

    final RexNode simplified = simplifyIs2(kind, a, unknownAs);
    if (simplified != null) {
        return simplified;
    }
    return call;
}
 
Example 2
Source File: RexSimplify.java    From calcite with Apache License 2.0 5 votes vote down vote up
private RexNode simplifyIs(RexCall call, RexUnknownAs unknownAs) {
  final SqlKind kind = call.getKind();
  final RexNode a = call.getOperands().get(0);

  // UnknownAs.FALSE corresponds to x IS TRUE evaluation
  // UnknownAs.TRUE to x IS NOT FALSE
  // Note that both UnknownAs.TRUE and UnknownAs.FALSE only changes the meaning of Unknown
  // (1) if we are already in UnknownAs.FALSE mode; x IS TRUE can be simplified to x
  // (2) similarily in UnknownAs.TRUE mode; x IS NOT FALSE can be simplified to x
  // (3) x IS FALSE could be rewritten to (NOT x) IS TRUE and from there the 1. rule applies
  // (4) x IS NOT TRUE can be rewritten to (NOT x) IS NOT FALSE and from there the 2. rule applies
  if (kind == SqlKind.IS_TRUE && unknownAs == RexUnknownAs.FALSE) {
    return simplify(a, unknownAs);
  }
  if (kind == SqlKind.IS_FALSE && unknownAs == RexUnknownAs.FALSE) {
    return simplify(rexBuilder.makeCall(SqlStdOperatorTable.NOT, a), unknownAs);
  }
  if (kind == SqlKind.IS_NOT_FALSE && unknownAs == RexUnknownAs.TRUE) {
    return simplify(a, unknownAs);
  }
  if (kind == SqlKind.IS_NOT_TRUE && unknownAs == RexUnknownAs.TRUE) {
    return simplify(rexBuilder.makeCall(SqlStdOperatorTable.NOT, a), unknownAs);
  }
  final RexNode pred = simplifyIsPredicate(kind, a);
  if (pred != null) {
    return pred;
  }

  final RexNode simplified = simplifyIs2(kind, a, unknownAs);
  if (simplified != null) {
    return simplified;
  }
  return call;
}
 
Example 3
Source File: DruidRules.java    From calcite with Apache License 2.0 4 votes vote down vote up
private static RexNode stripFilter(RexNode node) {
  if (node.getKind() == SqlKind.IS_TRUE) {
    return ((RexCall) node).getOperands().get(0);
  }
  return node;
}