Skip to content

Commit 47f7180

Browse files
committed
Refactor
1 parent 80e2d01 commit 47f7180

10 files changed

Lines changed: 74 additions & 136 deletions

File tree

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/impl/ClientRPCServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ public TSExecuteStatementResp executeFastLastDataQueryForOnePrefixPath(
12271227
for (final Map.Entry<String, Pair<TSDataType, TimeValuePair>> measurementLastEntry :
12281228
device2MeasurementLastEntry.getValue().entrySet()) {
12291229
final TimeValuePair tvPair = measurementLastEntry.getValue().getRight();
1230-
if (tvPair != TableDeviceLastCache.EMPTY_TIME_VALUE_PAIR) {
1230+
if (tvPair != TableDeviceLastCache.PLACEHOLDER_EMPTY_COLUMN) {
12311231
LastQueryUtil.appendLastValueRespectBlob(
12321232
builder,
12331233
tvPair.getTimestamp(),

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/process/last/AbstractUpdateLastCacheOperator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ protected void mayUpdateLastCache(
127127
new TimeValuePair[] {
128128
Objects.nonNull(value)
129129
? new TimeValuePair(time, value)
130-
: needUpdateNullEntry ? TableDeviceLastCache.EMPTY_TIME_VALUE_PAIR : null
130+
: needUpdateNullEntry ? TableDeviceLastCache.PLACEHOLDER_EMPTY_COLUMN : null
131131
},
132132
fullPath.isUnderAlignedEntity(),
133133
new IMeasurementSchema[] {fullPath.getMeasurementSchema()});
@@ -139,7 +139,7 @@ protected void mayUpdateLastCache(
139139
seriesScanInfo.right = new TimeValuePair(time, value);
140140
} else {
141141
seriesScanInfo.right =
142-
needUpdateNullEntry ? TableDeviceLastCache.EMPTY_TIME_VALUE_PAIR : null;
142+
needUpdateNullEntry ? TableDeviceLastCache.PLACEHOLDER_EMPTY_COLUMN : null;
143143
}
144144
}
145145

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/LastQueryAggTableScanOperator.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
import static com.google.common.base.Preconditions.checkState;
5454
import static org.apache.iotdb.calc.execution.operator.source.relational.aggregation.Utils.serializeTimeValueWithNull;
5555
import static org.apache.iotdb.commons.queryengine.plan.relational.type.InternalTypeManager.getTSDataType;
56-
import static org.apache.iotdb.db.queryengine.plan.relational.metadata.fetcher.cache.TableDeviceLastCache.EMPTY_PRIMITIVE_TYPE;
57-
import static org.apache.iotdb.db.queryengine.plan.relational.metadata.fetcher.cache.TableDeviceLastCache.EMPTY_TIME_VALUE_PAIR;
56+
import static org.apache.iotdb.db.queryengine.plan.relational.metadata.fetcher.cache.TableDeviceLastCache.PLACEHOLDER_EMPTY_COLUMN;
57+
import static org.apache.iotdb.db.queryengine.plan.relational.metadata.fetcher.cache.TableDeviceLastCache.PLACEHOLDER_NO_VALUE;
5858

5959
/**
6060
* This class is used to execute aggregation table scan when apply {@code canUseLastCacheOptimize()}
@@ -279,7 +279,7 @@ private void buildResultUseLastRowCache() {
279279
TsPrimitiveType tsPrimitiveType =
280280
lastRowCacheResults.get(currentHitCacheIndex).getRight()[measurementIdx];
281281
long lastByTime = lastRowCacheResults.get(currentHitCacheIndex).getLeft().getAsLong();
282-
if (tsPrimitiveType == EMPTY_PRIMITIVE_TYPE) {
282+
if (tsPrimitiveType == PLACEHOLDER_NO_VALUE) {
283283
// there is no data for this time series
284284
if (aggregator.getStep().isOutputPartial()) {
285285
columnBuilder.writeBinary(
@@ -322,7 +322,7 @@ private void buildResultUseLastValuesCache() {
322322
TsPrimitiveType timeLastValue = currentHitResult[currentHitResult.length - 1].getValue();
323323
// when there is no data, no need to append result if the query is GROUP BY or output of
324324
// aggregator is partial (final operator will produce NULL result)
325-
if (timeLastValue == EMPTY_PRIMITIVE_TYPE
325+
if (timeLastValue == PLACEHOLDER_NO_VALUE
326326
&& (groupingKeySize != 0 || tableAggregators.get(0).getStep().isOutputPartial())) {
327327
outputDeviceIndex++;
328328
currentHitCacheIndex++;
@@ -346,7 +346,7 @@ private void buildResultUseLastValuesCache() {
346346
getNthIdColumnValue(
347347
cachedDeviceEntries.get(currentHitCacheIndex), aggColumnsIndexArray[columnIdx]);
348348
if (aggregator.getAccumulator() instanceof LastDescAccumulator) {
349-
if (timeLastValue == EMPTY_PRIMITIVE_TYPE || id == null) {
349+
if (timeLastValue == PLACEHOLDER_NO_VALUE || id == null) {
350350
columnBuilder.appendNull();
351351
} else {
352352
if (aggregator.getStep().isOutputPartial()) {
@@ -368,7 +368,7 @@ private void buildResultUseLastValuesCache() {
368368
long lastTime =
369369
lastValuesCacheResults.get(currentHitCacheIndex)[measurementIdx].getTimestamp();
370370

371-
if (timeLastValue == EMPTY_PRIMITIVE_TYPE || id == null) {
371+
if (timeLastValue == PLACEHOLDER_NO_VALUE || id == null) {
372372
if (aggregator.getStep().isOutputPartial()) {
373373
columnBuilder.writeBinary(
374374
new Binary(
@@ -399,7 +399,7 @@ private void buildResultUseLastValuesCache() {
399399
cachedDeviceEntries.get(currentHitCacheIndex)
400400
.getAttributeColumnValues()[aggColumnsIndexArray[columnIdx]];
401401
if (aggregator.getAccumulator() instanceof LastDescAccumulator) {
402-
if (timeLastValue == EMPTY_PRIMITIVE_TYPE || attribute == null) {
402+
if (timeLastValue == PLACEHOLDER_NO_VALUE || attribute == null) {
403403
columnBuilder.appendNull();
404404
} else {
405405
if (aggregator.getStep().isOutputPartial()) {
@@ -420,7 +420,7 @@ private void buildResultUseLastValuesCache() {
420420
lastValuesCacheResults.get(currentHitCacheIndex)[measurementIdx].getTimestamp();
421421

422422
// last_by
423-
if (timeLastValue == EMPTY_PRIMITIVE_TYPE || attribute == null) {
423+
if (timeLastValue == PLACEHOLDER_NO_VALUE || attribute == null) {
424424
if (aggregator.getStep().isOutputPartial()) {
425425
columnBuilder.writeBinary(
426426
new Binary(
@@ -448,7 +448,7 @@ private void buildResultUseLastValuesCache() {
448448
case TIME:
449449
if (aggregator.getAccumulator() instanceof LastDescAccumulator) {
450450
// for last(time) aggregation
451-
if (timeLastValue == EMPTY_PRIMITIVE_TYPE) {
451+
if (timeLastValue == PLACEHOLDER_NO_VALUE) {
452452
columnBuilder.appendNull();
453453
} else {
454454
if (aggregator.getStep().isOutputPartial()) {
@@ -471,7 +471,7 @@ private void buildResultUseLastValuesCache() {
471471
TsPrimitiveType tsPrimitiveType =
472472
lastValuesCacheResults.get(currentHitCacheIndex)[measurementIdx].getValue();
473473

474-
if (tsPrimitiveType == EMPTY_PRIMITIVE_TYPE) {
474+
if (tsPrimitiveType == PLACEHOLDER_NO_VALUE) {
475475
// there is no data
476476
if (aggregator.getStep().isOutputPartial()) {
477477
columnBuilder.writeBinary(
@@ -509,7 +509,7 @@ private void buildResultUseLastValuesCache() {
509509
TsPrimitiveType tsPrimitiveType =
510510
lastValuesCacheResults.get(currentHitCacheIndex)[measurementIdx].getValue();
511511

512-
if (tsPrimitiveType == EMPTY_PRIMITIVE_TYPE) {
512+
if (tsPrimitiveType == PLACEHOLDER_NO_VALUE) {
513513
// there is no data for this time series
514514
columnBuilder.appendNull();
515515
} else {
@@ -559,7 +559,7 @@ private void updateLastCacheUseLastRowIfPossible() {
559559
new TsPrimitiveType.TsLong(lastAccumulator.getMaxTime())));
560560
} else {
561561
currentDeviceEntry = deviceEntries.get(currentDeviceIndex);
562-
updateTimeValuePairList.add(EMPTY_TIME_VALUE_PAIR);
562+
updateTimeValuePairList.add(PLACEHOLDER_EMPTY_COLUMN);
563563
}
564564
} else {
565565
LastByDescAccumulator lastByAccumulator =
@@ -589,12 +589,12 @@ private void updateLastCacheUseLastRowIfPossible() {
589589
updateMeasurementList.add(schema.getName());
590590
updateTimeValuePairList.add(
591591
lastByAccumulator.isXNull()
592-
? new TimeValuePair(lastByTime, EMPTY_PRIMITIVE_TYPE)
592+
? new TimeValuePair(lastByTime, PLACEHOLDER_NO_VALUE)
593593
: new TimeValuePair(
594594
lastByTime, cloneTsPrimitiveType(lastByAccumulator.getXResult())));
595595
} else {
596596
updateMeasurementList.add(schema.getName());
597-
updateTimeValuePairList.add(EMPTY_TIME_VALUE_PAIR);
597+
updateTimeValuePairList.add(PLACEHOLDER_EMPTY_COLUMN);
598598
}
599599
break;
600600
default:
@@ -631,7 +631,7 @@ private void updateLastCacheUseLastValuesIfPossible() {
631631
new TsPrimitiveType.TsLong(lastAccumulator.getMaxTime())));
632632
} else {
633633
currentDeviceEntry = deviceEntries.get(currentDeviceIndex);
634-
updateTimeValuePairList.add(EMPTY_TIME_VALUE_PAIR);
634+
updateTimeValuePairList.add(PLACEHOLDER_EMPTY_COLUMN);
635635
}
636636
}
637637
break;
@@ -648,7 +648,7 @@ private void updateLastCacheUseLastValuesIfPossible() {
648648
lastAccumulator.getMaxTime(),
649649
cloneTsPrimitiveType(lastAccumulator.getLastValue())));
650650
} else {
651-
updateTimeValuePairList.add(EMPTY_TIME_VALUE_PAIR);
651+
updateTimeValuePairList.add(PLACEHOLDER_EMPTY_COLUMN);
652652
}
653653
break;
654654
default:

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/DataNodeTableOperatorGenerator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@
199199
import static org.apache.iotdb.db.queryengine.plan.analyze.PredicateUtils.convertPredicateToFilter;
200200
import static org.apache.iotdb.db.queryengine.plan.planner.OperatorTreeGenerator.isFilterGtOrGe;
201201
import static org.apache.iotdb.db.queryengine.plan.planner.plan.parameter.SeriesScanOptions.updateFilterUsingTTL;
202-
import static org.apache.iotdb.db.queryengine.plan.relational.metadata.fetcher.cache.TableDeviceLastCache.EMPTY_PRIMITIVE_TYPE;
203-
import static org.apache.iotdb.db.queryengine.plan.relational.metadata.fetcher.cache.TableDeviceLastCache.STALE_PRIMITIVE_TYPE;
202+
import static org.apache.iotdb.db.queryengine.plan.relational.metadata.fetcher.cache.TableDeviceLastCache.PLACEHOLDER_NO_VALUE;
203+
import static org.apache.iotdb.db.queryengine.plan.relational.metadata.fetcher.cache.TableDeviceLastCache.PLACEHOLDER_STALE_VALUE;
204204
import static org.apache.tsfile.read.common.type.TimestampType.TIMESTAMP;
205205

206206
public class DataNodeTableOperatorGenerator
@@ -1627,7 +1627,7 @@ private LastQueryAggTableScanOperator constructLastQueryAggTableScanOperator(
16271627
if (tsPrimitiveType == null
16281628
// Known-null at the aligned row time can still hit cache. Only miss or stale target
16291629
// values need to fall back to scan for correctness.
1630-
|| tsPrimitiveType == STALE_PRIMITIVE_TYPE
1630+
|| tsPrimitiveType == PLACEHOLDER_STALE_VALUE
16311631
|| (updateTimeFilter != null
16321632
&& !LastQueryUtil.satisfyFilter(
16331633
updateTimeFilter,
@@ -1727,7 +1727,7 @@ private LastQueryAggTableScanOperator constructLastQueryAggTableScanOperator(
17271727
parameter.getSeriesScanOptions().getGlobalTimeFilter(), timeValuePair)) {
17281728
if (isFilterGtOrGe(updateTimeFilter)) {
17291729
// it means there is no data meets Filter
1730-
timeValuePair.setValue(EMPTY_PRIMITIVE_TYPE);
1730+
timeValuePair.setValue(PLACEHOLDER_NO_VALUE);
17311731
} else {
17321732
allHitCache = false;
17331733
break;

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/OperatorTreeGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2923,7 +2923,7 @@ public Operator visitLastQueryScan(LastQueryScanNode node, LocalExecutionPlanCon
29232923

29242924
if (timeValuePair == null) { // last value is not cached
29252925
unCachedMeasurementIndexes.add(i);
2926-
} else if (timeValuePair.getValue() == TableDeviceLastCache.EMPTY_PRIMITIVE_TYPE) {
2926+
} else if (timeValuePair.getValue() == TableDeviceLastCache.PLACEHOLDER_NO_VALUE) {
29272927
// there is no data for this time series, just ignore
29282928
} else if (!LastQueryUtil.satisfyFilter(filter, timeValuePair)) {
29292929
// cached last value is not satisfied

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/fetcher/cache/TableDeviceLastCache.java

Lines changed: 20 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import org.apache.iotdb.db.schemaengine.table.DataNodeTableCache;
2323

24-
import org.apache.tsfile.enums.TSDataType;
2524
import org.apache.tsfile.read.TimeValuePair;
2625
import org.apache.tsfile.utils.Pair;
2726
import org.apache.tsfile.utils.RamUsageEstimator;
@@ -53,86 +52,24 @@ public class TableDeviceLastCache {
5352
* Cache hit and the measurement is known to be null at the aligned last-row time. For stored
5453
* entries, it is only used as the value part of the time column's cached {@link TimeValuePair}.
5554
*/
56-
public static final TsPrimitiveType EMPTY_PRIMITIVE_TYPE =
57-
new TsPrimitiveType() {
58-
@Override
59-
public void setObject(Object o) {
60-
// Do nothing
61-
}
62-
63-
@Override
64-
public void reset() {
65-
// Do nothing
66-
}
67-
68-
@Override
69-
public int getSize() {
70-
return 0;
71-
}
72-
73-
@Override
74-
public Object getValue() {
75-
return null;
76-
}
77-
78-
@Override
79-
public String getStringValue() {
80-
return null;
81-
}
82-
83-
@Override
84-
public TSDataType getDataType() {
85-
return null;
86-
}
87-
};
55+
public static final TsPrimitiveType PLACEHOLDER_NO_VALUE = new TsPrimitiveType.TsInt();
8856

8957
/**
9058
* Cache hit but the target measurement is stale under a newer aligned last-row time. This
9159
* sentinel is only returned by {@link #getLastRow(String, List)} and is never stored in cache.
9260
*/
93-
public static final TsPrimitiveType STALE_PRIMITIVE_TYPE =
94-
new TsPrimitiveType() {
95-
@Override
96-
public void setObject(Object o) {
97-
// Do nothing
98-
}
99-
100-
@Override
101-
public void reset() {
102-
// Do nothing
103-
}
104-
105-
@Override
106-
public int getSize() {
107-
return 0;
108-
}
109-
110-
@Override
111-
public Object getValue() {
112-
return null;
113-
}
114-
115-
@Override
116-
public String getStringValue() {
117-
return null;
118-
}
119-
120-
@Override
121-
public TSDataType getDataType() {
122-
return null;
123-
}
124-
};
61+
public static final TsPrimitiveType PLACEHOLDER_STALE_VALUE = new TsPrimitiveType.TsInt();
12562

12663
private static final Optional<Pair<OptionalLong, TsPrimitiveType[]>> HIT_AND_ALL_NULL =
12764
Optional.of(new Pair<>(OptionalLong.empty(), null));
12865

12966
/** This means the measurement has been cached and is known to have no values at all. */
130-
public static final TimeValuePair EMPTY_TIME_VALUE_PAIR =
131-
new TimeValuePair(Long.MIN_VALUE, EMPTY_PRIMITIVE_TYPE);
67+
public static final TimeValuePair PLACEHOLDER_EMPTY_COLUMN =
68+
new TimeValuePair(Long.MIN_VALUE, PLACEHOLDER_NO_VALUE);
13269

13370
/** This means that the tv pair has been declared, and is ready for the next put. */
134-
private static final TimeValuePair PLACEHOLDER_TIME_VALUE_PAIR =
135-
new TimeValuePair(Long.MIN_VALUE, EMPTY_PRIMITIVE_TYPE);
71+
private static final TimeValuePair PLACEHOLDER_NO_CACHE =
72+
new TimeValuePair(Long.MIN_VALUE, PLACEHOLDER_NO_VALUE);
13673

13774
// Time is seen as "" as a measurement
13875
private final Map<String, TimeValuePair> measurement2CachedLastMap = new ConcurrentHashMap<>();
@@ -165,7 +102,7 @@ int initOrInvalidate(
165102
if (isInvalidate && measurement2CachedLastKnownNullTimeMap.remove(finalMeasurement) != null) {
166103
diff.addAndGet(-getKnownNullTimeEntrySize());
167104
}
168-
final TimeValuePair newPair = isInvalidate ? null : PLACEHOLDER_TIME_VALUE_PAIR;
105+
final TimeValuePair newPair = isInvalidate ? null : PLACEHOLDER_NO_CACHE;
169106

170107
measurement2CachedLastMap.compute(
171108
finalMeasurement,
@@ -241,7 +178,7 @@ int tryUpdate(
241178
"",
242179
(time, tvPair) ->
243180
tvPair.getTimestamp() < finalLastTime
244-
? new TimeValuePair(finalLastTime, EMPTY_PRIMITIVE_TYPE)
181+
? new TimeValuePair(finalLastTime, PLACEHOLDER_NO_VALUE)
245182
: tvPair);
246183
return diff.get();
247184
}
@@ -291,32 +228,32 @@ private static int getTvPairSize(final TimeValuePair tvPair) {
291228

292229
private static boolean isEmptyTvPair(final TimeValuePair tvPair) {
293230
return Objects.isNull(tvPair)
294-
|| tvPair == PLACEHOLDER_TIME_VALUE_PAIR
295-
|| tvPair == EMPTY_TIME_VALUE_PAIR;
231+
|| tvPair == PLACEHOLDER_NO_CACHE
232+
|| tvPair == PLACEHOLDER_EMPTY_COLUMN;
296233
}
297234

298235
private static boolean isKnownNullAtAlignedTime(
299236
final @Nonnull String measurement, final @Nonnull TimeValuePair timeValuePair) {
300237
return !measurement.isEmpty()
301-
&& timeValuePair != EMPTY_TIME_VALUE_PAIR
302-
&& timeValuePair.getValue() == EMPTY_PRIMITIVE_TYPE;
238+
&& timeValuePair != PLACEHOLDER_EMPTY_COLUMN
239+
&& timeValuePair.getValue() == PLACEHOLDER_NO_VALUE;
303240
}
304241

305242
@Nullable
306243
TimeValuePair getTimeValuePair(final @Nonnull String measurement) {
307244
final TimeValuePair result = measurement2CachedLastMap.get(measurement);
308-
return result != PLACEHOLDER_TIME_VALUE_PAIR ? result : null;
245+
return result != PLACEHOLDER_NO_CACHE ? result : null;
309246
}
310247

311248
// Shall pass in "" if last by time
312249
Optional<Pair<OptionalLong, TsPrimitiveType[]>> getLastRow(
313250
final @Nonnull String sourceMeasurement, final List<String> targetMeasurements) {
314251
final TimeValuePair pair = measurement2CachedLastMap.get(sourceMeasurement);
315-
if (Objects.isNull(pair) || pair == PLACEHOLDER_TIME_VALUE_PAIR) {
252+
if (Objects.isNull(pair) || pair == PLACEHOLDER_NO_CACHE) {
316253
return Optional.empty();
317254
}
318255

319-
if (pair == EMPTY_TIME_VALUE_PAIR) {
256+
if (pair == PLACEHOLDER_EMPTY_COLUMN) {
320257
return HIT_AND_ALL_NULL;
321258
}
322259
final long alignTime = pair.getTimestamp();
@@ -345,15 +282,15 @@ private static TsPrimitiveType getLastRowTargetValue(
345282
final @Nullable TimeValuePair tvPair,
346283
final @Nullable Long knownNullTime) {
347284
if (knownNullTime != null && knownNullTime == alignTime) {
348-
return EMPTY_PRIMITIVE_TYPE;
285+
return PLACEHOLDER_NO_VALUE;
349286
}
350-
if (Objects.isNull(tvPair) || tvPair == PLACEHOLDER_TIME_VALUE_PAIR) {
287+
if (Objects.isNull(tvPair) || tvPair == PLACEHOLDER_NO_CACHE) {
351288
return null;
352289
}
353-
if (tvPair == EMPTY_TIME_VALUE_PAIR) {
354-
return EMPTY_PRIMITIVE_TYPE;
290+
if (tvPair == PLACEHOLDER_EMPTY_COLUMN) {
291+
return PLACEHOLDER_NO_VALUE;
355292
}
356-
return tvPair.getTimestamp() == alignTime ? tvPair.getValue() : STALE_PRIMITIVE_TYPE;
293+
return tvPair.getTimestamp() == alignTime ? tvPair.getValue() : PLACEHOLDER_STALE_VALUE;
357294
}
358295

359296
int estimateSize() {

0 commit comments

Comments
 (0)