You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2022/04/14 03:15:58 UTC

[GitHub] [incubator-doris] EmmyMiao87 commented on a diff in pull request #8947: [feature](statistics) Statistics derivation.Step 1:ScanNode implement…

EmmyMiao87 commented on code in PR #8947:
URL: https://github.com/apache/incubator-doris/pull/8947#discussion_r850043905


##########
fe/fe-core/src/main/java/org/apache/doris/statistics/StatsDeriveResult.java:
##########
@@ -0,0 +1,73 @@
+// 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.doris.statistics;
+
+import com.google.common.collect.Maps;
+
+import java.util.Map;
+
+// This structure is maintained in each operator to store the statistical information results obtained by the operator.
+public class StatsDeriveResult {
+    private long cardinality;
+    private long rowCount;
+    // The data size of the corresponding column in the operator
+    // The actual key is slotId
+    private final Map<Long, Long> columnToDataSize = Maps.newHashMap();
+    // The ndv of the corresponding column in the operator
+    // The actual key is slotId
+    private final Map<Long, Long> columnToNdv = Maps.newHashMap();
+
+    public StatsDeriveResult() {
+        cardinality = -1;
+        rowCount = -1;
+    }
+
+    public StatsDeriveResult(long cardinality, long rowCount, Map<Long, Long> columnToDataSize, Map<Long, Long> columnToNdv) {
+        this.cardinality = cardinality;
+        this.rowCount = rowCount;
+        this.columnToDataSize.putAll(columnToDataSize);
+        this.columnToNdv.putAll(columnToNdv);
+    }
+
+    public void set(StatsDeriveResult statsDeriveResult) {

Review Comment:
   duplicate code ~



##########
fe/fe-core/src/main/java/org/apache/doris/statistics/BaseStatsDerive.java:
##########
@@ -0,0 +1,122 @@
+// 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.doris.statistics;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import org.apache.doris.analysis.Expr;
+import org.apache.doris.planner.PlanNode;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public abstract class BaseStatsDerive {
+    // estimate of the output cardinality of this node;
+    // invalid: -1
+    protected long cardinality;

Review Comment:
   What's this attribute used for ? 



##########
fe/fe-core/src/main/java/org/apache/doris/statistics/StatsDeriveResult.java:
##########
@@ -0,0 +1,73 @@
+// 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.doris.statistics;
+
+import com.google.common.collect.Maps;
+
+import java.util.Map;
+
+// This structure is maintained in each operator to store the statistical information results obtained by the operator.
+public class StatsDeriveResult {
+    private long cardinality;

Review Comment:
   ```suggestion
       private long cardinality = -1;
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/statistics/StatsDeriveResult.java:
##########
@@ -0,0 +1,73 @@
+// 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.doris.statistics;
+
+import com.google.common.collect.Maps;
+
+import java.util.Map;
+
+// This structure is maintained in each operator to store the statistical information results obtained by the operator.
+public class StatsDeriveResult {
+    private long cardinality;
+    private long rowCount;

Review Comment:
   ```suggestion
       private long rowCount = -1;
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/statistics/StatsDeriveResult.java:
##########
@@ -0,0 +1,73 @@
+// 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.doris.statistics;
+
+import com.google.common.collect.Maps;
+
+import java.util.Map;
+
+// This structure is maintained in each operator to store the statistical information results obtained by the operator.
+public class StatsDeriveResult {
+    private long cardinality;
+    private long rowCount;
+    // The data size of the corresponding column in the operator
+    // The actual key is slotId
+    private final Map<Long, Long> columnToDataSize = Maps.newHashMap();
+    // The ndv of the corresponding column in the operator
+    // The actual key is slotId
+    private final Map<Long, Long> columnToNdv = Maps.newHashMap();
+
+    public StatsDeriveResult() {
+        cardinality = -1;
+        rowCount = -1;
+    }
+
+    public StatsDeriveResult(long cardinality, long rowCount, Map<Long, Long> columnToDataSize, Map<Long, Long> columnToNdv) {
+        this.cardinality = cardinality;
+        this.rowCount = rowCount;
+        this.columnToDataSize.putAll(columnToDataSize);
+        this.columnToNdv.putAll(columnToNdv);
+    }
+
+    public void set(StatsDeriveResult statsDeriveResult) {
+        this.cardinality = statsDeriveResult.cardinality;
+        this.rowCount = statsDeriveResult.rowCount;
+        this.columnToDataSize.putAll(statsDeriveResult.columnToDataSize);
+        this.columnToNdv.putAll(statsDeriveResult.columnToNdv);
+    }
+
+    public void setRowCount(long rowCount) {
+        this.rowCount = rowCount;
+    }
+
+    public void setCardinality(long cardinality) {
+        this.cardinality = cardinality;
+    }
+
+    public boolean isStatsDerived() {
+        return cardinality != -1 && rowCount != -1 && columnToDataSize.isEmpty() && columnToNdv.isEmpty();

Review Comment:
   ```suggestion
           return cardinality != -1 && rowCount != -1 && !columnToDataSize.isEmpty() && !columnToNdv.isEmpty();
   ```



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org