getvartype
This function requires Streaming Data Framework for MATLAB® Production Server™.
Description
Examples
Get Data Types of Exported Variables in Event Stream
Assume that you have a Kafka® server running at the network address kafka.host.com:9092
that has the topics Triangles
and
numericTriangles
.
Create a KafkaStream
object connected to the Triangles
topic.
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 a
, b
, and
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"
Use 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);
Use 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
getvartype
.
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 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"
Export the timetable to the new stream. The triangle side lengths in this stream are
of type double
.
writetimetable(outKS,tt);
Input Arguments
opts
— Event stream export options
ExportOptions
object
Event stream export options, specified as an ExportOptions
object.
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
opts
object.
Example: 'FanID'
Example: "FanID"
Example: {'FanID','vMotor'}
Example: ["FanID" "vMotor"]
Data Types: char
| string
| cell
Output Arguments
type
— Data types of variables
string array
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 selection
.
Otherwise, the order matches the order of the variable names in the timetable row used
to create opts
in the call to detectExportOptions
.
name
— Names of variables
string array
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 type
.
Version History
Introduced in R2022b
See Also
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)