sql-formatter-org / sql-formatter

A whitespace formatter for different query languages
https://sql-formatter-org.github.io/sql-formatter/
MIT License
2.37k stars 405 forks source link

Formatting Error with Temporary Functions #739

Closed dmill166 closed 6 months ago

dmill166 commented 6 months ago

Issue is with use of temporary function in SQL scripts. I illustrate the problem below. You can see that in the formatted result, there is now a space between foo_bar and the left parentheses (. This is no longer treated as a function and the function itself is no longer applied. I also provide a corrected output where after formatting, the temporary function foo_bar has the ( immediately beside it (meaning the function will now be applied).

Which SQL and options did you provide as input?

CREATE TEMPORARY FUNCTION foo_bar AS 'FooBar' USING jar 'hdfs://localhost:9000/user/hive/FooBar.jar';

SELECT    foo_bar ('fwfrgwre12a3') fun_res ;

Expected Output

CREATE TEMPORARY FUNCTION foo_bar AS 'FooBar' USING jar 'hdfs://localhost:9000/user/hive/FooBar.jar';

SELECT
    foo_bar('fwfrgwre12a3') fun_res;

Actual Output

CREATE TEMPORARY FUNCTION foo_bar AS 'FooBar' USING jar 'hdfs://localhost:9000/user/hive/FooBar.jar';

SELECT
    foo_bar ('fwfrgwre12a3') fun_res;

Usage

dmill166 commented 6 months ago

Perusing the README, I did see that there is a successor to this extension, SQL Formatter VS Code (currently on v4.1.1). image

I want to clarify that this issue ALSO exists there (would appreciate a fix in either/both locs :) ).

nene commented 6 months ago

Thanks for reporting.

This is duplicate of #444. It's a known problem with all user-defined functions (not just temporary ones).