Github user juliuszsompolski commented on a diff in the pull request:
https://github.com/apache/spark/pull/18479#discussion_r127680994
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/statsEstimation/BasicStatsPlanVisitor.scala
---
@@ -0,0 +1,82 @@
+/*
+ * 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.spark.sql.catalyst.plans.logical.statsEstimation
+
+import org.apache.spark.sql.catalyst.plans.logical
+import org.apache.spark.sql.catalyst.plans.logical._
+import org.apache.spark.sql.types.LongType
+
+/**
+ * An [[LogicalPlanVisitor]] that computes a the statistics used in a
cost-based optimizer.
+ */
+object BasicStatsPlanVisitor extends LogicalPlanVisitor[Statistics] {
+
+ /** Falls back to the estimation computed by
[[SizeInBytesOnlyStatsPlanVisitor]]. */
+ private def fallback(p: LogicalPlan): Statistics =
SizeInBytesOnlyStatsPlanVisitor.visit(p)
+
+ override def default(p: LogicalPlan): Statistics = fallback(p)
+
+ override def visitAggregate(p: Aggregate): Statistics = {
+ AggregateEstimation.estimate(p).getOrElse(fallback(p))
+ }
+
+ override def visitDistinct(p: Distinct): Statistics = fallback(p)
+
+ override def visitExcept(p: Except): Statistics = fallback(p)
+
+ override def visitExpand(p: Expand): Statistics = fallback(p)
+
+ override def visitFilter(p: Filter): Statistics = {
+ FilterEstimation(p).estimate.getOrElse(fallback(p))
+ }
+
+ override def visitGenerate(p: Generate): Statistics = fallback(p)
+
+ override def visitGlobalLimit(p: GlobalLimit): Statistics = fallback(p)
+
+ override def visitHint(p: ResolvedHint): Statistics = fallback(p)
+
+ override def visitIntersect(p: Intersect): Statistics = fallback(p)
+
+ override def visitJoin(p: Join): Statistics = {
+ JoinEstimation.estimate(p).getOrElse(fallback(p))
+ }
+
+ override def visitLocalLimit(p: LocalLimit): Statistics = fallback(p)
+
+ override def visitPivot(p: Pivot): Statistics = fallback(p)
+
+ override def visitProject(p: Project): Statistics = {
+ ProjectEstimation.estimate(p).getOrElse(fallback(p))
+ }
+
+ override def visitRange(p: logical.Range): Statistics = {
+ val sizeInBytes = LongType.defaultSize * p.numElements
+ Statistics(sizeInBytes = sizeInBytes)
+ }
+
+ override def visitRepartition(p: Repartition): Statistics = fallback(p)
+
+ override def visitRepartitionByExpr(p: RepartitionByExpression):
Statistics = fallback(p)
--- End diff --
Like in repartition - child attribute stats should be propagated.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]