Skip to content
Open
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
18 changes: 13 additions & 5 deletions lib/clients/DataTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from "@uwdata/mosaic-core";
import {
asc,
column,
Copy link
Author

@ayjayt ayjayt Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

column() contructs an actual column node:

https://github.com/uwdata/mosaic/blob/9dc9d0aa1ec9a18aaee3dc87820071f5f3aff1ff/packages/mosaic/sql/src/functions/column.ts#L15-L23

If column's second argument table is other than undefined, query comes out like SELECT "table"."colname"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

desc,
type FilterExpr,
Query,
Expand Down Expand Up @@ -57,7 +58,9 @@ export async function datatable(
let empty = await options.coordinator.query(
Query
.from(table)
.select(options.columns ?? ["*"])
.select(options.columns?.map( columnName => {
return column(columnName, undefined);
}) ?? ["*"])
.limit(0),
{ type: "arrow" },
);
Expand Down Expand Up @@ -176,6 +179,11 @@ export class DataTable extends MosaicClient {
get #columns() {
return this.#meta.schema.fields.map((field) => field.name);
}
get #columnsAsNodes() {
return this.#meta.schema.fields.map((field) => {
return column(field.name, undefined);
});
}

/**
* Mosaic function. Client defines the query to be executed by the coordinator.
Expand All @@ -185,7 +193,7 @@ export class DataTable extends MosaicClient {
*/
override query(filter?: FilterExpr | null | undefined): SelectQuery {
let query = Query.from(this.#meta.table)
.select(this.#columns)
.select(this.#columnsAsNodes)
.where(filter ?? [])
.orderby(
this.#orderby
Expand Down Expand Up @@ -246,9 +254,9 @@ export class DataTable extends MosaicClient {
override async prepare(): Promise<void> {
const infos = await queryFieldInfo(
this.coordinator!,
this.#columns.map((column) => ({
this.#columns.map((column_name) => ({
table: this.#meta.table,
column,
column: column(column_name, undefined),
stats: [],
})),
);
Expand All @@ -272,7 +280,7 @@ export class DataTable extends MosaicClient {
</tr>`;

let cols = this.#meta.schema.fields.map((field) => {
let info = infos.find((c) => c.column === field.name);
let info = infos.find((c) => c.column === `"${field.name}"`);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frustratingly, mosaic doesn't handle identifier syntax properly if a string (completely ignores quotes).

However, round-tripping from a column ref node like this seems to produce properly escaped column names.

A bit speculative.

assert(info, `No info for column ${field.name}`);
let vis: ColumnSummaryClient | undefined = undefined;
if (info.type === "number" || info.type === "date") {
Expand Down
Loading