mihaibudiu commented on code in PR #4339:
URL: https://github.com/apache/calcite/pull/4339#discussion_r2213944947
##########
core/src/main/java/org/apache/calcite/sql/parser/StringAndPos.java:
##########
@@ -52,8 +53,54 @@ private StringAndPos(String sql, int cursor, @Nullable
SqlParserPos pos) {
}
/**
- * Looks for one or two carets in a SQL string, and if present, converts
- * them into a parser position.
+ * Checks if the SQL expression is a simple XOR pattern that can be safely
processed.
+ *
+ * <p>This method provides special handling for the BITXOR_OPERATOR (^) in
Apache Calcite
Review Comment:
I think these patterns are overly specific and not really that useful just
for allowing people to skip one caret in a test case.
If you really want special processing, you could treat a string with a
single caret specially, by interpreting the caret as a normal character.
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -16294,6 +16299,48 @@ private static void
checkLogicalOrFunc(SqlOperatorFixture f) {
f.checkAgg("logical_or(x)", values4, isNullValue());
}
+ @Test void testBitXorOperatorParserFunc() throws SqlParseException {
+ String sql = "SELECT 5 ^ 3 ";
+ SqlNode sqlNode = SqlParser.create(sql,
SqlParser.Config.DEFAULT).parseStmt();
+
+ assertInstanceOf(SqlSelect.class, sqlNode);
+ SqlSelect select = (SqlSelect) sqlNode;
+
+ SqlNode selectItem = select.getSelectList().get(0);
+ assertInstanceOf(SqlBasicCall.class, selectItem);
+ SqlBasicCall call = (SqlBasicCall) selectItem;
+ assertEquals(SqlStdOperatorTable.BITXOR_OPERATOR, call.getOperator());
+ assertEquals(2, call.getOperandList().size());
+ }
+
+ @Test void testBitXorOperatorScalarFunc() {
+ final SqlOperatorFixture f = fixture();
+ f.setFor(SqlStdOperatorTable.BITXOR_OPERATOR, VM_EXPAND);
+
+ // Basic XOR between two integer literals
+ f.checkScalar("2 ^ 3", "1", "INTEGER NOT NULL");
+ f.checkScalar("CAST(2 AS INTEGER) ^ CAST(3 AS BIGINT)", "1", "BIGINT NOT
NULL");
+ f.checkScalar("-5 ^ 7", "-4", "INTEGER NOT NULL");
+ f.checkScalar("-5 ^ -7", "2", "INTEGER NOT NULL");
+ f.checkScalar("CAST(-5 AS TINYINT) ^ CAST(7 AS TINYINT)", "-4", "TINYINT
NOT NULL");
+ f.checkScalar("CAST(-5 AS TINYINT) ^ CAST(-31 AS TINYINT)", "26", "TINYINT
NOT NULL");
+ f.checkType("CAST(2 AS TINYINT) ^ CAST(6 AS TINYINT)", "TINYINT NOT NULL");
+ f.checkType("CAST(2 AS SMALLINT) ^ CAST(6 AS SMALLINT)", "SMALLINT NOT
NULL");
+ f.checkType("CAST(2 AS BIGINT) ^ CAST(6 AS BIGINT)", "BIGINT NOT NULL");
Review Comment:
we now support unsigned numbers, can you add one test with one of these?
##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -3226,7 +3226,6 @@ public static ByteString bitNot(ByteString b) {
return new ByteString(result);
}
-
Review Comment:
this edit is not particularly useful
--
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]