Main Content

writetimetable

Write timetable to event stream

Since R2022b

    This function requires Streaming Data Framework for MATLAB® Production Server™.

    Description

    example

    writetimetable(stream,tt) writes the timetable tt to the end of the event stream stream.

    writetimetable converts rows of a timetable into events in an event stream, where:

    • The column names in the timetable become variable names in the event body.

    • The values in each event row become the values of those variables.

    • The row timestamp becomes the event timestamp.

    You can append data to a stream but cannot modify data that is already written to a stream.

    example

    writetimetable(ks,tt,MissingTopic=action) specifies whether to create a topic when writing a timetable to an event stream hosted by Kafka® or fail the write operation when the topic is missing. If the Kafka cluster that you are writing to is configured to auto-create topics, specifying action has no effect.

    Examples

    collapse all

    Load air quality data and weather measurements into a timetable.

    load indoors

    Create an InMemoryStream object to connect to an event stream hosted by MATLAB.

    i = inMemoryStream;

    Write the timetable to the event stream.

    writetimetable(i,indoors)

    Preview the data in the event stream.

    preview(i)
    ans =
    
      8×2 timetable
    
               Time            Humidity    AirQuality
        ___________________    ________    __________
    
        2015-11-15 00:00:24       36           80    
        2015-11-15 01:13:35       36           80    
        2015-11-15 02:26:47       37           79    
        2015-11-15 03:39:59       37           82    
        2015-11-15 04:53:11       36           80    
        2015-11-15 06:06:23       36           80    
        2015-11-15 07:19:35       36           80    
        2015-11-15 08:32:47       37           80    

    Load air quality data and weather measurements into a timetable.

    load indoors

    Assume that you have a Kafka host running at network address kafka.host.com:9092. Create a KafkaStream object that processes 10 stream events at a time.

    ks = kafkaStream("kafka.host.com",9092,"IndoorTemp",Rows=10);

    Create the IndoorTemp topic and write the timetable to it.

    writetimetable(ks,indoors)

    Read the first 10 events from the stream.

    tt1 = readtimetable(ks)
    tt1 =
    
      10×3 timetable
    
             timestamp          Humidity    AirQuality    key
        ____________________    ________    __________    ___
    
        15-Nov-2015 00:00:24       36           80        "" 
        15-Nov-2015 01:13:35       36           80        "" 
        15-Nov-2015 02:26:47       37           79        "" 
        15-Nov-2015 03:39:59       37           82        "" 
        15-Nov-2015 04:53:11       36           80        "" 
        15-Nov-2015 06:06:23       36           80        "" 
        15-Nov-2015 07:19:35       36           80        "" 
        15-Nov-2015 08:32:47       37           80        "" 
        15-Nov-2015 09:45:59       37           79        "" 
        15-Nov-2015 10:59:11       36           80        "" 

    Read the next 10 events from the stream.

    tt2 = readtimetable(ks)
    tt2 =
    
      10×3 timetable
    
             timestamp          Humidity    AirQuality    key
        ____________________    ________    __________    ___
    
        16-Nov-2015 00:24:22       36           81        "" 
        16-Nov-2015 01:37:34       37           80        "" 
        16-Nov-2015 02:50:46       36           79        "" 
        16-Nov-2015 04:03:58       37           80        "" 
        16-Nov-2015 05:17:09       37           81        "" 
        16-Nov-2015 06:30:21       36           79        "" 
        16-Nov-2015 07:43:33       37           79        "" 
        16-Nov-2015 08:56:45       37           79        "" 
        16-Nov-2015 10:09:57       37           85        "" 
        16-Nov-2015 11:23:09       37           80        ""  

    Input Arguments

    collapse all

    Object connected to an event stream, specified as a KafkaStream, InMemoryStream, or TestStream object.

    Input timetable.

    Object connected to a Kafka stream topic, specified as a KafkaStream object.

    Action to take if the topic to write the timetable to does not exist, specified as one of the following values:

    • "create" — Creates new topic, if you have the required permissions on the Kafka host.

    • "fail" — Does not create a new topic and the write operation fails.

    Data Types: char | string

    Version History

    Introduced in R2022b