dolphindb 3.1.56 → 3.1.58

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/README.md CHANGED
@@ -611,8 +611,24 @@ After the connection is established, the received streaming data will be called
611
611
  ```ts
612
612
  export interface StreamingParams {
613
613
  table: string
614
+
614
615
  action?: string
615
616
 
617
+ /** offset is the position of the first message after the subscription task starts. A message is a row in the stream table.
618
+ If not specified, or set to -1, the subscription starts from the current row of the stream table.
619
+ If offset = -2, the system retrieves the offset persisted to disk and starts the subscription from that position. Note: persistOffset = true must be set at the same time for offset = -2 to take effect; otherwise offset becomes -1.
620
+ offset corresponds to the first row when the stream table was created. If some rows have been deleted due to memory limits, they are still taken into account when determining the position to start the subscription. */
621
+ offset?: number
622
+
623
+ filters?: {
624
+ /** Needs to be used together with the setStreamTableFilterColumn function
625
+ https://docs.dolphindb.cn/en/funcs/s/subscribeTable.html */
626
+ column?: DdbObj
627
+
628
+ /** DolphinDB expression of the filter condition */
629
+ expression?: string
630
+ }
631
+
616
632
  handler (message: StreamingMessage): any
617
633
  }
618
634
 
@@ -647,6 +663,37 @@ export interface StreamingMessage <TRows = any> extends StreamingParams {
647
663
  }
648
664
  ```
649
665
 
666
+ #### Example of using the filters option
667
+
668
+ With the `filters` option, filter conditions can be constructed on the js side, so that only streaming data satisfying the conditions is received
669
+
670
+ Before subscribing, you need to execute `setStreamTableFilterColumn` on the stream table on the server side to specify the filter column, e.g.: `setStreamTableFilterColumn(table_name, 'sym')`
671
+
672
+ ```ts
673
+ import { DdbVectorSymbol } from 'dolphindb'
674
+
675
+ let sddb = new DDB('ws://127.0.0.1:8848', {
676
+ autologin: true,
677
+ streaming: {
678
+ table: 'name of the stream table to subscribe to',
679
+
680
+ filters: {
681
+ // Construct the filter column values (DdbObj) on the js side, corresponding to the filter parameter of subscribeTable
682
+ // Here only rows whose sym column value is 'aaa' or 'bbb' are received. If the filter column is of other types, use DdbVectorInt, etc.
683
+ column: new DdbVectorSymbol(['aaa', 'bbb']),
684
+ },
685
+
686
+ // Stream data processing callback
687
+ handler (message) {
688
+ console.log(message)
689
+ }
690
+ }
691
+ })
692
+
693
+ // Start subscription
694
+ await sddb.connect()
695
+ ```
696
+
650
697
  To close streaming data subscription, use the following two methods to disconnect:
651
698
  - Automatically disconnect by closing the browser page
652
699
  - Manually disconnect by calling `sddb.disconnect()`
package/README.zh.md CHANGED
@@ -591,8 +591,24 @@ await sddb.connect()
591
591
  ```ts
592
592
  export interface StreamingParams {
593
593
  table: string
594
+
594
595
  action?: string
595
596
 
597
+ /** offset 是订阅任务开始后的第一条消息所在的位置。消息是流数据表中的行。
598
+ 如果未指定,或设为 -1,订阅将会从流数据表的当前行开始。
599
+ 如果 offset = -2,系统会获取持久化到磁盘上的 offset,并从该位置开始订阅。注意:须同时设置 persistOffset = true,offset = -2 才会生效;否则 offset 会变为 -1。
600
+ offset 与流数据表创建时的第一行对应。如果某些行因为内存限制被删除,在决定订阅开始的位置时,这些行仍然考虑在内。 */
601
+ offset?: number
602
+
603
+ filters?: {
604
+ /** 需要配合 setStreamTableFilterColumn 函数一起使用
605
+ https://docs.dolphindb.cn/zh/funcs/s/subscribeTable.html */
606
+ column?: DdbObj
607
+
608
+ /** 过滤条件的 DolphinDB 表达式 */
609
+ expression?: string
610
+ }
611
+
596
612
  handler (message: StreamingMessage): any
597
613
  }
598
614
 
@@ -627,6 +643,37 @@ export interface StreamingMessage <TRows = any> extends StreamingParams {
627
643
  }
628
644
  ```
629
645
 
