SQL function TIMESTAMPDIFF returns INTEGER type for MICROSECOND time unit, but sometimes precession of int is not enough to store value. For example, value for
is 7689602122000, and it's more then maximum int value. It's better to extend TIMESTAMPDIFF return type to BIGINT for MICROSECOND time unit (SqlTimestampDiffFunction.RETURN_TYPE_INFERENCE should be changed).
The main problem - this function is defined in Calcite and hardcoded in the parser (see TimestampDiffFunctionCall in Parser.jj), so it's not so easy to provide our own implementation.