diff --git a/cpp/perspective/src/cpp/server.cpp b/cpp/perspective/src/cpp/server.cpp index 58f9cad558..b3dd40f3a7 100644 --- a/cpp/perspective/src/cpp/server.cpp +++ b/cpp/perspective/src/cpp/server.cpp @@ -1017,17 +1017,32 @@ coerce_to(const t_dtype dtype, const A& val) { case DTYPE_BOOL: scalar.set(val == "true"); return scalar; + case DTYPE_FLOAT32: + scalar.set(std::stof(val)); + return scalar; case DTYPE_FLOAT64: scalar.set(std::stod(val)); return scalar; + case DTYPE_UINT8: + scalar.set((std::uint8_t)std::stoul(val)); + return scalar; + case DTYPE_UINT16: + scalar.set((std::uint16_t)std::stoul(val)); + return scalar; case DTYPE_UINT32: scalar.set((std::uint32_t)std::stoul(val)); return scalar; case DTYPE_UINT64: scalar.set((std::uint64_t)std::stoull(val)); return scalar; + case DTYPE_INT8: + scalar.set((std::int8_t)std::stoi(val)); + return scalar; + case DTYPE_INT16: + scalar.set((std::int16_t)std::stoi(val)); + return scalar; case DTYPE_INT32: - scalar.set(std::stoi(val)); + scalar.set((std::int32_t)std::stoi(val)); return scalar; case DTYPE_INT64: scalar.set((std::int64_t)std::stoll(val)); @@ -1946,12 +1961,36 @@ ProtoServer::_handle_request(std::uint32_t client_id, const Request& req) { case DTYPE_BOOL: s->set_bool_(scalar.get()); break; + case DTYPE_FLOAT32: + s->set_float_(scalar.get()); + break; case DTYPE_FLOAT64: s->set_float_(scalar.get()); break; + case DTYPE_INT8: + s->set_float_((double)scalar.get()); + break; + case DTYPE_INT16: + s->set_float_((double)scalar.get()); + break; + case DTYPE_INT32: + s->set_float_((double)scalar.get()); + break; case DTYPE_INT64: s->set_float_((double)scalar.get()); break; + case DTYPE_UINT8: + s->set_float_((double)scalar.get()); + break; + case DTYPE_UINT16: + s->set_float_((double)scalar.get()); + break; + case DTYPE_UINT32: + s->set_float_((double)scalar.get()); + break; + case DTYPE_UINT64: + s->set_float_((double)scalar.get()); + break; case DTYPE_STR: s->set_string(scalar.get()); break; diff --git a/rust/perspective-js/test/arrow/float32.arrow b/rust/perspective-js/test/arrow/float32.arrow new file mode 100644 index 0000000000..91fdf6e557 Binary files /dev/null and b/rust/perspective-js/test/arrow/float32.arrow differ diff --git a/rust/perspective-js/test/js/constructors.spec.js b/rust/perspective-js/test/js/constructors.spec.js index 278da54ae8..93a0036a4e 100644 --- a/rust/perspective-js/test/js/constructors.spec.js +++ b/rust/perspective-js/test/js/constructors.spec.js @@ -966,6 +966,19 @@ function validate_typed_array(typed_array, column_data) { table.delete(); }); + test("Arrow float32 constructor", async function () { + const table = await perspective.table(arrows.float32_arrow.slice()); + const view = await table.view(); + const result = await view.to_columns(); + expect(result).toEqual({ + id: [1, 2, 3], + name: ["Alice", "Bob", "Charlie"], + score: [92.5, 87.30000305175781, 95.80000305175781], + }); + view.delete(); + table.delete(); + }); + test("Arrow date64 constructor", async function () { const table = await perspective.table(arrows.date64_arrow.slice()); const view = await table.view(); diff --git a/rust/perspective-js/test/js/filters.spec.js b/rust/perspective-js/test/js/filters.spec.js index 36abecfd73..00ce8eba93 100644 --- a/rust/perspective-js/test/js/filters.spec.js +++ b/rust/perspective-js/test/js/filters.spec.js @@ -12,6 +12,7 @@ import { test, expect } from "@finos/perspective-test"; import perspective from "./perspective_client"; +import * as arrows from "./test_arrows.js"; var yesterday = new Date(); yesterday.setDate(yesterday.getDate() - 1); @@ -471,6 +472,37 @@ const datetime_data_local = [ }); }); + test.describe("Arrow types", function () { + // https://github.com/finos/perspective/issues/2881 + test("Arrow float32 filters", async function () { + const table = await perspective.table( + arrows.float32_arrow.slice() + ); + + const view = await table.view({ filter: [["score", "<", 93]] }); + const result = await view.to_columns(); + expect(result).toEqual({ + id: [1, 2], + name: ["Alice", "Bob"], + score: [92.5, 87.30000305175781], + }); + + const cfg = await view.get_config(); + expect(cfg).toEqual({ + aggregates: {}, + columns: ["id", "name", "score"], + expressions: {}, + filter: [["score", "<", 93]], + group_by: [], + sort: [], + split_by: [], + }); + + view.delete(); + table.delete(); + }); + }); + test.describe("multiple", function () { test("x > 1 & x < 4", async function () { var table = await perspective.table(data); diff --git a/rust/perspective-js/test/js/test_arrows.js b/rust/perspective-js/test/js/test_arrows.js index e464fdb038..ce00b3fc07 100644 --- a/rust/perspective-js/test/js/test_arrows.js +++ b/rust/perspective-js/test/js/test_arrows.js @@ -71,6 +71,10 @@ export const int_float_str_file_arrow = load_arrow( path.join(__dirname, "..", "arrow", "int_float_str_file.arrow") ); +export const float32_arrow = load_arrow( + path.join(__dirname, "..", "arrow", "float32.arrow") +); + export const date32_arrow = load_arrow( path.join(__dirname, "..", "arrow", "date32.arrow") );