主要内容

本页采用了机器翻译。点击此处可查看最新英文版本。

getvartype

用于将变量导出到流的数据类型

自 R2022b 起

    此函数需要 Streaming Data Framework for MATLAB® Production Server™

    说明

    当使用 opts 指定的导出选项将变量导出到事件流时,type = getvartype(opts) 返回变量的数据类型。

    示例

    [name,type] = getvartype(opts) 还返回变量的名称。

    示例

    ___ = getvartype(opts,selection) 仅返回 selection 指定的变量的数据类型和可选的名称。

    示例

    示例

    全部折叠

    假设您有一个在网络地址 kafka.host.com:9092 上运行的 Kafka® 服务器,该服务器包含主题 TrianglesnumericTriangles

    创建一个连接到 Triangles 主题的 KafkaStream 对象。

    inKS = kafkaStream("kafka.host.com",9092,"Triangles");

    Triangles 主题中的事件读入时间表。通过查看第一行来预览数据。abc 三角形边长存储为字符串。

    tt = readtimetable(inKS);
    row = tt(1,:)
    row =
    
      1×3 timetable
    
         timestamp      a       b       c  
        ___________    ____    ____    ____
    
        03-Sep-2022    "15"    "31"    "36"

    使用 detectExportOptions 从 Kafka 流对象生成 ExportOptions 对象。该函数获取用于从时间表第一行导出变量的类型。

    opts = detectExportOptions(inKS,row);

    使用 getvartype 确认边长变量当前以字符串的形式导出到流中。

    type = getvartype(opts,["a" "b" "c"]);
    
    type = 
    
      1×3 string array
    
        "string"    "string"    "string"

    更新导出选项,以便将边长导出为 double 值。使用 getvartype 确认更新的选项。

    opts = setvartype(opts,["a","b","c"],"double");
    
    [name,type] = getvartype(opts);
    fprintf("%s: %s\n", [name; type])
    a: double
    b: double
    c: double

    连接到流以将数据导出到 numericTriangles

    outKS = kafkaStream("kafka.host.com",9092,"numericTriangles", ...
        ExportOptions=opts)
    
    outKS = 
    
      KafkaStream with properties:
    
                      Topic: "numericTriangles"
                      Group: "85c42e39-695d-467a-86f0-f0095792e7de"
                      Order: EventTime
                       Host: "kafka.host.com"
                       Port: 9092
          ConnectionTimeout: 30
             RequestTimeout: 61
              ImportOptions: "None"
              ExportOptions: "Source: string"
              PublishSchema: "true"
                 WindowSize: 50
                KeyVariable: "key"
                KeyEncoding: "utf16"
                    KeyType: "text"
               KeyByteOrder: "BigEndian"
               BodyEncoding: "utf8"
                 BodyFormat: "JSON"
                  ReadLimit: "Size"
        TimestampResolution: "Milliseconds"
    

    将时间表导出至新流。此流中的三角形边长为 double 类型。

    writetimetable(outKS,tt);
    

    输入参数

    全部折叠

    事件流导出选项,指定为 ExportOptions 对象。

    选定的变量,指定为字符向量、字符串标量、字符向量元胞数组或字符串数组。

    变量名必须是 opts 对象识别的名称的子集。

    示例: 'FanID'

    示例: "FanID"

    示例: {'FanID','vMotor'}

    示例: ["FanID" "vMotor"]

    数据类型: char | string | cell

    输出参量

    全部折叠

    导出到流的变量的数据类型,以字符串数组的形式返回。

    type 的每个元素指定流中变量的数据类型。如果指定了 selection,则返回类型的顺序与 selection 中命名的变量的顺序相匹配。否则,该顺序与在调用 detectExportOptions 时用于创建 opts 的时间表行中的变量名称的顺序相匹配。

    导出到流的变量的名称,以字符串数组的形式返回。

    name 的每个元素指定流中变量的名称。返回的名称的数量和顺序与 type 返回的数据类型的数量和顺序相匹配。

    版本历史记录

    在 R2022b 中推出