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:00 UTC
[iotdb] 01/05: add freemarker files and remove contantfill
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 701ea4258805716cb34e18a35ae4453dadf359bd
Author: Alima777 <wx...@gmail.com>
AuthorDate: Tue Nov 1 21:06:20 2022 +0800
add freemarker files and remove contantfill
---
pom.xml | 3 ++
server/pom.xml | 42 +++++++++++++++
server/src/main/codegen/config.fmpp | 7 +++
server/src/main/codegen/templates/constantFill.ftl | 55 +++++++++++++++++++
.../process/fill/constant/BinaryConstantFill.java | 63 ----------------------
.../process/fill/constant/BooleanConstantFill.java | 62 ---------------------
.../process/fill/constant/DoubleConstantFill.java | 62 ---------------------
.../process/fill/constant/FloatConstantFill.java | 62 ---------------------
.../process/fill/constant/IntConstantFill.java | 62 ---------------------
.../process/fill/constant/LongConstantFill.java | 62 ---------------------
10 files changed, 107 insertions(+), 373 deletions(-)
diff --git a/pom.xml b/pom.xml
index 192c89a951..1fe7183b07 100644
--- a/pom.xml
+++ b/pom.xml
@@ -224,6 +224,9 @@
<commons-lang.version>2.6</commons-lang.version>
<influxdb-java.version>2.21</influxdb-java.version>
<JTransforms.version>3.1</JTransforms.version>
+ <!-- codegen -->
+ <drill.freemarker.maven.plugin.version>1.17.0</drill.freemarker.maven.plugin.version>
+ <codegen.phase>generate-sources</codegen.phase>
</properties>
<!--
if we claim dependencies in dependencyManagement, then we do not claim
diff --git a/server/pom.xml b/server/pom.xml
index 31d8ef3587..b835f49872 100644
--- a/server/pom.xml
+++ b/server/pom.xml
@@ -296,6 +296,48 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <artifactId>maven-resources-plugin</artifactId>
+ <executions>
+ <execution>
+ <!-- copy all templates/data in the same location to compile them at once -->
+ <id>copy-fmpp-resources</id>
+ <phase>initialize</phase>
+ <goals>
+ <goal>copy-resources</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${project.build.directory}/codegen</outputDirectory>
+ <resources>
+ <resource>
+ <directory>src/main/codegen</directory>
+ <filtering>false</filtering>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <!-- generate sources from fmpp -->
+ <groupId>org.apache.drill.tools</groupId>
+ <artifactId>drill-fmpp-maven-plugin</artifactId>
+ <version>${drill.freemarker.maven.plugin.version}</version>
+ <executions>
+ <execution>
+ <id>generate-fmpp</id>
+ <phase>${codegen.phase}</phase>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ <configuration>
+ <config>${project.build.directory}/codegen/config.fmpp</config>
+ <output>${project.build.directory}/generated-sources</output>
+ <templates>${project.build.directory}/codegen/templates</templates>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
<profiles>
diff --git a/server/src/main/codegen/config.fmpp b/server/src/main/codegen/config.fmpp
new file mode 100644
index 0000000000..80402a94d6
--- /dev/null
+++ b/server/src/main/codegen/config.fmpp
@@ -0,0 +1,7 @@
+data: {
+ dataTypes: tdd(../data/DataType.tdd),
+ decimalDataTypes: tdd(../data/DataType.tdd),
+}
+freemarkerLinks: {
+ includes: includes/
+}
\ No newline at end of file
diff --git a/server/src/main/codegen/templates/constantFill.ftl b/server/src/main/codegen/templates/constantFill.ftl
new file mode 100644
index 0000000000..d2080816aa
--- /dev/null
+++ b/server/src/main/codegen/templates/constantFill.ftl
@@ -0,0 +1,55 @@
+<@pp.dropOutputFile />
+
+<#list dataTypes.types as type>
+
+ <#assign className = "${operator.upperDataType}ConstantFill">
+ <@pp.changeOutputFile name="/org/apache/iotdb/db/mpp/execution/operator/process/fill/constant/${className}.java" />
+package org.apache.iotdb.db.mpp.execution.operator.process.fill.constant;
+
+import org.apache.iotdb.db.mpp.execution.operator.process.fill.IFill;
+import org.apache.iotdb.tsfile.read.common.block.column.${type.upperDataType}Column;
+import org.apache.iotdb.tsfile.read.common.block.column.Column;
+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;
+
+public class ${className} implements IFill {
+
+ // fill value
+ private final ${type.dataType} value;
+ // used for constructing RunLengthEncodedColumn, size of it must be 1
+ private final ${type.dataType}[] valueArray;
+
+ public ${className}(${type.dataType} value) {
+ this.value = value;
+ this.valueArray = new ${type.dataType}[] {value};
+ }
+
+ @Override
+ public Column fill(Column valueColumn) {
+ int size = valueColumn.getPositionCount();
+ // if this valueColumn doesn't have any null value, or it's empty, just return itself;
+ if (!valueColumn.mayHaveNull() || size == 0) {
+ return valueColumn;
+ }
+ // if its values are all null
+ if (valueColumn instanceof RunLengthEncodedColumn) {
+ return new RunLengthEncodedColumn(new ${type.upperDataType}Column(1, Optional.empty(), valueArray), size);
+ } else {
+ ${type.dataType}[] array = new ${type.dataType}[size];
+ for (int i = 0; i < size; i++) {
+ if (valueColumn.isNull(i)) {
+ array[i] = value;
+ } else {
+ array[i] = valueColumn.get${type.upperDataType}(i);
+ }
+ }
+ return new ${type.upperDataType}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/constant/BinaryConstantFill.java b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/constant/BinaryConstantFill.java
deleted file mode 100644
index f590adced3..0000000000
--- a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/constant/BinaryConstantFill.java
+++ /dev/null
@@ -1,63 +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.constant;
-
-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.Column;
-import org.apache.iotdb.tsfile.read.common.block.column.RunLengthEncodedColumn;
-import org.apache.iotdb.tsfile.utils.Binary;
-
-import java.util.Optional;
-
-public class BinaryConstantFill implements IFill {
-
- // fill value
- private final Binary value;
- // used for constructing RunLengthEncodedColumn, size of it must be 1
- private final Binary[] valueArray;
-
- public BinaryConstantFill(Binary value) {
- this.value = value;
- this.valueArray = new Binary[] {value};
- }
-
- @Override
- public Column fill(Column valueColumn) {
- int size = valueColumn.getPositionCount();
- // if this valueColumn doesn't have any null value, or it's empty, just return itself;
- if (!valueColumn.mayHaveNull() || size == 0) {
- return valueColumn;
- }
- // if its values are all null
- if (valueColumn instanceof RunLengthEncodedColumn) {
- return new RunLengthEncodedColumn(new BinaryColumn(1, Optional.empty(), valueArray), size);
- } else {
- Binary[] array = new Binary[size];
- for (int i = 0; i < size; i++) {
- if (valueColumn.isNull(i)) {
- array[i] = value;
- } else {
- array[i] = valueColumn.getBinary(i);
- }
- }
- return new BinaryColumn(size, Optional.empty(), array);
- }
- }
-}
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/constant/BooleanConstantFill.java b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/constant/BooleanConstantFill.java
deleted file mode 100644
index 7604248242..0000000000
--- a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/constant/BooleanConstantFill.java
+++ /dev/null
@@ -1,62 +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.constant;
-
-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.Column;
-import org.apache.iotdb.tsfile.read.common.block.column.RunLengthEncodedColumn;
-
-import java.util.Optional;
-
-public class BooleanConstantFill implements IFill {
-
- // fill value
- private final boolean value;
- // used for constructing RunLengthEncodedColumn
- private final boolean[] valueArray;
-
- public BooleanConstantFill(boolean value) {
- this.value = value;
- this.valueArray = new boolean[] {value};
- }
-
- @Override
- public Column fill(Column valueColumn) {
- int size = valueColumn.getPositionCount();
- // if this valueColumn doesn't have any null value, or it's empty, just return itself;
- if (!valueColumn.mayHaveNull() || size == 0) {
- return valueColumn;
- }
- // if its values are all null
- if (valueColumn instanceof RunLengthEncodedColumn) {
- return new RunLengthEncodedColumn(new BooleanColumn(1, Optional.empty(), valueArray), size);
- } else {
- boolean[] array = new boolean[size];
- for (int i = 0; i < size; i++) {
- if (valueColumn.isNull(i)) {
- array[i] = value;
- } else {
- array[i] = valueColumn.getBoolean(i);
- }
- }
- return new BooleanColumn(size, Optional.empty(), array);
- }
- }
-}
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/constant/DoubleConstantFill.java b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/constant/DoubleConstantFill.java
deleted file mode 100644
index 4615619312..0000000000
--- a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/constant/DoubleConstantFill.java
+++ /dev/null
@@ -1,62 +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.constant;
-
-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.RunLengthEncodedColumn;
-
-import java.util.Optional;
-
-public class DoubleConstantFill implements IFill {
-
- // fill value
- private final double value;
- // used for constructing RunLengthEncodedColumn
- private final double[] valueArray;
-
- public DoubleConstantFill(double value) {
- this.value = value;
- this.valueArray = new double[] {value};
- }
-
- @Override
- public Column fill(Column valueColumn) {
- int size = valueColumn.getPositionCount();
- // if this valueColumn doesn't have any null value, or it's empty, just return itself;
- if (!valueColumn.mayHaveNull() || size == 0) {
- return valueColumn;
- }
- // if its values are all null
- if (valueColumn instanceof RunLengthEncodedColumn) {
- return new RunLengthEncodedColumn(new DoubleColumn(1, Optional.empty(), valueArray), size);
- } else {
- double[] array = new double[size];
- for (int i = 0; i < size; i++) {
- if (valueColumn.isNull(i)) {
- array[i] = value;
- } else {
- array[i] = valueColumn.getDouble(i);
- }
- }
- return new DoubleColumn(size, Optional.empty(), array);
- }
- }
-}
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/constant/FloatConstantFill.java b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/constant/FloatConstantFill.java
deleted file mode 100644
index f7d0dc0f32..0000000000
--- a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/constant/FloatConstantFill.java
+++ /dev/null
@@ -1,62 +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.constant;
-
-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.RunLengthEncodedColumn;
-
-import java.util.Optional;
-
-public class FloatConstantFill implements IFill {
-
- // fill value
- private final float value;
- // used for constructing RunLengthEncodedColumn
- private final float[] valueArray;
-
- public FloatConstantFill(float value) {
- this.value = value;
- this.valueArray = new float[] {value};
- }
-
- @Override
- public Column fill(Column valueColumn) {
- int size = valueColumn.getPositionCount();
- // if this valueColumn doesn't have any null value, or it's empty, just return itself;
- if (!valueColumn.mayHaveNull() || size == 0) {
- return valueColumn;
- }
- // if its values are all null
- if (valueColumn instanceof RunLengthEncodedColumn) {
- return new RunLengthEncodedColumn(new FloatColumn(1, Optional.empty(), valueArray), size);
- } else {
- float[] array = new float[size];
- for (int i = 0; i < size; i++) {
- if (valueColumn.isNull(i)) {
- array[i] = value;
- } else {
- array[i] = valueColumn.getFloat(i);
- }
- }
- return new FloatColumn(size, Optional.empty(), array);
- }
- }
-}
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/constant/IntConstantFill.java b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/constant/IntConstantFill.java
deleted file mode 100644
index bbe34abf6c..0000000000
--- a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/constant/IntConstantFill.java
+++ /dev/null
@@ -1,62 +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.constant;
-
-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.RunLengthEncodedColumn;
-
-import java.util.Optional;
-
-public class IntConstantFill implements IFill {
-
- // fill value
- private final int value;
- // used for constructing RunLengthEncodedColumn
- private final int[] valueArray;
-
- public IntConstantFill(int value) {
- this.value = value;
- this.valueArray = new int[] {value};
- }
-
- @Override
- public Column fill(Column valueColumn) {
- int size = valueColumn.getPositionCount();
- // if this valueColumn doesn't have any null value, or it's empty, just return itself;
- if (!valueColumn.mayHaveNull() || size == 0) {
- return valueColumn;
- }
- // if its values are all null
- if (valueColumn instanceof RunLengthEncodedColumn) {
- return new RunLengthEncodedColumn(new IntColumn(1, Optional.empty(), valueArray), size);
- } else {
- int[] array = new int[size];
- for (int i = 0; i < size; i++) {
- if (valueColumn.isNull(i)) {
- array[i] = value;
- } else {
- array[i] = valueColumn.getInt(i);
- }
- }
- return new IntColumn(size, Optional.empty(), array);
- }
- }
-}
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/constant/LongConstantFill.java b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/constant/LongConstantFill.java
deleted file mode 100644
index 72721980da..0000000000
--- a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/process/fill/constant/LongConstantFill.java
+++ /dev/null
@@ -1,62 +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.constant;
-
-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.RunLengthEncodedColumn;
-
-import java.util.Optional;
-
-public class LongConstantFill implements IFill {
-
- // fill value
- private final long value;
- // used for constructing RunLengthEncodedColumn
- private final long[] valueArray;
-
- public LongConstantFill(long value) {
- this.value = value;
- this.valueArray = new long[] {value};
- }
-
- @Override
- public Column fill(Column valueColumn) {
- int size = valueColumn.getPositionCount();
- // if this valueColumn doesn't have any null value, or it's empty, just return itself;
- if (!valueColumn.mayHaveNull() || size == 0) {
- return valueColumn;
- }
- // if its values are all null
- if (valueColumn instanceof RunLengthEncodedColumn) {
- return new RunLengthEncodedColumn(new LongColumn(1, Optional.empty(), valueArray), size);
- } else {
- long[] array = new long[size];
- for (int i = 0; i < size; i++) {
- if (valueColumn.isNull(i)) {
- array[i] = value;
- } else {
- array[i] = valueColumn.getLong(i);
- }
- }
- return new LongColumn(size, Optional.empty(), array);
- }
- }
-}