korlov42 commented on a change in pull request #9276:
URL: https://github.com/apache/ignite/pull/9276#discussion_r679948439
##########
File path:
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/TableDescriptorImpl.java
##########
@@ -516,6 +516,11 @@ private Object clone(Object val) throws
IgniteCheckedException {
return fieldName == null ? null : descriptorsMap.get(fieldName);
}
+ /** {@inheritDoc} */
+ @Override public ColumnDescriptor columnDescriptor(int fieldIdx) {
+ return descriptors[fieldIdx];
Review comment:
What if the given fieldIdx will be outside of the range
[descriptors.length)?
##########
File path:
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/metadata/IgniteMdRowCount.java
##########
@@ -117,6 +118,13 @@ public double getRowCount(IgniteSortedIndexSpool rel,
RelMetadataQuery mq) {
return rel.estimateRowCount(mq);
}
+ /**
+ * Estimation of row count for table scan.
+ */
+ public double getRowCount(IgniteTableScan rel, RelMetadataQuery mq) {
Review comment:
why is this change necessary?
##########
File path:
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/IgniteStatisticsImpl.java
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.ignite.internal.processors.query.calcite.schema;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import com.google.common.collect.ImmutableList;
+import org.apache.calcite.rel.RelCollation;
+import org.apache.calcite.rel.RelReferentialConstraint;
+import org.apache.calcite.schema.Statistic;
+import org.apache.calcite.util.ImmutableBitSet;
+import
org.apache.ignite.internal.processors.query.calcite.trait.IgniteDistribution;
+import org.apache.ignite.internal.processors.query.stat.ColumnStatistics;
+import org.apache.ignite.internal.processors.query.stat.ObjectStatisticsImpl;
+
+/** Calcite statistics wrapper. */
+public class IgniteStatisticsImpl implements Statistic {
+ /** Internal statistics implementation. */
+ private final ObjectStatisticsImpl statistics;
+
+ /**
+ * Constructor.
+ *
+ * @param statistics Internal object statistics or {@code null}.
Review comment:
probably it's better to make it NotNull
##########
File path:
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/AbstractPlannerTest.java
##########
@@ -653,10 +653,10 @@ protected static IgniteSchema createSchema(TestTable...
tbls) {
private final RewindabilityTrait rewindable;
/** */
- private final double rowCnt;
+ private final TableDescriptor desc;
/** */
- private final TableDescriptor desc;
+ private ObjectStatisticsImpl stat;
Review comment:
can we have this `final`?
##########
File path:
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/ArrayRowHandler.java
##########
@@ -33,7 +33,7 @@ private ArrayRowHandler() {}
/** {@inheritDoc} */
@Override public Object get(int field, Object[] row) {
- return row[field];
+ return (row == null) ? null : row[field];
Review comment:
this is not look right. Could you please describe a case where null is
passed to `row` argument?
##########
File path:
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/BaseStatisticsUsagePlannerTest.java
##########
@@ -0,0 +1,289 @@
+/*
+ * 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.ignite.internal.processors.query.calcite.planner;
+
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.Arrays;
+import java.util.HashMap;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.schema.SchemaPlus;
+import
org.apache.ignite.internal.processors.query.calcite.metadata.ColocationGroup;
+import
org.apache.ignite.internal.processors.query.calcite.prepare.PlanningContext;
+import org.apache.ignite.internal.processors.query.calcite.rel.IgniteRel;
+import org.apache.ignite.internal.processors.query.calcite.schema.IgniteSchema;
+import
org.apache.ignite.internal.processors.query.calcite.schema.IgniteStatisticsImpl;
+import
org.apache.ignite.internal.processors.query.calcite.trait.IgniteDistribution;
+import
org.apache.ignite.internal.processors.query.calcite.trait.IgniteDistributions;
+import
org.apache.ignite.internal.processors.query.calcite.type.IgniteTypeFactory;
+import
org.apache.ignite.internal.processors.query.calcite.type.IgniteTypeSystem;
+import org.apache.ignite.internal.processors.query.stat.ColumnStatistics;
+import org.apache.ignite.internal.processors.query.stat.ObjectStatisticsImpl;
+import org.h2.value.ValueBoolean;
+import org.h2.value.ValueByte;
+import org.h2.value.ValueDate;
+import org.h2.value.ValueDouble;
+import org.h2.value.ValueFloat;
+import org.h2.value.ValueInt;
+import org.h2.value.ValueLong;
+import org.h2.value.ValueShort;
+import org.h2.value.ValueString;
+import org.h2.value.ValueTime;
+import org.h2.value.ValueTimestamp;
+import org.junit.Test;
+
+import static org.apache.calcite.tools.Frameworks.createRootSchema;
+
+/**
+ * Statistic related simple tests.
+ */
+public class BaseStatisticsUsagePlannerTest extends AbstractPlannerTest {
Review comment:
Is this class is finished or it's WIP still ?
##########
File path:
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rel/ProjectableFilterableTableScan.java
##########
@@ -134,7 +134,7 @@ protected RelWriter explainTerms0(RelWriter pw) {
/** {@inheritDoc} */
@Override public double estimateRowCount(RelMetadataQuery mq) {
- return table.getRowCount() * mq.getSelectivity(this, null);
+ return table.getRowCount() * mq.getSelectivity(this, condition);
Review comment:
Why did you decide to put `condition` instead of `null` here?
##########
File path:
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/IgniteStatisticsImpl.java
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.ignite.internal.processors.query.calcite.schema;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import com.google.common.collect.ImmutableList;
+import org.apache.calcite.rel.RelCollation;
+import org.apache.calcite.rel.RelReferentialConstraint;
+import org.apache.calcite.schema.Statistic;
+import org.apache.calcite.util.ImmutableBitSet;
+import
org.apache.ignite.internal.processors.query.calcite.trait.IgniteDistribution;
+import org.apache.ignite.internal.processors.query.stat.ColumnStatistics;
+import org.apache.ignite.internal.processors.query.stat.ObjectStatisticsImpl;
+
+/** Calcite statistics wrapper. */
+public class IgniteStatisticsImpl implements Statistic {
+ /** Internal statistics implementation. */
+ private final ObjectStatisticsImpl statistics;
+
+ /**
+ * Constructor.
+ *
+ * @param statistics Internal object statistics or {@code null}.
+ */
+ public IgniteStatisticsImpl(ObjectStatisticsImpl statistics) {
+ this.statistics = statistics;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Double getRowCount() {
+ // TBD: default values.
+ long rows = (statistics == null) ? 1000 : statistics.rowCount();
+
+ return (double)rows;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean isKey(ImmutableBitSet cols) {
+ return false; // TODO
+ }
+
+ /** {@inheritDoc} */
+ @Override public List<ImmutableBitSet> getKeys() {
+ return null; // TODO
+ }
+
+ /** {@inheritDoc} */
+ @Override public List<RelReferentialConstraint>
getReferentialConstraints() {
+ return ImmutableList.of();
+ }
+
+ /** {@inheritDoc} */
+ @Override public List<RelCollation> getCollations() {
+ return ImmutableList.of(); // The method isn't used
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgniteDistribution getDistribution() {
+ return null;
+ }
+
+ /**
+ * @return Column statistics map.
+ */
+ public Map<String, ColumnStatistics> getColumnsStatistics() {
Review comment:
do we really need both `getColumnsStatistics()` and
`getColumnStatistics(String colName)` methods?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]