This is an automated email from the ASF dual-hosted git repository. caogaofei pushed a commit to branch beyyes/TableModelGrammar_DistributePlan in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit f9dae8997b6d74cc087f70a91dac68c72a216efc Author: Beyyes <[email protected]> AuthorDate: Thu Jun 13 14:27:40 2024 +0800 fix diff type --- .../relational/cost/CachingTableStatsProvider.java | 51 ------- .../plan/relational/cost/ColumnStatistics.java | 156 --------------------- .../plan/relational/cost/DoubleRange.java | 104 -------------- .../queryengine/plan/relational/cost/Estimate.java | 84 ----------- .../plan/relational/cost/StatsUtil.java | 43 ------ .../plan/relational/cost/TableStatistics.java | 112 --------------- .../plan/relational/cost/TableStatsProvider.java | 20 --- .../relational/metadata/TableMetadataImpl.java | 2 +- 8 files changed, 1 insertion(+), 571 deletions(-) diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/cost/CachingTableStatsProvider.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/cost/CachingTableStatsProvider.java deleted file mode 100644 index d3c9da443ab..00000000000 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/cost/CachingTableStatsProvider.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed 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.plan.relational.cost; - -import org.apache.iotdb.db.queryengine.plan.relational.metadata.Metadata; -import org.apache.iotdb.db.queryengine.plan.relational.metadata.TableHandle; -import org.apache.iotdb.session.Session; - -import com.google.common.collect.ImmutableMap; - -import java.util.Map; -import java.util.WeakHashMap; - -import static java.util.Objects.requireNonNull; - -public class CachingTableStatsProvider implements TableStatsProvider { - private final Metadata metadata; - private final Session session; - - private final Map<TableHandle, TableStatistics> cache = new WeakHashMap<>(); - - public CachingTableStatsProvider(Metadata metadata, Session session) { - this.metadata = requireNonNull(metadata, "metadata is null"); - this.session = requireNonNull(session, "session is null"); - } - - @Override - public TableStatistics getTableStatistics(TableHandle tableHandle) { - TableStatistics stats = cache.get(tableHandle); - if (stats == null) { - // stats = metadata.getTableStatistics(session, tableHandle); - cache.put(tableHandle, TableStatistics.empty()); - } - return stats; - } - - public Map<TableHandle, TableStatistics> getCachedTableStatistics() { - return ImmutableMap.copyOf(cache); - } -} diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/cost/ColumnStatistics.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/cost/ColumnStatistics.java deleted file mode 100644 index 4895d9096e6..00000000000 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/cost/ColumnStatistics.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Licensed 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.plan.relational.cost; - -import java.util.Objects; -import java.util.Optional; - -import static java.lang.String.format; -import static java.util.Objects.requireNonNull; - -public final class ColumnStatistics { - private static final ColumnStatistics EMPTY = - new ColumnStatistics( - Estimate.unknown(), Estimate.unknown(), Estimate.unknown(), Optional.empty()); - - private final Estimate nullsFraction; - private final Estimate distinctValuesCount; - private final Estimate dataSize; - private final Optional<DoubleRange> range; - - public static ColumnStatistics empty() { - return EMPTY; - } - - public ColumnStatistics( - Estimate nullsFraction, - Estimate distinctValuesCount, - Estimate dataSize, - Optional<DoubleRange> range) { - this.nullsFraction = requireNonNull(nullsFraction, "nullsFraction is null"); - if (!nullsFraction.isUnknown()) { - if (nullsFraction.getValue() < 0 || nullsFraction.getValue() > 1) { - throw new IllegalArgumentException( - format("nullsFraction must be between 0 and 1: %s", nullsFraction.getValue())); - } - } - this.distinctValuesCount = requireNonNull(distinctValuesCount, "distinctValuesCount is null"); - if (!distinctValuesCount.isUnknown() && distinctValuesCount.getValue() < 0) { - throw new IllegalArgumentException( - format( - "distinctValuesCount must be greater than or equal to 0: %s", - distinctValuesCount.getValue())); - } - this.dataSize = requireNonNull(dataSize, "dataSize is null"); - if (!dataSize.isUnknown() && dataSize.getValue() < 0) { - throw new IllegalArgumentException( - format("dataSize must be greater than or equal to 0: %s", dataSize.getValue())); - } - this.range = requireNonNull(range, "range is null"); - } - - public Estimate getNullsFraction() { - return nullsFraction; - } - - public Estimate getDistinctValuesCount() { - return distinctValuesCount; - } - - public Estimate getDataSize() { - return dataSize; - } - - public Optional<DoubleRange> getRange() { - return range; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - ColumnStatistics that = (ColumnStatistics) o; - return Objects.equals(nullsFraction, that.nullsFraction) - && Objects.equals(distinctValuesCount, that.distinctValuesCount) - && Objects.equals(dataSize, that.dataSize) - && Objects.equals(range, that.range); - } - - @Override - public int hashCode() { - return Objects.hash(nullsFraction, distinctValuesCount, dataSize, range); - } - - @Override - public String toString() { - return "ColumnStatistics{" - + "nullsFraction=" - + nullsFraction - + ", distinctValuesCount=" - + distinctValuesCount - + ", dataSize=" - + dataSize - + ", range=" - + range - + '}'; - } - - public static Builder builder() { - return new Builder(); - } - - /** - * If one of the estimates below is unspecified (i.e. left as "unknown"), the optimizer may not be - * able to derive the statistics needed for performing cost-based query plan optimizations. - */ - public static final class Builder { - private Estimate nullsFraction = Estimate.unknown(); - private Estimate distinctValuesCount = Estimate.unknown(); - private Estimate dataSize = Estimate.unknown(); - private Optional<DoubleRange> range = Optional.empty(); - - public Builder setNullsFraction(Estimate nullsFraction) { - this.nullsFraction = requireNonNull(nullsFraction, "nullsFraction is null"); - return this; - } - - public Builder setDistinctValuesCount(Estimate distinctValuesCount) { - this.distinctValuesCount = requireNonNull(distinctValuesCount, "distinctValuesCount is null"); - return this; - } - - public Builder setDataSize(Estimate dataSize) { - this.dataSize = requireNonNull(dataSize, "dataSize is null"); - return this; - } - - public Builder setRange(DoubleRange range) { - this.range = Optional.of(requireNonNull(range, "range is null")); - return this; - } - - public Builder setRange(Optional<DoubleRange> range) { - this.range = requireNonNull(range, "range is null"); - return this; - } - - public ColumnStatistics build() { - return new ColumnStatistics(nullsFraction, distinctValuesCount, dataSize, range); - } - } -} diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/cost/DoubleRange.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/cost/DoubleRange.java deleted file mode 100644 index 2baad720db5..00000000000 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/cost/DoubleRange.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Licensed 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.plan.relational.cost; - -import org.apache.tsfile.read.common.type.Type; - -import java.util.Objects; -import java.util.Optional; -import java.util.OptionalDouble; - -import static java.lang.Double.isNaN; -import static java.lang.Math.max; -import static java.lang.Math.min; -import static java.lang.String.format; -import static java.util.Objects.requireNonNull; -import static org.apache.iotdb.db.queryengine.plan.relational.cost.StatsUtil.toStatsRepresentation; - -public class DoubleRange { - private final double min; - private final double max; - - /** Creates DoubleRange from Trino native representation. */ - public static Optional<DoubleRange> from( - Type type, Object minTrinoNativeValue, Object maxTrinoNativeValue) { - requireNonNull(minTrinoNativeValue, "minTrinoNativeValue is null"); - requireNonNull(maxTrinoNativeValue, "maxTrinoNativeValue is null"); - - OptionalDouble min = toStatsRepresentation(type, minTrinoNativeValue); - OptionalDouble max = toStatsRepresentation(type, maxTrinoNativeValue); - - if (!min.isPresent() && !max.isPresent()) { - return Optional.empty(); - } - if (!min.isPresent() || !max.isPresent()) { - throw new IllegalStateException( - format( - "One of min/max was converted to stats representation while the other was not for type %s: %s, %s", - type, min, max)); - } - return Optional.of(new DoubleRange(min.getAsDouble(), max.getAsDouble())); - } - - public DoubleRange(double min, double max) { - if (isNaN(min)) { - throw new IllegalArgumentException("min must not be NaN"); - } - if (isNaN(max)) { - throw new IllegalArgumentException("max must not be NaN"); - } - if (min > max) { - throw new IllegalArgumentException( - format("max must be greater than or equal to min. min: %s. max: %s. ", min, max)); - } - this.min = min; - this.max = max; - } - - public double getMin() { - return min; - } - - public double getMax() { - return max; - } - - public static DoubleRange union(DoubleRange first, DoubleRange second) { - requireNonNull(first, "first is null"); - requireNonNull(second, "second is null"); - return new DoubleRange(min(first.min, second.min), max(first.max, second.max)); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - DoubleRange range = (DoubleRange) o; - return Double.compare(range.min, min) == 0 && Double.compare(range.max, max) == 0; - } - - @Override - public int hashCode() { - return Objects.hash(min, max); - } - - @Override - public String toString() { - return "DoubleRange{" + "min=" + min + ", max=" + max + '}'; - } -} diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/cost/Estimate.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/cost/Estimate.java deleted file mode 100644 index 85366b89090..00000000000 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/cost/Estimate.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed 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.plan.relational.cost; - -import java.util.Objects; - -import static java.lang.Double.NaN; -import static java.lang.Double.isInfinite; -import static java.lang.Double.isNaN; - -public final class Estimate { - // todo eventually add some notion of statistic reliability - // Skipping for now as there hard to compute it properly and so far we do not have - // usecase for that. - - private static final Estimate UNKNOWN = new Estimate(NaN); - private static final Estimate ZERO = new Estimate(0); - - private final double value; - - public static Estimate unknown() { - return UNKNOWN; - } - - public static Estimate zero() { - return ZERO; - } - - public static Estimate of(double value) { - if (isNaN(value)) { - throw new IllegalArgumentException("value is NaN"); - } - if (isInfinite(value)) { - throw new IllegalArgumentException("value is infinite"); - } - return new Estimate(value); - } - - private Estimate(double value) { - this.value = value; - } - - public boolean isUnknown() { - return isNaN(value); - } - - public double getValue() { - return value; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - Estimate estimate = (Estimate) o; - return Double.compare(estimate.value, value) == 0; - } - - @Override - public int hashCode() { - return Objects.hash(value); - } - - @Override - public String toString() { - return String.valueOf(value); - } -} diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/cost/StatsUtil.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/cost/StatsUtil.java deleted file mode 100644 index 7f9180782fc..00000000000 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/cost/StatsUtil.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed 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.plan.relational.cost; - -import org.apache.tsfile.read.common.type.Type; - -import java.util.OptionalDouble; - -import static java.util.Objects.requireNonNull; -import static org.apache.tsfile.read.common.type.BooleanType.BOOLEAN; -import static org.apache.tsfile.read.common.type.DoubleType.DOUBLE; -import static org.apache.tsfile.read.common.type.IntType.INT32; - -public final class StatsUtil { - private StatsUtil() {} - - public static OptionalDouble toStatsRepresentation(Type type, Object value) { - requireNonNull(type, "type is null"); - requireNonNull(value, "value is null"); - - if (type == BOOLEAN) { - return OptionalDouble.of((boolean) value ? 1 : 0); - } - if (type == INT32) { - return OptionalDouble.of((long) value); - } - if (type == DOUBLE) { - return OptionalDouble.of((double) value); - } - return OptionalDouble.empty(); - } -} diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/cost/TableStatistics.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/cost/TableStatistics.java deleted file mode 100644 index 9a610107d91..00000000000 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/cost/TableStatistics.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Licensed 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.plan.relational.cost; - -import org.apache.iotdb.db.queryengine.plan.relational.metadata.ColumnHandle; - -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Objects; - -import static java.lang.String.format; -import static java.util.Collections.unmodifiableMap; -import static java.util.Objects.requireNonNull; - -public final class TableStatistics { - private static final TableStatistics EMPTY = TableStatistics.builder().build(); - - private final Estimate rowCount; - private final Map<ColumnHandle, ColumnStatistics> columnStatistics; - - public static TableStatistics empty() { - return EMPTY; - } - - public TableStatistics(Estimate rowCount, Map<ColumnHandle, ColumnStatistics> columnStatistics) { - this.rowCount = requireNonNull(rowCount, "rowCount cannot be null"); - if (!rowCount.isUnknown() && rowCount.getValue() < 0) { - throw new IllegalArgumentException( - format("rowCount must be greater than or equal to 0: %s", rowCount.getValue())); - } - this.columnStatistics = - unmodifiableMap(requireNonNull(columnStatistics, "columnStatistics cannot be null")); - } - - public Estimate getRowCount() { - return rowCount; - } - - public Map<ColumnHandle, ColumnStatistics> getColumnStatistics() { - return columnStatistics; - } - - public boolean isEmpty() { - return equals(empty()); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - TableStatistics that = (TableStatistics) o; - return Objects.equals(rowCount, that.rowCount) - && Objects.equals(columnStatistics, that.columnStatistics); - } - - @Override - public int hashCode() { - return Objects.hash(rowCount, columnStatistics); - } - - @Override - public String toString() { - return "TableStatistics{" - + "rowCount=" - + rowCount - + ", columnStatistics=" - + columnStatistics - + '}'; - } - - public static Builder builder() { - return new Builder(); - } - - public static final class Builder { - private final Map<ColumnHandle, ColumnStatistics> columnStatisticsMap = new LinkedHashMap<>(); - private Estimate rowCount = Estimate.unknown(); - - public Builder setRowCount(Estimate rowCount) { - this.rowCount = requireNonNull(rowCount, "rowCount cannot be null"); - return this; - } - - public Builder setColumnStatistics( - ColumnHandle columnHandle, ColumnStatistics columnStatistics) { - requireNonNull(columnHandle, "columnHandle cannot be null"); - requireNonNull(columnStatistics, "columnStatistics cannot be null"); - this.columnStatisticsMap.put(columnHandle, columnStatistics); - return this; - } - - public TableStatistics build() { - return new TableStatistics(rowCount, columnStatisticsMap); - } - } -} diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/cost/TableStatsProvider.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/cost/TableStatsProvider.java deleted file mode 100644 index 72fd4d6932e..00000000000 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/cost/TableStatsProvider.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Licensed 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.plan.relational.cost; - -import org.apache.iotdb.db.queryengine.plan.relational.metadata.TableHandle; - -public interface TableStatsProvider { - TableStatistics getTableStatistics(TableHandle tableHandle); -} diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java index 67f030ede35..f3ff0b59834 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java @@ -123,7 +123,7 @@ public class TableMetadataImpl implements Metadata { + functionName.toLowerCase(Locale.ENGLISH) + " only supports one numeric data types [INT32, INT64, FLOAT, DOUBLE] and one boolean"); } - return argumentTypes.get(0); + return DOUBLE; } else if (BuiltinScalarFunction.ROUND.getFunctionName().equalsIgnoreCase(functionName)) { if (!isOneNumericType(argumentTypes) && !isTwoNumericType(argumentTypes)) { throw new SemanticException(
