Skip to content

Commit 10696c9

Browse files
authored
Fix: Escape col names by manually generating node (#94)
1 parent e6f3900 commit 10696c9

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/clients/DataTable.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from "@uwdata/mosaic-core";
88
import {
99
asc,
10+
column,
1011
desc,
1112
type FilterExpr,
1213
Query,
@@ -57,7 +58,9 @@ export async function datatable(
5758
let empty = await options.coordinator.query(
5859
Query
5960
.from(table)
60-
.select(options.columns ?? ["*"])
61+
.select(options.columns?.map( columnName => {
62+
return column(columnName, undefined);
63+
}) ?? ["*"])
6164
.limit(0),
6265
{ type: "arrow" },
6366
);
@@ -176,6 +179,11 @@ export class DataTable extends MosaicClient {
176179
get #columns() {
177180
return this.#meta.schema.fields.map((field) => field.name);
178181
}
182+
get #columnsAsNodes() {
183+
return this.#meta.schema.fields.map((field) => {
184+
return column(field.name, undefined);
185+
});
186+
}
179187

180188
/**
181189
* Mosaic function. Client defines the query to be executed by the coordinator.
@@ -185,7 +193,7 @@ export class DataTable extends MosaicClient {
185193
*/
186194
override query(filter?: FilterExpr | null | undefined): SelectQuery {
187195
let query = Query.from(this.#meta.table)
188-
.select(this.#columns)
196+
.select(this.#columnsAsNodes)
189197
.where(filter ?? [])
190198
.orderby(
191199
this.#orderby
@@ -246,9 +254,9 @@ export class DataTable extends MosaicClient {
246254
override async prepare(): Promise<void> {
247255
const infos = await queryFieldInfo(
248256
this.coordinator!,
249-
this.#columns.map((column) => ({
257+
this.#columns.map((column_name) => ({
250258
table: this.#meta.table,
251-
column,
259+
column: column(column_name, undefined),
252260
stats: [],
253261
})),
254262
);
@@ -272,7 +280,7 @@ export class DataTable extends MosaicClient {
272280
</tr>`;
273281

274282
let cols = this.#meta.schema.fields.map((field) => {
275-
let info = infos.find((c) => c.column === field.name);
283+
let info = infos.find((c) => c.column === `"${field.name}"`);
276284
assert(info, `No info for column ${field.name}`);
277285
let vis: ColumnSummaryClient | undefined = undefined;
278286
if (info.type === "number" || info.type === "date") {

0 commit comments

Comments
 (0)