liyuheng55555 commented on code in PR #9438:
URL: https://github.com/apache/iotdb/pull/9438#discussion_r1155520762


##########
server/src/main/java/org/apache/iotdb/db/mpp/transformation/dag/column/CaseWhenThenColumnTransformer.java:
##########
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.mpp.transformation.dag.column;
+
+import org.apache.iotdb.tsfile.read.common.block.column.Column;
+import org.apache.iotdb.tsfile.read.common.block.column.ColumnBuilder;
+import org.apache.iotdb.tsfile.read.common.type.BinaryType;
+import org.apache.iotdb.tsfile.read.common.type.BooleanType;
+import org.apache.iotdb.tsfile.read.common.type.DoubleType;
+import org.apache.iotdb.tsfile.read.common.type.FloatType;
+import org.apache.iotdb.tsfile.read.common.type.IntType;
+import org.apache.iotdb.tsfile.read.common.type.LongType;
+import org.apache.iotdb.tsfile.read.common.type.Type;
+import org.apache.iotdb.tsfile.utils.Pair;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class CaseWhenThenColumnTransformer extends ColumnTransformer {
+
+  //  List<WhenThenColumnTransformer> whenThenTransformers;
+  List<Pair<ColumnTransformer, ColumnTransformer>> whenThenTransformers;
+  ColumnTransformer elseTransformer;
+
+  public CaseWhenThenColumnTransformer(
+      Type returnType,
+      List<ColumnTransformer> whenTransformers,
+      List<ColumnTransformer> thenTransformers,
+      ColumnTransformer elseTransformer) {
+    super(returnType);
+    if (whenTransformers.size() != thenTransformers.size()) {
+      throw new UnsupportedOperationException(
+          "the size of whenTransformers and thenTransformers need to be 
same.");
+    }
+    this.whenThenTransformers = new ArrayList<>();
+    for (int i = 0; i < whenTransformers.size(); i++) {
+      this.whenThenTransformers.add(new Pair<>(whenTransformers.get(i), 
thenTransformers.get(i)));
+    }
+    this.elseTransformer = elseTransformer;
+  }
+
+  public List<Pair<ColumnTransformer, ColumnTransformer>> 
getWhenThenColumnTransformers() {
+    return whenThenTransformers;
+  }
+
+  public ColumnTransformer getElseTransformer() {
+    return elseTransformer;
+  }
+
+  private void writeToColumnBuilder(
+      ColumnTransformer childTransformer, Column column, int index, 
ColumnBuilder builder) {
+    if (returnType instanceof BooleanType) {
+      builder.writeBoolean(childTransformer.getType().getBoolean(column, 
index));
+    } else if (returnType instanceof IntType) {
+      builder.writeInt(childTransformer.getType().getInt(column, index));
+    } else if (returnType instanceof LongType) {
+      builder.writeLong(childTransformer.getType().getLong(column, index));
+    } else if (returnType instanceof FloatType) {
+      builder.writeFloat(childTransformer.getType().getFloat(column, index));
+    } else if (returnType instanceof DoubleType) {
+      builder.writeDouble(childTransformer.getType().getDouble(column, index));
+    } else if (returnType instanceof BinaryType) {
+      builder.writeBinary(childTransformer.getType().getBinary(column, index));
+    } else {
+      throw new UnsupportedOperationException("Unsupported Type");
+    }
+  }

Review Comment:
   The function has been called twice in evaluate(). Removing this function may 
eliminate redundant code.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to