Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.2k
Finish window function query planning stage.#15151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
7411b10e78b5ab56e9dcbceaaf4493990abb64d98c869a293ea542c86b974abf4ed43602e3f468046876430d756591174c85374da858726965c06dd45f425c7f51f405ac09abfc6873800ea70620b405af11a3792e1ab81243e17a044586ca941c06ecc175384ba9cd4bcb07f12252899b5958c3221331605b6a4aeb67f7735b97e0cfbdb87d4c97eeeca34830f1608165b9115695110967ed5ad9f66ce863b5767ffdec686af25b406f90f9278053ca65c8703145efe8c3ad821f104b0013c1e771056b5224b64File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -171,6 +171,9 @@ private TsBlock getFilterTsBlock(TsBlock input) { | ||
| if (!hasNonMappableUDF) { | ||
| // get result of calculated common sub expressions | ||
| for (ColumnTransformer columnTransformer : commonTransformerList) { | ||
| // CASE WHEN clause would clear all its cache | ||
| // evaluate again to acquire cache | ||
| columnTransformer.tryEvaluate(); | ||
CopilotAI | ||
| resultColumns.add(columnTransformer.getColumn()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * 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.queryengine.execution.operator.process.window.function; | ||
| import org.apache.iotdb.db.queryengine.execution.operator.process.window.function.rank.CumeDistFunction; | ||
| import org.apache.iotdb.db.queryengine.execution.operator.process.window.function.rank.DenseRankFunction; | ||
| import org.apache.iotdb.db.queryengine.execution.operator.process.window.function.rank.NTileFunction; | ||
| import org.apache.iotdb.db.queryengine.execution.operator.process.window.function.rank.PercentRankFunction; | ||
| import org.apache.iotdb.db.queryengine.execution.operator.process.window.function.rank.RankFunction; | ||
| import org.apache.iotdb.db.queryengine.execution.operator.process.window.function.rank.RowNumberFunction; | ||
| import org.apache.iotdb.db.queryengine.execution.operator.process.window.function.value.FirstValueFunction; | ||
| import org.apache.iotdb.db.queryengine.execution.operator.process.window.function.value.LagFunction; | ||
| import org.apache.iotdb.db.queryengine.execution.operator.process.window.function.value.LastValueFunction; | ||
| import org.apache.iotdb.db.queryengine.execution.operator.process.window.function.value.LeadFunction; | ||
| import org.apache.iotdb.db.queryengine.execution.operator.process.window.function.value.NthValueFunction; | ||
| import java.util.List; | ||
| public class WindowFunctionFactory { | ||
| public static WindowFunction createBuiltinWindowFunction( | ||
| String functionName, List<Integer> argumentChannels, boolean ignoreNulls) { | ||
| switch (functionName) { | ||
| case "nth_value": | ||
| return new NthValueFunction(argumentChannels, ignoreNulls); | ||
| case "first_value": | ||
| return new FirstValueFunction(argumentChannels.get(0), ignoreNulls); | ||
| case "last_value": | ||
| return new LastValueFunction(argumentChannels.get(0), ignoreNulls); | ||
| case "lead": | ||
| return new LeadFunction(argumentChannels, ignoreNulls); | ||
| case "lag": | ||
| return new LagFunction(argumentChannels, ignoreNulls); | ||
| case "rank": | ||
| return new RankFunction(); | ||
| case "dense_rank": | ||
| return new DenseRankFunction(); | ||
| case "row_number": | ||
| return new RowNumberFunction(); | ||
| case "percent_rank": | ||
| return new PercentRankFunction(); | ||
| case "cume_dist": | ||
| return new CumeDistFunction(); | ||
| case "ntile": | ||
| return new NTileFunction(argumentChannels.get(0)); | ||
| default: | ||
| throw new UnsupportedOperationException( | ||
| "Unsupported built-in window function name: " + functionName); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -22,23 +22,34 @@ | ||
| import org.apache.iotdb.db.queryengine.execution.operator.process.window.partition.Partition; | ||
| import org.apache.tsfile.block.column.ColumnBuilder; | ||
| import org.apache.tsfile.enums.TSDataType; | ||
| import org.apache.tsfile.write.UnSupportedDataTypeException; | ||
| import java.util.List; | ||
| public class LagFunction extends ValueWindowFunction { | ||
| private final int channel; | ||
| private final Integer offset; | ||
| private final Object defaultVal; | ||
| private final int offsetChannel; | ||
| private final int defaultValChannel; | ||
| private final boolean ignoreNull; | ||
| public LagFunction(int channel, Integer offset, Object defaultVal, boolean ignoreNull) { | ||
| this.channel = channel; | ||
| this.offset = offset == null ? 1 : offset; | ||
| this.defaultVal = defaultVal; | ||
| public LagFunction(List<Integer> argumentChannels, boolean ignoreNull) { | ||
| this.channel = argumentChannels.get(0); | ||
| this.offsetChannel = argumentChannels.size() > 1 ? argumentChannels.get(1) : -1; | ||
| this.defaultValChannel = argumentChannels.size() > 2 ? argumentChannels.get(2) : -1; | ||
| this.ignoreNull = ignoreNull; | ||
| } | ||
| @Override | ||
| public void transform( | ||
| Partition partition, ColumnBuilder builder, int index, int frameStart, int frameEnd) { | ||
| if (offsetChannel >= 0 && partition.isNull(offsetChannel, index)) { | ||
| builder.appendNull(); | ||
| return; | ||
| } | ||
| int offset = offsetChannel >= 0 ? partition.getInt(offsetChannel, index) : 1; | ||
| int pos; | ||
| if (ignoreNull) { | ||
| int nonNullCount = 0; | ||
| @@ -63,13 +74,45 @@ public void transform( | ||
| } else { | ||
| builder.appendNull(); | ||
| } | ||
| } else if (defaultVal != null) { | ||
| builder.writeObject(defaultVal); | ||
| } else if (defaultValChannel >= 0) { | ||
| writeDefaultValue(partition, defaultValChannel, index, builder); | ||
| } else { | ||
| builder.appendNull(); | ||
| } | ||
| } | ||
| private void writeDefaultValue( | ||
| Partition partition, int defaultValChannel, int index, ColumnBuilder builder) { | ||
| TSDataType dataType = builder.getDataType(); | ||
| switch (dataType) { | ||
| case INT32: | ||
| case DATE: | ||
| builder.writeInt(partition.getInt(defaultValChannel, index)); | ||
| return; | ||
| case INT64: | ||
| case TIMESTAMP: | ||
| builder.writeLong(partition.getLong(defaultValChannel, index)); | ||
| return; | ||
| case FLOAT: | ||
| builder.writeFloat(partition.getFloat(defaultValChannel, index)); | ||
| return; | ||
| case DOUBLE: | ||
| builder.writeDouble(partition.getDouble(defaultValChannel, index)); | ||
| return; | ||
| case BOOLEAN: | ||
| builder.writeBoolean(partition.getBoolean(defaultValChannel, index)); | ||
| return; | ||
| case TEXT: | ||
| case STRING: | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. | ||
| case BLOB: | ||
| builder.writeBinary(partition.getBinary(defaultValChannel, index)); | ||
| return; | ||
| default: | ||
| throw new UnSupportedDataTypeException( | ||
| "Unsupported default value's data type in Lag: " + dataType); | ||
| } | ||
| } | ||
| @Override | ||
| public boolean needFrame() { | ||
| return false; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -22,24 +22,34 @@ | ||
| import org.apache.iotdb.db.queryengine.execution.operator.process.window.partition.Partition; | ||
| import org.apache.tsfile.block.column.ColumnBuilder; | ||
| import org.apache.tsfile.enums.TSDataType; | ||
| import org.apache.tsfile.write.UnSupportedDataTypeException; | ||
| import java.util.List; | ||
| public class LeadFunction extends ValueWindowFunction { | ||
| private final int channel; | ||
| private final Integer offset; | ||
| private final Integer defaultVal; | ||
| private final int offsetChannel; | ||
| private final int defaultValChannel; | ||
| private final boolean ignoreNull; | ||
| public LeadFunction(int channel, Integer offset, Integer defaultVal, boolean ignoreNull) { | ||
| this.channel = channel; | ||
| this.offset = offset == null ? 1 : offset; | ||
| this.defaultVal = defaultVal; | ||
| public LeadFunction(List<Integer> argumentChannels, boolean ignoreNull) { | ||
| this.channel = argumentChannels.get(0); | ||
| this.offsetChannel = argumentChannels.size() > 1 ? argumentChannels.get(1) : -1; | ||
| this.defaultValChannel = argumentChannels.size() > 2 ? argumentChannels.get(2) : -1; | ||
| this.ignoreNull = ignoreNull; | ||
| } | ||
| @Override | ||
| public void transform( | ||
| Partition partition, ColumnBuilder builder, int index, int frameStart, int frameEnd) { | ||
| if (offsetChannel >= 0 && partition.isNull(offsetChannel, index)) { | ||
| builder.appendNull(); | ||
| return; | ||
| } | ||
| int length = partition.getPositionCount(); | ||
| int offset = offsetChannel >= 0 ? partition.getInt(offsetChannel, index) : 1; | ||
| int pos; | ||
| if (ignoreNull) { | ||
| @@ -65,13 +75,45 @@ public void transform( | ||
| } else { | ||
| builder.appendNull(); | ||
| } | ||
| } else if (defaultVal != null) { | ||
| builder.writeObject(defaultVal); | ||
| } else if (defaultValChannel >= 0) { | ||
| writeDefaultValue(partition, defaultValChannel, index, builder); | ||
| } else { | ||
| builder.appendNull(); | ||
| } | ||
| } | ||
| private void writeDefaultValue( | ||
| Partition partition, int defaultValChannel, int index, ColumnBuilder builder) { | ||
| TSDataType dataType = builder.getDataType(); | ||
| switch (dataType) { | ||
| case INT32: | ||
| case DATE: | ||
| builder.writeInt(partition.getInt(defaultValChannel, index)); | ||
| return; | ||
| case INT64: | ||
| case TIMESTAMP: | ||
| builder.writeLong(partition.getLong(defaultValChannel, index)); | ||
| return; | ||
| case FLOAT: | ||
| builder.writeFloat(partition.getFloat(defaultValChannel, index)); | ||
| return; | ||
| case DOUBLE: | ||
| builder.writeDouble(partition.getDouble(defaultValChannel, index)); | ||
| return; | ||
| case BOOLEAN: | ||
| builder.writeBoolean(partition.getBoolean(defaultValChannel, index)); | ||
| return; | ||
| case TEXT: | ||
| case STRING: | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. | ||
| case BLOB: | ||
| builder.writeBinary(partition.getBinary(defaultValChannel, index)); | ||
| return; | ||
| default: | ||
| throw new UnSupportedDataTypeException( | ||
| "Unsupported default value's data type in Lag: " + dataType); | ||
| } | ||
| } | ||
| @Override | ||
| public boolean needFrame() { | ||
| return false; | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why add this new line? Are there any bugs before? If so, you may need to add IT about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there is no
.tryEvaluate,getColumnmay return null.