use of org.apache.calcite.sql.SqlSpecialOperator in project calcite by apache.
the class RexProgramTest method testIsDeterministic.
@Test
public void testIsDeterministic() {
SqlOperator ndc = new SqlSpecialOperator("NDC", SqlKind.OTHER_FUNCTION, 0, false, ReturnTypes.BOOLEAN, null, null) {
@Override
public boolean isDeterministic() {
return false;
}
};
RexNode n = rexBuilder.makeCall(ndc);
assertFalse(RexUtil.isDeterministic(n));
assertEquals(0, RexUtil.retainDeterministic(RelOptUtil.conjunctions(n)).size());
}
use of org.apache.calcite.sql.SqlSpecialOperator in project calcite by apache.
the class SqlValidatorTest method testOperatorsSortedByPrecedence.
/**
* Tests that operators, sorted by precedence, are in a sane order. Each
* operator has a {@link SqlOperator#getLeftPrec() left} and
* {@link SqlOperator#getRightPrec()} right} precedence, but we would like
* the order to remain the same even if we tweak particular operators'
* precedences. If you need to update the expected output, you might also
* need to change
* <a href="http://calcite.apache.org/docs/reference.html#operator-precedence">
* the documentation</a>.
*/
@Test
public void testOperatorsSortedByPrecedence() {
final StringBuilder b = new StringBuilder();
final Comparator<SqlOperator> comparator = new Comparator<SqlOperator>() {
public int compare(SqlOperator o1, SqlOperator o2) {
int c = Integer.compare(prec(o1), prec(o2));
if (c != 0) {
return -c;
}
c = o1.getName().compareTo(o2.getName());
if (c != 0) {
return c;
}
return o1.getSyntax().compareTo(o2.getSyntax());
}
};
final List<SqlOperator> operators = SqlStdOperatorTable.instance().getOperatorList();
int p = -1;
for (SqlOperator op : Ordering.from(comparator).sortedCopy(operators)) {
final String type;
switch(op.getSyntax()) {
case FUNCTION:
case FUNCTION_ID:
case FUNCTION_STAR:
case INTERNAL:
continue;
case PREFIX:
type = "pre";
break;
case POSTFIX:
type = "post";
break;
case BINARY:
if (op.getLeftPrec() < op.getRightPrec()) {
type = "left";
} else {
type = "right";
}
break;
default:
if (op instanceof SqlSpecialOperator) {
type = "-";
} else {
continue;
}
}
if (prec(op) != p) {
b.append('\n');
p = prec(op);
}
b.append(op.getName()).append(' ').append(type).append('\n');
}
final String expected = "\n" + "ARRAY -\n" + "ARRAY -\n" + "COLUMN_LIST -\n" + "CURSOR -\n" + "LATERAL -\n" + "MAP -\n" + "MAP -\n" + "MULTISET -\n" + "MULTISET -\n" + "ROW -\n" + "TABLE -\n" + "UNNEST -\n" + "\n" + "CURRENT_VALUE -\n" + "DEFAULT -\n" + "DOT -\n" + "ITEM -\n" + "NEXT_VALUE -\n" + "PATTERN_EXCLUDE -\n" + "PATTERN_PERMUTE -\n" + "\n" + "PATTERN_QUANTIFIER -\n" + "\n" + " left\n" + "$LiteralChain -\n" + "+ pre\n" + "- pre\n" + "FINAL pre\n" + "RUNNING pre\n" + "\n" + "| left\n" + "\n" + "% left\n" + "* left\n" + "/ left\n" + "/INT left\n" + "|| left\n" + "\n" + "+ left\n" + "+ -\n" + "- left\n" + "- -\n" + "EXISTS pre\n" + "\n" + "< ALL left\n" + "< SOME left\n" + "<= ALL left\n" + "<= SOME left\n" + "<> ALL left\n" + "<> SOME left\n" + "= ALL left\n" + "= SOME left\n" + "> ALL left\n" + "> SOME left\n" + ">= ALL left\n" + ">= SOME left\n" + "BETWEEN ASYMMETRIC -\n" + "BETWEEN SYMMETRIC -\n" + "IN left\n" + "LIKE -\n" + "NOT BETWEEN ASYMMETRIC -\n" + "NOT BETWEEN SYMMETRIC -\n" + "NOT IN left\n" + "NOT LIKE -\n" + "NOT SIMILAR TO -\n" + "SIMILAR TO -\n" + "\n" + "$IS_DIFFERENT_FROM left\n" + "< left\n" + "<= left\n" + "<> left\n" + "= left\n" + "> left\n" + ">= left\n" + "CONTAINS left\n" + "EQUALS left\n" + "IMMEDIATELY PRECEDES left\n" + "IMMEDIATELY SUCCEEDS left\n" + "IS DISTINCT FROM left\n" + "IS NOT DISTINCT FROM left\n" + "MEMBER OF left\n" + "OVERLAPS left\n" + "PRECEDES left\n" + "SUBMULTISET OF left\n" + "SUCCEEDS left\n" + "\n" + "IS A SET post\n" + "IS FALSE post\n" + "IS NOT FALSE post\n" + "IS NOT NULL post\n" + "IS NOT TRUE post\n" + "IS NOT UNKNOWN post\n" + "IS NULL post\n" + "IS TRUE post\n" + "IS UNKNOWN post\n" + "\n" + "NOT pre\n" + "\n" + "AND left\n" + "\n" + "OR left\n" + "\n" + "=> -\n" + "AS -\n" + "DESC post\n" + "OVER left\n" + "TABLESAMPLE -\n" + "\n" + "INTERSECT left\n" + "INTERSECT ALL left\n" + "MULTISET INTERSECT left\n" + "MULTISET INTERSECT ALL left\n" + "NULLS FIRST post\n" + "NULLS LAST post\n" + "\n" + "EXCEPT left\n" + "EXCEPT ALL left\n" + "MULTISET EXCEPT left\n" + "MULTISET EXCEPT ALL left\n" + "MULTISET UNION left\n" + "MULTISET UNION ALL left\n" + "UNION left\n" + "UNION ALL left\n" + "\n" + "$throw -\n" + "FILTER left\n" + "Reinterpret -\n" + "TABLE pre\n" + "VALUES -\n" + "\n" + "CALL pre\n" + "ESCAPE -\n" + "NEW pre\n";
assertThat(b.toString(), is(expected));
}
Aggregations