Class TsFileWriter

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public class TsFileWriter
    extends java.lang.Object
    implements java.lang.AutoCloseable
    TsFileWriter is the entrance for writing processing. It receives a record and send it to responding chunk group write. It checks memory size for all writing processing along its strategy and flush data stored in memory to OutputStream. At the end of writing, user should call close() method to flush the last data outside and close the normal outputStream and error outputStream.
    • Field Detail

      • schema

        protected final Schema schema
        schema of this TsFile.
    • Constructor Detail

      • TsFileWriter

        public TsFileWriter​(java.io.File file)
                     throws java.io.IOException
        init this TsFileWriter.
        Parameters:
        file - the File to be written by this TsFileWriter
        Throws:
        java.io.IOException
      • TsFileWriter

        public TsFileWriter​(TsFileIOWriter fileWriter)
                     throws java.io.IOException
        init this TsFileWriter.
        Parameters:
        fileWriter - the io writer of this TsFile
        Throws:
        java.io.IOException
      • TsFileWriter

        public TsFileWriter​(java.io.File file,
                            Schema schema)
                     throws java.io.IOException
        init this TsFileWriter.
        Parameters:
        file - the File to be written by this TsFileWriter
        schema - the schema of this TsFile
        Throws:
        java.io.IOException
      • TsFileWriter

        public TsFileWriter​(TsFileOutput output,
                            Schema schema)
                     throws java.io.IOException
        init this TsFileWriter.
        Parameters:
        output - the TsFileOutput of the file to be written by this TsFileWriter
        schema - the schema of this TsFile
        Throws:
        java.io.IOException
      • TsFileWriter

        public TsFileWriter​(java.io.File file,
                            Schema schema,
                            TSFileConfig conf)
                     throws java.io.IOException
        init this TsFileWriter.
        Parameters:
        file - the File to be written by this TsFileWriter
        schema - the schema of this TsFile
        conf - the configuration of this TsFile
        Throws:
        java.io.IOException
      • TsFileWriter

        protected TsFileWriter​(TsFileIOWriter fileWriter,
                               Schema schema,
                               TSFileConfig conf)
                        throws java.io.IOException
        init this TsFileWriter.
        Parameters:
        fileWriter - the io writer of this TsFile
        schema - the schema of this TsFile
        conf - the configuration of this TsFile
        Throws:
        java.io.IOException
    • Method Detail

      • registerSchemaTemplate

        public void registerSchemaTemplate​(java.lang.String templateName,
                                           java.util.Map<java.lang.String,​MeasurementSchema> template,
                                           boolean isAligned)
      • registerDevice

        public void registerDevice​(java.lang.String deviceId,
                                   java.lang.String templateName)
                            throws WriteProcessException
        This method is used to register all timeseries in the specified template under the specified device.
        Parameters:
        deviceId -
        templateName -
        Throws:
        WriteProcessException
      • registerTimeseries

        public void registerTimeseries​(Path devicePath,
                                       java.util.List<MeasurementSchema> measurementSchemas)
        Register nonAligned timeseries by groups.
        Parameters:
        devicePath -
        measurementSchemas -
      • registerAlignedTimeseries

        public void registerAlignedTimeseries​(Path devicePath,
                                              java.util.List<MeasurementSchema> measurementSchemas)
                                       throws WriteProcessException
        Register aligned timeseries. Once the device is registered for aligned timeseries, it cannot be expanded.
        Parameters:
        devicePath -
        measurementSchemas -
        Throws:
        WriteProcessException
      • write

        public boolean write​(TSRecord record)
                      throws java.io.IOException,
                             WriteProcessException
        write a record in type of T.
        Parameters:
        record - - record responding a data line
        Returns:
        true -size of tsfile or metadata reaches the threshold. false - otherwise
        Throws:
        java.io.IOException - exception in IO
        WriteProcessException - exception in write process
      • write

        public boolean write​(Tablet tablet)
                      throws java.io.IOException,
                             WriteProcessException
        write a tablet
        Parameters:
        tablet - - multiple time series of one device that share a time column
        Throws:
        java.io.IOException - exception in IO
        WriteProcessException - exception in write process
      • flushAllChunkGroups

        public boolean flushAllChunkGroups()
                                    throws java.io.IOException
        flush the data in all series writers of all chunk group writers and their page writers to outputStream.
        Returns:
        true - size of tsfile or metadata reaches the threshold. false - otherwise. But this function just return false, the Override of IoTDB may return true.
        Throws:
        java.io.IOException - exception in IO
      • close

        public void close()
                   throws java.io.IOException
        calling this method to write the last data remaining in memory and close the normal and error OutputStream.
        Specified by:
        close in interface java.lang.AutoCloseable
        Throws:
        java.io.IOException - exception in IO
      • getIOWriter

        public TsFileIOWriter getIOWriter()
        this function is only for Test.
        Returns:
        TsFileIOWriter