From 56bd61d20712e39a913d2639be42b2114f0af2dd Mon Sep 17 00:00:00 2001 From: Salvatore Mesoraca Date: Thu, 26 Oct 2023 13:09:20 +0200 Subject: [PATCH] Rename formatQueryOneLine -> formatQuerySingleLine --- .../functions/other-functions.md | 12 +++++----- src/Functions/formatQuery.cpp | 12 +++++----- .../0_stateless/02882_formatQuery.reference | 2 +- .../queries/0_stateless/02882_formatQuery.sql | 22 +++++++++---------- .../aspell-ignore/en/aspell-dict.txt | 2 +- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/docs/en/sql-reference/functions/other-functions.md b/docs/en/sql-reference/functions/other-functions.md index 2e52d067b45..d7809be86bf 100644 --- a/docs/en/sql-reference/functions/other-functions.md +++ b/docs/en/sql-reference/functions/other-functions.md @@ -2831,14 +2831,14 @@ WHERE (a > 3) AND (b < 3) │ └───────────────────────────────────────────────────────────────┘ ``` -## formatQueryOneLine +## formatQuerySingleLine Like formatQuery() but the returned formatted string contains no line breaks. **Syntax** ```sql -formatQueryOneLine(query) +formatQuerySingleLine(query) ``` **Arguments** @@ -2852,13 +2852,13 @@ formatQueryOneLine(query) **Example** ```sql -SELECT formatQueryOneLine('select 1;'); +SELECT formatQuerySingleLine('select a, b FRom tab WHERE a > 3 and b < 3'); ``` Result: ```result -┌─formatQueryOneLine('select a, b FRom tab WHERE a > 3 and b < 3')─┐ -│ SELECT a, b FROM tab WHERE (a > 3) AND (b < 3) │ -└──────────────────────────────────────────────────────────────────────┘ +┌─formatQuerySingleLine('select a, b FRom tab WHERE a > 3 and b < 3')─┐ +│ SELECT a, b FROM tab WHERE (a > 3) AND (b < 3) │ +└─────────────────────────────────────────────────────────────────────────┘ ``` diff --git a/src/Functions/formatQuery.cpp b/src/Functions/formatQuery.cpp index ca853a155b5..f4cb937eed4 100644 --- a/src/Functions/formatQuery.cpp +++ b/src/Functions/formatQuery.cpp @@ -98,9 +98,9 @@ struct NameFormatQuery static constexpr auto name = "formatQuery"; }; -struct NameFormatQueryOneLine +struct NameFormatQuerySingleLine { - static constexpr auto name = "formatQueryOneLine"; + static constexpr auto name = "formatQuerySingleLine"; }; REGISTER_FUNCTION(formatQuery) @@ -121,16 +121,16 @@ REGISTER_FUNCTION(formatQuery) .categories{"Other"}}); } -REGISTER_FUNCTION(formatQueryOneLine) +REGISTER_FUNCTION(formatQuerySingleLine) { - factory.registerFunction>(FunctionDocumentation{ + factory.registerFunction>(FunctionDocumentation{ .description = "Like formatQuery() but the returned formatted string contains no line breaks.\n[example:multiline]", - .syntax = "formatQueryOneLine(query)", + .syntax = "formatQuerySingleLine(query)", .arguments = {{"query", "The SQL query to be formatted. [String](../../sql-reference/data-types/string.md)"}}, .returned_value = "The formatted query. [String](../../sql-reference/data-types/string.md).", .examples{ {"multiline", - "SELECT formatQuery('select a, b FRom tab WHERE a > 3 and b < 3');", + "SELECT formatQuerySingleLine('select a, b FRom tab WHERE a > 3 and b < 3');", "SELECT a, b FROM tab WHERE (a > 3) AND (b < 3)"}}, .categories{"Other"}}); } diff --git a/tests/queries/0_stateless/02882_formatQuery.reference b/tests/queries/0_stateless/02882_formatQuery.reference index a7bd2dbe822..fd84a9505b1 100644 --- a/tests/queries/0_stateless/02882_formatQuery.reference +++ b/tests/queries/0_stateless/02882_formatQuery.reference @@ -7,7 +7,7 @@ INSERT INTO tab FORMAT Values CREATE TABLE default.no_prop_table\n(\n `some_column` UInt64\n)\nENGINE = MergeTree\nORDER BY tuple()\nSETTINGS index_granularity = 8192 EXPLAIN SYNTAX\nSELECT\n CAST(1, \'INT\'),\n CEIL(1),\n CEILING(1),\n CHAR(49),\n CHAR_LENGTH(\'1\'),\n CHARACTER_LENGTH(\'1\'),\n COALESCE(1),\n CONCAT(\'1\', \'1\'),\n CORR(1, 1),\n COS(1),\n COUNT(1),\n COVAR_POP(1, 1),\n COVAR_SAMP(1, 1),\n DATABASE(),\n SCHEMA(),\n dateDiff(\'DAY\', toDate(\'2020-10-24\'), toDate(\'2019-10-24\')),\n EXP(1),\n FLATTEN([[1]]),\n FLOOR(1),\n FQDN(),\n GREATEST(1),\n IF(1, 1, 1),\n IFNULL(1, 1),\n LCASE(\'A\'),\n LEAST(1),\n LENGTH(\'1\'),\n LN(1),\n LOCATE(\'1\', \'1\'),\n LOG(1),\n LOG10(1),\n LOG2(1),\n LOWER(\'A\'),\n MAX(1),\n MID(\'123\', 1, 1),\n MIN(1),\n MOD(1, 1),\n NOT 1,\n NOW(),\n NOW64(),\n NULLIF(1, 1),\n PI(),\n position(\'123\', \'2\'),\n POW(1, 1),\n POWER(1, 1),\n RAND(),\n REPLACE(\'1\', \'1\', \'2\'),\n REVERSE(\'123\'),\n ROUND(1),\n SIN(1),\n SQRT(1),\n STDDEV_POP(1),\n STDDEV_SAMP(1),\n SUBSTR(\'123\', 2),\n substring(\'123\', 2),\n SUM(1),\n TAN(1),\n TANH(1),\n TRUNC(1),\n TRUNCATE(1),\n UCASE(\'A\'),\n UPPER(\'A\'),\n USER(),\n VAR_POP(1),\n VAR_SAMP(1),\n WEEK(toDate(\'2020-10-24\')),\n YEARWEEK(toDate(\'2020-10-24\'))\nFORMAT TSVRaw 1 -formatQueryOneLine +formatQuerySingleLine SELECT 1 SELECT 1 SELECT 1 diff --git a/tests/queries/0_stateless/02882_formatQuery.sql b/tests/queries/0_stateless/02882_formatQuery.sql index 9edb07cb0e3..767283552d5 100644 --- a/tests/queries/0_stateless/02882_formatQuery.sql +++ b/tests/queries/0_stateless/02882_formatQuery.sql @@ -8,14 +8,14 @@ SELECT formatQuery('CREATE TABLE default.no_prop_table(`some_column` UInt64) ENG SELECT formatQuery('EXPLAIN SYNTAX SELECT CAST(1 AS INT), CEIL(1), CEILING(1), CHAR(49), CHAR_LENGTH(\'1\'), CHARACTER_LENGTH(\'1\'), COALESCE(1), CONCAT(\'1\', \'1\'), CORR(1, 1), COS(1), COUNT(1), COVAR_POP(1, 1), COVAR_SAMP(1, 1), DATABASE(), SCHEMA(), DATEDIFF(\'DAY\', toDate(\'2020-10-24\'), toDate(\'2019-10-24\')), EXP(1), FLATTEN([[1]]), FLOOR(1), FQDN(), GREATEST(1), IF(1, 1, 1), IFNULL(1, 1), LCASE(\'A\'), LEAST(1), LENGTH(\'1\'), LN(1), LOCATE(\'1\', \'1\'), LOG(1), LOG10(1), LOG2(1), LOWER(\'A\'), MAX(1), MID(\'123\', 1, 1), MIN(1), MOD(1, 1), NOT(1), NOW(), NOW64(), NULLIF(1, 1), PI(), POSITION(\'123\', \'2\'), POW(1, 1), POWER(1, 1), RAND(), REPLACE(\'1\', \'1\', \'2\'), REVERSE(\'123\'), ROUND(1), SIN(1), SQRT(1), STDDEV_POP(1), STDDEV_SAMP(1), SUBSTR(\'123\', 2), SUBSTRING(\'123\', 2), SUM(1), TAN(1), TANH(1), TRUNC(1), TRUNCATE(1), UCASE(\'A\'), UPPER(\'A\'), USER(), VAR_POP(1), VAR_SAMP(1), WEEK(toDate(\'2020-10-24\')), YEARWEEK(toDate(\'2020-10-24\')) format TSVRaw;'); SELECT normalizedQueryHash(formatQuery('select 1')) = normalizedQueryHash(formatQuery('SELECT 1')); SELECT formatQuery('SEECTwrong'); -- { serverError SYNTAX_ERROR } -SELECT 'formatQueryOneLine'; -SELECT formatQueryOneLine('select 1;'); -SELECT formatQueryOneLine('select 1'); -SELECT formatQueryOneLine('SELECT 1;'); -SELECT formatQueryOneLine('SELECT 1'); -SELECT formatQueryOneLine('select 1;') == formatQueryOneLine('SeLecT 1'); -SELECT formatQueryOneLine('INSERT INTO tab VALUES (\'\') (\'test\')'); -SELECT formatQueryOneLine('CREATE TABLE default.no_prop_table(`some_column` UInt64) ENGINE = MergeTree ORDER BY tuple() SETTINGS index_granularity = 8192'); -SELECT formatQueryOneLine('EXPLAIN SYNTAX SELECT CAST(1 AS INT), CEIL(1), CEILING(1), CHAR(49), CHAR_LENGTH(\'1\'), CHARACTER_LENGTH(\'1\'), COALESCE(1), CONCAT(\'1\', \'1\'), CORR(1, 1), COS(1), COUNT(1), COVAR_POP(1, 1), COVAR_SAMP(1, 1), DATABASE(), SCHEMA(), DATEDIFF(\'DAY\', toDate(\'2020-10-24\'), toDate(\'2019-10-24\')), EXP(1), FLATTEN([[1]]), FLOOR(1), FQDN(), GREATEST(1), IF(1, 1, 1), IFNULL(1, 1), LCASE(\'A\'), LEAST(1), LENGTH(\'1\'), LN(1), LOCATE(\'1\', \'1\'), LOG(1), LOG10(1), LOG2(1), LOWER(\'A\'), MAX(1), MID(\'123\', 1, 1), MIN(1), MOD(1, 1), NOT(1), NOW(), NOW64(), NULLIF(1, 1), PI(), POSITION(\'123\', \'2\'), POW(1, 1), POWER(1, 1), RAND(), REPLACE(\'1\', \'1\', \'2\'), REVERSE(\'123\'), ROUND(1), SIN(1), SQRT(1), STDDEV_POP(1), STDDEV_SAMP(1), SUBSTR(\'123\', 2), SUBSTRING(\'123\', 2), SUM(1), TAN(1), TANH(1), TRUNC(1), TRUNCATE(1), UCASE(\'A\'), UPPER(\'A\'), USER(), VAR_POP(1), VAR_SAMP(1), WEEK(toDate(\'2020-10-24\')), YEARWEEK(toDate(\'2020-10-24\')) format TSVRaw;'); -SELECT normalizedQueryHash(formatQueryOneLine('select 1')) = normalizedQueryHash(formatQueryOneLine('SELECT 1')); -SELECT formatQueryOneLine('SEECTwrong'); -- { serverError SYNTAX_ERROR } +SELECT 'formatQuerySingleLine'; +SELECT formatQuerySingleLine('select 1;'); +SELECT formatQuerySingleLine('select 1'); +SELECT formatQuerySingleLine('SELECT 1;'); +SELECT formatQuerySingleLine('SELECT 1'); +SELECT formatQuerySingleLine('select 1;') == formatQuerySingleLine('SeLecT 1'); +SELECT formatQuerySingleLine('INSERT INTO tab VALUES (\'\') (\'test\')'); +SELECT formatQuerySingleLine('CREATE TABLE default.no_prop_table(`some_column` UInt64) ENGINE = MergeTree ORDER BY tuple() SETTINGS index_granularity = 8192'); +SELECT formatQuerySingleLine('EXPLAIN SYNTAX SELECT CAST(1 AS INT), CEIL(1), CEILING(1), CHAR(49), CHAR_LENGTH(\'1\'), CHARACTER_LENGTH(\'1\'), COALESCE(1), CONCAT(\'1\', \'1\'), CORR(1, 1), COS(1), COUNT(1), COVAR_POP(1, 1), COVAR_SAMP(1, 1), DATABASE(), SCHEMA(), DATEDIFF(\'DAY\', toDate(\'2020-10-24\'), toDate(\'2019-10-24\')), EXP(1), FLATTEN([[1]]), FLOOR(1), FQDN(), GREATEST(1), IF(1, 1, 1), IFNULL(1, 1), LCASE(\'A\'), LEAST(1), LENGTH(\'1\'), LN(1), LOCATE(\'1\', \'1\'), LOG(1), LOG10(1), LOG2(1), LOWER(\'A\'), MAX(1), MID(\'123\', 1, 1), MIN(1), MOD(1, 1), NOT(1), NOW(), NOW64(), NULLIF(1, 1), PI(), POSITION(\'123\', \'2\'), POW(1, 1), POWER(1, 1), RAND(), REPLACE(\'1\', \'1\', \'2\'), REVERSE(\'123\'), ROUND(1), SIN(1), SQRT(1), STDDEV_POP(1), STDDEV_SAMP(1), SUBSTR(\'123\', 2), SUBSTRING(\'123\', 2), SUM(1), TAN(1), TANH(1), TRUNC(1), TRUNCATE(1), UCASE(\'A\'), UPPER(\'A\'), USER(), VAR_POP(1), VAR_SAMP(1), WEEK(toDate(\'2020-10-24\')), YEARWEEK(toDate(\'2020-10-24\')) format TSVRaw;'); +SELECT normalizedQueryHash(formatQuerySingleLine('select 1')) = normalizedQueryHash(formatQuerySingleLine('SELECT 1')); +SELECT formatQuerySingleLine('SEECTwrong'); -- { serverError SYNTAX_ERROR } diff --git a/utils/check-style/aspell-ignore/en/aspell-dict.txt b/utils/check-style/aspell-ignore/en/aspell-dict.txt index edafd4e7a55..b506794b5cf 100644 --- a/utils/check-style/aspell-ignore/en/aspell-dict.txt +++ b/utils/check-style/aspell-ignore/en/aspell-dict.txt @@ -1477,7 +1477,7 @@ formatDateTime formatDateTimeInJoda formatDateTimeInJodaSyntax formatQuery -formatQueryOneLine +formatQuerySingleLine formatReadableDecimalSize formatReadableQuantity formatReadableSize