Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@ public void test() throws Exception {
false);
compareQueryResults(
session,
"select * from (select time, battery as device1 from view1 where battery = 'b1') as t1 full outer join (select time, battery as device2 from view2 where battery = 'b') as t2 using(time)",
"select * from (select time, battery as device1 from table1 where battery = 'b1') as t1 full outer join (select time, battery as device2 from table1 where battery = 'b') as t2 using(time)",
"select * from (select time, battery as battery1 from view1 where battery = 'b1') as t1 full outer join (select time, battery as battery2 from view2 where battery = 'b') as t2 using(time)",
"select * from (select time, battery as battery1 from table1 where battery = 'b1') as t1 full outer join (select time, battery as battery2 from table1 where battery = 'b') as t2 using(time)",
true);
compareQueryResults(
session,
Expand Down Expand Up @@ -380,6 +380,48 @@ public void test() throws Exception {
"select count(distinct battery) from view4 where battery = 'b1'",
"select count(distinct battery) from table1 where battery = 'b1'",
true);

compareQueryResults(
session,
"select count(time) from view1 where time > 604800000",
"select count(time) from table1 where time > 604800000",
true);

compareQueryResults(
session,
"select count(battery),count(time) from view1 where time > 604800000",
"select count(battery),count(time) from table1 where time > 604800000",
true);

compareQueryResults(
session,
"select count(battery),count(time),count(current) from view1 where time > 604800000",
"select count(battery),count(time),count(current) from table1 where time > 604800000",
true);

compareQueryResults(
session,
"select distinct battery from view1 where time > 604800000",
"select distinct battery from table1 where time > 604800000",
true);

compareQueryResults(
session,
"select count(current) from view1 where time > 604800000 group by battery",
"select count(current) from table1 where time > 604800000 group by battery",
true);

compareQueryResults(
session,
"select count(current) from view1 group by date_bin(2ms,time)",
"select count(current) from table1 group by date_bin(2ms,time)",
true);

compareQueryResults(
session,
"select count(current) from view1 group by battery,date_bin(2ms,time)",
"select count(current) from table1 group by battery,date_bin(2ms,time)",
true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.iotdb.db.queryengine.plan.relational.metadata.AlignedDeviceEntry;
import org.apache.iotdb.db.queryengine.plan.relational.metadata.ColumnSchema;
import org.apache.iotdb.db.queryengine.plan.relational.metadata.DeviceEntry;
import org.apache.iotdb.db.queryengine.plan.relational.planner.Symbol;
import org.apache.iotdb.db.queryengine.plan.statement.component.Ordering;
import org.apache.iotdb.db.storageengine.dataregion.read.IQueryDataSource;
import org.apache.iotdb.db.storageengine.dataregion.read.QueryDataSource;
Expand Down Expand Up @@ -71,7 +72,7 @@
public abstract class AbstractAggTableScanOperator extends AbstractDataSourceOperator {

private boolean finished = false;
private TsBlock inputTsBlock;
protected TsBlock inputTsBlock;

protected List<TableAggregator> tableAggregators;
protected final List<ColumnSchema> groupingKeySchemas;
Expand Down Expand Up @@ -104,11 +105,11 @@
// e.g. for aggregation `last(s1), count(s2), count(s1)`, the inputChannels should be [0, 1, 0]
protected List<Integer> aggregatorInputChannels;

private QueryDataSource queryDataSource;
protected QueryDataSource queryDataSource;

protected ITableTimeRangeIterator timeIterator;

private boolean allAggregatorsHasFinalResult = false;
protected boolean allAggregatorsHasFinalResult = false;

protected AbstractAggTableScanOperator(AbstractAggTableScanOperatorParameter parameter) {

Expand Down Expand Up @@ -193,7 +194,7 @@
}

/** Return true if we have the result of this timeRange. */
protected Optional<Boolean> calculateAggregationResultForCurrentTimeRange() {
protected Optional<Boolean> calculateAggregationResultForCurrentTimeRange() throws Exception {

Check failure on line 197 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/AbstractAggTableScanOperator.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 19 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZzkgUCdguHjumTnDTP-&open=AZzkgUCdguHjumTnDTP-&pullRequest=17294

Check warning on line 197 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/AbstractAggTableScanOperator.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Expected @throws tag for 'Exception'.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZzkgUCdguHjumTnDTQA&open=AZzkgUCdguHjumTnDTQA&pullRequest=17294
try {
if (calcFromCachedData()) {
updateResultTsBlock();
Expand Down Expand Up @@ -706,7 +707,7 @@
return true;
}

private void checkIfAllAggregatorHasFinalResult() {
protected void checkIfAllAggregatorHasFinalResult() throws Exception {
if (allAggregatorsHasFinalResult
&& (timeIterator.getType() == ITableTimeRangeIterator.TimeIteratorType.SINGLE_TIME_ITERATOR
|| tableAggregators.isEmpty())) {
Expand All @@ -729,7 +730,7 @@
}
}

private void nextDevice() {
protected void nextDevice() throws Exception {

Check warning on line 733 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/AbstractAggTableScanOperator.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace generic exceptions with specific library exceptions or a custom exception.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZzkgUCdguHjumTnDTP9&open=AZzkgUCdguHjumTnDTP9&pullRequest=17294

Check warning on line 733 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/AbstractAggTableScanOperator.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the declaration of thrown exception 'java.lang.Exception', as it cannot be thrown from method's body.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZzkgUCdguHjumTnDTP_&open=AZzkgUCdguHjumTnDTP_&pullRequest=17294
currentDeviceIndex++;
this.operatorContext.recordSpecifiedInfo(
CURRENT_DEVICE_INDEX_STRING, Integer.toString(currentDeviceIndex));
Expand Down Expand Up @@ -812,6 +813,8 @@
protected List<DeviceEntry> deviceEntries;
protected int deviceCount;

private List<Symbol> outputSymbols;

public AbstractAggTableScanOperatorParameter(
PlanNodeId sourceId,
OperatorContext context,
Expand All @@ -830,7 +833,8 @@
boolean ascending,
boolean canUseStatistics,
List<Integer> aggregatorInputChannels,
String timeColumnName) {
String timeColumnName,
List<Symbol> outputSymbols) {
this.sourceId = sourceId;
this.context = context;
this.aggColumnSchemas = aggColumnSchemas;
Expand All @@ -849,6 +853,11 @@
this.canUseStatistics = canUseStatistics;
this.aggregatorInputChannels = aggregatorInputChannels;
this.timeColumnName = timeColumnName;
this.outputSymbols = outputSymbols;
}

public List<Symbol> getOutputSymbols() {
return outputSymbols;
}

public OperatorContext getOperatorContext() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.google.common.util.concurrent.ListenableFuture;
import org.apache.tsfile.enums.TSDataType;
import org.apache.tsfile.read.common.block.TsBlock;
import org.apache.tsfile.utils.Accountable;
import org.apache.tsfile.utils.RamUsageEstimator;
import org.apache.tsfile.write.schema.IMeasurementSchema;

Expand Down Expand Up @@ -113,7 +114,7 @@ private void constructCurrentDeviceOperatorTree() {
}
DeviceEntry deviceEntry = this.deviceEntries.get(this.currentDeviceIndex);

deviceChildOperatorTreeGenerator.generateCurrentDeviceOperatorTree(deviceEntry);
deviceChildOperatorTreeGenerator.generateCurrentDeviceOperatorTree(deviceEntry, true);
currentDeviceRootOperator = deviceChildOperatorTreeGenerator.getCurrentDeviceRootOperator();
dataSourceOperators = deviceChildOperatorTreeGenerator.getCurrentDeviceDataSourceOperators();
currentDeviceInit = false;
Expand Down Expand Up @@ -185,7 +186,13 @@ public long ramBytesUsed() {
return INSTANCE_SIZE
+ MemoryEstimationHelper.getEstimatedSizeOfAccountableObject(operatorContext)
+ MemoryEstimationHelper.getEstimatedSizeOfAccountableObject(currentDeviceRootOperator)
+ RamUsageEstimator.sizeOfCollection(deviceEntries);
+ RamUsageEstimator.sizeOfCollection(deviceEntries)
+ MemoryEstimationHelper.getEstimatedSizeOfAccountableObject(
deviceChildOperatorTreeGenerator);
}

public DeviceChildOperatorTreeGenerator getDeviceChildOperatorTreeGenerator() {
return deviceChildOperatorTreeGenerator;
}

public static class TreeNonAlignedDeviceViewScanParameters {
Expand All @@ -212,12 +219,12 @@ public TreeNonAlignedDeviceViewScanParameters(
}
}

public interface DeviceChildOperatorTreeGenerator {
public interface DeviceChildOperatorTreeGenerator extends Accountable {
// Do the offset and limit operator need to keep after the device iterator
boolean keepOffsetAndLimitOperatorAfterDeviceIterator();

// Generate the following operator subtree based on the current deviceEntry
void generateCurrentDeviceOperatorTree(DeviceEntry deviceEntry);
void generateCurrentDeviceOperatorTree(DeviceEntry deviceEntry, boolean needAdaptor);

// Returns the root operator of the subtree
Operator getCurrentDeviceRootOperator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
}

/** Main process logic, calc the last aggregation results of current device. */
private void processCurrentDevice() {
private void processCurrentDevice() throws Exception {

Check warning on line 159 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/LastQueryAggTableScanOperator.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Expected @throws tag for 'Exception'.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZzkgUC_guHjumTnDTQJ&open=AZzkgUC_guHjumTnDTQJ&pullRequest=17294
if (currentHitCacheIndex < hitCachesIndexes.size()
&& outputDeviceIndex == hitCachesIndexes.get(currentHitCacheIndex)) {
currentDeviceEntry = cachedDeviceEntries.get(currentHitCacheIndex);
Expand All @@ -175,7 +175,7 @@
}
}

private void buildResultUseLastRowCache() {

Check warning on line 178 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/LastQueryAggTableScanOperator.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

A "Brain Method" was detected. Refactor it to reduce at least one of the following metrics: LOC from 136 to 64, Complexity from 18 to 14, Nesting Level from 4 to 2, Number of Variables from 14 to 6.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZzkgUC_guHjumTnDTQI&open=AZzkgUC_guHjumTnDTQI&pullRequest=17294
appendGroupKeysToResult(cachedDeviceEntries, currentHitCacheIndex);
Pair<OptionalLong, TsPrimitiveType[]> currentHitResult =
lastRowCacheResults.get(currentHitCacheIndex);
Expand Down
Loading
Loading