Skip to content

Commit

Permalink
Merge pull request #733 from finos/index-update
Browse files Browse the repository at this point in the history
Enable update with __INDEX__ on explicit index column
  • Loading branch information
texodus authored Sep 22, 2019
2 parents b3ee97c + 9824430 commit c139992
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 6 deletions.
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

0 comments on commit c139992

Please sign in to comment.