Skip to content

Commit ccc50a1

Browse files
committed
Revert "Modify tablet usage (#358)"
This reverts commit 12bbf56.
1 parent 94f655d commit ccc50a1

13 files changed

Lines changed: 115 additions & 201 deletions

File tree

java/examples/src/main/java/org/apache/tsfile/TsFileWriteAlignedWithTablet.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ private static void writeNonAlignedWithTablet(TsFileWriter tsFileWriter)
133133
measurementSchemas.add(new MeasurementSchema(SENSOR_1, TSDataType.INT64, TSEncoding.RLE));
134134
measurementSchemas.add(new MeasurementSchema(SENSOR_2, TSDataType.INT64, TSEncoding.RLE));
135135
Tablet tablet = new Tablet(DEVICE_2, measurementSchemas);
136+
long[] timestamps = tablet.timestamps;
137+
Object[] values = tablet.values;
136138
int rowNum = 100;
137139
int sensorNum = measurementSchemas.size();
138140
long timestamp = 1;
@@ -141,7 +143,8 @@ private static void writeNonAlignedWithTablet(TsFileWriter tsFileWriter)
141143
int row = tablet.getRowSize();
142144
tablet.addTimestamp(row, timestamp++);
143145
for (int i = 0; i < sensorNum; i++) {
144-
tablet.addValue(row, i, value);
146+
long[] sensor = (long[]) values[i];
147+
sensor[row] = value;
145148
}
146149
// write
147150
if (tablet.getRowSize() == tablet.getMaxRowNumber()) {

java/examples/src/main/java/org/apache/tsfile/TsFileWriteWithTablet.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,12 @@ private static void writeWithTablet(
8888
long startValue)
8989
throws IOException, WriteProcessException {
9090
Tablet tablet = new Tablet(deviceId, schemas);
91+
long[] timestamps = tablet.timestamps;
9192
long sensorNum = schemas.size();
9293

9394
for (long r = 0; r < rowNum; r++, startValue++) {
9495
int row = tablet.getRowSize();
95-
tablet.addTimestamp(row, startTime++);
96+
timestamps[row] = startTime++;
9697
for (int i = 0; i < sensorNum; i++) {
9798
tablet.addValue(
9899
schemas.get(i).getMeasurementName(),

java/tsfile/src/main/java/org/apache/tsfile/read/query/dataset/AbstractResultSet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ protected Field getNonNullField(int columnIndex) {
168168
}
169169

170170
protected Field getField(int columnIndex) {
171-
if (columnIndex > this.columnNameToColumnIndexMap.size() || columnIndex <= 0) {
171+
if (columnIndex > this.columnNameToColumnIndexMap.size()) {
172172
throw new IndexOutOfBoundsException("column index " + columnIndex + " out of bound");
173173
}
174174
Field field;

java/tsfile/src/main/java/org/apache/tsfile/utils/TsFileGeneratorUtils.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,16 @@ public static void writeWithTablet(
117117
boolean isAligned)
118118
throws IOException, WriteProcessException {
119119
Tablet tablet = new Tablet(deviceId, schemas);
120+
long[] timestamps = tablet.timestamps;
121+
Object[] values = tablet.values;
120122
long sensorNum = schemas.size();
121123

122124
for (long r = 0; r < rowNum; r++, startValue++) {
123125
int row = tablet.getRowSize();
124126
tablet.addTimestamp(row, startTime++);
125127
for (int i = 0; i < sensorNum; i++) {
126-
tablet.addValue(row, i, startValue);
128+
long[] sensor = (long[]) values[i];
129+
sensor[row] = startValue;
127130
}
128131
// write
129132
if (tablet.getRowSize() == tablet.getMaxRowNumber()) {

java/tsfile/src/main/java/org/apache/tsfile/write/chunk/AlignedChunkGroupWriterImpl.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public int write(Tablet tablet, int startRowIndex, int endRowIndex)
233233
// TODO: changing to a column-first style by calculating the remaining page space of each
234234
// column firsts
235235
for (int row = startRowIndex; row < endRowIndex; row++) {
236-
long time = tablet.getTimestamps()[row];
236+
long time = tablet.timestamps[row];
237237
checkIsHistoryData(time);
238238
for (int columnIndex = 0; columnIndex < tablet.getSchemas().size(); columnIndex++) {
239239
if (tablet.getColumnTypes() != null
@@ -242,43 +242,42 @@ public int write(Tablet tablet, int startRowIndex, int endRowIndex)
242242
}
243243

244244
boolean isNull =
245-
tablet.getBitMaps() != null
246-
&& tablet.getBitMaps()[columnIndex] != null
247-
&& tablet.getBitMaps()[columnIndex].isMarked(row);
245+
tablet.bitMaps != null
246+
&& tablet.bitMaps[columnIndex] != null
247+
&& tablet.bitMaps[columnIndex].isMarked(row);
248248
// check isNull by bitMap in tablet
249249
ValueChunkWriter valueChunkWriter =
250250
tryToAddSeriesWriterInternal(measurementSchemas.get(columnIndex));
251251
switch (measurementSchemas.get(columnIndex).getType()) {
252252
case BOOLEAN:
253-
valueChunkWriter.write(
254-
time, ((boolean[]) tablet.getValues()[columnIndex])[row], isNull);
253+
valueChunkWriter.write(time, ((boolean[]) tablet.values[columnIndex])[row], isNull);
255254
break;
256255
case INT32:
257-
valueChunkWriter.write(time, ((int[]) tablet.getValues()[columnIndex])[row], isNull);
256+
valueChunkWriter.write(time, ((int[]) tablet.values[columnIndex])[row], isNull);
258257
break;
259258
case DATE:
260259
valueChunkWriter.write(
261260
time,
262261
isNull
263262
? 0
264263
: DateUtils.parseDateExpressionToInt(
265-
((LocalDate[]) tablet.getValues()[columnIndex])[row]),
264+
((LocalDate[]) tablet.values[columnIndex])[row]),
266265
isNull);
267266
break;
268267
case INT64:
269268
case TIMESTAMP:
270-
valueChunkWriter.write(time, ((long[]) tablet.getValues()[columnIndex])[row], isNull);
269+
valueChunkWriter.write(time, ((long[]) tablet.values[columnIndex])[row], isNull);
271270
break;
272271
case FLOAT:
273-
valueChunkWriter.write(time, ((float[]) tablet.getValues()[columnIndex])[row], isNull);
272+
valueChunkWriter.write(time, ((float[]) tablet.values[columnIndex])[row], isNull);
274273
break;
275274
case DOUBLE:
276-
valueChunkWriter.write(time, ((double[]) tablet.getValues()[columnIndex])[row], isNull);
275+
valueChunkWriter.write(time, ((double[]) tablet.values[columnIndex])[row], isNull);
277276
break;
278277
case TEXT:
279278
case BLOB:
280279
case STRING:
281-
valueChunkWriter.write(time, ((Binary[]) tablet.getValues()[columnIndex])[row], isNull);
280+
valueChunkWriter.write(time, ((Binary[]) tablet.values[columnIndex])[row], isNull);
282281
break;
283282
default:
284283
throw new UnSupportedDataTypeException(

java/tsfile/src/main/java/org/apache/tsfile/write/chunk/NonAlignedChunkGroupWriterImpl.java

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -121,51 +121,42 @@ public int write(Tablet tablet, int startRowIndex, int endRowIndex)
121121
pointCount = 0;
122122
for (int row = startRowIndex; row < endRowIndex; row++) {
123123
// check isNull in tablet
124-
if (tablet.getBitMaps() != null
125-
&& tablet.getBitMaps()[column] != null
126-
&& tablet.getBitMaps()[column].isMarked(row)) {
124+
if (tablet.bitMaps != null
125+
&& tablet.bitMaps[column] != null
126+
&& tablet.bitMaps[column].isMarked(row)) {
127127
continue;
128128
}
129-
long time = tablet.getTimestamps()[row];
129+
long time = tablet.timestamps[row];
130130
checkIsHistoryData(measurementId, time);
131131
pointCount++;
132132
switch (tsDataType) {
133133
case INT32:
134-
chunkWriters.get(measurementId).write(time, ((int[]) tablet.getValues()[column])[row]);
134+
chunkWriters.get(measurementId).write(time, ((int[]) tablet.values[column])[row]);
135135
break;
136136
case DATE:
137137
chunkWriters
138138
.get(measurementId)
139139
.write(
140140
time,
141-
DateUtils.parseDateExpressionToInt(
142-
((LocalDate[]) tablet.getValues()[column])[row]));
141+
DateUtils.parseDateExpressionToInt(((LocalDate[]) tablet.values[column])[row]));
143142
break;
144143
case INT64:
145144
case TIMESTAMP:
146-
chunkWriters.get(measurementId).write(time, ((long[]) tablet.getValues()[column])[row]);
145+
chunkWriters.get(measurementId).write(time, ((long[]) tablet.values[column])[row]);
147146
break;
148147
case FLOAT:
149-
chunkWriters
150-
.get(measurementId)
151-
.write(time, ((float[]) tablet.getValues()[column])[row]);
148+
chunkWriters.get(measurementId).write(time, ((float[]) tablet.values[column])[row]);
152149
break;
153150
case DOUBLE:
154-
chunkWriters
155-
.get(measurementId)
156-
.write(time, ((double[]) tablet.getValues()[column])[row]);
151+
chunkWriters.get(measurementId).write(time, ((double[]) tablet.values[column])[row]);
157152
break;
158153
case BOOLEAN:
159-
chunkWriters
160-
.get(measurementId)
161-
.write(time, ((boolean[]) tablet.getValues()[column])[row]);
154+
chunkWriters.get(measurementId).write(time, ((boolean[]) tablet.values[column])[row]);
162155
break;
163156
case TEXT:
164157
case BLOB:
165158
case STRING:
166-
chunkWriters
167-
.get(measurementId)
168-
.write(time, ((Binary[]) tablet.getValues()[column])[row]);
159+
chunkWriters.get(measurementId).write(time, ((Binary[]) tablet.values[column])[row]);
169160
break;
170161
default:
171162
throw new UnSupportedDataTypeException(

java/tsfile/src/main/java/org/apache/tsfile/write/record/Tablet.java

Lines changed: 11 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,14 @@ public class Tablet {
8080
/** MeasurementId->indexOf({@link MeasurementSchema}) */
8181
private final Map<String, Integer> measurementIndex;
8282

83-
private long[] timestamps;
83+
/** Timestamps in this {@link Tablet} */
84+
public long[] timestamps;
8485

85-
private Object[] values;
86+
/** Each object is a primitive type array, which represents values of one measurement */
87+
public Object[] values;
8688

87-
private BitMap[] bitMaps;
89+
/** Each {@link BitMap} represents the existence of each value in the current column. */
90+
public BitMap[] bitMaps;
8891

8992
/**
9093
* For compatibility with the usage of directly modifying Tablet content through public fields.
@@ -289,7 +292,6 @@ public void initBitMaps() {
289292
public void addTimestamp(int rowIndex, long timestamp) {
290293
timestamps[rowIndex] = timestamp;
291294
this.rowSize = Math.max(this.rowSize, rowIndex + 1);
292-
initBitMapsWithApiUsage();
293295
}
294296

295297
public void addValue(final String measurementId, final int rowIndex, final Object value) {
@@ -411,10 +413,6 @@ public void addValue(int rowIndex, String measurement, int val) {
411413

412414
@TsFileApi
413415
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-
}
418416
final int[] sensor = (int[]) values[columnIndex];
419417
sensor[rowIndex] = val;
420418
updateBitMap(rowIndex, columnIndex, false);
@@ -428,10 +426,6 @@ public void addValue(int rowIndex, String measurement, long val) {
428426

429427
@TsFileApi
430428
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-
}
435429
final long[] sensor = (long[]) values[columnIndex];
436430
sensor[rowIndex] = val;
437431
updateBitMap(rowIndex, columnIndex, false);
@@ -445,10 +439,6 @@ public void addValue(int rowIndex, String measurement, float val) {
445439

446440
@TsFileApi
447441
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-
}
452442
final float[] sensor = (float[]) values[columnIndex];
453443
sensor[rowIndex] = val;
454444
updateBitMap(rowIndex, columnIndex, false);
@@ -462,10 +452,6 @@ public void addValue(int rowIndex, String measurement, double val) {
462452

463453
@TsFileApi
464454
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-
}
469455
final double[] sensor = (double[]) values[columnIndex];
470456
sensor[rowIndex] = val;
471457
updateBitMap(rowIndex, columnIndex, false);
@@ -479,10 +465,6 @@ public void addValue(int rowIndex, String measurement, boolean val) {
479465

480466
@TsFileApi
481467
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-
}
486468
final boolean[] sensor = (boolean[]) values[columnIndex];
487469
sensor[rowIndex] = val;
488470
updateBitMap(rowIndex, columnIndex, false);
@@ -496,10 +478,6 @@ public void addValue(int rowIndex, String measurement, String val) {
496478

497479
@TsFileApi
498480
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-
}
503481
final Binary[] sensor = (Binary[]) values[columnIndex];
504482
sensor[rowIndex] = new Binary(val, TSFileConfig.STRING_CHARSET);
505483
updateBitMap(rowIndex, columnIndex, false);
@@ -513,10 +491,6 @@ public void addValue(int rowIndex, String measurement, byte[] val) {
513491

514492
@TsFileApi
515493
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-
}
520494
final Binary[] sensor = (Binary[]) values[columnIndex];
521495
sensor[rowIndex] = new Binary(val);
522496
updateBitMap(rowIndex, columnIndex, false);
@@ -530,10 +504,6 @@ public void addValue(int rowIndex, String measurement, LocalDate val) {
530504

531505
@TsFileApi
532506
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-
}
537507
final LocalDate[] sensor = (LocalDate[]) values[columnIndex];
538508
sensor[rowIndex] = val;
539509
updateBitMap(rowIndex, columnIndex, false);
@@ -551,15 +521,6 @@ private int getColumnIndexByMeasurement(String measurement) {
551521
}
552522

553523
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() {
563524
if (bitMaps == null) {
564525
initBitMaps();
565526
}
@@ -569,6 +530,11 @@ private void initBitMapsWithApiUsage() {
569530
bitMap.markAll();
570531
}
571532
}
533+
if (mark) {
534+
bitMaps[columnIndex].mark(rowIndex);
535+
} else {
536+
bitMaps[columnIndex].unmark(rowIndex);
537+
}
572538
}
573539

574540
public List<IMeasurementSchema> getSchemas() {
@@ -1229,34 +1195,6 @@ public void setRowSize(int rowSize) {
12291195
this.rowSize = rowSize;
12301196
}
12311197

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-
12601198
public enum ColumnCategory {
12611199
TAG,
12621200
FIELD,
@@ -1309,13 +1247,4 @@ public void setTableName(String tableName) {
13091247
public List<ColumnCategory> getColumnTypes() {
13101248
return columnCategories;
13111249
}
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-
}
13211250
}

0 commit comments

Comments
 (0)