646
+ #### 使用 filters 选项的例子
647
+
648
+ 通过 `filters` 选项可以在 js 侧构造过滤条件,只接收满足条件的流数据
649
+
650
+ 需要事先在服务器端对被订阅的流表执行 `setStreamTableFilterColumn` 指定过滤列,例如: `setStreamTableFilterColumn(table_name, 'sym')`
651
+
652
+ ```ts
653
+ import { DdbVectorSymbol } from 'dolphindb'
654
+
655
+ let sddb = new DDB('ws://127.0.0.1:8848', {
656
+ autologin: true,
657
+ streaming: {
658
+ table: '要订阅的流表名称',
659
+
660
+ filters: {
661
+ // 在 js 侧构造过滤列值 (DdbObj), 对应 subscribeTable 的 filter 参数
662
+ // 这里只接收 sym 列值为 'aaa' 或 'bbb' 的行, 过滤列是其它类型时可换用 DdbVectorInt 等
663
+ column: new DdbVectorSymbol(['aaa', 'bbb']),
664
+ },
665
+
666
+ // 流数据处理回调
667
+ handler (message) {
668
+ console.log(message)
669
+ }
670
+ }
671
+ })
672
+
673
+ // 开始订阅
674
+ await sddb.connect()
675
+ ```
676
+
630
677
  关闭流数据订阅使用下面两种断开连接的方法
631
678
  - 关闭浏览器页面自动断开连接
632
679
  - 调用 `sddb.disconnect()` 手动断开连接
package/browser.d.ts CHANGED
@@ -52,6 +52,12 @@ export interface DdbChartValue {
52
52
  auto_scale_y_axes?: boolean;
53
53
  };
54
54
  data: DdbMatrixObj;
55
+ /** 箱线图 (Boxplot) 的离群点,服务端 plot(chartType = BOXPLOT) 返回的 chart 可能具有该属性
56
+ 原属性 outliers
57
+ N×2 矩阵,每行为 [序列编号, 离群点值],序列编号从 0 开始,对应 data 的行号
58
+ data 每行为一个箱子的 [下须, Q1, median, Q3, 上须],首尾值为须端点 (服务端按 whis = 1.5 计算)
59
+ 无离群点时为 0×2 矩阵 */
60
+ outliers?: DdbMatrixObj;
55
61
  }
56
62
  export type DdbValue = DdbScalarValue | DdbVectorValue | DdbMatrixValue | DdbDictValue | DdbChartValue | DdbTensorValue | DdbExtObjValue;
57
63
  export type DdbStringObj = DdbObj<string>;
@@ -656,8 +662,8 @@ export declare class BigInt128Array {
656
662
  value: bigint;
657
663
  done: boolean;
658
664
  } | {
659
- done: boolean;
660
665
  value?: undefined;
666
+ done: boolean;
661
667
  };
662
668
  };
663
669
  toString(): string;
package/browser.js CHANGED
@@ -158,7 +158,7 @@ export class DdbObj {
158
158
  if (form === DdbForm.dict)
159
159
  return dict;
160
160
  else {
161
- const { chartType: type, stacking, binStart: bin_start, binEnd: bin_end, binCount: bin_count, title: titles, extras, data, ...others } = dict.to_dict();
161
+ const { chartType: type, stacking, binStart: bin_start, binEnd: bin_end, binCount: bin_count, title: titles, extras, data, outliers, ...others } = dict.to_dict();
162
162
  const [chart, x_axis, y_axis, z_axis] = titles.value;
163
163
  dict.form = DdbForm.chart;
164
164
  dict.value = {
@@ -174,6 +174,7 @@ export class DdbObj {
174
174
  ...bin_count ? { bin_count } : {},
175
175
  ...extras ? { extras: map_keys(extras.data()) } : {},
176
176
  data,
177
+ ...outliers ? { outliers } : {},
177
178
  ...others,
178
179
  };
179
180
  return dict;
@@ -941,7 +942,7 @@ export class DdbObj {
941
942
  case DdbForm.dict:
942
943
  return [value[0].pack(), value[1].pack()];
943
944
  case DdbForm.chart: {
944
- const { type, stacking, bin_start, bin_end, bin_count, titles: { chart, x_axis, y_axis, z_axis }, extras, data } = this.value;
945
+ const { type, stacking, bin_start, bin_end, bin_count, titles: { chart, x_axis, y_axis, z_axis }, extras, data, outliers } = this.value;
945
946
  const { value: [keys, values] } = new DdbDict({
946
947
  chartType: new DdbInt(type),
947
948
  stacking,
@@ -950,6 +951,7 @@ export class DdbObj {
950
951
  title: new DdbVectorString([chart, x_axis, y_axis, z_axis]),
951
952
  ...extras ? { extras: new DdbDict(map_keys(extras, to_lower_camel_case)) } : {},
952
953
  data,
954
+ ...outliers ? { outliers } : {},
953
955
  });
954
956
  return [keys.pack(), values.pack()];
955
957
  }