From 02b478733c74b99fbc8a39345a72a53fb5c22ddc Mon Sep 17 00:00:00 2001 From: Yann Amsellem Date: Thu, 16 Oct 2025 18:05:19 +0200 Subject: [PATCH] chore: parse schema from url --- src/lib/olap-engine/engine-remote.ts | 32 ++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/lib/olap-engine/engine-remote.ts b/src/lib/olap-engine/engine-remote.ts index 9398c98..40034a7 100644 --- a/src/lib/olap-engine/engine-remote.ts +++ b/src/lib/olap-engine/engine-remote.ts @@ -4,6 +4,9 @@ import type { Events, ExecOptions, OLAPEngine, OLAPResponse, Table } from './ind import CLICKHOUSE_GET_SCHEMA from './queries/clickhouse_get_schema.sql?raw'; import CLICKHOUSE_GET_UDFS from './queries/clickhouse_get_udfs.sql?raw'; +const TABLE_PATTERN = + /^(?:[a-zA-Z_]+:[a-zA-Z_]+=[a-zA-Z()0-9]+(?:,[a-zA-Z_]+=[a-zA-Z()0-9]+)*;)*[a-zA-Z_]+:[a-zA-Z_]+=[a-zA-Z()0-9]+(?:,[a-zA-Z_]+=[a-zA-Z()0-9]+)*$/; + export class RemoteEngine extends InternalEventEmitter implements OLAPEngine { readonly isAbortable = true; @@ -31,9 +34,10 @@ export class RemoteEngine extends InternalEventEmitter implements OLAPEn } async getSchema() { + const customs = this.getCustomSchemaFromUrl(); const response = await this.exec(CLICKHOUSE_GET_SCHEMA, {}, false); - if (!response) return []; - return response.data as Table[]; + if (!response) return customs; + return customs.concat(response.data as Table[]); } async getUDFs() { @@ -42,6 +46,30 @@ export class RemoteEngine extends InternalEventEmitter implements OLAPEn return response.data.map((row) => row.name as string); } + + private getCustomSchemaFromUrl(): Table[] { + const schema = new URLSearchParams(window.location.search).get('schema'); + if (!schema) return []; + if (!TABLE_PATTERN.test(schema)) { + console.warn('Bad schema passed'); + return []; + } + + return schema.split(';').map((raw) => { + const [name, _columns] = raw.split(':'); + + return { + engine: 'custom', + name, + short: name, + url: '', + columns: _columns.split(',').map((_column) => { + const [name, type] = _column.split('='); + return { name, type }; + }) + }; + }); + } } interface RemoteEngineException {