Skip to content

Commit 5ca0f53

Browse files
committed
Merge remote-tracking branch 'origin/1.3.x' into 1.4.x
2 parents 6d758ad + f3abbd8 commit 5ca0f53

File tree

3 files changed

+94
-1
lines changed

3 files changed

+94
-1
lines changed

src/Doctrine/Mapping/ClassMetadataFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct(string $tmpDir)
2929
protected function initialize(): void
3030
{
3131
$drivers = [];
32-
if (class_exists(AnnotationReader::class)) {
32+
if (class_exists(AnnotationDriver::class) && class_exists(AnnotationReader::class)) {
3333
$docParser = new DocParser();
3434
$docParser->setIgnoreNotImportedAnnotations(true);
3535
$drivers[] = new AnnotationDriver(new AnnotationReader($docParser));

src/Type/Doctrine/Query/QueryResultTypeWalker.php

+17
Original file line numberDiff line numberDiff line change
@@ -933,12 +933,29 @@ public function walkAggregateExpression($aggExpression): string
933933
switch ($aggExpression->functionName) {
934934
case 'MAX':
935935
case 'MIN':
936+
$type = $this->unmarshalType(
937+
$this->walkSimpleArithmeticExpression($aggExpression->pathExpression)
938+
);
939+
940+
return $this->marshalType(TypeCombinator::addNull($type));
941+
936942
case 'AVG':
943+
$type = $this->unmarshalType(
944+
$this->walkSimpleArithmeticExpression($aggExpression->pathExpression)
945+
);
946+
947+
$type = TypeCombinator::union($type, $type->toFloat());
948+
$type = TypeUtils::generalizeType($type, GeneralizePrecision::lessSpecific());
949+
950+
return $this->marshalType(TypeCombinator::addNull($type));
951+
937952
case 'SUM':
938953
$type = $this->unmarshalType(
939954
$this->walkSimpleArithmeticExpression($aggExpression->pathExpression)
940955
);
941956

957+
$type = TypeUtils::generalizeType($type, GeneralizePrecision::lessSpecific());
958+
942959
return $this->marshalType(TypeCombinator::addNull($type));
943960

944961
case 'COUNT':

tests/Type/Doctrine/Query/QueryResultTypeWalkerTest.php

+76
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,82 @@ public function getTestData(): iterable
681681
',
682682
];
683683

684+
yield 'aggregate on literal' => [
685+
$this->constantArray([
686+
[
687+
new ConstantIntegerType(1),
688+
TypeCombinator::union(
689+
new ConstantStringType('1'),
690+
new ConstantIntegerType(1),
691+
new NullType()
692+
),
693+
],
694+
[
695+
new ConstantIntegerType(2),
696+
TypeCombinator::union(
697+
new ConstantStringType('0'),
698+
new ConstantIntegerType(0),
699+
new ConstantStringType('1'),
700+
new ConstantIntegerType(1),
701+
new NullType()
702+
),
703+
],
704+
[
705+
new ConstantIntegerType(3),
706+
TypeCombinator::union(
707+
new ConstantStringType('1'),
708+
new ConstantIntegerType(1),
709+
new NullType()
710+
),
711+
],
712+
[
713+
new ConstantIntegerType(4),
714+
TypeCombinator::union(
715+
new ConstantStringType('0'),
716+
new ConstantIntegerType(0),
717+
new ConstantStringType('1'),
718+
new ConstantIntegerType(1),
719+
new NullType()
720+
),
721+
],
722+
[
723+
new ConstantIntegerType(5),
724+
TypeCombinator::union(
725+
$this->intStringified(),
726+
new FloatType(),
727+
new NullType()
728+
),
729+
],
730+
[
731+
new ConstantIntegerType(6),
732+
TypeCombinator::union(
733+
$this->intStringified(),
734+
new FloatType(),
735+
new NullType()
736+
),
737+
],
738+
[
739+
new ConstantIntegerType(7),
740+
TypeCombinator::addNull($this->intStringified()),
741+
],
742+
[
743+
new ConstantIntegerType(8),
744+
TypeCombinator::addNull($this->intStringified()),
745+
],
746+
]),
747+
'
748+
SELECT MAX(1),
749+
MAX(CASE WHEN m.intColumn = 0 THEN 1 ELSE 0 END),
750+
MIN(1),
751+
MIN(CASE WHEN m.intColumn = 0 THEN 1 ELSE 0 END),
752+
AVG(1),
753+
AVG(CASE WHEN m.intColumn = 0 THEN 1 ELSE 0 END),
754+
SUM(1),
755+
SUM(CASE WHEN m.intColumn = 0 THEN 1 ELSE 0 END)
756+
FROM QueryResult\Entities\Many m
757+
',
758+
];
759+
684760
yield 'literal' => [
685761
$this->constantArray([
686762
[

0 commit comments

Comments
 (0)