diff --git a/java/common/src/main/java/org/apache/tsfile/annotations/TableModel.java b/java/common/src/main/java/org/apache/tsfile/annotations/TableModel.java new file mode 100644 index 000000000..a59f89530 --- /dev/null +++ b/java/common/src/main/java/org/apache/tsfile/annotations/TableModel.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tsfile.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * This annotation indicates that the related filed, method, or constructor is only used for + * TableModel. + */ +@Target({ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR}) +@Retention(RetentionPolicy.SOURCE) +public @interface TableModel {} diff --git a/java/common/src/main/java/org/apache/tsfile/annotations/TreeModel.java b/java/common/src/main/java/org/apache/tsfile/annotations/TreeModel.java new file mode 100644 index 000000000..bb0520aaa --- /dev/null +++ b/java/common/src/main/java/org/apache/tsfile/annotations/TreeModel.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tsfile.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * This annotation indicates that the related filed, method, or constructor is only used for + * TreeModel. + */ +@Target({ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR}) +@Retention(RetentionPolicy.SOURCE) +public @interface TreeModel {} diff --git a/java/tsfile/src/main/java/org/apache/tsfile/common/TsFileApi.java b/java/common/src/main/java/org/apache/tsfile/annotations/TsFileApi.java similarity index 96% rename from java/tsfile/src/main/java/org/apache/tsfile/common/TsFileApi.java rename to java/common/src/main/java/org/apache/tsfile/annotations/TsFileApi.java index d27f0aca4..a97160438 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/common/TsFileApi.java +++ b/java/common/src/main/java/org/apache/tsfile/annotations/TsFileApi.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.tsfile.common; +package org.apache.tsfile.annotations; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/java/tsfile/src/main/java/org/apache/tsfile/file/metadata/ColumnSchemaBuilder.java b/java/tsfile/src/main/java/org/apache/tsfile/file/metadata/ColumnSchemaBuilder.java index 8e6747649..7fcb66d7e 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/file/metadata/ColumnSchemaBuilder.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/file/metadata/ColumnSchemaBuilder.java @@ -19,7 +19,7 @@ package org.apache.tsfile.file.metadata; -import org.apache.tsfile.common.TsFileApi; +import org.apache.tsfile.annotations.TsFileApi; import org.apache.tsfile.enums.TSDataType; import org.apache.tsfile.write.record.Tablet.ColumnCategory; diff --git a/java/tsfile/src/main/java/org/apache/tsfile/file/metadata/TableSchema.java b/java/tsfile/src/main/java/org/apache/tsfile/file/metadata/TableSchema.java index f9c9f5d89..c5792e892 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/file/metadata/TableSchema.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/file/metadata/TableSchema.java @@ -19,7 +19,7 @@ package org.apache.tsfile.file.metadata; -import org.apache.tsfile.common.TsFileApi; +import org.apache.tsfile.annotations.TsFileApi; import org.apache.tsfile.compatibility.DeserializeConfig; import org.apache.tsfile.enums.TSDataType; import org.apache.tsfile.utils.ReadWriteForEncodingUtils; diff --git a/java/tsfile/src/main/java/org/apache/tsfile/read/TsFileReader.java b/java/tsfile/src/main/java/org/apache/tsfile/read/TsFileReader.java index bf0a3440c..158607266 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/read/TsFileReader.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/read/TsFileReader.java @@ -19,7 +19,7 @@ package org.apache.tsfile.read; -import org.apache.tsfile.common.TsFileApi; +import org.apache.tsfile.annotations.TsFileApi; import org.apache.tsfile.read.controller.CachedChunkLoaderImpl; import org.apache.tsfile.read.controller.IChunkLoader; import org.apache.tsfile.read.controller.IMetadataQuerier; diff --git a/java/tsfile/src/main/java/org/apache/tsfile/read/query/dataset/AbstractResultSet.java b/java/tsfile/src/main/java/org/apache/tsfile/read/query/dataset/AbstractResultSet.java index 8a28866de..5b07dd46d 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/read/query/dataset/AbstractResultSet.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/read/query/dataset/AbstractResultSet.java @@ -19,7 +19,7 @@ package org.apache.tsfile.read.query.dataset; -import org.apache.tsfile.common.TsFileApi; +import org.apache.tsfile.annotations.TsFileApi; import org.apache.tsfile.enums.TSDataType; import org.apache.tsfile.exception.NullFieldException; import org.apache.tsfile.read.common.Field; diff --git a/java/tsfile/src/main/java/org/apache/tsfile/read/query/dataset/ResultSet.java b/java/tsfile/src/main/java/org/apache/tsfile/read/query/dataset/ResultSet.java index 02f23071a..0f2d72bf1 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/read/query/dataset/ResultSet.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/read/query/dataset/ResultSet.java @@ -19,7 +19,7 @@ package org.apache.tsfile.read.query.dataset; -import org.apache.tsfile.common.TsFileApi; +import org.apache.tsfile.annotations.TsFileApi; import java.io.IOException; import java.time.LocalDate; diff --git a/java/tsfile/src/main/java/org/apache/tsfile/read/query/dataset/ResultSetMetadata.java b/java/tsfile/src/main/java/org/apache/tsfile/read/query/dataset/ResultSetMetadata.java index 506346b31..aeef3d948 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/read/query/dataset/ResultSetMetadata.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/read/query/dataset/ResultSetMetadata.java @@ -19,7 +19,7 @@ package org.apache.tsfile.read.query.dataset; -import org.apache.tsfile.common.TsFileApi; +import org.apache.tsfile.annotations.TsFileApi; import org.apache.tsfile.enums.TSDataType; public interface ResultSetMetadata { diff --git a/java/tsfile/src/main/java/org/apache/tsfile/read/query/dataset/TreeResultSet.java b/java/tsfile/src/main/java/org/apache/tsfile/read/query/dataset/TreeResultSet.java index e9c162cb8..0f3aade64 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/read/query/dataset/TreeResultSet.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/read/query/dataset/TreeResultSet.java @@ -19,7 +19,7 @@ package org.apache.tsfile.read.query.dataset; -import org.apache.tsfile.common.TsFileApi; +import org.apache.tsfile.annotations.TsFileApi; import org.apache.tsfile.read.common.Path; import java.io.IOException; diff --git a/java/tsfile/src/main/java/org/apache/tsfile/read/v4/DeviceTableModelReader.java b/java/tsfile/src/main/java/org/apache/tsfile/read/v4/DeviceTableModelReader.java index 50f6ab6e3..f9c9870a9 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/read/v4/DeviceTableModelReader.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/read/v4/DeviceTableModelReader.java @@ -19,7 +19,7 @@ package org.apache.tsfile.read.v4; -import org.apache.tsfile.common.TsFileApi; +import org.apache.tsfile.annotations.TsFileApi; import org.apache.tsfile.enums.TSDataType; import org.apache.tsfile.exception.read.ReadProcessException; import org.apache.tsfile.exception.write.NoMeasurementException; diff --git a/java/tsfile/src/main/java/org/apache/tsfile/read/v4/ITsFileReader.java b/java/tsfile/src/main/java/org/apache/tsfile/read/v4/ITsFileReader.java index 9f0312378..885e84524 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/read/v4/ITsFileReader.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/read/v4/ITsFileReader.java @@ -19,7 +19,7 @@ package org.apache.tsfile.read.v4; -import org.apache.tsfile.common.TsFileApi; +import org.apache.tsfile.annotations.TsFileApi; import org.apache.tsfile.exception.read.ReadProcessException; import org.apache.tsfile.exception.write.NoMeasurementException; import org.apache.tsfile.exception.write.NoTableException; diff --git a/java/tsfile/src/main/java/org/apache/tsfile/read/v4/TsFileReaderBuilder.java b/java/tsfile/src/main/java/org/apache/tsfile/read/v4/TsFileReaderBuilder.java index a6fcc196d..16be54738 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/read/v4/TsFileReaderBuilder.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/read/v4/TsFileReaderBuilder.java @@ -19,7 +19,7 @@ package org.apache.tsfile.read.v4; -import org.apache.tsfile.common.TsFileApi; +import org.apache.tsfile.annotations.TsFileApi; import java.io.File; import java.io.IOException; diff --git a/java/tsfile/src/main/java/org/apache/tsfile/write/TsFileWriter.java b/java/tsfile/src/main/java/org/apache/tsfile/write/TsFileWriter.java index d2f77400c..a4f43fa45 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/write/TsFileWriter.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/write/TsFileWriter.java @@ -18,7 +18,7 @@ */ package org.apache.tsfile.write; -import org.apache.tsfile.common.TsFileApi; +import org.apache.tsfile.annotations.TsFileApi; import org.apache.tsfile.common.conf.TSFileConfig; import org.apache.tsfile.common.conf.TSFileDescriptor; import org.apache.tsfile.encrypt.EncryptParameter; diff --git a/java/tsfile/src/main/java/org/apache/tsfile/write/record/TSRecord.java b/java/tsfile/src/main/java/org/apache/tsfile/write/record/TSRecord.java index 68aa126a8..b7c248310 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/write/record/TSRecord.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/write/record/TSRecord.java @@ -18,7 +18,7 @@ */ package org.apache.tsfile.write.record; -import org.apache.tsfile.common.TsFileApi; +import org.apache.tsfile.annotations.TsFileApi; import org.apache.tsfile.common.conf.TSFileConfig; import org.apache.tsfile.file.metadata.IDeviceID; import org.apache.tsfile.file.metadata.IDeviceID.Factory; diff --git a/java/tsfile/src/main/java/org/apache/tsfile/write/record/Tablet.java b/java/tsfile/src/main/java/org/apache/tsfile/write/record/Tablet.java index 4acf943b1..02fbb72e8 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/write/record/Tablet.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/write/record/Tablet.java @@ -19,7 +19,9 @@ package org.apache.tsfile.write.record; -import org.apache.tsfile.common.TsFileApi; +import org.apache.tsfile.annotations.TableModel; +import org.apache.tsfile.annotations.TreeModel; +import org.apache.tsfile.annotations.TsFileApi; import org.apache.tsfile.common.conf.TSFileConfig; import org.apache.tsfile.enums.TSDataType; import org.apache.tsfile.file.metadata.IDeviceID; @@ -105,10 +107,12 @@ public class Tablet { * @param schemas the list of {@link MeasurementSchema}s for creating the tablet, only * measurementId and type take effects */ + @TreeModel public Tablet(String deviceId, List schemas) { this(deviceId, schemas, DEFAULT_SIZE); } + @TreeModel public Tablet(String deviceId, List schemas, int maxRowNumber) { this.insertTargetName = deviceId; this.schemas = new ArrayList<>(schemas); @@ -122,10 +126,12 @@ public Tablet(String deviceId, List schemas, int maxRowNumbe reset(); } + @TreeModel public Tablet(IDeviceID deviceID, List measurementList, List dataTypeList) { this(deviceID, measurementList, dataTypeList, DEFAULT_SIZE); } + @TreeModel public Tablet( IDeviceID deviceID, List measurementList, @@ -136,10 +142,12 @@ public Tablet( measurementList, dataTypeList, ColumnCategory.nCopy(ColumnCategory.MEASUREMENT, measurementList.size()), - maxRowNumber); + maxRowNumber, + true); } @TsFileApi + @TableModel public Tablet(List columnNameList, List dataTypeList) { this(columnNameList, dataTypeList, DEFAULT_SIZE); } @@ -153,25 +161,28 @@ public Tablet(List columnNameList, List dataTypeList) { * @param maxRowNum the maximum number of rows for this tablet */ @TsFileApi + @TableModel public Tablet(List columnNameList, List dataTypeList, int maxRowNum) { this(null, columnNameList, dataTypeList, null, maxRowNum, false); } + @TableModel public Tablet( String tableName, - List measurementList, + List columnNameList, List dataTypeList, List columnCategoryList) { - this(tableName, measurementList, dataTypeList, columnCategoryList, DEFAULT_SIZE); + this(tableName, columnNameList, dataTypeList, columnCategoryList, DEFAULT_SIZE); } + @TableModel public Tablet( - String insertTargetName, - List measurementList, + String tableName, + List columnNameList, List dataTypeList, List columnCategoryList, int maxRowNum) { - this(insertTargetName, measurementList, dataTypeList, columnCategoryList, maxRowNum, true); + this(tableName, columnNameList, dataTypeList, columnCategoryList, maxRowNum, true); } protected Tablet( @@ -210,6 +221,7 @@ protected Tablet( * @param bitMaps given {@link BitMap}s * @param maxRowNumber the maximum number of rows for this {@link Tablet} */ + @TreeModel public Tablet( String deviceId, List schemas, @@ -217,25 +229,29 @@ public Tablet( Object[] values, BitMap[] bitMaps, int maxRowNumber) { - this( - deviceId, - schemas, - ColumnCategory.nCopy(ColumnCategory.MEASUREMENT, schemas.size()), - timestamps, - values, - bitMaps, - maxRowNumber); + this.insertTargetName = deviceId; + this.schemas = schemas; + setColumnCategories(ColumnCategory.nCopy(ColumnCategory.MEASUREMENT, schemas.size())); + this.timestamps = timestamps; + this.values = values; + this.bitMaps = bitMaps; + this.maxRowNumber = maxRowNumber; + // rowSize == maxRowNumber in this case + this.rowSize = maxRowNumber; + measurementIndex = new HashMap<>(); + constructMeasurementIndexMap(); } + @TableModel public Tablet( - String insertTargetName, + String tableName, List schemas, List columnCategories, long[] timestamps, Object[] values, BitMap[] bitMaps, int maxRowNumber) { - this.insertTargetName = insertTargetName; + this.insertTargetName = tableName; this.schemas = schemas; setColumnCategories(columnCategories); this.timestamps = timestamps; @@ -1144,6 +1160,7 @@ public Object getValue(int i, int j) { * @param i a row number. * @return the IDeviceID of the i-th row. */ + @TableModel public IDeviceID getDeviceID(int i) { String[] idArray = new String[idColumnIndexes.size() + 1]; idArray[0] = getTableName(); @@ -1193,6 +1210,7 @@ public static List nCopy(ColumnCategory type, int n) { * * @return the insertTargetName as the deviceId */ + @TreeModel public String getDeviceId() { return insertTargetName; } @@ -1202,10 +1220,12 @@ public String getDeviceId() { * * @param deviceId set the deviceId as the insertTargetName */ + @TreeModel public void setDeviceId(String deviceId) { this.insertTargetName = deviceId; } + @TableModel public String getTableName() { return insertTargetName == null ? null : insertTargetName.toLowerCase(); } @@ -1215,6 +1235,7 @@ public String getTableName() { * * @param tableName set the tableName as the insertTargetName */ + @TableModel public void setTableName(String tableName) { this.insertTargetName = tableName.toLowerCase(); } diff --git a/java/tsfile/src/main/java/org/apache/tsfile/write/schema/MeasurementSchema.java b/java/tsfile/src/main/java/org/apache/tsfile/write/schema/MeasurementSchema.java index 7d078477d..6c36dfe1d 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/write/schema/MeasurementSchema.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/write/schema/MeasurementSchema.java @@ -18,7 +18,7 @@ */ package org.apache.tsfile.write.schema; -import org.apache.tsfile.common.TsFileApi; +import org.apache.tsfile.annotations.TsFileApi; import org.apache.tsfile.common.conf.TSFileDescriptor; import org.apache.tsfile.encoding.encoder.Encoder; import org.apache.tsfile.encoding.encoder.TSEncodingBuilder; diff --git a/java/tsfile/src/main/java/org/apache/tsfile/write/v4/AbstractTableModelTsFileWriter.java b/java/tsfile/src/main/java/org/apache/tsfile/write/v4/AbstractTableModelTsFileWriter.java index 80069d3eb..c22787530 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/write/v4/AbstractTableModelTsFileWriter.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/write/v4/AbstractTableModelTsFileWriter.java @@ -19,7 +19,7 @@ package org.apache.tsfile.write.v4; -import org.apache.tsfile.common.TsFileApi; +import org.apache.tsfile.annotations.TsFileApi; import org.apache.tsfile.common.conf.TSFileConfig; import org.apache.tsfile.common.conf.TSFileDescriptor; import org.apache.tsfile.encrypt.EncryptParameter; diff --git a/java/tsfile/src/main/java/org/apache/tsfile/write/v4/DeviceTableModelWriter.java b/java/tsfile/src/main/java/org/apache/tsfile/write/v4/DeviceTableModelWriter.java index 4b517759d..bae685e14 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/write/v4/DeviceTableModelWriter.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/write/v4/DeviceTableModelWriter.java @@ -19,7 +19,7 @@ package org.apache.tsfile.write.v4; -import org.apache.tsfile.common.TsFileApi; +import org.apache.tsfile.annotations.TsFileApi; import org.apache.tsfile.exception.write.ConflictDataTypeException; import org.apache.tsfile.exception.write.NoMeasurementException; import org.apache.tsfile.exception.write.NoTableException; diff --git a/java/tsfile/src/main/java/org/apache/tsfile/write/v4/ITsFileWriter.java b/java/tsfile/src/main/java/org/apache/tsfile/write/v4/ITsFileWriter.java index e3a34634c..8610ee1fd 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/write/v4/ITsFileWriter.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/write/v4/ITsFileWriter.java @@ -19,7 +19,7 @@ package org.apache.tsfile.write.v4; -import org.apache.tsfile.common.TsFileApi; +import org.apache.tsfile.annotations.TsFileApi; import org.apache.tsfile.exception.write.WriteProcessException; import org.apache.tsfile.write.record.Tablet; diff --git a/java/tsfile/src/main/java/org/apache/tsfile/write/v4/TsFileWriterBuilder.java b/java/tsfile/src/main/java/org/apache/tsfile/write/v4/TsFileWriterBuilder.java index da3ebc4c3..267bc8614 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/write/v4/TsFileWriterBuilder.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/write/v4/TsFileWriterBuilder.java @@ -19,7 +19,7 @@ package org.apache.tsfile.write.v4; -import org.apache.tsfile.common.TsFileApi; +import org.apache.tsfile.annotations.TsFileApi; import org.apache.tsfile.file.metadata.TableSchema; import java.io.File;