Unexpected warning when using the SQL TRIM function with less than 4 parameters

Description

The ANSI SQL TRIM function is defined as:

1 TRIM([LEADING | TRAILING | BOTH] [char] FROM [expression])

However, the first three arguments to the function are optional. Therefore, all the following calls to this function are valid:

1 2 3 4 5 6 7 TRIM( ' A sample text message. ') TRIM(LEADING FROM ' A sample text message. ') TRIM(TRAILING FROM ' A sample text message. ') TRIM(BOTH FROM ' A sample text message. ') TRIM(LEADING ' ' FROM ' A sample text message. ') TRIM(TRAILING ' FROM ' A sample text message. ') TRIM(BOTH ' ' FROM ' A sample text message. ')

However, any time this function is called from HQL with less than the maximum allowed of 4 parameters, the following warning message is seen in the logs, generated from the class org.hibernate.dialect.function.TemplateRenderer:

1 HHH000174: Function template anticipated 4 arguments, but <n> arguments encountered

For example, the following Spring Data JPA repository method (which generates an HQL query) leads to this error:

1 2 3 4 public interface TopicRepository extends JpaRepository<Topic, Long> { @Query("SELECT topic FROM Topic topic WHERE TRIM(topic.name) = TRIM(?1)") Topic findByName(String name); }

This warning message has no impact on the actual execution of the code, which works as expected. However, WARN log level seems excessive for this case. The following portion of the code generates the warning:

1 2 3 4 5 6 7 public String render(List args, SessionFactoryImplementor factory) { final int numberOfArguments = args.size(); if ( getAnticipatedNumberOfArguments() > 0 && numberOfArguments != getAnticipatedNumberOfArguments() ) { LOG.missingArguments( getAnticipatedNumberOfArguments(), numberOfArguments ); } ... }

At the very least, the severity level for this message should be changed to INFO. A proper check should know the minimum and maximum number of mandatory arguments allowed for the SQL function and compare the supplied number of arguments with this range. If the number of arguments is outside this range, the method must halt the operation by throwing an exception, instead of just logging a message and continuing.

Have attached a Maven project as a sample. Just run the test cases to see the aforementioned warning message being displayed.

Environment

Any OS

Status

Assignee

Unassigned

Reporter

Manish J

Fix versions

None

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

4.3.10
4.2.20
4.3.8
4.3.9
5.1.0

Priority

Minor