35 lines
1.2 KiB
C#
35 lines
1.2 KiB
C#
using System;
|
|
|
|
namespace BCG {
|
|
public class AddColumnsStream : ViewStream {
|
|
public static Tuple<string, Type, object> parse_exp(string exp) {
|
|
string[] toks = exp.Split(':');
|
|
string col_name = toks[0];
|
|
string col_value = toks[1];
|
|
Tuple<Type, object> tup = BlueDataUtility.guess_type(col_value);
|
|
return Tuple.Create(col_name, tup.Item1, tup.Item2);
|
|
}
|
|
|
|
private Tuple<string, Type, object> _new_col;
|
|
private IBlueTableSchema _out_schema;
|
|
|
|
public AddColumnsStream(ViewStream vs, string col_def) {
|
|
_new_col = parse_exp(col_def);
|
|
ViewStream rs = new MapStream(vs, (IBlueTableSchema s) => _get_schema(s), (IBlueRow r) => _map(r));
|
|
mySetRealSource(rs);
|
|
}
|
|
|
|
private IBlueTableSchema _get_schema(IBlueTableSchema input_schema) {
|
|
if (_out_schema == null)
|
|
_out_schema = BlueDataUtility.add_column(input_schema, _new_col.Item1, _new_col.Item2);
|
|
return _out_schema;
|
|
}
|
|
|
|
private IBlueRow _map(IBlueRow r) {
|
|
MutableBlueRow rv = new MutableBlueRow(_get_schema(r.schema), r);
|
|
rv.setValue(_new_col.Item1, _new_col.Item3);
|
|
return rv;
|
|
}
|
|
}
|
|
}
|