This is an automated email from the ASF dual-hosted git repository.

jackietien pushed a commit to branch ty/sonar
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/ty/sonar by this push:
     new 941baedd366 
server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill 
done
941baedd366 is described below

commit 941baedd366d1422038fd3246cc4aa35288ccef0
Author: JackieTien97 <[email protected]>
AuthorDate: Tue Jun 20 21:26:58 2023 +0800

    
server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill 
done
---
 .../mpp/execution/operator/process/fill/IFill.java |  1 +
 .../operator/process/fill/ILinearFill.java         |  7 ++-
 .../process/fill/identity/IdentityFill.java        |  1 +
 .../process/fill/identity/IdentityLinearFill.java  |  5 +-
 .../operator/process/fill/linear/LinearFill.java   | 57 +++++++++++++---------
 5 files changed, 46 insertions(+), 25 deletions(-)

diff --git 
a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/IFill.java
 
b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/IFill.java
index d43325a21c4..32a35d76bc4 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/IFill.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/IFill.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.db.mpp.execution.operator.process.fill;
 
 import org.apache.iotdb.tsfile.read.common.block.column.Column;
diff --git 
a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/ILinearFill.java
 
b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/ILinearFill.java
index d0edfc59611..1854aa2a659 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/ILinearFill.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/ILinearFill.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.db.mpp.execution.operator.process.fill;
 
 import org.apache.iotdb.tsfile.read.common.block.column.Column;
