@@ -118,7 +118,7 @@ CONV_FN(ExprColAlias, eca)
118118 }
119119}
120120
121- void convertToSQLString (String & ret, const String & s)
121+ static void convertToSQLString (String & ret, const String & s)
122122{
123123 for (size_t i = 0 ; i < s.length (); i++)
124124 {
@@ -704,7 +704,7 @@ CONV_FN(EnumDefValue, edf)
704704 ret += std::to_string (edf.number ());
705705}
706706
707- void BottomTypeNameToString (String & ret, const uint32_t quote, const bool lcard, const BottomTypeName & btn)
707+ static void BottomTypeNameToString (String & ret, const uint32_t quote, const bool lcard, const BottomTypeName & btn)
708708{
709709 using BottomTypeNameType = BottomTypeName::BottomOneOfCase;
710710 switch (btn.bottom_one_of_case ())
@@ -1790,7 +1790,7 @@ CONV_FN(GenerateSeriesFunc, gsf)
17901790
17911791CONV_FN (TableFunction, tf);
17921792
1793- void TableOrFunctionToString (String & ret, const bool tudf, const TableOrFunction & tof)
1793+ static void TableOrFunctionToString (String & ret, const bool tudf, const TableOrFunction & tof)
17941794{
17951795 using TableOrFunctionType = TableOrFunction::JtfOneofCase;
17961796 switch (tof.jtf_oneof_case ())
@@ -2001,6 +2001,45 @@ CONV_FN(MergeTreeIndexFunc, mfunc)
20012001 ret += " )" ;
20022002}
20032003
2004+ CONV_FN (GenerateRandomFunc, grfunc)
2005+ {
2006+ ret += " generateRandom('" ;
2007+ ret += grfunc.structure ();
2008+ ret += " '" ;
2009+ if (grfunc.has_random_seed ())
2010+ {
2011+ ret += " , " ;
2012+ ret += std::to_string (grfunc.random_seed ());
2013+ }
2014+ if (grfunc.has_max_string_length ())
2015+ {
2016+ ret += " , " ;
2017+ ret += std::to_string (grfunc.max_string_length ());
2018+ }
2019+ if (grfunc.has_max_array_length ())
2020+ {
2021+ ret += " , " ;
2022+ ret += std::to_string (grfunc.max_array_length ());
2023+ }
2024+ ret += " )" ;
2025+ }
2026+
2027+ static void ValuesStatementToString (String & ret, const bool tudf, const ValuesStatement & values)
2028+ {
2029+ ret += " VALUES " ;
2030+ ret += tudf ? " (" : " " ;
2031+ ret += " (" ;
2032+ ExprListToString (ret, values.expr_list ());
2033+ ret += " )" ;
2034+ for (int i = 0 ; i < values.extra_expr_lists_size (); i++)
2035+ {
2036+ ret += " , (" ;
2037+ ExprListToString (ret, values.extra_expr_lists (i));
2038+ ret += " )" ;
2039+ }
2040+ ret += tudf ? " )" : " " ;
2041+ }
2042+
20042043CONV_FN (TableFunction, tf)
20052044{
20062045 using TableFunctionType = TableFunction::JtfOneofCase;
@@ -2047,6 +2086,12 @@ CONV_FN(TableFunction, tf)
20472086 TableOrFunctionToString (ret, true , tf.loop ());
20482087 ret += " )" ;
20492088 break ;
2089+ case TableFunctionType::kGrandom :
2090+ GenerateRandomFuncToString (ret, tf.grandom ());
2091+ break ;
2092+ case TableFunctionType::kValues :
2093+ ValuesStatementToString (ret, true , tf.values ());
2094+ break ;
20502095 default :
20512096 ret += " numbers(10)" ;
20522097 }
@@ -3016,71 +3061,9 @@ CONV_FN(Drop, dt)
30163061 }
30173062}
30183063
3019- CONV_FN (ValuesStatement, values)
3020- {
3021- if (values.has_setting_values ())
3022- {
3023- ret += " SETTINGS " ;
3024- SettingValuesToString (ret, values.setting_values ());
3025- ret += " " ;
3026- }
3027- ret += " VALUES (" ;
3028- ExprListToString (ret, values.expr_list ());
3029- ret += " )" ;
3030- for (int i = 0 ; i < values.extra_expr_lists_size (); i++)
3031- {
3032- ret += " , (" ;
3033- ExprListToString (ret, values.extra_expr_lists (i));
3034- ret += " )" ;
3035- }
3036- }
3037-
3038- CONV_FN (InsertFromFile, insert_file)
3039- {
3040- ret += " FROM INFILE '" ;
3041- ret += insert_file.path ();
3042- ret += " '" ;
3043- if (insert_file.has_fcomp ())
3044- {
3045- ret += " COMPRESSION '" ;
3046- ret += FileCompression_Name (insert_file.fcomp ()).substr (4 );
3047- ret += " '" ;
3048- }
3049- if (insert_file.has_settings ())
3050- {
3051- ret += " SETTINGS " ;
3052- SettingValuesToString (ret, insert_file.settings ());
3053- }
3054- ret += " FORMAT " ;
3055- ret += InFormat_Name (insert_file.format ()).substr (3 );
3056- }
3057-
3058- CONV_FN (InsertSelect, insert_sel)
3059- {
3060- if (insert_sel.has_setting_values ())
3061- {
3062- ret += " SETTINGS " ;
3063- SettingValuesToString (ret, insert_sel.setting_values ());
3064- ret += " " ;
3065- }
3066- SelectToString (ret, insert_sel.select ());
3067- }
3068-
3069- CONV_FN (InsertStringQuery, insert_query)
3070- {
3071- if (insert_query.has_setting_values ())
3072- {
3073- ret += " SETTINGS " ;
3074- SettingValuesToString (ret, insert_query.setting_values ());
3075- ret += " " ;
3076- }
3077- ret += " VALUES " ;
3078- ret += insert_query.query ();
3079- }
3080-
30813064CONV_FN (Insert, insert)
30823065{
3083- if (insert.has_ctes () && insert.has_est () && insert.has_insert_select ())
3066+ if (insert.has_ctes () && insert.has_est () && insert.has_select ())
30843067 {
30853068 CTEsToString (ret, insert.ctes ());
30863069 }
@@ -3108,21 +3091,45 @@ CONV_FN(Insert, insert)
31083091 ret += " )" ;
31093092 }
31103093 ret += " " ;
3094+ if (!insert.has_insert_file () && insert.has_setting_values ())
3095+ {
3096+ ret += " SETTINGS " ;
3097+ SettingValuesToString (ret, insert.setting_values ());
3098+ ret += " " ;
3099+ }
31113100 if (insert.has_values ())
31123101 {
3113- ValuesStatementToString (ret, insert.values ());
3102+ ValuesStatementToString (ret, false , insert.values ());
31143103 }
3115- else if (insert.has_insert_select ())
3104+ else if (insert.has_select ())
31163105 {
3117- InsertSelectToString (ret, insert.insert_select ());
3106+ SelectToString (ret, insert.select ());
31183107 }
31193108 else if (insert.has_insert_file ())
31203109 {
3121- InsertFromFileToString (ret, insert.insert_file ());
3110+ const InsertFromFile & insert_file = insert.insert_file ();
3111+
3112+ ret += " FROM INFILE '" ;
3113+ ret += insert_file.path ();
3114+ ret += " '" ;
3115+ if (insert_file.has_fcomp ())
3116+ {
3117+ ret += " COMPRESSION '" ;
3118+ ret += FileCompression_Name (insert_file.fcomp ()).substr (4 );
3119+ ret += " '" ;
3120+ }
3121+ if (insert.has_setting_values ())
3122+ {
3123+ ret += " SETTINGS " ;
3124+ SettingValuesToString (ret, insert.setting_values ());
3125+ }
3126+ ret += " FORMAT " ;
3127+ ret += InFormat_Name (insert_file.format ()).substr (3 );
31223128 }
31233129 else if (insert.has_query ())
31243130 {
3125- InsertStringQueryToString (ret, insert.query ());
3131+ ret += " VALUES " ;
3132+ ret += insert.query ();
31263133 }
31273134 else
31283135 {
@@ -3276,7 +3283,7 @@ CONV_FN(DeduplicateExpr, de)
32763283 if (de.has_col_list ())
32773284 {
32783285 ret += " BY " ;
3279- ExprColumnListToString (ret, de.col_list ());
3286+ ColumnPathListToString (ret, 0 , de.col_list ());
32803287 }
32813288 else if (de.has_ded_star ())
32823289 {
@@ -3285,7 +3292,7 @@ CONV_FN(DeduplicateExpr, de)
32853292 else if (de.has_ded_star_except ())
32863293 {
32873294 ret += " BY * EXCEPT (" ;
3288- ExprColumnListToString (ret, de.ded_star_except ());
3295+ ColumnPathListToString (ret, 0 , de.ded_star_except ());
32893296 ret += " )" ;
32903297 }
32913298}
0 commit comments