Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1505, #998, #1225 - results after remove are correct #1528

Merged
merged 6 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
call_process in num_rows, add remove tests
  • Loading branch information
sc1f committed Sep 2, 2021
commit 307b040a13323d5c0da3495acf82c28e760c4c2b
2 changes: 2 additions & 0 deletions packages/perspective/src/js/perspective.js
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ export default function(Module) {
* integer/float type, the Promise returns undefined.
*/
view.prototype.col_to_js_typed_array = function(col_name, options = {}) {
_call_process(this.table.get_id());
const format_function = __MODULE__[`col_to_js_typed_array`];
return column_to_format.call(this, col_name, options, format_function);
};
Expand Down Expand Up @@ -751,6 +752,7 @@ export default function(Module) {
* @returns {Promise<number>} The number of aggregated rows.
*/
view.prototype.num_rows = function() {
_call_process(this.table.get_id());
return this._View.num_rows();
};

Expand Down
126 changes: 126 additions & 0 deletions packages/perspective/test/js/updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,132 @@ module.exports = perspective => {
await view.delete();
await table.delete();
});

it("Removes out of order", async function() {
const table = await perspective.table(
{
x: "string",
y: "integer"
},
{index: "x"}
);

table.update({
x: ["b", "1", "a", "c"],
y: [3, 1, 2, 4]
});

const view = await table.view();
expect(await view.to_columns()).toEqual({
x: ["1", "a", "b", "c"],
y: [1, 2, 3, 4]
});

table.remove(["a", "c", "1", "b"]);

// num_rows should always reflect latest - we did not call_process
// in num_rows and I think the viewer covered that up because
// it would immediately serialize and thus flush the queue.
expect(await view.num_rows()).toEqual(0);
expect(await view.to_json()).toEqual([]);

await view.delete();
await table.delete();
});

it("No-op on pkeys not in the set", async function() {
const table = await perspective.table(
{
x: "string",
y: "integer"
},
{index: "x"}
);

table.update({
x: ["b", "1", "a", "c"],
y: [3, 1, 2, 4]
});

const view = await table.view();
expect(await view.to_columns()).toEqual({
x: ["1", "a", "b", "c"],
y: [1, 2, 3, 4]
});

table.remove(["z", "ff", "2312", "b"]);

expect(await view.to_columns()).toEqual({
x: ["1", "a", "c"],
y: [1, 2, 4]
});

await view.delete();
await table.delete();
});

it("conflation order is consistent", async function() {
const table = await perspective.table(
{
x: "string",
y: "integer"
},
{index: "x"}
);

table.update({
x: ["b", "1", "a", "c"],
y: [3, 1, 2, 4]
});
table.remove(["1", "c"]);

// removes applied after update
const view = await table.view();
expect(await view.to_columns()).toEqual({
x: ["a", "b"],
y: [2, 3]
});

table.update({
x: ["b"],
y: [103]
});
table.remove(["b"]);

expect(await view.to_columns()).toEqual({
x: ["a"],
y: [2]
});

table.update({
x: ["b"],
y: [100]
});

table.remove(["a"]);

expect(await view.to_columns()).toEqual({
x: ["b"],
y: [100]
});

// remove applied after update
for (let i = 0; i < 100; i++) {
table.update({
x: ["c", "a"],
y: [i + 1, i + 2]
});
table.remove(["c", "a"]);
}

expect(await view.to_columns()).toEqual({
x: ["b"],
y: [100]
});

await view.delete();
await table.delete();
});
});

describe("Schema", function() {
Expand Down