Package org.apache.iotdb.tsfile.write
Class TsFileWriter
- java.lang.Object
-
- org.apache.iotdb.tsfile.write.TsFileWriter
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class TsFileWriter extends java.lang.Object implements java.lang.AutoCloseableTsFileWriter 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 callclose()method to flush the last data outside and close the normal outputStream and error outputStream.
-
-
Field Summary
Fields Modifier and Type Field Description protected static TSFileConfigconfigprotected Schemaschemaschema of this TsFile.
-
Constructor Summary
Constructors Modifier Constructor Description TsFileWriter(java.io.File file)init this TsFileWriter.TsFileWriter(java.io.File file, Schema schema)init this TsFileWriter.TsFileWriter(java.io.File file, Schema schema, TSFileConfig conf)init this TsFileWriter.TsFileWriter(TsFileIOWriter fileWriter)init this TsFileWriter.protectedTsFileWriter(TsFileIOWriter fileWriter, Schema schema, TSFileConfig conf)init this TsFileWriter.TsFileWriter(TsFileOutput output, Schema schema)init this TsFileWriter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()calling this method to write the last data remaining in memory and close the normal and error OutputStream.booleanflushAllChunkGroups()flush the data in all series writers of all chunk group writers and their page writers to outputStream.TsFileIOWritergetIOWriter()this function is only for Test.voidregisterAlignedTimeseries(Path devicePath, java.util.List<MeasurementSchema> measurementSchemas)Register aligned timeseries.voidregisterDevice(java.lang.String deviceId, java.lang.String templateName)This method is used to register all timeseries in the specified template under the specified device.voidregisterSchemaTemplate(java.lang.String templateName, java.util.Map<java.lang.String,MeasurementSchema> template, boolean isAligned)voidregisterTimeseries(Path devicePath, java.util.List<MeasurementSchema> measurementSchemas)Register nonAligned timeseries by groups.voidregisterTimeseries(Path devicePath, MeasurementSchema measurementSchema)Register nonAligned timeseries by single.booleanwrite(Tablet tablet)write a tabletbooleanwrite(TSRecord record)write a record in type of T.booleanwriteAligned(Tablet tablet)booleanwriteAligned(TSRecord record)
-
-
-
Field Detail
-
config
protected static final TSFileConfig config
-
schema
protected final Schema schema
schema of this TsFile.
-
-
Constructor Detail
-
TsFileWriter
public TsFileWriter(java.io.File file) throws java.io.IOExceptioninit 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.IOExceptioninit this TsFileWriter.- Parameters:
file- the File to be written by this TsFileWriterschema- 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 TsFileWriterschema- the schema of this TsFile- Throws:
java.io.IOException
-
TsFileWriter
public TsFileWriter(java.io.File file, Schema schema, TSFileConfig conf) throws java.io.IOExceptioninit this TsFileWriter.- Parameters:
file- the File to be written by this TsFileWriterschema- the schema of this TsFileconf- 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 TsFileschema- the schema of this TsFileconf- 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 WriteProcessExceptionThis 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, MeasurementSchema measurementSchema) throws WriteProcessException
Register nonAligned timeseries by single.- Parameters:
devicePath-measurementSchema-- 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 IOWriteProcessException- exception in write process
-
writeAligned
public boolean writeAligned(TSRecord record) throws java.io.IOException, WriteProcessException
- Throws:
java.io.IOExceptionWriteProcessException
-
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 IOWriteProcessException- exception in write process
-
writeAligned
public boolean writeAligned(Tablet tablet) throws java.io.IOException, WriteProcessException
- Throws:
java.io.IOExceptionWriteProcessException
-
flushAllChunkGroups
public boolean flushAllChunkGroups() throws java.io.IOExceptionflush 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.IOExceptioncalling this method to write the last data remaining in memory and close the normal and error OutputStream.- Specified by:
closein interfacejava.lang.AutoCloseable- Throws:
java.io.IOException- exception in IO
-
getIOWriter
public TsFileIOWriter getIOWriter()
this function is only for Test.- Returns:
- TsFileIOWriter
-
-