|
22 | 22 | #include <algorithm> |
23 | 23 | #include <format> |
24 | 24 | #include <map> |
| 25 | +#include <memory> |
25 | 26 | #include <optional> |
26 | 27 | #include <string_view> |
27 | 28 | #include <vector> |
@@ -389,8 +390,15 @@ bool CountStarAggregate::HasValue(const DataFile& file) const { |
389 | 390 | MaxAggregate::MaxAggregate(std::shared_ptr<BoundTerm> term) |
390 | 391 | : BoundAggregate(Expression::Operation::kMax, std::move(term)) {} |
391 | 392 |
|
392 | | -std::shared_ptr<MaxAggregate> MaxAggregate::Make(std::shared_ptr<BoundTerm> term) { |
393 | | - return std::shared_ptr<MaxAggregate>(new MaxAggregate(std::move(term))); |
| 393 | +Result<std::unique_ptr<MaxAggregate>> MaxAggregate::Make( |
| 394 | + std::shared_ptr<BoundTerm> term) { |
| 395 | + if (!term) { |
| 396 | + return InvalidExpression("Bound max aggregate requires non-null term"); |
| 397 | + } |
| 398 | + if (!term->type()->is_primitive()) { |
| 399 | + return InvalidExpression("Max aggregate term should be primitive"); |
| 400 | + } |
| 401 | + return std::unique_ptr<MaxAggregate>(new MaxAggregate(std::move(term))); |
394 | 402 | } |
395 | 403 |
|
396 | 404 | Result<Literal> MaxAggregate::Evaluate(const StructLike& data) const { |
@@ -420,8 +428,15 @@ bool MaxAggregate::HasValue(const DataFile& file) const { |
420 | 428 | MinAggregate::MinAggregate(std::shared_ptr<BoundTerm> term) |
421 | 429 | : BoundAggregate(Expression::Operation::kMin, std::move(term)) {} |
422 | 430 |
|
423 | | -std::shared_ptr<MinAggregate> MinAggregate::Make(std::shared_ptr<BoundTerm> term) { |
424 | | - return std::shared_ptr<MinAggregate>(new MinAggregate(std::move(term))); |
| 431 | +Result<std::unique_ptr<MinAggregate>> MinAggregate::Make( |
| 432 | + std::shared_ptr<BoundTerm> term) { |
| 433 | + if (!term) { |
| 434 | + return InvalidExpression("Bound min aggregate requires non-null term"); |
| 435 | + } |
| 436 | + if (!term->type()->is_primitive()) { |
| 437 | + return InvalidExpression("Max aggregate term should be primitive"); |
| 438 | + } |
| 439 | + return std::unique_ptr<MinAggregate>(new MinAggregate(std::move(term))); |
425 | 440 | } |
426 | 441 |
|
427 | 442 | Result<Literal> MinAggregate::Evaluate(const StructLike& data) const { |
|
0 commit comments