24 lines
952 B
C#
24 lines
952 B
C#
namespace Bts.SharedStreams.FunctionEvaluators;
|
|
|
|
using BCG;
|
|
|
|
using bts.BlueOrb;
|
|
|
|
using Bts.DataStreamCore;
|
|
|
|
public class RowAddColumnEvaluator : ExtensionFunctionEvaluator<IBlueRow> {
|
|
public RowAddColumnEvaluator() {
|
|
AddOverload<string, string, IFunctionEvaluator>("addColumn", (row, colName, colTypeName, applyFn) => {
|
|
var colType = Type.GetType(colTypeName) ?? throw new ArgumentException("Failed to parse column type", nameof(colTypeName));
|
|
var colInfos = row.schema.columnInfo;
|
|
var outputColInfos = new ColumnInfo[colInfos.Length + 1];
|
|
outputColInfos[^1] = new(colName, colInfos.Length, colType);
|
|
var outputSchema = new BlueTableSchema(outputColInfos, string.Empty);
|
|
return new AddColumnRow(row, outputSchema, GetValue(row), colInfos.Length);
|
|
|
|
object? GetValue(IBlueRow r) =>
|
|
applyFn.Evaluate(string.Empty, new StreamArgument[] { (null, 0, r) });
|
|
});
|
|
}
|
|
}
|