strongduanmu commented on code in PR #4074:
URL: https://github.com/apache/calcite/pull/4074#discussion_r1881391654
##########
core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java:
##########
@@ -2690,6 +2690,48 @@ private static class ContainsSubstrImplementor extends
AbstractRexCallImplemento
}
}
+ /** Implementor for MYSQL {@code BIT_COUNT} function. */
+ private static class BitCountMySQLImplementor extends
AbstractRexCallImplementor {
+ BitCountMySQLImplementor() {
+ super("bitCount", NullPolicy.STRICT, false);
+ }
+
+ @Override Expression implementSafe(final RexToLixTranslator translator,
+ final RexCall call, final List<Expression> argValueList) {
+ Expression expr = argValueList.get(0);
+ RelDataType relDataType = call.getOperands().get(0).getType();
+ if (SqlTypeUtil.isNull(relDataType)) {
+ return argValueList.get(0);
+ }
+ // In MySQL, BIT_COUNT(TIMESTAMP '1996-08-03 16:22:34') is converted to
+ // BIT_COUNT('19960803162234') for calculation, so the internal int value
+ // needs to be converted to DATE/TIME and TIMESTAMP.
+ SqlTypeName type = relDataType.getSqlTypeName();
+ switch (type) {
+ case VARBINARY:
+ case BINARY:
+ return Expressions.call(SqlFunctions.class, "bitCount", expr);
+ case DATE:
+ expr = Expressions.call(BuiltInMethod.INTERNAL_TO_DATE.method, expr);
+ break;
+ case TIME:
+ case TIME_WITH_LOCAL_TIME_ZONE:
+ case TIME_TZ:
+ expr = Expressions.call(BuiltInMethod.INTERNAL_TO_TIME.method, expr);
+ break;
+ case TIMESTAMP:
+ case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
Review Comment:
Hi @mihaibudiu, I checked the documentation of MySQL TIMESTAMP -
https://dev.mysql.com/doc/refman/8.4/en/datetime.html, and found that it does
not provide syntax for `with time zone` and `with local time zone`. Does this
mean I should remove `TIMESTAMP_WITH_LOCAL_TIME_ZONE` and `TIMESTAMP_TZ` here?
--
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]