@malloydata/malloy 0.0.105-dev231124203430 → 0.0.105-dev231127183208

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/malloy.d.ts CHANGED
@@ -1234,6 +1234,7 @@ declare class DataNull extends Data<null> {
1234
1234
  export declare class DataArray extends Data<QueryData> implements Iterable<DataRecord> {
1235
1235
  private queryData;
1236
1236
  protected _field: Explore;
1237
+ private rowCache;
1237
1238
  constructor(queryData: QueryData, field: Explore, parent: DataArrayOrRecord | undefined, parentRecord: DataRecord | undefined);
1238
1239
  /**
1239
1240
  * @return The `Explore` that describes the structure of this data.
@@ -1256,6 +1257,7 @@ export declare class DataRecord extends Data<{
1256
1257
  private queryDataRow;
1257
1258
  protected _field: Explore;
1258
1259
  readonly index: number | undefined;
1260
+ private cellCache;
1259
1261
  constructor(queryDataRow: QueryDataRow, index: number | undefined, field: Explore, parent: DataArrayOrRecord | undefined, parentRecord: DataRecord | undefined);
1260
1262
  toObject(): QueryDataRow;
1261
1263
  path(...path: (number | string)[]): DataColumn;
package/dist/malloy.js CHANGED
@@ -2611,6 +2611,7 @@ class DataNull extends Data {
2611
2611
  class DataArray extends Data {
2612
2612
  constructor(queryData, field, parent, parentRecord) {
2613
2613
  super(field, parent, parentRecord);
2614
+ this.rowCache = new Map();
2614
2615
  this.queryData = queryData;
2615
2616
  this._field = field;
2616
2617
  }
@@ -2630,6 +2631,12 @@ class DataArray extends Data {
2630
2631
  return getPath(this, path);
2631
2632
  }
2632
2633
  row(index) {
2634
+ let record = this.rowCache.get(index);
2635
+ if (!record) {
2636
+ record = new DataRecord(this.queryData[index], index, this.field, this, this.parentRecord);
2637
+ this.rowCache.set(index, record);
2638
+ }
2639
+ return record;
2633
2640
  return new DataRecord(this.queryData[index], index, this.field, this, this.parentRecord);
2634
2641
  }
2635
2642
  get rowCount() {
@@ -2674,6 +2681,7 @@ function getPath(data, path) {
2674
2681
  class DataRecord extends Data {
2675
2682
  constructor(queryDataRow, index, field, parent, parentRecord) {
2676
2683
  super(field, parent, parentRecord);
2684
+ this.cellCache = new Map();
2677
2685
  this.queryDataRow = queryDataRow;
2678
2686
  this._field = field;
2679
2687
  this.index = index;
@@ -2687,41 +2695,48 @@ class DataRecord extends Data {
2687
2695
  cell(fieldOrName) {
2688
2696
  const fieldName = typeof fieldOrName === 'string' ? fieldOrName : fieldOrName.name;
2689
2697
  const field = this._field.getFieldByName(fieldName);
2690
- const value = this.queryDataRow[fieldName];
2691
- if (value === null) {
2692
- return new DataNull(field, this, this);
2693
- }
2694
- if (field.isAtomicField()) {
2695
- if (field.isBoolean()) {
2696
- return new DataBoolean(value, field, this, this);
2697
- }
2698
- else if (field.isDate()) {
2699
- return new DataDate(value, field, this, this);
2700
- }
2701
- else if (field.isJSON()) {
2702
- return new DataJSON(value, field, this, this);
2703
- }
2704
- else if (field.isTimestamp()) {
2705
- return new DataTimestamp(value, field, this, this);
2698
+ let column = this.cellCache.get(fieldName);
2699
+ if (!column) {
2700
+ const value = this.queryDataRow[fieldName];
2701
+ if (value === null) {
2702
+ column = new DataNull(field, this, this);
2706
2703
  }
2707
- else if (field.isNumber()) {
2708
- return new DataNumber(value, field, this, this);
2709
- }
2710
- else if (field.isString()) {
2711
- return new DataString(value, field, this, this);
2712
- }
2713
- else if (field.isUnsupported()) {
2714
- return new DataUnsupported(value, field, this, this);
2715
- }
2716
- }
2717
- else if (field.isExploreField()) {
2718
- if (Array.isArray(value)) {
2719
- return new DataArray(value, field, this, this);
2704
+ else if (field.isAtomicField()) {
2705
+ if (field.isBoolean()) {
2706
+ column = new DataBoolean(value, field, this, this);
2707
+ }
2708
+ else if (field.isDate()) {
2709
+ column = new DataDate(value, field, this, this);
2710
+ }
2711
+ else if (field.isJSON()) {
2712
+ column = new DataJSON(value, field, this, this);
2713
+ }
2714
+ else if (field.isTimestamp()) {
2715
+ column = new DataTimestamp(value, field, this, this);
2716
+ }
2717
+ else if (field.isNumber()) {
2718
+ column = new DataNumber(value, field, this, this);
2719
+ }
2720
+ else if (field.isString()) {
2721
+ column = new DataString(value, field, this, this);
2722
+ }
2723
+ else if (field.isUnsupported()) {
2724
+ column = new DataUnsupported(value, field, this, this);
2725
+ }
2720
2726
  }
2721
- else {
2722
- return new DataRecord(value, undefined, field, this, this);
2727
+ else if (field.isExploreField()) {
2728
+ if (Array.isArray(value)) {
2729
+ column = new DataArray(value, field, this, this);
2730
+ }
2731
+ else {
2732
+ column = new DataRecord(value, undefined, field, this, this);
2733
+ }
2723
2734
  }
2735
+ if (column)
2736
+ this.cellCache.set(fieldName, column);
2724
2737
  }
2738
+ if (column)
2739
+ return column;
2725
2740
  throw new Error(`Internal Error: could not construct data column for field '${fieldName}'.`);
2726
2741
  }
2727
2742
  get value() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.105-dev231124203430",
3
+ "version": "0.0.105-dev231127183208",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",