FluidDataSet .append

Greetings,

I’ve found the FluidDataSet .merge and the FluidDataSetQuery .transformJoin, however I’m wondering if there is a .append. Something so that DataSet A:

“a”: 0, 1
“b”, 2, 3

and DataSet B:

“a”: 4, 5, 6
“b”: 7, 8, 9

could be “appended”(/transformed/whatever) into:

“a”: 0, 1, 4, 5, 6
“b”: 2, 3, 7, 8, 9

Thanks!

This could be efficient-ized a bit, but:

(
Routine{
	var append_ds = {
		arg ds0, ds1, action;
		ds0.dump({
			arg dict0;
			ds1.dump({
				arg dict1;

				dict1.at("data").keysValuesDo({
					arg key, val;
					if(dict0.at("data").at(key).notNil,{
						dict0.at("data").put(key,dict0.at("data").at(key).addAll(val));
					},{
						"Key % not found in FluidDataSet 0".format(key).error;
					});
				});

				dict0.at("data").keysDo({
					arg key;
					if(dict1.at("data").at(key).isNil,{
						"Key % not found in FluidDataSet 1".format(key).error;
					});
				});

				dict0.put("cols",dict0.at("cols") + dict1.at("cols"));

				Routine{
					var new_ds = FluidDataSet(s);
					s.sync;
					new_ds.load(dict0);
					s.sync;
					action.(new_ds);
				}.play;
			});
		});
	};
	a = FluidDataSet(s);
	b = FluidDataSet(s);

	c = Buffer.alloc(s,2);
	d = Buffer.alloc(s,3);
	s.sync;

	c.setn(0,[1,2]);
	s.sync;

	a.addPoint("one",c);
	s.sync;

	c.setn(0,[3,4]);
	s.sync;

	a.addPoint("two",c);
	s.sync;

	d.setn(0,[100,200,300]);
	s.sync;

	b.addPoint("one",d);
	s.sync;

	d.setn(0,[400,500,600]);
	s.sync;

	b.addPoint("two",d);
	s.sync;

	"before:".postln;

	a.print;
	s.sync;

	b.print;
	s.sync;

	"after:".postln;

	append_ds.(a,b,{
		arg new;
		new.print;
	});

}.play;
)

Hi Ted,
This can be done with FluidDataSetQuery#transformJoin

~da = Dictionary()
~da.add("cols"->2)
~da.add("data"->Dictionary.newFrom(["a",[0,1.0],"b",[2,3]]))

~db = Dictionary.newFrom(["cols",3])
~db.add("data"->Dictionary.newFrom(["a",[4,5,6],"b",[7,8,9]]))

~dsA = FluidDataSet.new(s)
~dsA.load(~da)

~dsB = FluidDataSet.new(s) 
~dsB.load(~db)

~dsCombined = FluidDataSet.new(s)

~dsq = FluidDataSetQuery.new(s)
~dsq.clear
~dsq.addRange(0,3)
~dsq.transformJoin(~dsB,~dsA,~dsCombined)

~dsCombined.print
1 Like

Thank you!

Another thought. I currently can’t merge with an empty dataset. I’d love to be able to do something like this (below) basically start with an empty dataset and then merge in a few datasets one by one.

a = FluidDataSet(s);
b = FluidDataSet(s);

c = Dictionary.newFrom(["cols",2,"data",Dictionary.newFrom(["a",[1,2],"b",[3,4]])]);

b.load(c);

a.merge(b);

that feels more like an unexpected behaviour to me, I’ll add a ticket as I thought it should have worked indeed.

1 Like