Skip to content

GenericSQLVirtualServerModel mangles column names with underscores #3187

@logan-hcg

Description

@logan-hcg

Bug Report

Steps to Reproduce:

package.json:

{
  "name": "perspective-underscore-alias-repro",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "description": "repro",
  "scripts": {
    "repro": "node repro.mjs"
  },
  "dependencies": {
    "@perspective-dev/client": "4.5.1"
  }
}

repro.mjs:

import { GenericSQLVirtualServerModel } from '@perspective-dev/client/node';

const model = new GenericSQLVirtualServerModel();

const sql = model.tableMakeView('memory.t', 'v', {
  sort: [],
  group_by: [],
  split_by: [],
  columns: ['account_number'],
  filter: [],
  expressions: {},
  aggregates: {},
});

console.log(sql);
// CREATE TABLE v AS (SELECT "account_number" as "account-number" FROM memory.t ORDER BY rowid)

To run:

npm install
npm run repo

Expected Result:

Column names with underscores (eg account_name) are passed through unchanged.

Actual Result:

Underscores are replaced with hyphens, so account_name becomes account-name.

In addition to not matching the underlying data, this leads to issues using the datatable, because the table "data" uses the mangled names, but the column picker uses the correct (ie underscore) names. Additionally, sorting breaks with error messages like "Uncaught (in promise) Error: Unknown column "account-name" in field sort" because the names don't match the actual columns:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions