Skip to content
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
7 changes: 5 additions & 2 deletions cpp/perspective/src/cpp/arrow_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ load_file(
} else {
std::shared_ptr<arrow::ipc::RecordBatchFileReader> batch_reader =
*status;

std::vector<std::shared_ptr<arrow::RecordBatch>> batches;
auto num_batches = batch_reader->num_record_batches();
for (int i = 0; i < num_batches; ++i) {

auto status2 = batch_reader->ReadRecordBatch(i);
if (!status2.ok()) {
PSP_COMPLAIN_AND_ABORT(
Expand All @@ -91,7 +91,10 @@ load_file(
std::shared_ptr<arrow::RecordBatch> chunk = *status2;
batches.push_back(chunk);
}
auto status3 = arrow::Table::FromRecordBatches(batches);

auto status3 =
arrow::Table::FromRecordBatches(batch_reader->schema(), batches);

if (!status3.ok()) {
std::stringstream ss;
ss << "Failed to create Table from RecordBatches: "
Expand Down
5 changes: 3 additions & 2 deletions docs/src/components/DocItem/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

import "@finos/perspective-viewer";
import "@finos/perspective-viewer-datagrid";
import { SUPERSTORE_TABLE } from "@site/src/data/superstore.js";

export async function main(colorMode) {
await import("@finos/perspective-viewer", { type: "module" });
await import("@finos/perspective-viewer-datagrid");

await customElements.whenDefined("perspective-viewer");
const viewers = document.querySelectorAll(
"perspective-viewer:not(.nosuperstore)"
Expand Down
2 changes: 1 addition & 1 deletion examples/blocks/src/raycasting/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ for (var j := 0; j <= radialSegments; j += 1) {
vs[i0] := vs[i0] * bcos - vs[i0 + 2] * bsin;
vs[i0 + 2] := b * bsin + vs[i0 + 2] * bcos;
}
}
};

// Render scene
var scale := resolution / (tan(fov / 2) * 400);
Expand Down
6 changes: 5 additions & 1 deletion packages/perspective-esbuild-plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ const { WorkerPlugin } = require("./worker.js");
exports.PerspectiveEsbuildPlugin = function PerspectiveEsbuildPlugin(
options = {}
) {
const wasm_plugin = WasmPlugin(!!options.wasm?.inline);
const wasm_plugin = WasmPlugin(
!!options.wasm?.inline,
!options.wasm?.webpack_hack
);

const worker_plugin = WorkerPlugin({
targetdir: options.worker?.targetdir,
});
Expand Down
67 changes: 36 additions & 31 deletions packages/perspective-esbuild-plugin/wasm.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
const fs = require("fs");
const path = require("path");

exports.WasmPlugin = function WasmPlugin(inline) {
exports.WasmPlugin = function WasmPlugin(inline, webpack_hack) {
function setup(build) {
const options = build.initialOptions;
options.metafile = true;
Expand Down Expand Up @@ -62,12 +62,14 @@ exports.WasmPlugin = function WasmPlugin(inline) {
.toString()
.slice(2)}__`;
KEYSET.push(key);
const url = webpack_hack ? `${key}(wasm)` : `wasm`;

return {
pluginData: args.pluginData,
contents: `
import wasm from ${JSON.stringify(args.path)};
export default function() {
return fetch(new URL(${key}(wasm), import.meta.url));
return fetch(new URL(${url}, import.meta.url));
};
`,
};
Expand All @@ -84,39 +86,42 @@ exports.WasmPlugin = function WasmPlugin(inline) {
});

build.onEnd(({ metafile }) => {
for (const file of Object.keys(metafile.outputs)) {
if (file.endsWith(".js")) {
let contents = fs.readFileSync(file).toString();
let updated = false;
for (const key of KEYSET) {
const symbol = contents.match(
new RegExp(`${key}\\(([a-zA-Z0-9_\$]+?)\\)`)
);

if (symbol?.[1]) {
updated = true;
const escapedSymbol = symbol[1].replace(
/\$/g,
"\\$"
);
const filename = contents.match(
new RegExp(
`${escapedSymbol}\\s*?=\\s*?\\"(.+?)\\"`
)
if (webpack_hack) {
for (const file of Object.keys(metafile.outputs)) {
if (file.endsWith(".js")) {
let contents = fs.readFileSync(file).toString();
let updated = false;
for (const key of KEYSET) {
const symbol = contents.match(
new RegExp(`${key}\\(([a-zA-Z0-9_\$]+?)\\)`)
);

contents = contents.replace(
new RegExp(
`${key}\\(([a-zA-Z0-9_\$]+?)\\)`,
"g"
),
`"${filename[1]}"`
);
if (symbol?.[1]) {
updated = true;
const escapedSymbol = symbol[1].replace(
/\$/g,
"\\$"
);

const filename = contents.match(
new RegExp(
`(?<![a-zA-Z0-9_\$])${escapedSymbol}\\s*?=\\s*?\\"(.+?)\\"`
)
);

contents = contents.replace(
new RegExp(
`${key}\\(([a-zA-Z0-9_\$]+?)\\)`,
"g"
),
`"${filename[1]}"`
);
}
}
}

if (updated) {
fs.writeFileSync(file, contents);
if (updated) {
fs.writeFileSync(file, contents);
}
}
}
}
Expand Down
23 changes: 0 additions & 23 deletions packages/perspective-esbuild-plugin/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,29 +154,6 @@ exports.WorkerPlugin = function WorkerPlugin(options = {}) {
loader: "text",
};
});

build.onEnd(({ metafile }) => {
for (const file of Object.keys(metafile.outputs)) {
if (file.endsWith(".js")) {
let contents = fs.readFileSync(file).toString();
const symbol = contents.match(
/__PSP_INLINE_WORKER__\(([a-zA-Z0-9_\$]+?)\)/
);
if (symbol?.[1]) {
const filename = contents.match(
new RegExp(`${symbol[1]}\\s*?=\\s*?\\"(.+?)\\"`)
);

contents = contents.replace(
/__PSP_INLINE_WORKER__\([a-zA-Z0-9_\$]+?\)/,
`"${filename[1]}"`
);

fs.writeFileSync(file, contents);
}
}
}
});
}

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,27 @@ def test_table_arrow_loads_int_stream(self, util):
"d": data[3],
}

def test_empty_arrow(self, util):
table = pa.table(
{
"col1": [1, 2, 3],
"col2": ["abc", "foo", "bar"],
}
)

empty_table = table.schema.empty_table()
assert client.table(table, name="table").size() == 3
assert client.table(empty_table, name="table_empty_bad").size() == 0
assert client.table(table, name="table").schema() == {
"col1": "integer",
"col2": "string",
}

assert client.table(empty_table, name="table").schema() == {
"col1": "integer",
"col2": "string",
}

def test_table_arrow_loads_float_stream(self, util):
data = [[i for i in range(10)], [i * 1.5 for i in range(10)]]
arrow_data = util.make_arrow(["a", "b"], data)
Expand Down
8 changes: 4 additions & 4 deletions rust/perspective-python/src/client/client_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use super::python::*;
use crate::py_err::ResultTClientErrorExt;
use crate::server::PySyncServer;

#[pyclass]
#[pyclass(module = "perspective")]
#[derive(Clone)]
pub struct ProxySession(perspective_client::ProxySession);

Expand Down Expand Up @@ -81,7 +81,7 @@ trait PyFutureExt: Future {
impl<F: Future> PyFutureExt for F {}

#[doc = crate::inherit_docs!("client.md")]
#[pyclass(subclass)]
#[pyclass(subclass, module = "perspective")]
pub struct Client(pub(crate) PyClient);

#[pymethods]
Expand Down Expand Up @@ -147,7 +147,7 @@ impl Client {
}

#[doc = crate::inherit_docs!("table.md")]
#[pyclass(subclass, name = "Table")]
#[pyclass(subclass, name = "Table", module = "perspective")]
pub struct Table(PyTable);

assert_table_api!(Table);
Expand Down Expand Up @@ -272,7 +272,7 @@ impl Table {
}

#[doc = crate::inherit_docs!("view.md")]
#[pyclass(subclass, name = "View")]
#[pyclass(subclass, name = "View", module = "perspective")]
pub struct View(PyView);

assert_view_api!(View);
Expand Down
4 changes: 2 additions & 2 deletions rust/perspective-python/src/server/server_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ use pyo3::types::{PyAny, PyBytes};

use crate::client::python::PyClient;

#[pyclass]
#[pyclass(module = "perspective")]
#[derive(Clone)]
pub struct PySyncSession {
session: Arc<RwLock<Option<LocalSession>>>,
}

#[pyclass(subclass)]
#[pyclass(subclass, module = "perspective")]
#[derive(Clone, Default)]
pub struct PySyncServer {
pub server: Server,
Expand Down