Kusto-phase2: fix style

This commit is contained in:
Yong Wang 2023-08-09 07:33:23 -07:00
parent 1c3a3debb4
commit ff9b985490
6 changed files with 18 additions and 17 deletions

View File

@ -154,7 +154,7 @@ bool DayOfWeek::convertImpl(String & out, IParser::Pos & pos)
++pos;
const String datetime_str = getConvertedArgument(fn_name, pos);
out = std::format("concat((toDayOfWeek({})%7)::String , '.00:00:00')", datetime_str);
out = std::format("concat((toDayOfWeek({})%7)::String, '.00:00:00')", datetime_str);
return true;
}
@ -399,7 +399,7 @@ bool FormatTimeSpan::convertImpl(String & out, IParser::Pos & pos)
formatspecifier = formatspecifier + "%i";
else if (arg == "h" || arg == "hh")
{
if (is_hour_zero) //To handle the CH limit for 12hr format(01-12). If not handled , 1.00:00:00 returned as 1.12:00:00(in 12 hr format)
if (is_hour_zero) //To handle the CH limit for 12hr format(01-12). If not handled, 1.00:00:00 returned as 1.12:00:00(in 12 hr format)
formatspecifier = formatspecifier + "%h";
else
formatspecifier = formatspecifier + "%H";
@ -574,7 +574,7 @@ bool MakeTimeSpan::convertImpl(String & out, IParser::Pos & pos)
datetime_str = "0000-00-00 " + datetime_str;
out = std::format(
"CONCAT('{}',toString(SUBSTRING(toString(toTime(parseDateTime64BestEffortOrNull('{}', 9 ,'UTC'))),12)))", day, datetime_str);
"CONCAT('{}',toString(SUBSTRING(toString(toTime(parseDateTime64BestEffortOrNull('{}', 9,'UTC'))),12)))", day, datetime_str);
return true;
}
@ -604,7 +604,7 @@ bool MakeDateTime::convertImpl(String & out, IParser::Pos & pos)
if (arg_count < 7)
{
for (int i = arg_count; i < 7; ++i)
arguments = arguments + "0 ,";
arguments = arguments + "0,";
}
arguments = arguments + "7,'UTC'";
@ -646,7 +646,7 @@ bool StartOfDay::convertImpl(String & out, IParser::Pos & pos)
++pos;
offset = getConvertedArgument(fn_name, pos);
}
out = std::format("date_add(DAY,{}, parseDateTime64BestEffortOrNull(toString((toStartOfDay({}))) , 9 , 'UTC')) ", offset, datetime_str);
out = std::format("date_add(DAY,{}, parseDateTime64BestEffortOrNull(toString((toStartOfDay({}))), 9, 'UTC')) ", offset, datetime_str);
return true;
}
@ -666,7 +666,7 @@ bool StartOfMonth::convertImpl(String & out, IParser::Pos & pos)
offset = getConvertedArgument(fn_name, pos);
}
out = std::format(
"date_add(MONTH,{}, parseDateTime64BestEffortOrNull(toString((toStartOfMonth({}))) , 9 , 'UTC')) ", offset, datetime_str);
"date_add(MONTH,{}, parseDateTime64BestEffortOrNull(toString((toStartOfMonth({}))), 9, 'UTC')) ", offset, datetime_str);
return true;
}
@ -686,7 +686,7 @@ bool StartOfWeek::convertImpl(String & out, IParser::Pos & pos)
offset = getConvertedArgument(fn_name, pos);
}
out = std::format(
"date_add(Week,{}, parseDateTime64BestEffortOrNull(toString((toStartOfWeek({}))) , 9 , 'UTC')) ", offset, datetime_str);
"date_add(Week,{}, parseDateTime64BestEffortOrNull(toString((toStartOfWeek({}))), 9, 'UTC')) ", offset, datetime_str);
return true;
}
@ -706,7 +706,7 @@ bool StartOfYear::convertImpl(String & out, IParser::Pos & pos)
offset = getConvertedArgument(fn_name, pos);
}
out = std::format(
"date_add(YEAR,{}, parseDateTime64BestEffortOrNull(toString((toStartOfYear({}, 'UTC'))) , 9 , 'UTC'))", offset, datetime_str);
"date_add(YEAR,{}, parseDateTime64BestEffortOrNull(toString((toStartOfYear({}, 'UTC'))), 9, 'UTC'))", offset, datetime_str);
return true;
}
@ -762,8 +762,8 @@ bool UnixTimeSecondsToDateTime::convertImpl(String & out, IParser::Pos & pos)
String expression = getConvertedArgument(fn_name, pos);
out = std::format(
" if(toTypeName({0}) = 'Int64' OR toTypeName({0}) = 'Int32'OR toTypeName({0}) = 'Float64' OR toTypeName({0}) = 'UInt32' OR "
"toTypeName({0}) = 'UInt64', toDateTime64({0}, 9, 'UTC') , toDateTime64(throwIf(true, '{1} only accepts Int , Long and double type "
"of arguments'),9,'UTC'))",
"toTypeName({0}) = 'UInt64', toDateTime64({0}, 9, 'UTC'), toDateTime64(throwIf(true, '{1} only accepts Int, Long and double type "
"of arguments'), 9, 'UTC'))",
expression,
fn_name);