@@ -25,7 +26,7 @@ public interface ILinearFill {
 
   /**
    * Before we call this method, we need to make sure the nextValue has been 
prepared or noMoreNext
-   * has been set to true
+   * has been set to true.
    *
    * @param timeColumn TimeColumn of valueColumn
    * @param valueColumn valueColumn that need to be filled
@@ -35,6 +36,8 @@ public interface ILinearFill {
   Column fill(TimeColumn timeColumn, Column valueColumn, long currentRowIndex);
 
   /**
+   * Whether need prepare for next.
+   *
    * @param rowIndex row index for end time of current valueColumn that need 
to be filled
    * @param valueColumn valueColumn that need to be filled
    * @return true if valueColumn can't be filled using current information, 
and we need to get next
@@ -44,6 +47,8 @@ public interface ILinearFill {
   boolean needPrepareForNext(long rowIndex, Column valueColumn);
 
   /**
+   * prepare for next.
+   *
    * @param startRowIndex row index for start time of nextValueColumn
    * @param endRowIndex row index for end time of current valueColumn that 
need to be filled
    * @param nextTimeColumn TimeColumn of next TsBlock
diff --git 
a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/identity/IdentityFill.java
 
b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/identity/IdentityFill.java
index 25a5264bb78..8f9021aa026 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/identity/IdentityFill.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/identity/IdentityFill.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.db.mpp.execution.operator.process.fill.identity;
 
 import org.apache.iotdb.db.mpp.execution.operator.process.fill.IFill;
diff --git 
a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/identity/IdentityLinearFill.java
 
b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/identity/IdentityLinearFill.java
index 34f329baf01..92b78ef336d 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/identity/IdentityLinearFill.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/identity/IdentityLinearFill.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.db.mpp.execution.operator.process.fill.identity;
 
 import org.apache.iotdb.db.mpp.execution.operator.process.fill.ILinearFill;
@@ -37,7 +38,7 @@ public class IdentityLinearFill implements ILinearFill {
   @Override
   public boolean prepareForNext(
       long startRowIndex, long endRowIndex, TimeColumn nextTimeColumn, Column 
nextValueColumn) {
-    throw new IllegalArgumentException(
-        "We won't call prepareForNext in IdentityLinearFill, because 
needPrepareForNext() method will always return false.");
+    throw new UnsupportedOperationException(
+        "IdentityLinearFill's needPrepareForNext() method should always return 
false.");
   }
 }
diff --git 
a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/linear/LinearFill.java
 
b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/linear/LinearFill.java
index 238fb911378..13fc1a793ee 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/linear/LinearFill.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/linear/LinearFill.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.iotdb.db.mpp.execution.operator.process.fill.linear;
 
 import org.apache.iotdb.db.mpp.execution.operator.process.fill.ILinearFill;
@@ -44,7 +45,6 @@ public abstract class LinearFill implements ILinearFill {
   @Override
   public Column fill(TimeColumn timeColumn, Column valueColumn, long 
startRowIndex) {
     int size = valueColumn.getPositionCount();
-    // if this valueColumn is empty, just return itself;
     if (size == 0) {
       return valueColumn;
     }
@@ -59,16 +59,7 @@ public abstract class LinearFill implements ILinearFill {
 
     // if its values are all null
     if (valueColumn instanceof RunLengthEncodedColumn) {
-      // previous value is null or next value is null, we just return 
NULL_VALUE_BLOCK
-      if (previousIsNull || nextRowIndex < startRowIndex) {
-        return new RunLengthEncodedColumn(createNullValueColumn(), size);
-      } else {
-        prepareForNextValueInCurrentColumn(
-            startRowIndex + timeColumn.getPositionCount() - 1,
-            timeColumn.getPositionCount(),
-            valueColumn);
-        return new RunLengthEncodedColumn(createFilledValueColumn(), size);
-      }
+      return doWithAllNulls(startRowIndex, size, timeColumn, valueColumn);
     } else {
       Object array = createValueArray(size);
       boolean[] isNull = new boolean[size];
@@ -78,16 +69,7 @@ public abstract class LinearFill implements ILinearFill {
       for (int i = 0; i < size; i++) {
         // current value is null, we need to fill it
         if (valueColumn.isNull(i)) {
-          long currentRowIndex = startRowIndex + i;
-          prepareForNextValueInCurrentColumn(currentRowIndex, i + 1, 
valueColumn);
-          // we don't fill it, if either previous value or next value is null
-          if (previousIsNull || nextIsNull(currentRowIndex)) {
-            isNull[i] = true;
-            hasNullValue = true;
-          } else {
-            // fill value using previous and next value
-            fillValue(array, i);
-          }
+          hasNullValue = fill(startRowIndex, i, isNull, valueColumn, array) || 
hasNullValue;
         } else { // current is not null
           // fill value using its own value
           fillValue(valueColumn, i, array);
@@ -100,7 +82,38 @@ public abstract class LinearFill implements ILinearFill {
     }
   }
 
+  private Column doWithAllNulls(
+      long startRowIndex, int size, Column timeColumn, Column valueColumn) {
+    // previous value is null or next value is null, we just return 
NULL_VALUE_BLOCK
+    if (previousIsNull || nextRowIndex < startRowIndex) {
+      return new RunLengthEncodedColumn(createNullValueColumn(), size);
+    } else {
+      prepareForNextValueInCurrentColumn(
+          startRowIndex + timeColumn.getPositionCount() - 1,
+          timeColumn.getPositionCount(),
+          valueColumn);
+      return new RunLengthEncodedColumn(createFilledValueColumn(), size);
+    }
+  }
+
+  private boolean fill(
+      long startRowIndex, int i, boolean[] isNull, Column valueColumn, Object 
array) {
+    long currentRowIndex = startRowIndex + i;
+    prepareForNextValueInCurrentColumn(currentRowIndex, i + 1, valueColumn);
+    // we don't fill it, if either previous value or next value is null
+    if (previousIsNull || nextIsNull(currentRowIndex)) {
+      isNull[i] = true;
+      return true;
+    } else {
+      // fill value using previous and next value
+      fillValue(array, i);
+      return false;
+    }
+  }
+
   /**
+   * Whether need prepare for next.
+   *
    * @param rowIndex end time of current valueColumn that need to be filled
    * @param valueColumn valueColumn that need to be filled
    * @return true if valueColumn can't be filled using current information, 
and we need to get next
@@ -173,6 +186,6 @@ public abstract class LinearFill implements ILinearFill {
 
   abstract void updateNextValueInCurrentColumn(Column nextValueColumn, int 
index);
 
-  /** update nextValueInCurrentColumn using value of next Column */
+  /** update nextValueInCurrentColumn using value of next Column. */
   abstract void updateNextValueInCurrentColumn();
 }

Reply via email to