Skip to content

Commit

Permalink
Remove cell deltas from public API
Browse files Browse the repository at this point in the history
  • Loading branch information
sc1f committed Oct 24, 2020
1 parent ee5ecb1 commit b708912
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 260 deletions.
22 changes: 1 addition & 21 deletions cpp/perspective/src/cpp/context_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,6 @@ t_ctx0::notify(const t_data_table& flattened, const t_data_table& delta,
}
psp_log_time(repr() + " notify.has_filter_path.updated_traversal");

// calculate cell deltas if enabled
if (get_deltas_enabled()) {
calc_step_delta(flattened, prev, curr, transitions);
}

m_has_delta = m_deltas->size() > 0 || m_delta_pkeys.size() > 0 || delete_encountered;

psp_log_time(repr() + " notify.has_filter_path.exit");
Expand Down Expand Up @@ -447,10 +442,7 @@ t_ctx0::notify(const t_data_table& flattened, const t_data_table& delta,

psp_log_time(repr() + " notify.no_filter_path.updated_traversal");

// calculate cell deltas if enabled
if (get_deltas_enabled()) {
calc_step_delta(flattened, prev, curr, transitions);
}

m_has_delta = m_deltas->size() > 0 || m_delta_pkeys.size() > 0 || delete_encountered;

psp_log_time(repr() + " notify.no_filter_path.exit");
Expand Down Expand Up @@ -489,12 +481,6 @@ t_ctx0::notify(const t_data_table& flattened) {
add_delta_pkey(pkey);
}

// Calculate the step delta, if enabled in the context through an on_update
// callback with the "cell" or "row" mode set.
if (get_deltas_enabled()) {
calc_step_delta(flattened);
}

return;
}

Expand All @@ -513,12 +499,6 @@ t_ctx0::notify(const t_data_table& flattened) {
// Add primary key to track row delta
add_delta_pkey(pkey);
}

// Calculate the step delta, if enabled in the context through an on_update
// callback with the "cell" or "row" mode set.
if (get_deltas_enabled()) {
calc_step_delta(flattened);
}
}

void
Expand Down
15 changes: 15 additions & 0 deletions cpp/perspective/src/cpp/gnode_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,21 @@ t_gstate::read_column(const std::string& colname, const std::vector<t_tscalar>&
std::swap(rval, out_data);
}

void
t_gstate::read_column(const std::string& colname, std::vector<t_tscalar>& out_data) const {
std::shared_ptr<const t_column> col = m_table->get_const_column(colname);
const t_column* col_ = col.get();
t_uindex col_size = col_->size();
std::vector<t_tscalar> rval(col_size);

for (t_index idx = 0; idx < col_size; ++idx) {
rval[idx].set(col_->get_scalar(idx));
}

std::swap(rval, out_data);
}


