Public
Edited
Jul 11, 2024
Importers
11 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// adds a row, as key (a=4) not yet in data
data
.concat(aq.table({ a: [4], b: ['z'] }).antijoin(data, 'a'))
.view()
Insert cell
// does not add row, as key (a=3) already in data
data
.concat(aq.table({ a: [3], b: ['z'] }).antijoin(data, 'a'))
.view()
Insert cell
Insert cell
Insert cell
{
const y = aq.table({ a: [2, 3], b: ['z', 'z'] });
return data
.join_left(y, 'a', update(data, y))
.view();
}
Insert cell
// generate a join value specification that performs updates
// if a column is not defined in other, simply return the primary value
// if the secondary value is defined, return it
function update(table, other) {
return table.columnNames().reduce((values, name) => {
const f = `[${JSON.stringify(name)}]`;
values[name] = other.columnIndex(name) >= 0
? `(a, b) => b${f} === undefined ? a${f} : b${f}`
: `a => a${f}`;
return values;
}, {});
}
Insert cell
Insert cell
Insert cell
{
const y = aq.table({ a: [2, 3], b: ['z', 'z'] });
return data
.join_left(y, 'a', patch(data, y))
.view();
}
Insert cell
// generate a join value specification that performs patching
// if a column is not defined in other, simply return the primary value
// if the primary value is null/undefined, return the secondary value
function patch(table, other) {
return table.columnNames().reduce((values, name) => {
const f = `[${JSON.stringify(name)}]`;
values[name] = other.columnIndex(name) >= 0
? `(a, b) => a${f} == null ? b${f} : a${f}`
: `a => a${f}`;
return values;
}, {});
}
Insert cell
Insert cell
Insert cell
{
const z = aq.table({ a: [2, 3, 4], b: ['z', 'z', 'z'] });
return data
.join_full(z, 'a', update(data, z))
.view();
}
Insert cell
Insert cell
Insert cell
data
.antijoin(aq.table({ a: [2, 3] }), 'a')
.view()
Insert cell
Insert cell
data
.antijoin(aq.table({ a: [2, 3], b: ['b', 'b'] }), 'a')
.view()
Insert cell
Insert cell
data
.antijoin(aq.table({ a: [2, 3], b: ['b', 'b'] }), ['a', 'b'])
.view()
Insert cell
Insert cell
Insert cell
// add new table methods to column table prototype
Object.assign(aq.ColumnTable.prototype, {
delete(other, joinKey) { return this.antijoin(other, joinKey); },
insert(other, joinKey) { return this.concat(other.antijoin(this, joinKey)); },
patch(other, joinKey) { return this.join_left(other, joinKey, patch(this, other)); },
update(other, joinKey) { return this.join_left(other, joinKey, update(this, other)); },
upsert(other, joinKey) { return this.join_full(other, joinKey, update(this, other)); }
})
Insert cell
data
.insert(aq.table({ a: [4], b: ['z'] }))
.view()
Insert cell
data
.update(aq.table({ a: [2, 3], b: ['z', 'z'] }), 'a')
.view()
Insert cell
data
.patch(aq.table({ a: [2, 3], b: ['z', 'z'] }), 'a')
.view()
Insert cell
data
.upsert(aq.table({ a: [2, 3, 4], b: ['z', 'z', 'z'] }), 'a')
.view()
Insert cell
data
.delete(aq.table({ a: [2, 3] }))
.view()
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more