View File

@ -294,7 +294,7 @@ bool ExtractJson::convertImpl(String & out, IParser::Pos & pos)
if (datatype == "Decimal")
{
out = std::format("countSubstrings({0}, '.') > 1 ? NULL: length(substr({0}, position({0},'.') + 1)))", json_val);
out = std::format("toDecimal128OrNull({0}::String ,{1})", json_val, out);
out = std::format("toDecimal128OrNull({0}::String, {1})", json_val, out);
}
else
{
@ -563,7 +563,7 @@ bool Split::convertImpl(String & out, IParser::Pos & pos)
requested_index = std::stoi(arg);
requested_index += 1;
out = std::format(
"multiIf(length({0}) >= {1} AND {1} > 0 , arrayPushBack([],arrayElement({0}, {1})) , {1}=0 ,{0} , arrayPushBack([] "
"multiIf(length({0}) >= {1} AND {1} > 0, arrayPushBack([],arrayElement({0}, {1})), {1}=0, {0}, arrayPushBack([] "
",arrayElement(NULL,1)))",
split_res,
requested_index);
@ -712,7 +712,7 @@ bool Translate::convertImpl(String & out, IParser::Pos & pos)
String len_diff = std::format("length({}) - length({})", from, to);
String to_str = std::format(
"multiIf(length({1}) = 0, {0}, {2} > 0, concat({1},repeat(substr({1},length({1}),1),toUInt16({2}))),{2} < 0 , "
"multiIf(length({1}) = 0, {0}, {2} > 0, concat({1},repeat(substr({1},length({1}),1),toUInt16({2}))),{2} < 0, "
"substr({1},1,length({0})),{1})",
from,
to,

View File

@ -52,7 +52,7 @@ INSTANTIATE_TEST_SUITE_P(ParserKQLQuery_Datetime, ParserKQLTest,
},
{
"print unixtime_seconds_todatetime(1546300899)",
"SELECT if((toTypeName(1546300899) = 'Int64') OR (toTypeName(1546300899) = 'Int32') OR (toTypeName(1546300899) = 'Float64') OR (toTypeName(1546300899) = 'UInt32') OR (toTypeName(1546300899) = 'UInt64'), toDateTime64(1546300899, 9, 'UTC'), toDateTime64(throwIf(true, 'unixtime_seconds_todatetime only accepts Int , Long and double type of arguments'), 9, 'UTC'))"
"SELECT if((toTypeName(1546300899) = 'Int64') OR (toTypeName(1546300899) = 'Int32') OR (toTypeName(1546300899) = 'Float64') OR (toTypeName(1546300899) = 'UInt32') OR (toTypeName(1546300899) = 'UInt64'), toDateTime64(1546300899, 9, 'UTC'), toDateTime64(throwIf(true, 'unixtime_seconds_todatetime only accepts Int, Long and double type of arguments'), 9, 'UTC'))"
},
{
"print dayofweek(datetime(2015-12-20))",

View File

@ -606,7 +606,7 @@ INSTANTIATE_TEST_SUITE_P(ParserKQLQuery, ParserKQLTest,
"SELECT\n * EXCEPT duration,\n endTime - startTime AS duration\nFROM\n(\n SELECT\n endTime,\n startTime\n FROM T\n)"
},
{
"T | extend c =c*2, b-a, d = a +b , a*b",
"T | extend c =c*2, b-a, d = a + b, a*b",
"SELECT\n * EXCEPT c EXCEPT d,\n c * 2 AS c,\n b - a AS Column1,\n a + b AS d,\n a * b AS Column2\nFROM T"
}
})));

View File

@ -1,3 +1,5 @@
#pragma once
#include <Parsers/IParser.h>
#include <gtest/gtest.h>

View File

@ -15,8 +15,7 @@ AND name NOT IN (
'h3ToGeoBoundary', 'h3ToParent', 'h3ToString', 'h3UnidirectionalEdgeIsValid', 'h3kRing', 'stringToH3',
'geoToS2', 's2CapContains', 's2CapUnion', 's2CellsIntersect', 's2GetNeighbors', 's2RectAdd', 's2RectContains', 's2RectIntersection', 's2RectUnion', 's2ToGeo',
'normalizeUTF8NFC', 'normalizeUTF8NFD', 'normalizeUTF8NFKC', 'normalizeUTF8NFKD',
'lemmatize', 'tokenize', 'stem', 'synonyms',
'lemmatize', 'tokenize', 'stem', 'synonyms', 'kql_array_sort_asc', 'kql_array_sort_desc',
'detectCharset', 'detectLanguageUnknown', 'detectProgrammingLanguage', 'detectTonality'
-- these functions are not enabled in fast test
'lemmatize', 'tokenize', 'stem', 'synonyms', 'kql_array_sort_asc', 'kql_array_sort_desc' -- these functions are not enabled in fast test
) ORDER BY name;