@@ -254,7 +254,7 @@ void StatementGenerator::setTableRemote(
254254 first = false ;
255255 }
256256 this ->remote_entries .clear ();
257- sfunc->set_structure ( buf);
257+ sfunc->mutable_structure ()-> mutable_lit_val ()-> set_string_lit ( std::move ( buf) );
258258 if (!t.file_comp .empty ())
259259 {
260260 sfunc->set_fcomp (t.file_comp );
@@ -319,6 +319,72 @@ auto StatementGenerator::getQueryTableLambda()
319319 };
320320}
321321
322+ void StatementGenerator::addRandomRelation (RandomGenerator & rg, const std::optional<String> rel_name, const uint32_t ncols, Expr * expr)
323+ {
324+ if (rg.nextBool ())
325+ {
326+ // / Use generateRandomStructure function
327+ SQLFuncCall * sfc = expr->mutable_comp_expr ()->mutable_func_call ();
328+ sfc->mutable_func ()->set_catalog_func (FUNCgenerateRandomStructure);
329+
330+ // / Number of columns parameter
331+ sfc->add_args ()->mutable_expr ()->mutable_lit_val ()->mutable_int_lit ()->set_uint_lit (static_cast <uint64_t >(ncols));
332+ // / Seed parameter
333+ sfc->add_args ()->mutable_expr ()->mutable_lit_val ()->mutable_int_lit ()->set_uint_lit (rg.nextRandomUInt64 ());
334+ if (rel_name.has_value ())
335+ {
336+ SQLRelation rel (rel_name.value ());
337+
338+ for (uint32_t i = 0 ; i < ncols; i++)
339+ {
340+ rel.cols .emplace_back (SQLRelationCol (rel_name.value (), {" c" + std::to_string (i + 1 )}));
341+ }
342+ this ->levels [this ->current_level ].rels .emplace_back (rel);
343+ }
344+ }
345+ else
346+ {
347+ // / Use BuzzHouse approach
348+ String buf;
349+ bool first = true ;
350+ uint32_t col_counter = 0 ;
351+ const uint32_t type_mask_backup = this ->next_type_mask ;
352+ std::unordered_map<uint32_t , std::unique_ptr<SQLType>> centries;
353+
354+ this ->next_type_mask = fc.type_mask ;
355+ for (uint32_t i = 0 ; i < ncols; i++)
356+ {
357+ const uint32_t ncame = col_counter++;
358+ auto tp = std::unique_ptr<SQLType>(randomNextType (rg, this ->next_type_mask , col_counter, nullptr ));
359+
360+ buf += fmt::format (" {}c{} {}" , first ? " " : " , " , ncame, tp->typeName (false ));
361+ first = false ;
362+ centries[ncame] = std::move (tp);
363+ }
364+ this ->next_type_mask = type_mask_backup;
365+ expr->mutable_lit_val ()->set_string_lit (std::move (buf));
366+ if (rel_name.has_value ())
367+ {
368+ SQLRelation rel (rel_name.value ());
369+
370+ flatColumnPath (flat_tuple | flat_nested | flat_json | to_table_entries | collect_generated, centries);
371+ for (const auto & entry : this ->table_entries )
372+ {
373+ DB::Strings names;
374+
375+ names.reserve (entry.path .size ());
376+ for (const auto & path : entry.path )
377+ {
378+ names.push_back (path.cname );
379+ }
380+ rel.cols .emplace_back (SQLRelationCol (rel_name.value (), std::move (names)));
381+ }
382+ this ->table_entries .clear ();
383+ this ->levels [this ->current_level ].rels .emplace_back (rel);
384+ }
385+ }
386+ }
387+
322388bool StatementGenerator::joinedTableOrFunction (
323389 RandomGenerator & rg, const String & rel_name, const uint32_t allowed_clauses, const bool under_remote, TableOrFunction * tof)
324390{
@@ -743,66 +809,15 @@ bool StatementGenerator::joinedTableOrFunction(
743809 < (derived_table + cte + table + view + remote_udf + generate_series_udf + system_table + merge_udf + cluster_udf
744810 + merge_index_udf + loop_udf + values_udf + random_data_udf + 1 ))
745811 {
746- SQLRelation rel (rel_name);
747- const uint32_t ncols = (rg.nextSmallNumber () < 8 ) ? rg.nextSmallNumber () : rg.nextMediumNumber ();
748812 GenerateRandomFunc * grf = tof->mutable_tfunc ()->mutable_grandom ();
749813 std::uniform_int_distribution<uint64_t > string_length_dist (1 , 8192 );
750814 std::uniform_int_distribution<uint64_t > nested_rows_dist (fc.min_nested_rows , fc.max_nested_rows );
751815
752- if (rg.nextBool ())
753- {
754- // / Use generateRandomStructure function
755- SQLFuncCall * sfc = grf->mutable_structure ()->mutable_comp_expr ()->mutable_func_call ();
756- sfc->mutable_func ()->set_catalog_func (FUNCgenerateRandomStructure);
757-
758- // / Number of columns parameter
759- sfc->add_args ()->mutable_expr ()->mutable_lit_val ()->mutable_int_lit ()->set_uint_lit (static_cast <uint64_t >(ncols));
760- // / Seed parameter
761- sfc->add_args ()->mutable_expr ()->mutable_lit_val ()->mutable_int_lit ()->set_uint_lit (rg.nextRandomUInt64 ());
762- for (uint32_t i = 0 ; i < ncols; i++)
763- {
764- rel.cols .emplace_back (SQLRelationCol (rel_name, {" c" + std::to_string (i + 1 )}));
765- }
766- }
767- else
768- {
769- // / Use BuzzHouse approach
770- String buf;
771- bool first = true ;
772- uint32_t col_counter = 0 ;
773- const uint32_t type_mask_backup = this ->next_type_mask ;
774- std::unordered_map<uint32_t , std::unique_ptr<SQLType>> centries;
775-
776- this ->next_type_mask = fc.type_mask ;
777- for (uint32_t i = 0 ; i < ncols; i++)
778- {
779- const uint32_t ncame = col_counter++;
780- auto tp = std::unique_ptr<SQLType>(randomNextType (rg, this ->next_type_mask , col_counter, nullptr ));
781-
782- buf += fmt::format (" {}c{} {}" , first ? " " : " , " , ncame, tp->typeName (false ));
783- first = false ;
784- centries[ncame] = std::move (tp);
785- }
786- this ->next_type_mask = type_mask_backup;
787- grf->mutable_structure ()->mutable_lit_val ()->set_string_lit (std::move (buf));
788- flatColumnPath (flat_tuple | flat_nested | flat_json | to_table_entries | collect_generated, centries);
789- for (const auto & entry : this ->table_entries )
790- {
791- DB::Strings names;
792-
793- names.reserve (entry.path .size ());
794- for (const auto & path : entry.path )
795- {
796- names.push_back (path.cname );
797- }
798- rel.cols .emplace_back (SQLRelationCol (rel_name, std::move (names)));
799- }
800- this ->table_entries .clear ();
801- }
816+ addRandomRelation (
817+ rg, rel_name, (rg.nextSmallNumber () < 8 ) ? rg.nextSmallNumber () : rg.nextMediumNumber (), grf->mutable_structure ());
802818 grf->set_random_seed (rg.nextRandomUInt64 ());
803819 grf->set_max_string_length (string_length_dist (rg.generator ));
804820 grf->set_max_array_length (nested_rows_dist (rg.generator ));
805- this ->levels [this ->current_level ].rels .emplace_back (rel);
806821 }
807822 else if (
808823 dictionary
0 commit comments