Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ClickHouse Virtual Server

Perspective provides a built-in virtual server for ClickHouse, allowing <perspective-viewer> to query ClickHouse tables directly from the browser.

For server-side Python usage, see the Python ClickHouse guide.

Installation

npm install @perspective-dev/client @perspective-dev/viewer @clickhouse/client-web

Usage

Connect to a ClickHouse instance and bind it to a Perspective viewer:

import perspective from "@perspective-dev/client";
import "@perspective-dev/viewer";
import { createClient } from "@clickhouse/client-web";

// Connect to ClickHouse
const clickhouseClient = createClient({
    url: "http://localhost:8123",
    database: "default",
});

// Create a Perspective virtual server backed by ClickHouse
const handler = perspective.ClickhouseHandler(clickhouseClient);
const messageHandler = perspective.createMessageHandler(handler);

// Connect a viewer
const client = await perspective.worker(messageHandler);
const table = await client.open_table("my_table");
document.getElementById("viewer").load(table);

Supported features

The ClickHouse virtual server supports:

  • group_by — aggregation via ClickHouse’s GROUP BY
  • sort — ordering results
  • filter — standard filter operators (==, !=, >, <, >=, <=, LIKE, IS NOT NULL, etc.)
  • expressions — computed columns via ClickHouse SQL expressions

Note that split_by is not currently supported with ClickHouse.

Examples