You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by xi...@apache.org on 2022/11/02 08:43:03 UTC
[iotdb] 04/05: add linearFill.ftl template
This is an automated email from the ASF dual-hosted git repository.
xiangweiwei pushed a commit to branch freemarker
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit d9130df67bc7145c4e75f2e71a9c9640f1345150
Author: Alima777 <wx...@gmail.com>
AuthorDate: Wed Nov 2 16:26:49 2022 +0800
add linearFill.ftl template
---
server/src/main/codegen/templates/linearFill.ftl | 112 +++++++++++++++++++++
.../process/fill/linear/DoubleLinearFill.java | 94 -----------------
.../process/fill/linear/FloatLinearFill.java | 94 -----------------
.../process/fill/linear/IntLinearFill.java | 94 -----------------
.../process/fill/linear/LongLinearFill.java | 94 -----------------
5 files changed, 112 insertions(+), 376 deletions(-)
diff --git a/server/src/main/codegen/templates/linearFill.ftl b/server/src/main/codegen/templates/linearFill.ftl
new file mode 100644
index 0000000000..9a4adbb858
--- /dev/null
+++ b/server/src/main/codegen/templates/linearFill.ftl
@@ -0,0 +1,112 @@
+/*
+* 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.
+*/
+<@pp.dropOutputFile />
+
+<#list decimalDataTypes.types as type>
+
+ <#assign className = "${type.dataType?cap_first}LinearFill">
+ <@pp.changeOutputFile name="/org/apache/iotdb/db/mpp/execution/operator/process/fill/linear/${className}.java" />
+package org.apache.iotdb.db.mpp.execution.operator.process.fill.linear;
+
+import org.apache.iotdb.tsfile.read.common.block.column.Column;
+import org.apache.iotdb.tsfile.read.common.block.column.${type.column};
+import org.apache.iotdb.tsfile.read.common.block.column.${type.column}Builder;
+
+import java.util.Optional;
+
+/*
+* This class is generated using freemarker and the ${.template_name} template.
+*/
+@SuppressWarnings("unused")
+public class ${className} extends LinearFill {
+
+ // previous value
+ private ${type.dataType} previousValue;
+ // next non-null value whose time is closest to the current TsBlock's endTime
+ private ${type.dataType} nextValue;
+
+ private ${type.dataType} nextValueInCurrentColumn;
+
+ @Override
+ void fillValue(Column column, int index, Object array) {
+ ((${type.dataType}[]) array)[index] = column.get${type.dataType?cap_first}(index);
+ }
+
+ @Override
+ void fillValue(Object array, int index) {
+ ((${type.dataType}[]) array)[index] = getFilledValue();
+ }
+
+ @Override
+ Object createValueArray(int size) {
+ return new ${type.dataType}[size];
+ }
+
+ @Override
+ Column createNullValueColumn() {
+ return ${type.column}Builder.NULL_VALUE_BLOCK;
+ }
+
+ @Override
+ Column createFilledValueColumn() {
+ ${type.dataType} filledValue = getFilledValue();
+ return new ${type.column}(1, Optional.empty(), new ${type.dataType}[] {filledValue});
+ }
+
+ @Override
+ Column createFilledValueColumn(Object array, boolean[] isNull, boolean hasNullValue, int size) {
+ if (hasNullValue) {
+ return new ${type.column}(size, Optional.of(isNull), (${type.dataType}[]) array);
+ } else {
+ return new ${type.column}(size, Optional.empty(), (${type.dataType}[]) array);
+ }
+ }
+
+ @Override
+ void updatePreviousValue(Column column, int index) {
+ previousValue = column.get${type.dataType?cap_first}(index);
+ }
+
+ @Override
+ void updateNextValue(Column nextValueColumn, int index) {
+ this.nextValue = nextValueColumn.get${type.dataType?cap_first}(index);
+ }
+
+ @Override
+ void updateNextValueInCurrentColumn(Column nextValueColumn, int index) {
+ this.nextValueInCurrentColumn = nextValueColumn.get${type.dataType?cap_first}(index);
+ }
+
+ @Override
+ void updateNextValueInCurrentColumn() {
+ this.nextValueInCurrentColumn = this.nextValue;
+ }
+
+ private ${type.dataType} getFilledValue() {
+ <#if type.dataType == "double">
+ return (previousValue + nextValueInCurrentColumn) / 2.0;
+ <#elseif type.dataType == "float">
+ return (previousValue + nextValueInCurrentColumn) / 2.0f;
+ <#else>
+ return (previousValue + nextValueInCurrentColumn) / 2;
+ </#if>
+ }
+}
+
+</#list>
\ No newline at end of file
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/linear/DoubleLinearFill.java b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/linear/DoubleLinearFill.java
deleted file mode 100644
index 52a228b1e4..0000000000
--- a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/linear/DoubleLinearFill.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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.execution.operator.process.fill.linear;
-
-import org.apache.iotdb.tsfile.read.common.block.column.Column;
-import org.apache.iotdb.tsfile.read.common.block.column.DoubleColumn;
-import org.apache.iotdb.tsfile.read.common.block.column.DoubleColumnBuilder;
-
-import java.util.Optional;
-
-public class DoubleLinearFill extends LinearFill {
-
- // previous value
- private double previousValue;
- // next non-null value whose time is closest to the current TsBlock's endTime
- private double nextValue;
-
- private double nextValueInCurrentColumn;
-
- @Override
- void fillValue(Column column, int index, Object array) {
- ((double[]) array)[index] = column.getDouble(index);
- }
-
- @Override
- void fillValue(Object array, int index) {
- ((double[]) array)[index] = getFilledValue();
- }
-
- @Override
- Object createValueArray(int size) {
- return new double[size];
- }
-
- @Override
- Column createNullValueColumn() {
- return DoubleColumnBuilder.NULL_VALUE_BLOCK;
- }
-
- @Override
- Column createFilledValueColumn() {
- double filledValue = getFilledValue();
- return new DoubleColumn(1, Optional.empty(), new double[] {filledValue});
- }
-
- @Override
- Column createFilledValueColumn(Object array, boolean[] isNull, boolean hasNullValue, int size) {
- if (hasNullValue) {
- return new DoubleColumn(size, Optional.of(isNull), (double[]) array);
- } else {
- return new DoubleColumn(size, Optional.empty(), (double[]) array);
- }
- }
-
- @Override
- void updatePreviousValue(Column column, int index) {
- previousValue = column.getDouble(index);
- }
-
- @Override
- void updateNextValue(Column nextValueColumn, int index) {
- this.nextValue = nextValueColumn.getDouble(index);
- }
-
- @Override
- void updateNextValueInCurrentColumn(Column nextValueColumn, int index) {
- this.nextValueInCurrentColumn = nextValueColumn.getDouble(index);
- }
-
- @Override
- void updateNextValueInCurrentColumn() {
- this.nextValueInCurrentColumn = this.nextValue;
- }
-
- private double getFilledValue() {
- return (previousValue + nextValueInCurrentColumn) / 2.0;
- }
-}
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/linear/FloatLinearFill.java b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/linear/FloatLinearFill.java
deleted file mode 100644
index a32c60d61e..0000000000
--- a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/linear/FloatLinearFill.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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.execution.operator.process.fill.linear;
-
-import org.apache.iotdb.tsfile.read.common.block.column.Column;
-import org.apache.iotdb.tsfile.read.common.block.column.FloatColumn;
-import org.apache.iotdb.tsfile.read.common.block.column.FloatColumnBuilder;
-
-import java.util.Optional;
-
-public class FloatLinearFill extends LinearFill {
-
- // previous value
- private float previousValue;
- // next non-null value whose time is closest to the current TsBlock's endTime
- private float nextValue;
-
- private float nextValueInCurrentColumn;
-
- @Override
- void fillValue(Column column, int index, Object array) {
- ((float[]) array)[index] = column.getFloat(index);
- }
-
- @Override
- void fillValue(Object array, int index) {
- ((float[]) array)[index] = getFilledValue();
- }
-
- @Override
- Object createValueArray(int size) {
- return new float[size];
- }
-
- @Override
- Column createNullValueColumn() {
- return FloatColumnBuilder.NULL_VALUE_BLOCK;
- }
-
- @Override
- Column createFilledValueColumn() {
- float filledValue = getFilledValue();
- return new FloatColumn(1, Optional.empty(), new float[] {filledValue});
- }
-
- @Override
- Column createFilledValueColumn(Object array, boolean[] isNull, boolean hasNullValue, int size) {
- if (hasNullValue) {
- return new FloatColumn(size, Optional.of(isNull), (float[]) array);
- } else {
- return new FloatColumn(size, Optional.empty(), (float[]) array);
- }
- }
-
- @Override
- void updatePreviousValue(Column column, int index) {
- previousValue = column.getFloat(index);
- }
-
- @Override
- void updateNextValue(Column nextValueColumn, int index) {
- this.nextValue = nextValueColumn.getFloat(index);
- }
-
- @Override
- void updateNextValueInCurrentColumn(Column nextValueColumn, int index) {
- this.nextValueInCurrentColumn = nextValueColumn.getFloat(index);
- }
-
- @Override
- void updateNextValueInCurrentColumn() {
- this.nextValueInCurrentColumn = this.nextValue;
- }
-
- private float getFilledValue() {
- return (previousValue + nextValueInCurrentColumn) / 2.0f;
- }
-}
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/linear/IntLinearFill.java b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/linear/IntLinearFill.java
deleted file mode 100644
index baf4806551..0000000000
--- a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/linear/IntLinearFill.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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.execution.operator.process.fill.linear;
-
-import org.apache.iotdb.tsfile.read.common.block.column.Column;
-import org.apache.iotdb.tsfile.read.common.block.column.IntColumn;
-import org.apache.iotdb.tsfile.read.common.block.column.IntColumnBuilder;
-
-import java.util.Optional;
-
-public class IntLinearFill extends LinearFill {
-
- // previous value
- private int previousValue;
- // next non-null value whose time is closest to the current TsBlock's endTime
- private int nextValue;
-
- private int nextValueInCurrentColumn;
-
- @Override
- void fillValue(Column column, int index, Object array) {
- ((int[]) array)[index] = column.getInt(index);
- }
-
- @Override
- void fillValue(Object array, int index) {
- ((int[]) array)[index] = getFilledValue();
- }
-
- @Override
- Object createValueArray(int size) {
- return new int[size];
- }
-
- @Override
- Column createNullValueColumn() {
- return IntColumnBuilder.NULL_VALUE_BLOCK;
- }
-
- @Override
- Column createFilledValueColumn() {
- int filledValue = getFilledValue();
- return new IntColumn(1, Optional.empty(), new int[] {filledValue});
- }
-
- @Override
- Column createFilledValueColumn(Object array, boolean[] isNull, boolean hasNullValue, int size) {
- if (hasNullValue) {
- return new IntColumn(size, Optional.of(isNull), (int[]) array);
- } else {
- return new IntColumn(size, Optional.empty(), (int[]) array);
- }
- }
-
- @Override
- void updatePreviousValue(Column column, int index) {
- previousValue = column.getInt(index);
- }
-
- @Override
- void updateNextValue(Column nextValueColumn, int index) {
- this.nextValue = nextValueColumn.getInt(index);
- }
-
- @Override
- void updateNextValueInCurrentColumn(Column nextValueColumn, int index) {
- this.nextValueInCurrentColumn = nextValueColumn.getInt(index);
- }
-
- @Override
- void updateNextValueInCurrentColumn() {
- this.nextValueInCurrentColumn = this.nextValue;
- }
-
- private int getFilledValue() {
- return (previousValue + nextValueInCurrentColumn) / 2;
- }
-}
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/linear/LongLinearFill.java b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/linear/LongLinearFill.java
deleted file mode 100644
index 04dba1613a..0000000000
--- a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/linear/LongLinearFill.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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.execution.operator.process.fill.linear;
-
-import org.apache.iotdb.tsfile.read.common.block.column.Column;
-import org.apache.iotdb.tsfile.read.common.block.column.LongColumn;
-import org.apache.iotdb.tsfile.read.common.block.column.LongColumnBuilder;
-
-import java.util.Optional;
-
-public class LongLinearFill extends LinearFill {
-
- // previous value
- private long previousValue;
- // next non-null value whose time is closest to the current TsBlock's endTime
- private long nextValue;
-
- private long nextValueInCurrentColumn;
-
- @Override
- void fillValue(Column column, int index, Object array) {
- ((long[]) array)[index] = column.getLong(index);
- }
-
- @Override
- void fillValue(Object array, int index) {
- ((long[]) array)[index] = getFilledValue();
- }
-
- @Override
- Object createValueArray(int size) {
- return new long[size];
- }
-
- @Override
- Column createNullValueColumn() {
- return LongColumnBuilder.NULL_VALUE_BLOCK;
- }
-
- @Override
- Column createFilledValueColumn() {
- long filledValue = getFilledValue();
- return new LongColumn(1, Optional.empty(), new long[] {filledValue});
- }
-
- @Override
- Column createFilledValueColumn(Object array, boolean[] isNull, boolean hasNullValue, int size) {
- if (hasNullValue) {
- return new LongColumn(size, Optional.of(isNull), (long[]) array);
- } else {
- return new LongColumn(size, Optional.empty(), (long[]) array);
- }
- }
-
- @Override
- void updatePreviousValue(Column column, int index) {
- previousValue = column.getLong(index);
- }
-
- @Override
- void updateNextValue(Column nextValueColumn, int index) {
- this.nextValue = nextValueColumn.getLong(index);
- }
-
- @Override
- void updateNextValueInCurrentColumn(Column nextValueColumn, int index) {
- this.nextValueInCurrentColumn = nextValueColumn.getLong(index);
- }
-
- @Override
- void updateNextValueInCurrentColumn() {
- this.nextValueInCurrentColumn = this.nextValue;
- }
-
- private long getFilledValue() {
- return (previousValue + nextValueInCurrentColumn) / 2L;
- }
-}