Skip to content

Commit

Permalink
Unified result of comparing values with nulls
Browse files Browse the repository at this point in the history
  • Loading branch information
norberttech committed Jul 5, 2024
1 parent 139b9c4 commit 7f60b76
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 14 deletions.
4 changes: 4 additions & 0 deletions src/core/etl/src/Flow/ETL/Function/GreaterThan.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public function eval(Row $row) : bool

$this->assertComparable($base, $next, '>');

if ($base === null || $next === null) {
return false;
}

return $base > $next;
}
}
4 changes: 4 additions & 0 deletions src/core/etl/src/Flow/ETL/Function/GreaterThanEqual.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public function eval(Row $row) : bool

$this->assertComparable($base, $next, '>=');

if ($base === null || $next === null) {
return false;
}

return $base >= $next;
}
}
4 changes: 4 additions & 0 deletions src/core/etl/src/Flow/ETL/Function/LessThan.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public function eval(Row $row) : bool

$this->assertComparable($base, $next, '<');

if ($base === null || $next === null) {
return false;
}

return $base < $next;
}
}
4 changes: 4 additions & 0 deletions src/core/etl/src/Flow/ETL/Function/LessThanEqual.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public function eval(Row $row) : bool

$this->assertComparable($base, $next, '<=');

if ($base === null || $next === null) {
return false;
}

return $base <= $next;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,23 @@ public function test_greater_than() : void
int_entry('c', 10),
datetime_entry('d', '2023-01-01 00:00:00 UTC'),
datetime_entry('e', '2023-01-02 00:00:00 UTC'),
int_entry('f', null),
);

self::assertTrue((new GreaterThan(ref('a'), ref('c')))->eval($row));
self::assertFalse((new GreaterThan(ref('a'), ref('f')))->eval($row));
self::assertFalse((new GreaterThan(ref('f'), ref('c')))->eval($row));
self::assertFalse((new GreaterThan(ref('f'), ref('f')))->eval($row));
self::assertFalse((new GreaterThan(ref('a'), ref('b')))->eval($row));
self::assertTrue((new GreaterThanEqual(ref('a'), ref('c')))->eval($row));
self::assertTrue((new GreaterThanEqual(ref('a'), ref('b')))->eval($row));
self::assertTrue((new GreaterThanEqual(ref('e'), ref('d')))->eval($row));
self::assertTrue((new GreaterThanEqual(ref('e'), lit(new \DateTimeImmutable('2022-01-01 00:00:00 UTC'))))->eval($row));
self::assertFalse((new GreaterThanEqual(ref('e'), lit(new \DateTimeImmutable('2024-01-01 00:00:00 UTC'))))->eval($row));
self::assertFalse((new GreaterThanEqual(ref('a'), ref('f')))->eval($row));
self::assertFalse((new GreaterThanEqual(ref('f'), ref('c')))->eval($row));
self::assertFalse((new GreaterThanEqual(ref('f'), ref('f')))->eval($row));

}

public function test_is_in() : void
Expand Down Expand Up @@ -101,20 +109,18 @@ public function test_is_type_with_non_existing_type_class() : void

public function test_less_than() : void
{
$row = Row::create(int_entry('a', 100), int_entry('b', 100), int_entry('c', 10));

self::assertFalse(
(new LessThan(ref('a'), ref('c')))->eval($row)
);
self::assertFalse(
(new LessThan(ref('a'), ref('b')))->eval($row)
);
self::assertTrue(
(new LessThanEqual(ref('c'), ref('a')))->eval($row)
);
self::assertTrue(
(new LessThanEqual(ref('a'), ref('b')))->eval($row)
);
$row = Row::create(int_entry('a', 100), int_entry('b', 100), int_entry('c', 10), int_entry('d', null));

self::assertFalse((new LessThan(ref('a'), ref('c')))->eval($row));
self::assertFalse((new LessThan(ref('a'), ref('d')))->eval($row));
self::assertFalse((new LessThan(ref('d'), ref('d')))->eval($row));
self::assertFalse((new LessThan(ref('d'), ref('c')))->eval($row));
self::assertFalse((new LessThan(ref('a'), ref('b')))->eval($row));
self::assertTrue((new LessThanEqual(ref('c'), ref('a')))->eval($row));
self::assertTrue((new LessThanEqual(ref('a'), ref('b')))->eval($row));
self::assertFalse((new LessThanEqual(ref('a'), ref('d')))->eval($row));
self::assertFalse((new LessThanEqual(ref('d'), ref('c')))->eval($row));
self::assertFalse((new LessThanEqual(ref('d'), ref('d')))->eval($row));
}

public function test_not_equals() : void
Expand Down

0 comments on commit 7f60b76

Please sign in to comment.