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 18815037b1e033aeff04299dd26600eb8cca6ede Author: Alima777 <[email protected]> AuthorDate: Wed Nov 2 16:42:17 2022 +0800 add previousFill.ftl template --- server/src/main/codegen/templates/previousFill.ftl | 99 ++++++++++++++++++++++ .../process/fill/previous/BinaryPreviousFill.java | 86 ------------------- .../process/fill/previous/BooleanPreviousFill.java | 85 ------------------- .../process/fill/previous/DoublePreviousFill.java | 85 ------------------- .../process/fill/previous/FloatPreviousFill.java | 85 ------------------- .../process/fill/previous/IntPreviousFill.java | 85 ------------------- .../process/fill/previous/LongPreviousFill.java | 85 ------------------- 7 files changed, 99 insertions(+), 511 deletions(-) diff --git a/server/src/main/codegen/templates/previousFill.ftl b/server/src/main/codegen/templates/previousFill.ftl new file mode 100644 index 0000000000..426e07cca6 --- /dev/null +++ b/server/src/main/codegen/templates/previousFill.ftl @@ -0,0 +1,99 @@ +/* +* 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 allDataTypes.types as type> + + <#assign className = "${type.dataType?cap_first}PreviousFill"> + <@pp.changeOutputFile name="/org/apache/iotdb/db/mpp/execution/operator/process/fill/previous/${className}.java" /> +package org.apache.iotdb.db.mpp.execution.operator.process.fill.previous; + +import org.apache.iotdb.db.mpp.execution.operator.process.fill.IFill; +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 org.apache.iotdb.tsfile.read.common.block.column.RunLengthEncodedColumn; +<#if type.dataType == "Binary"> + import org.apache.iotdb.tsfile.utils.Binary; +</#if> + +import java.util.Optional; + +/* +* This class is generated using freemarker and the ${.template_name} template. +*/ +@SuppressWarnings("unused") +public class ${className} implements IFill { + + // previous value + private ${type.dataType} value; + // whether previous value is null + private boolean previousIsNull = true; + + @Override + public Column fill(Column valueColumn) { + int size = valueColumn.getPositionCount(); + // if this valueColumn is empty, just return itself; + if (size == 0) { + return valueColumn; + } + // if this valueColumn doesn't have any null value, record the last value, and then return + // itself. + if (!valueColumn.mayHaveNull()) { + previousIsNull = false; + // update the value using last non-null value + value = valueColumn.get${type.dataType?cap_first}(size - 1); + return valueColumn; + } + // if its values are all null + if (valueColumn instanceof RunLengthEncodedColumn) { + if (previousIsNull) { + return new RunLengthEncodedColumn(${type.column}Builder.NULL_VALUE_BLOCK, size); + } else { + return new RunLengthEncodedColumn( + new ${type.column}(1, Optional.empty(), new ${type.dataType}[] {value}), size); + } + } else { + ${type.dataType}[] array = new ${type.dataType}[size]; + boolean[] isNull = new boolean[size]; + // have null value + boolean hasNullValue = false; + for (int i = 0; i < size; i++) { + if (valueColumn.isNull(i)) { + if (previousIsNull) { + isNull[i] = true; + hasNullValue = true; + } else { + array[i] = value; + } + } else { + array[i] = valueColumn.get${type.dataType?cap_first}(i); + value = array[i]; + previousIsNull = false; + } + } + if (hasNullValue) { + return new ${type.column}(size, Optional.of(isNull), array); + } else { + return new ${type.column}(size, Optional.empty(), array); + } + } + } +} +</#list> \ No newline at end of file diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/previous/BinaryPreviousFill.java b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/previous/BinaryPreviousFill.java deleted file mode 100644 index ef298e54c1..0000000000 --- a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/previous/BinaryPreviousFill.java +++ /dev/null @@ -1,86 +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.previous; - -import org.apache.iotdb.db.mpp.execution.operator.process.fill.IFill; -import org.apache.iotdb.tsfile.read.common.block.column.BinaryColumn; -import org.apache.iotdb.tsfile.read.common.block.column.BinaryColumnBuilder; -import org.apache.iotdb.tsfile.read.common.block.column.Column; -import org.apache.iotdb.tsfile.read.common.block.column.RunLengthEncodedColumn; -import org.apache.iotdb.tsfile.utils.Binary; - -import java.util.Optional; - -public class BinaryPreviousFill implements IFill { - - // previous value - private Binary value; - // whether previous value is null - private boolean previousIsNull = true; - - @Override - public Column fill(Column valueColumn) { - int size = valueColumn.getPositionCount(); - // if this valueColumn is empty, just return itself; - if (size == 0) { - return valueColumn; - } - // if this valueColumn doesn't have any null value, record the last value, and then return - // itself. - if (!valueColumn.mayHaveNull()) { - previousIsNull = false; - // update the value using last non-null value - value = valueColumn.getBinary(size - 1); - return valueColumn; - } - // if its values are all null - if (valueColumn instanceof RunLengthEncodedColumn) { - if (previousIsNull) { - return new RunLengthEncodedColumn(BinaryColumnBuilder.NULL_VALUE_BLOCK, size); - } else { - return new RunLengthEncodedColumn( - new BinaryColumn(1, Optional.empty(), new Binary[] {value}), size); - } - } else { - Binary[] array = new Binary[size]; - boolean[] isNull = new boolean[size]; - // have null value - boolean hasNullValue = false; - for (int i = 0; i < size; i++) { - if (valueColumn.isNull(i)) { - if (previousIsNull) { - isNull[i] = true; - hasNullValue = true; - } else { - array[i] = value; - } - } else { - array[i] = valueColumn.getBinary(i); - value = array[i]; - previousIsNull = false; - } - } - if (hasNullValue) { - return new BinaryColumn(size, Optional.of(isNull), array); - } else { - return new BinaryColumn(size, Optional.empty(), array); - } - } - } -} diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/previous/BooleanPreviousFill.java b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/previous/BooleanPreviousFill.java deleted file mode 100644 index 74bf4466a3..0000000000 --- a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/previous/BooleanPreviousFill.java +++ /dev/null @@ -1,85 +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.previous; - -import org.apache.iotdb.db.mpp.execution.operator.process.fill.IFill; -import org.apache.iotdb.tsfile.read.common.block.column.BooleanColumn; -import org.apache.iotdb.tsfile.read.common.block.column.BooleanColumnBuilder; -import org.apache.iotdb.tsfile.read.common.block.column.Column; -import org.apache.iotdb.tsfile.read.common.block.column.RunLengthEncodedColumn; - -import java.util.Optional; - -public class BooleanPreviousFill implements IFill { - - // previous value - private boolean value; - // whether previous value is null - private boolean previousIsNull = true; - - @Override - public Column fill(Column valueColumn) { - int size = valueColumn.getPositionCount(); - // if this valueColumn is empty, just return itself; - if (size == 0) { - return valueColumn; - } - // if this valueColumn doesn't have any null value, record the last value, and then return - // itself. - if (!valueColumn.mayHaveNull()) { - previousIsNull = false; - // update the value using last non-null value - value = valueColumn.getBoolean(size - 1); - return valueColumn; - } - // if its values are all null - if (valueColumn instanceof RunLengthEncodedColumn) { - if (previousIsNull) { - return new RunLengthEncodedColumn(BooleanColumnBuilder.NULL_VALUE_BLOCK, size); - } else { - return new RunLengthEncodedColumn( - new BooleanColumn(1, Optional.empty(), new boolean[] {value}), size); - } - } else { - boolean[] array = new boolean[size]; - boolean[] isNull = new boolean[size]; - // have null value - boolean hasNullValue = false; - for (int i = 0; i < size; i++) { - if (valueColumn.isNull(i)) { - if (previousIsNull) { - isNull[i] = true; - hasNullValue = true; - } else { - array[i] = value; - } - } else { - array[i] = valueColumn.getBoolean(i); - value = array[i]; - previousIsNull = false; - } - } - if (hasNullValue) { - return new BooleanColumn(size, Optional.of(isNull), array); - } else { - return new BooleanColumn(size, Optional.empty(), array); - } - } - } -} diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/previous/DoublePreviousFill.java b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/previous/DoublePreviousFill.java deleted file mode 100644 index 044d398705..0000000000 --- a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/previous/DoublePreviousFill.java +++ /dev/null @@ -1,85 +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.previous; - -import org.apache.iotdb.db.mpp.execution.operator.process.fill.IFill; -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 org.apache.iotdb.tsfile.read.common.block.column.RunLengthEncodedColumn; - -import java.util.Optional; - -public class DoublePreviousFill implements IFill { - - // previous value - private double value; - // whether previous value is null - private boolean previousIsNull = true; - - @Override - public Column fill(Column valueColumn) { - int size = valueColumn.getPositionCount(); - // if this valueColumn is empty, just return itself; - if (size == 0) { - return valueColumn; - } - // if this valueColumn doesn't have any null value, record the last value, and then return - // itself. - if (!valueColumn.mayHaveNull()) { - previousIsNull = false; - // update the value using last non-null value - value = valueColumn.getDouble(size - 1); - return valueColumn; - } - // if its values are all null - if (valueColumn instanceof RunLengthEncodedColumn) { - if (previousIsNull) { - return new RunLengthEncodedColumn(DoubleColumnBuilder.NULL_VALUE_BLOCK, size); - } else { - return new RunLengthEncodedColumn( - new DoubleColumn(1, Optional.empty(), new double[] {value}), size); - } - } else { - double[] array = new double[size]; - boolean[] isNull = new boolean[size]; - // have null value - boolean hasNullValue = false; - for (int i = 0; i < size; i++) { - if (valueColumn.isNull(i)) { - if (previousIsNull) { - isNull[i] = true; - hasNullValue = true; - } else { - array[i] = value; - } - } else { - array[i] = valueColumn.getDouble(i); - value = array[i]; - previousIsNull = false; - } - } - if (hasNullValue) { - return new DoubleColumn(size, Optional.of(isNull), array); - } else { - return new DoubleColumn(size, Optional.empty(), array); - } - } - } -} diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/previous/FloatPreviousFill.java b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/previous/FloatPreviousFill.java deleted file mode 100644 index 6eec0f1eb0..0000000000 --- a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/previous/FloatPreviousFill.java +++ /dev/null @@ -1,85 +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.previous; - -import org.apache.iotdb.db.mpp.execution.operator.process.fill.IFill; -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 org.apache.iotdb.tsfile.read.common.block.column.RunLengthEncodedColumn; - -import java.util.Optional; - -public class FloatPreviousFill implements IFill { - - // previous value - private float value; - // whether previous value is null - private boolean previousIsNull = true; - - @Override - public Column fill(Column valueColumn) { - int size = valueColumn.getPositionCount(); - // if this valueColumn is empty, just return itself; - if (size == 0) { - return valueColumn; - } - // if this valueColumn doesn't have any null value, record the last value, and then return - // itself. - if (!valueColumn.mayHaveNull()) { - previousIsNull = false; - // update the value using last non-null value - value = valueColumn.getFloat(size - 1); - return valueColumn; - } - // if its values are all null - if (valueColumn instanceof RunLengthEncodedColumn) { - if (previousIsNull) { - return new RunLengthEncodedColumn(FloatColumnBuilder.NULL_VALUE_BLOCK, size); - } else { - return new RunLengthEncodedColumn( - new FloatColumn(1, Optional.empty(), new float[] {value}), size); - } - } else { - float[] array = new float[size]; - boolean[] isNull = new boolean[size]; - // have null value - boolean hasNullValue = false; - for (int i = 0; i < size; i++) { - if (valueColumn.isNull(i)) { - if (previousIsNull) { - isNull[i] = true; - hasNullValue = true; - } else { - array[i] = value; - } - } else { - array[i] = valueColumn.getFloat(i); - value = array[i]; - previousIsNull = false; - } - } - if (hasNullValue) { - return new FloatColumn(size, Optional.of(isNull), array); - } else { - return new FloatColumn(size, Optional.empty(), array); - } - } - } -} diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/previous/IntPreviousFill.java b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/previous/IntPreviousFill.java deleted file mode 100644 index b2864fad39..0000000000 --- a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/previous/IntPreviousFill.java +++ /dev/null @@ -1,85 +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.previous; - -import org.apache.iotdb.db.mpp.execution.operator.process.fill.IFill; -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 org.apache.iotdb.tsfile.read.common.block.column.RunLengthEncodedColumn; - -import java.util.Optional; - -public class IntPreviousFill implements IFill { - - // previous value - private int value; - // whether previous value is null - private boolean previousIsNull = true; - - @Override - public Column fill(Column valueColumn) { - int size = valueColumn.getPositionCount(); - // if this valueColumn is empty, just return itself; - if (size == 0) { - return valueColumn; - } - // if this valueColumn doesn't have any null value, record the last value, and then return - // itself. - if (!valueColumn.mayHaveNull()) { - previousIsNull = false; - // update the value using last non-null value - value = valueColumn.getInt(size - 1); - return valueColumn; - } - // if its values are all null - if (valueColumn instanceof RunLengthEncodedColumn) { - if (previousIsNull) { - return new RunLengthEncodedColumn(IntColumnBuilder.NULL_VALUE_BLOCK, size); - } else { - return new RunLengthEncodedColumn( - new IntColumn(1, Optional.empty(), new int[] {value}), size); - } - } else { - int[] array = new int[size]; - boolean[] isNull = new boolean[size]; - // have null value - boolean hasNullValue = false; - for (int i = 0; i < size; i++) { - if (valueColumn.isNull(i)) { - if (previousIsNull) { - isNull[i] = true; - hasNullValue = true; - } else { - array[i] = value; - } - } else { - array[i] = valueColumn.getInt(i); - value = array[i]; - previousIsNull = false; - } - } - if (hasNullValue) { - return new IntColumn(size, Optional.of(isNull), array); - } else { - return new IntColumn(size, Optional.empty(), array); - } - } - } -} diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/previous/LongPreviousFill.java b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/previous/LongPreviousFill.java deleted file mode 100644 index a90ab9b039..0000000000 --- a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/previous/LongPreviousFill.java +++ /dev/null @@ -1,85 +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.previous; - -import org.apache.iotdb.db.mpp.execution.operator.process.fill.IFill; -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 org.apache.iotdb.tsfile.read.common.block.column.RunLengthEncodedColumn; - -import java.util.Optional; - -public class LongPreviousFill implements IFill { - - // previous value - private long value; - // whether previous value is null - private boolean previousIsNull = true; - - @Override - public Column fill(Column valueColumn) { - int size = valueColumn.getPositionCount(); - // if this valueColumn is empty, just return itself; - if (size == 0) { - return valueColumn; - } - // if this valueColumn doesn't have any null value, record the last value, and then return - // itself. - if (!valueColumn.mayHaveNull()) { - previousIsNull = false; - // update the value using last non-null value - value = valueColumn.getLong(size - 1); - return valueColumn; - } - // if its values are all null - if (valueColumn instanceof RunLengthEncodedColumn) { - if (previousIsNull) { - return new RunLengthEncodedColumn(LongColumnBuilder.NULL_VALUE_BLOCK, size); - } else { - return new RunLengthEncodedColumn( - new LongColumn(1, Optional.empty(), new long[] {value}), size); - } - } else { - long[] array = new long[size]; - boolean[] isNull = new boolean[size]; - // have null value - boolean hasNullValue = false; - for (int i = 0; i < size; i++) { - if (valueColumn.isNull(i)) { - if (previousIsNull) { - isNull[i] = true; - hasNullValue = true; - } else { - array[i] = value; - } - } else { - array[i] = valueColumn.getLong(i); - value = array[i]; - previousIsNull = false; - } - } - if (hasNullValue) { - return new LongColumn(size, Optional.of(isNull), array); - } else { - return new LongColumn(size, Optional.empty(), array); - } - } - } -}