t_tscalar
t_gstate::get(t_tscalar pkey, const std::string& colname) const {
t_mapping::const_iterator iter = m_mapping.find(pkey);
Expand Down
3 changes: 3 additions & 0 deletions cpp/perspective/src/include/perspective/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#pragma once

#ifdef WIN32
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
#endif // WIN32

Expand Down
6 changes: 6 additions & 0 deletions cpp/perspective/src/include/perspective/first.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@

#pragma once

#ifdef WIN32
#ifndef NOMINMAX
#define NOMINMAX
#endif // ifndex nominmax
#endif // win32

#ifdef PSP_VERIFY
#define PSP_STORAGE_VERIFY
#define PSP_COLUMN_VERIFY
Expand Down
8 changes: 8 additions & 0 deletions cpp/perspective/src/include/perspective/gnode_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ class PERSPECTIVE_EXPORT t_gstate {
void read_column(const std::string& colname, const std::vector<t_tscalar>& pkeys,
std::vector<double>& out_data, bool include_nones) const;

/**
* @brief Read the entirety of a column into `out_data`.
*
* @param colname
* @param out_data
*/
void read_column(const std::string& colname, std::vector<t_tscalar>& out_data) const;

/**
* @brief Apply the lambda `fn` to each primary-keyed value in the column,
* stopping when the lambda returns `true`.
Expand Down
13 changes: 0 additions & 13 deletions packages/perspective-bench/bench/perspective.benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,19 +219,6 @@ describe("Deltas", async () => {
});

describe("mixed", async () => {
describe("ctx0", async () => {
table = worker.table(data.arrow.slice());
view = table.view();
view.on_update(() => {}, {mode: "cell"});
const test_data = await static_view.to_arrow({end_row: 500});
benchmark("cell delta", async () => {
for (let i = 0; i < 3; i++) {
table.update(test_data.slice());
await table.size();
}
});
});

describe("ctx0", async () => {
table = worker.table(data.arrow.slice());
view = table.view();
Expand Down
32 changes: 8 additions & 24 deletions packages/perspective/src/js/perspective.js
Original file line number Diff line number Diff line change
Expand Up @@ -807,18 +807,16 @@ export default function(Module) {
* update was triggered on, and `delta`, whose value is dependent on the
* `mode` parameter:
* - "none" (default): `delta` is `undefined`.
* - "cell": `delta` is the new data for each updated cell, serialized
* to JSON format.
* - "row": `delta` is an Arrow of the updated rows.
*/
view.prototype.on_update = function(callback, {mode = "none"} = {}) {
_call_process(this.table.get_id());

if (["none", "cell", "row"].indexOf(mode) === -1) {
throw new Error(`Invalid update mode "${mode}" - valid modes are "none", "cell" and "row".`);
if (["none", "row"].indexOf(mode) === -1) {
throw new Error(`Invalid update mode "${mode}" - valid modes are "none" and "row".`);
}

if (mode === "cell" || mode === "row") {
if (mode === "row") {
// Enable deltas only if needed by callback
if (!this._View._get_deltas_enabled()) {
this._View._set_deltas_enabled(true);
Expand All @@ -838,25 +836,11 @@ export default function(Module) {

let updated = {port_id};

switch (mode) {
case "cell":
{
if (cache[port_id]["step_delta"] === undefined) {
cache[port_id]["step_delta"] = await this._get_step_delta();
}
updated.delta = cache[port_id]["step_delta"];
}
break;
case "row":
{
if (cache[port_id]["row_delta"] === undefined) {
cache[port_id]["row_delta"] = await this._get_row_delta();
}
updated.delta = cache[port_id]["row_delta"];
}
break;
default:
break;
if (mode === "row") {
if (cache[port_id]["row_delta"] === undefined) {
cache[port_id]["row_delta"] = await this._get_row_delta();
}
updated.delta = cache[port_id]["row_delta"];
}

// Call the callback with the updated object containing
Expand Down
38 changes: 0 additions & 38 deletions packages/perspective/test/js/computed/deltas.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,44 +92,6 @@ module.exports = perspective => {
});
});

it("Returns partially updated step delta for normal and computed columns", async function(done) {
let table = perspective.table(
[
{x: 1, y: "a", z: true},
{x: 2, y: "b", z: false},
{x: 3, y: "c", z: true},
{x: 4, y: "d", z: false}
],
{index: "x"}
);
let view = table.view({
computed_columns: [
{
column: "upper",
computed_function_name: "Uppercase",
inputs: ["y"]
}
]
});
view.on_update(
function(updated) {
expect(updated.delta).toEqual([
{x: 1, y: "string1", z: false, upper: "STRING1"},
{x: 2, y: "string2", z: true, upper: "STRING2"}
]);
view.delete();
table.delete();
done();
},
{mode: "cell"}
);

table.update([
{x: 1, y: "string1", z: false},
{x: 2, y: "string2", z: true}
]);
});

it("Returns partially updated rows for normal and computed columns", async function(done) {
const table = perspective.table(
{
Expand Down
131 changes: 0 additions & 131 deletions packages/perspective/test/js/delta.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,137 +41,6 @@ async function match_delta(perspective, delta, expected) {
}

module.exports = perspective => {
describe("Step delta", function() {
it("Should calculate step delta for 0-sided contexts", async function(done) {
let table = perspective.table(data, {index: "x"});
let view = table.view();
view.on_update(
function(updated) {
expect(updated.delta).toEqual([
{x: 1, y: "string1", z: true},
{x: 2, y: "string2", z: false}
]);
view.delete();
table.delete();
done();
},
{mode: "cell"}
);
table.update(partial_change_y);
});

it("Should calculate step delta for 0-sided contexts from schema", async function(done) {
let table = perspective.table(
{
x: "integer",
y: "string",
z: "boolean"
},
{index: "x"}
);
let view = table.view();
view.on_update(
function(updated) {
expect(updated.delta).toEqual(data);
view.delete();
table.delete();
done();
},
{mode: "cell"}
);
table.update(data);
});

it("Should calculate step delta for added rows in 0-sided contexts from schema", async function(done) {
let table = perspective.table({
x: "integer",
y: "string",
z: "boolean"
});
let view = table.view();
view.on_update(
function(updated) {
expect(updated.delta).toEqual(data);
view.delete();
table.delete();
done();
},
{mode: "cell"}
);
table.update(data);
});

it("Should calculate step delta for added rows in 0-sided filtered contexts from schema", async function(done) {
let table = perspective.table({
x: "integer",
y: "string",
z: "boolean"
});
let view = table.view({
filter: [["x", ">", 3]]
});
view.on_update(
function(updated) {
expect(updated.delta).toEqual([
{
x: 4,
y: "d",
z: false
}
]);
view.delete();
table.delete();
done();
},
{mode: "cell"}
);
table.update(data);
});

it("Should calculate step delta for added rows with partial nones in 0-sided contexts from schema", async function(done) {
let table = perspective.table({
x: "integer",
y: "string",
z: "boolean"
});
let view = table.view();
view.on_update(
function(updated) {
expect(updated.delta).toEqual([
{x: 1, y: "a", z: true},
{x: 2, y: "b", z: null}
]);
view.delete();
table.delete();
done();
},
{mode: "cell"}
);
table.update([
{x: 1, y: "a", z: true},
{x: 2, y: "b"}
]);
});

it.skip("Should calculate step delta for 0-sided contexts during non-sequential updates", async function(done) {
let table = perspective.table(data, {index: "x"});
let view = table.view();
view.on_update(
function(updated) {
expect(updated.delta).toEqual([
{x: 1, y: "string1", z: true},
{x: 4, y: "string2", z: false}
]);
view.delete();
table.delete();
done();
},
{mode: "cell"}
);
table.update(partial_change_nonseq);
});
});

describe("Row delta", function() {
describe("0-sided row delta", function() {
it("returns changed rows", async function(done) {
Expand Down
Loading

0 comments on commit b708912

Please sign in to comment.