| 1405 | } |
| 1406 | |
| 1407 | static FillColumnDescription getWithFillDescription(const ASTOrderByElement & order_by_elem, const ContextPtr & context) |
| 1408 | { |
| 1409 | FillColumnDescription descr; |
| 1410 | |
| 1411 | if (order_by_elem.getFillFrom()) |
| 1412 | std::tie(descr.fill_from, descr.fill_from_type) = getWithFillFieldValue(order_by_elem.getFillFrom(), context); |
| 1413 | if (order_by_elem.getFillTo()) |
| 1414 | std::tie(descr.fill_to, descr.fill_to_type) = getWithFillFieldValue(order_by_elem.getFillTo(), context); |
| 1415 | |
| 1416 | if (order_by_elem.getFillStep()) |
| 1417 | std::tie(descr.fill_step, descr.step_kind) = getWithFillValueWithIntervalKind(order_by_elem.getFillStep(), context); |
| 1418 | else |
| 1419 | descr.fill_step = order_by_elem.direction; |
| 1420 | |
| 1421 | if (order_by_elem.getFillStaleness()) |
| 1422 | { |
| 1423 | std::tie(descr.fill_staleness, descr.staleness_kind) = getWithFillValueWithIntervalKind(order_by_elem.getFillStaleness(), context); |
| 1424 | |
| 1425 | if (order_by_elem.getFillFrom()) |
| 1426 | throw Exception(ErrorCodes::INVALID_WITH_FILL_EXPRESSION, |
| 1427 | "WITH FILL STALENESS cannot be used together with WITH FILL FROM"); |
| 1428 | } |
| 1429 | |
| 1430 | if (accurateEquals(descr.fill_step, Field{0})) |
| 1431 | throw Exception(ErrorCodes::INVALID_WITH_FILL_EXPRESSION, "WITH FILL STEP value cannot be zero"); |
| 1432 | |
| 1433 | if (order_by_elem.direction == 1) |
| 1434 | { |
| 1435 | if (accurateLess(descr.fill_step, Field{0})) |
| 1436 | throw Exception(ErrorCodes::INVALID_WITH_FILL_EXPRESSION, "WITH FILL STEP value cannot be negative for sorting in ascending direction"); |
| 1437 | |
| 1438 | if (!descr.fill_from.isNull() && !descr.fill_to.isNull() && |
| 1439 | accurateLess(descr.fill_to, descr.fill_from)) |
| 1440 | { |
| 1441 | throw Exception(ErrorCodes::INVALID_WITH_FILL_EXPRESSION, |
| 1442 | "WITH FILL TO value cannot be less than FROM value for sorting in ascending direction"); |
| 1443 | } |
| 1444 | |
| 1445 | if (accurateLess(descr.fill_staleness, Field{0})) |
| 1446 | throw Exception(ErrorCodes::INVALID_WITH_FILL_EXPRESSION, |
| 1447 | "WITH FILL STALENESS value cannot be negative for sorting in ascending direction"); |
| 1448 | } |
| 1449 | else |
| 1450 | { |
| 1451 | if (accurateLess(Field{0}, descr.fill_step)) |
| 1452 | throw Exception(ErrorCodes::INVALID_WITH_FILL_EXPRESSION, "WITH FILL STEP value cannot be positive for sorting in descending direction"); |
| 1453 | |
| 1454 | if (!descr.fill_from.isNull() && !descr.fill_to.isNull() && |
| 1455 | accurateLess(descr.fill_from, descr.fill_to)) |
| 1456 | { |
| 1457 | throw Exception(ErrorCodes::INVALID_WITH_FILL_EXPRESSION, |
| 1458 | "WITH FILL FROM value cannot be less than TO value for sorting in descending direction"); |
| 1459 | } |
| 1460 | |
| 1461 | if (accurateLess(Field{0}, descr.fill_staleness)) |
| 1462 | throw Exception(ErrorCodes::INVALID_WITH_FILL_EXPRESSION, |
| 1463 | "WITH FILL STALENESS value cannot be positive for sorting in descending direction"); |
| 1464 | } |
no test coverage detected