| 217 | } |
| 218 | |
| 219 | MergeTreeDataSelectSamplingData MergeTreeDataSelectExecutor::getSampling( |
| 220 | const SelectQueryInfo & select_query_info, |
| 221 | NamesAndTypesList available_real_columns, |
| 222 | const RangesInDataParts & parts, |
| 223 | KeyCondition & key_condition, |
| 224 | const MergeTreeData & data, |
| 225 | const StorageMetadataPtr & metadata_snapshot, |
| 226 | ContextPtr context, |
| 227 | LoggerPtr log) |
| 228 | { |
| 229 | const Settings & settings = context->getSettingsRef(); |
| 230 | /// Sampling. |
| 231 | MergeTreeDataSelectSamplingData sampling; |
| 232 | |
| 233 | RelativeSize relative_sample_size = 0; |
| 234 | RelativeSize relative_sample_offset = 0; |
| 235 | |
| 236 | std::optional<ASTSampleRatio::Rational> sample_size_ratio; |
| 237 | std::optional<ASTSampleRatio::Rational> sample_offset_ratio; |
| 238 | |
| 239 | if (select_query_info.table_expression_modifiers) |
| 240 | { |
| 241 | const auto & table_expression_modifiers = *select_query_info.table_expression_modifiers; |
| 242 | sample_size_ratio = table_expression_modifiers.getSampleSizeRatio(); |
| 243 | sample_offset_ratio = table_expression_modifiers.getSampleOffsetRatio(); |
| 244 | } |
| 245 | else |
| 246 | { |
| 247 | auto & select = select_query_info.query->as<ASTSelectQuery &>(); |
| 248 | |
| 249 | auto select_sample_size = select.sampleSize(); |
| 250 | auto select_sample_offset = select.sampleOffset(); |
| 251 | |
| 252 | if (select_sample_size) |
| 253 | sample_size_ratio = select_sample_size->as<ASTSampleRatio &>().ratio; |
| 254 | |
| 255 | if (select_sample_offset) |
| 256 | sample_offset_ratio = select_sample_offset->as<ASTSampleRatio &>().ratio; |
| 257 | } |
| 258 | |
| 259 | if (sample_size_ratio) |
| 260 | { |
| 261 | relative_sample_size.assign(sample_size_ratio->numerator, sample_size_ratio->denominator); |
| 262 | |
| 263 | if (relative_sample_size < 0) |
| 264 | throw Exception(ErrorCodes::ARGUMENT_OUT_OF_BOUND, "Negative sample size"); |
| 265 | |
| 266 | relative_sample_offset = 0; |
| 267 | if (sample_offset_ratio) |
| 268 | relative_sample_offset.assign(sample_offset_ratio->numerator, sample_offset_ratio->denominator); |
| 269 | |
| 270 | if (relative_sample_offset < 0) |
| 271 | throw Exception(ErrorCodes::ARGUMENT_OUT_OF_BOUND, "Negative sample offset"); |
| 272 | |
| 273 | /// Convert absolute value of the sampling (in form `SAMPLE 1000000` - how many rows to |
| 274 | /// read) into the relative `SAMPLE 0.1` (how much data to read). |
| 275 | size_t approx_total_rows = 0; |
| 276 | if (relative_sample_size > 1 || relative_sample_offset > 1) |
nothing calls this directly
no test coverage detected