feat: Add function defs to DataStream DSL
This commit is contained in:
1 parent
0550078de0
commit
03294ffe37
55 files changed
+3332
-259
No files matched your search
@@ -20,9 +20,7 @@ namespace bts.BlueOrb {
|
||||
static ViewStream? build_stream(IDataStreamFactory streamFactory, string stream_expression) {
|
||||
try {
|
||||
var exp = DataStreamExpressionsInterpreter.Evaluate(stream_expression);
|
||||
var rv = exp.getView(new Dictionary<string, StatementExpression>(0), streamFactory);
|
||||
return rv;
|
||||
|
||||
return exp.Evaluate(streamFactory) as ViewStream;
|
||||
} catch (Exception ex) {
|
||||
Log.Gen.error($"Could not build stream: {stream_expression} ex: {ex}");
|
||||
return null;
|
||||
|
||||
@@ -41,9 +41,7 @@ namespace BCG {
|
||||
try
|
||||
{
|
||||
var exp = DataStreamExpressionsInterpreter.Evaluate(stream_expression);
|
||||
var rv = exp.getView(new Dictionary<string, StatementExpression>(0), streamFactory);
|
||||
return rv;
|
||||
|
||||
return exp.Evaluate(streamFactory) as ViewStream;
|
||||
} catch (Exception ex) {
|
||||
bts.Log.assert(false, $"Could not build stream: {stream_expression} ex: {ex}");
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace Bts.DataStream.Primitives;
|
||||
|
||||
using BCG;
|
||||
|
||||
using Bts.DataStreamCore;
|
||||
|
||||
using System;
|
||||
|
||||
class FilterEvaluator : IStreamFilter {
|
||||
readonly IFunctionEvaluator evaluator;
|
||||
|
||||
public FilterEvaluator(IFunctionEvaluator evaluator) =>
|
||||
this.evaluator = evaluator;
|
||||
|
||||
public bool filter(IBlueRow dr) =>
|
||||
evaluator.Evaluate(string.Empty, new (string?, int?, object?)[] { (null, 0, dr) })
|
||||
as bool? ?? throw new InvalidOperationException("FunctionEvaluator did not return bool");
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using bts;
|
||||
|
||||
using Bts.DataStream;
|
||||
using Bts.DataStream.Primitives;
|
||||
using Bts.DataStream.Primitives.Filter;
|
||||
using Bts.DataStreamCore;
|
||||
|
||||
@@ -26,6 +27,9 @@ namespace BCG.StreamWorld.Addition {
|
||||
public FilterStream(ViewStream vs, string filterExp)
|
||||
: this(vs, new BooleanExpressionFilter(filterExp)) { }
|
||||
|
||||
public FilterStream(ViewStream vs, IFunctionEvaluator functionEvaluator)
|
||||
: this(vs, new FilterEvaluator(functionEvaluator)) { }
|
||||
|
||||
public FilterStream(ViewStream vs, IStreamFilter filter) {
|
||||
myBaseStream = vs;
|
||||
myFilter = filter;
|
||||
@@ -190,6 +194,8 @@ namespace BCG
|
||||
: this(vs, new OnFilterWrapper(f))
|
||||
{ }
|
||||
|
||||
public FilterStream(ViewStream vs, IFunctionEvaluator functionEvaluator)
|
||||
: this(vs, new FilterEvaluator(functionEvaluator)) { }
|
||||
|
||||
public FilterStream(ViewStream vs, IStreamFilter filter)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user