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

Enable update with __INDEX__ on explicit index column #733

Merged
merged 1 commit into from
Sep 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 0 additions & 6 deletions cpp/perspective/src/cpp/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ Table::set_data_types(const std::vector<t_dtype>& data_types) {

void
Table::validate_columns(const std::vector<std::string>& column_names) {
bool implicit_index =
std::find(column_names.begin(), column_names.end(), "__INDEX__") != column_names.end();
if (m_index != "") {
// Check if index is valid after getting column names
bool explicit_index
Expand All @@ -185,10 +183,6 @@ Table::validate_columns(const std::vector<std::string>& column_names) {
std::cout << "Specified index " << m_index << " does not exist in data." << std::endl;
PSP_COMPLAIN_AND_ABORT("Specified index '" + m_index + "' does not exist in data.");
}
if (explicit_index && implicit_index) {
std::cout << "Specified index " << m_index << " twice - ignoring implicit __INDEX__" << std::endl;
PSP_COMPLAIN_AND_ABORT("Specified index '" + m_index + "' twice; ignoring implicit index.");
}
}
}

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

it("should apply updates using '__INDEX__' on a table with explicit index set", async function() {
let table = perspective.table(data, {index: "x"});
table.update([
{
__INDEX__: 2,
y: "new_string"
}
]);
let view = table.view();
let result = await view.to_json();

let expected = JSON.parse(JSON.stringify(data));
expected[1]["y"] = "new_string";

expect(result).toEqual(expected);
view.delete();
table.delete();
});

it("should apply mulitple sequential updates using '__INDEX__' on a table with explicit index set", async function() {
let table = perspective.table(data, {index: "x"});
table.update([
{
__INDEX__: 2,
y: "new_string"
},
{
__INDEX__: 3,
y: "new_string"
}
]);
let view = table.view();
let result = await view.to_json();

let expected = JSON.parse(JSON.stringify(data));
expected[1]["y"] = "new_string";
expected[2]["y"] = "new_string";

expect(result).toEqual(expected);
view.delete();
table.delete();
});

it("should apply mulitple nonsequential updates using '__INDEX__' on a table with explicit index set", async function() {
let table = perspective.table(data, {index: "x"});
table.update([
{
__INDEX__: 2,
y: "new_string"
},
{
__INDEX__: 4,
y: "new_string"
}
]);
let view = table.view();
let result = await view.to_json();

let expected = JSON.parse(JSON.stringify(data));
expected[1]["y"] = "new_string";
expected[3]["y"] = "new_string";

expect(result).toEqual(expected);
view.delete();
table.delete();
});

it("should apply multiple sequential partial updates on unindexed table using '__INDEX__'", async function() {
let table = perspective.table(data);
table.update([
Expand Down