Data types used to export variables to stream
This function requires Streaming Data Framework for MATLAB® Production Server™.
Get Data Types of Exported Variables in Event Stream
Assume that you have a Kafka® server running at the network address
that has the topics
KafkaStream object connected to the
inKS = kafkaStream("kafka.host.com",9092,"Triangles");
Read events from the
Triangles topic into a timetable. Preview the
data by viewing the first row. The
c triangle side lengths are stored as strings.
tt = readtimetable(inKS); row = tt(1,:)
row = 1×3 timetable timestamp a b c ___________ ____ ____ ____ 03-Sep-2022 "15" "31" "36"
detectExportOptions to generate an
ExportOptions object from the Kafka stream object. The function obtains the types used to export the variables
from the first row of the timetable.
opts = detectExportOptions(inKS,row);
getvartype to confirm that the side length variables are
currently exported to the stream as strings.
type = getvartype(opts,["a" "b" "c"]);
type = 1×3 string array "string" "string" "string"
Update the export options so that the side lengths are exported as
double values. Confirm the updated options by using
opts = setvartype(opts,["a","b","c"],"double"); [name,type] = getvartype(opts); fprintf("%s: %s\n", [name; type])
a: double b: double c: double
Connect to the stream to export data to
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"
Export the timetable to the new stream. The triangle side lengths in this stream are
opts — Event stream export options
Event stream export options, specified as an
selection — Selected variables
character vector | string scalar | cell array of character vectors | string array
Selected variables, specified as a character vector, string scalar, cell array of character vectors, or string array.
Variable names must be a subset of the names recognized by the
type — Data types of variables
Data types of variables exported to the stream, returned as a string array.
Each element of
type specifies the data type of a variable in
the stream. If you specified
selection, the order of the returned
types matches the order of the variables named in
Otherwise, the order matches the order of the variable names in the timetable row used
opts in the call to
name — Names of variables
Names of variables exported to the stream, returned as a string array.
Each element of
name specifies the name of a variable in the
stream. The number and order of the returned names matches the number and order of the
data types returned by
Introduced in R2022b