@@ -80,14 +80,11 @@ public class Tablet {
8080 /** MeasurementId->indexOf({@link MeasurementSchema}) */
8181 private final Map <String , Integer > measurementIndex ;
8282
83- /** Timestamps in this {@link Tablet} */
84- public long [] timestamps ;
83+ private long [] timestamps ;
8584
86- /** Each object is a primitive type array, which represents values of one measurement */
87- public Object [] values ;
85+ private Object [] values ;
8886
89- /** Each {@link BitMap} represents the existence of each value in the current column. */
90- public BitMap [] bitMaps ;
87+ private BitMap [] bitMaps ;
9188
9289 /**
9390 * For compatibility with the usage of directly modifying Tablet content through public fields.
@@ -292,6 +289,7 @@ public void initBitMaps() {
292289 public void addTimestamp (int rowIndex , long timestamp ) {
293290 timestamps [rowIndex ] = timestamp ;
294291 this .rowSize = Math .max (this .rowSize , rowIndex + 1 );
292+ initBitMapsWithApiUsage ();
295293 }
296294
297295 public void addValue (final String measurementId , final int rowIndex , final Object value ) {
@@ -413,6 +411,10 @@ public void addValue(int rowIndex, String measurement, int val) {
413411
414412 @ TsFileApi
415413 public void addValue (int rowIndex , int columnIndex , int val ) {
414+ if (!(values [columnIndex ] instanceof int [])) {
415+ throw new IllegalArgumentException (
416+ "The data type of column index " + columnIndex + " is not INT32" );
417+ }
416418 final int [] sensor = (int []) values [columnIndex ];
417419 sensor [rowIndex ] = val ;
418420 updateBitMap (rowIndex , columnIndex , false );
@@ -426,6 +428,10 @@ public void addValue(int rowIndex, String measurement, long val) {
426428
427429 @ TsFileApi
428430 public void addValue (int rowIndex , int columnIndex , long val ) {
431+ if (!(values [columnIndex ] instanceof long [])) {
432+ throw new IllegalArgumentException (
433+ "The data type of column index " + columnIndex + " is not INT64/TIMESTAMP" );
434+ }
429435 final long [] sensor = (long []) values [columnIndex ];
430436 sensor [rowIndex ] = val ;
431437 updateBitMap (rowIndex , columnIndex , false );
@@ -439,6 +445,10 @@ public void addValue(int rowIndex, String measurement, float val) {
439445
440446 @ TsFileApi
441447 public void addValue (int rowIndex , int columnIndex , float val ) {
448+ if (!(values [columnIndex ] instanceof float [])) {
449+ throw new IllegalArgumentException (
450+ "The data type of column index " + columnIndex + " is not FLOAT" );
451+ }
442452 final float [] sensor = (float []) values [columnIndex ];
443453 sensor [rowIndex ] = val ;
444454 updateBitMap (rowIndex , columnIndex , false );
@@ -452,6 +462,10 @@ public void addValue(int rowIndex, String measurement, double val) {
452462
453463 @ TsFileApi
454464 public void addValue (int rowIndex , int columnIndex , double val ) {
465+ if (!(values [columnIndex ] instanceof double [])) {
466+ throw new IllegalArgumentException (
467+ "The data type of column index " + columnIndex + " is not DOUBLE" );
468+ }
455469 final double [] sensor = (double []) values [columnIndex ];
456470 sensor [rowIndex ] = val ;
457471 updateBitMap (rowIndex , columnIndex , false );
@@ -465,6 +479,10 @@ public void addValue(int rowIndex, String measurement, boolean val) {
465479
466480 @ TsFileApi
467481 public void addValue (int rowIndex , int columnIndex , boolean val ) {
482+ if (!(values [columnIndex ] instanceof boolean [])) {
483+ throw new IllegalArgumentException (
484+ "The data type of column index " + columnIndex + " is not BOOLEAN" );
485+ }
468486 final boolean [] sensor = (boolean []) values [columnIndex ];
469487 sensor [rowIndex ] = val ;
470488 updateBitMap (rowIndex , columnIndex , false );
@@ -478,6 +496,10 @@ public void addValue(int rowIndex, String measurement, String val) {
478496
479497 @ TsFileApi
480498 public void addValue (int rowIndex , int columnIndex , String val ) {
499+ if (!(values [columnIndex ] instanceof Binary [])) {
500+ throw new IllegalArgumentException (
501+ "The data type of column index " + columnIndex + " is not TEXT/STRING/BLOB" );
502+ }
481503 final Binary [] sensor = (Binary []) values [columnIndex ];
482504 sensor [rowIndex ] = new Binary (val , TSFileConfig .STRING_CHARSET );
483505 updateBitMap (rowIndex , columnIndex , false );
@@ -491,6 +513,10 @@ public void addValue(int rowIndex, String measurement, byte[] val) {
491513
492514 @ TsFileApi
493515 public void addValue (int rowIndex , int columnIndex , byte [] val ) {
516+ if (!(values [columnIndex ] instanceof Binary [])) {
517+ throw new IllegalArgumentException (
518+ "The data type of column index " + columnIndex + " is not TEXT/STRING/BLOB" );
519+ }
494520 final Binary [] sensor = (Binary []) values [columnIndex ];
495521 sensor [rowIndex ] = new Binary (val );
496522 updateBitMap (rowIndex , columnIndex , false );
@@ -504,6 +530,10 @@ public void addValue(int rowIndex, String measurement, LocalDate val) {
504530
505531 @ TsFileApi
506532 public void addValue (int rowIndex , int columnIndex , LocalDate val ) {
533+ if (!(values [columnIndex ] instanceof LocalDate [])) {
534+ throw new IllegalArgumentException (
535+ "The data type of column index " + columnIndex + " is not DATE" );
536+ }
507537 final LocalDate [] sensor = (LocalDate []) values [columnIndex ];
508538 sensor [rowIndex ] = val ;
509539 updateBitMap (rowIndex , columnIndex , false );
@@ -521,6 +551,15 @@ private int getColumnIndexByMeasurement(String measurement) {
521551 }
522552
523553 private void updateBitMap (int rowIndex , int columnIndex , boolean mark ) {
554+ initBitMapsWithApiUsage ();
555+ if (mark ) {
556+ bitMaps [columnIndex ].mark (rowIndex );
557+ } else {
558+ bitMaps [columnIndex ].unmark (rowIndex );
559+ }
560+ }
561+
562+ private void initBitMapsWithApiUsage () {
524563 if (bitMaps == null ) {
525564 initBitMaps ();
526565 }
@@ -530,11 +569,6 @@ private void updateBitMap(int rowIndex, int columnIndex, boolean mark) {
530569 bitMap .markAll ();
531570 }
532571 }
533- if (mark ) {
534- bitMaps [columnIndex ].mark (rowIndex );
535- } else {
536- bitMaps [columnIndex ].unmark (rowIndex );
537- }
538572 }
539573
540574 public List <IMeasurementSchema > getSchemas () {
@@ -1195,6 +1229,34 @@ public void setRowSize(int rowSize) {
11951229 this .rowSize = rowSize ;
11961230 }
11971231
1232+ public long getTimestamp (int i ) {
1233+ return timestamps [i ];
1234+ }
1235+
1236+ public long [] getTimestamps () {
1237+ return timestamps ;
1238+ }
1239+
1240+ public void setTimestamps (long [] timestamps ) {
1241+ this .timestamps = timestamps ;
1242+ }
1243+
1244+ public Object [] getValues () {
1245+ return values ;
1246+ }
1247+
1248+ public void setValues (Object [] values ) {
1249+ this .values = values ;
1250+ }
1251+
1252+ public BitMap [] getBitMaps () {
1253+ return bitMaps ;
1254+ }
1255+
1256+ public void setBitMaps (BitMap [] bitMaps ) {
1257+ this .bitMaps = bitMaps ;
1258+ }
1259+
11981260 public enum ColumnCategory {
11991261 TAG ,
12001262 FIELD ,
@@ -1247,4 +1309,13 @@ public void setTableName(String tableName) {
12471309 public List <ColumnCategory > getColumnTypes () {
12481310 return columnCategories ;
12491311 }
1312+
1313+ public boolean isSorted () {
1314+ for (int i = 1 ; i < rowSize ; i ++) {
1315+ if (timestamps [i ] < timestamps [i - 1 ]) {
1316+ return false ;
1317+ }
1318+ }
1319+ return true ;
1320+ }
12501321}
0 commit comments