| 2144 | } |
| 2145 | |
| 2146 | std::unique_ptr<SQLType> |
| 2147 | StatementGenerator::randomNextType(RandomGenerator & rg, const uint64_t allowed_types, uint32_t & col_counter, TopTypeName * tp) |
| 2148 | { |
| 2149 | const uint32_t non_nullable_type = 70; |
| 2150 | const uint32_t nullable_type = 35 * static_cast<uint32_t>((allowed_types & allow_nullable) != 0); |
| 2151 | const uint32_t array_type = 10 * static_cast<uint32_t>((allowed_types & allow_array) != 0 && this->depth < this->fc.max_depth); |
| 2152 | const uint32_t map_type = 10 |
| 2153 | * static_cast<uint32_t>((allowed_types & allow_map) != 0 && this->depth < this->fc.max_depth && this->width < this->fc.max_width); |
| 2154 | const uint32_t tuple_type = 10 * static_cast<uint32_t>((allowed_types & allow_tuple) != 0 && this->depth < this->fc.max_depth); |
| 2155 | const uint32_t variant_type = 10 * static_cast<uint32_t>((allowed_types & allow_variant) != 0 && this->depth < this->fc.max_depth); |
| 2156 | const uint32_t nested_type = 10 |
| 2157 | * static_cast<uint32_t>((allowed_types & allow_nested) != 0 && this->depth < this->fc.max_depth |
| 2158 | && this->width < this->fc.max_width); |
| 2159 | std::unique_ptr<SQLType> result; |
| 2160 | |
| 2161 | rg.pickWeighted( |
| 2162 | {{non_nullable_type, |
| 2163 | [&] |
| 2164 | { |
| 2165 | /// Non nullable |
| 2166 | const bool lcard = (allowed_types & allow_low_cardinality) != 0 && rg.nextMediumNumber() < 18; |
| 2167 | auto res = bottomType( |
| 2168 | rg, allowed_types, lcard, tp ? (lcard ? tp->mutable_non_nullable_lcard() : tp->mutable_non_nullable()) : nullptr); |
| 2169 | result = lcard ? std::make_unique<LowCardinality>(std::move(res)) : std::move(res); |
| 2170 | }}, |
| 2171 | {nullable_type, |
| 2172 | [&] |
| 2173 | { |
| 2174 | /// Nullable |
| 2175 | const bool lcard = (allowed_types & allow_low_cardinality) != 0 && rg.nextMediumNumber() < 18; |
| 2176 | std::unique_ptr<SQLType> res = std::make_unique<Nullable>(bottomType( |
| 2177 | rg, |
| 2178 | allowed_types & ~(allow_dynamic | allow_aggregate), |
| 2179 | lcard, |
| 2180 | tp ? (lcard ? tp->mutable_nullable_lcard() : tp->mutable_nullable()) : nullptr)); |
| 2181 | result = lcard ? std::make_unique<LowCardinality>(std::move(res)) : std::move(res); |
| 2182 | }}, |
| 2183 | {array_type, |
| 2184 | [&] |
| 2185 | { |
| 2186 | /// Array |
| 2187 | TopTypeName * arr = tp ? tp->mutable_array() : nullptr; |
| 2188 | |
| 2189 | this->depth++; |
| 2190 | auto k = this->randomNextType(rg, this->next_type_mask & ~(allow_nested), col_counter, arr); |
| 2191 | this->depth--; |
| 2192 | result = std::make_unique<ArrayType>(std::move(k)); |
| 2193 | }}, |
| 2194 | {map_type, |
| 2195 | [&] |
| 2196 | { |
| 2197 | /// Map |
| 2198 | MapTypeDef * mt = tp ? tp->mutable_map() : nullptr; |
| 2199 | |
| 2200 | this->depth++; |
| 2201 | auto k = this->randomNextType( |
| 2202 | rg, this->next_type_mask & ~(allow_nullable | allow_nested), col_counter, mt ? mt->mutable_key() : nullptr); |
| 2203 | this->width++; |
no test coverage detected