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

Null aggregate fix #217

Merged
merged 4 commits into from
Aug 28, 2018
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
44 changes: 36 additions & 8 deletions packages/perspective/src/cpp/gnode_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,22 +490,50 @@ void
t_gstate::read_column(const t_str& colname,
const t_tscalvec& pkeys,
t_f64vec& out_data) const
{
read_column(colname, pkeys, out_data, true);
}

void
t_gstate::read_column(const t_str& colname,
const t_tscalvec& pkeys,
t_f64vec& out_data,
bool include_nones) const
{
t_index num = pkeys.size();
t_col_csptr col = m_table->get_const_column(colname);
const t_column* col_ = col.get();
t_f64vec rval(num);

for (t_index idx = 0; idx < num; ++idx)

if (include_nones)
{
t_mapping::const_iterator iter = m_mapping.find(pkeys[idx]);
if (iter != m_mapping.end())
t_f64vec rval(num);
for (t_index idx = 0; idx < num; ++idx)
{
rval[idx] = col_->get_scalar(iter->second).to_double();
t_mapping::const_iterator iter = m_mapping.find(pkeys[idx]);
if (iter != m_mapping.end())
{
rval[idx] = col_->get_scalar(iter->second).to_double();
}
}
std::swap(rval, out_data);
}

std::swap(rval, out_data);
else
{
t_f64vec rval;
for (t_index idx = 0; idx < num; ++idx)
{
t_mapping::const_iterator iter = m_mapping.find(pkeys[idx]);
if (iter != m_mapping.end())
{
auto tscalar = col_->get_scalar(iter->second);
if (tscalar.is_valid())
{
rval.push_back(tscalar.to_double());
}
}
}
std::swap(rval, out_data);
}
}

t_tscalar
Expand Down
2 changes: 1 addition & 1 deletion packages/perspective/src/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ _fill_col(val dcol, t_col_sptr col, t_bool is_arrow)
} else {
for (auto i = 0; i < nrows; ++i)
{
if (dcol[i].isUndefined()) continue;
if (dcol[i].isUndefined() || dcol[i].isNull()) continue;
auto elem = dcol[i].as<T>();
col->set_nth(i, elem);
}
Expand Down
17 changes: 3 additions & 14 deletions packages/perspective/src/cpp/sparse_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1204,22 +1204,11 @@ t_stree::update_agg_table(t_uindex nidx,
t_f64vec values;

gstate.read_column(
spec.get_dependencies()[0].name(), pkeys, values);
spec.get_dependencies()[0].name(), pkeys, values, false);

t_float64 nr = 0;
t_float64 dr = 0;
auto bit = values.begin();
auto eit = values.end();
auto nr = std::accumulate(values.begin(), values.end(), t_float64(0));
t_float64 dr = values.size();

for(; bit != eit; ++bit)
{
auto val = *bit;
if (val != NULL)
{
nr += val;
dr += 1;
}
}

t_f64pair* dst_pair =
dst->get_nth<t_f64pair>(dst_ridx);
Expand Down
5 changes: 5 additions & 0 deletions packages/perspective/src/include/perspective/gnode_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ class PERSPECTIVE_EXPORT t_gstate
const t_tscalvec& pkeys,
t_f64vec& out_data) const;

void read_column(const t_str& colname,
const t_tscalvec& pkeys,
t_f64vec& out_data,
bool include_nones) const;

t_table_sptr get_table();
t_table_csptr get_table() const;

Expand Down
11 changes: 8 additions & 3 deletions packages/perspective/src/js/perspective.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,15 @@ function parse_data(data, names, types) {
continue;
};
if (inferredType.value === __MODULE__.t_dtype.DTYPE_FLOAT64.value) {
col.push(Number(data[x][name]));
let val = data[x][name];
if (val !== null) {
val = Number(val);
}
col.push(val);
} else if (inferredType.value === __MODULE__.t_dtype.DTYPE_INT32.value) {
const val = Number(data[x][name]);
col.push(val);
let val = data[x][name];
if (val !== null) val = Number(val);
col.push(val);
if (val > 2147483647 || val < -2147483648) {
types[n] = __MODULE__.t_dtype.DTYPE_FLOAT64;
}
Expand Down
73 changes: 72 additions & 1 deletion packages/perspective/test/js/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,79 @@ module.exports = (perspective) => {

});

});
describe("nulls", function () {

it("x > 2", async function () {
var table = perspective.table([
{'x': 3, 'y':1},
{'x': 2, 'y':1},
{'x': null, 'y':1},
{'x': null, 'y':1},
{'x': 4, 'y':2},
{'x': null, 'y':2}
]);
var view = table.view({
filter: [
['x', '>', 2]
]
});
var answer = [
{'x': 3, 'y':1},
{'x': 4, 'y':2},
];
let result = await view.to_json();
expect(result).toEqual(answer);
});


it("x < 3", async function () {
var table = perspective.table([
{'x': 3, 'y':1},
{'x': 2, 'y':1},
{'x': null, 'y':1},
{'x': null, 'y':1},
{'x': 4, 'y':2},
{'x': null, 'y':2}
]);
var view = table.view({
filter: [
['x', '<', 3]
]
});
var answer = [
{'x': 2, 'y':1},
];
let result = await view.to_json();
expect(result).toEqual(answer);
});


it("x > 2", async function () {
var table = perspective.table({x: 'float', y: 'integer'});
table.update([
{'x': 3.5, 'y':1},
{'x': 2.5, 'y':1},
{'x': null, 'y':1},
{'x': null, 'y':1},
{'x': 4.5, 'y':2},
{'x': null, 'y':2}
]);
var view = table.view({
filter: [
['x', '>', 2.5]
]
});
var answer = [
{'x': 3.5, 'y':1},
{'x': 4.5, 'y':2},
];
let result = await view.to_json();
expect(answer).toEqual(result);
});

});

});

};

Loading