主要内容

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

detectExportOptions

根据事件流内容创建导出选项

自 R2022b 起

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

    说明

    opts = detectExportOptions(stream,row) 从事件流中检测导出选项并在 opts 中返回它们。这些选项指定将 MATLAB 变量转换为流处理数据的规则。为了确定哪种流处理数据类型与每个列变量的类型最匹配,detectExportOptions 会检查一行时间表数据并将类型信息包含在 opts 中。

    要获取和设置从 MATLAB 导出到流的变量类型,请使用 getvartypesetvartype

    要将数据从 MATLAB 导出到流,请使用 writetimetable

    示例

    opts = detectExportOptions(stream,row,Format=format) 可选地设置输出流格式。

    示例

    全部折叠

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

    创建一个连接到 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);
    

    输入参数

    全部折叠

    连接到事件流的对象,指定为 KafkaStreamTestStream 对象。

    MATLAB 时间表数据行。row 必须是您打算写入流的数据示例。detectExportOptions 使用此行的列来设置导出选项中的变量名称和类型。

    示例: tt(1,:) 从时间表 tt 中提取第一行数据。

    输出流的格式,指定为以下选项之一:

    • "Event" - 本机、默认偶数流格式

    • "InfluxDB" - InfluxDB 专门使用的格式

    数据类型: char | string

    输出参量

    全部折叠

    事件流导出选项,作为 ExportOptions 对象返回。

    版本历史记录

    在 R2022b 中推出