Fix some errors with the Map function

Signed-off-by: davidarendsen <davidarendsen@hey.com>
This commit is contained in:
davidarendsen 2023-01-12 12:11:28 +00:00
commit 0a4da04e58
2 changed files with 9 additions and 7 deletions

View file

@ -10,14 +10,16 @@ class Map extends Base
public static function with(string $name, string $content): Map public static function with(string $name, string $content): Map
{ {
self::$string = 'r with ' . $name . ': ' . $content; $object = new self();
return new self(); $object::$string = 'r with ' . $name . ': ' . $content;
return $object;
} }
public static function columns(array $columns) public static function columns(array $columns)
{ {
self::$string = new FieldRecordType($columns); $object = new self();
return new self(); $object::$string = new FieldRecordType($columns);
return $object;
} }
public function __toString() public function __toString()

View file

@ -34,9 +34,9 @@ final class MapFunctionTest extends TestCase
$expression = new Map(MapExpression::columns([ $expression = new Map(MapExpression::columns([
'time' => 'r._time', 'time' => 'r._time',
'source' => 'r.tag', 'source' => 'r.tag',
'alert' => SelectionExpression::if('r._value > 10')->then(true)->else(false), 'alert' => SelectionExpression::if('r._value > 10')->then(true)->else(false)->__toString(),
'test' => SelectionExpression::if('r._value > 10')->then('yes')->else('no') 'test' => SelectionExpression::if('r._value > 10')->then('yes')->else('no')->__toString()
])); ])->__toString());
$query = '|> map(fn: (r) => ({ {time: r._time, source: r.tag, ' . $query = '|> map(fn: (r) => ({ {time: r._time, source: r.tag, ' .
'alert: if r._value > 10 then true else false, ' . 'alert: if r._value > 10 then true else false, ' .