Skip to content

Commit

Permalink
remove metrics, because they are very slow
Browse files Browse the repository at this point in the history
  • Loading branch information
Davies Liu committed Jan 19, 2016
1 parent f0f3da6 commit 331b46d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ import scala.collection.mutable.ArrayBuffer
import org.apache.spark.rdd.RDD
import org.apache.spark.sql.SQLContext
import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.expressions.{Attribute, BoundReference, Expression, LeafExpression}
import org.apache.spark.sql.catalyst.expressions.{Attribute, BoundReference, LeafExpression}
import org.apache.spark.sql.catalyst.expressions.codegen._
import org.apache.spark.sql.catalyst.rules.Rule
import org.apache.spark.sql.execution.metric.LongSQLMetric

/**
* An interface for those physical operators that support codegen.
Expand Down Expand Up @@ -91,21 +90,9 @@ trait CodegenSupport extends SparkPlan {
* }
*/
def doConsume(ctx: CodegenContext, child: SparkPlan, input: Seq[ExprCode]): String

/**
* Return a term for a LongSQLMetric specified by given name.
*/
protected def termForLongMetric(ctx: CodegenContext, name: String): String = {
val metric = longMetric(name)
val idx = ctx.references.length
ctx.references += metric
val term = ctx.freshName(name)
val clsName = classOf[LongSQLMetric].getName
ctx.addMutableState(clsName, term, s"$term = ($clsName) references[$idx];")
term
}
}


/**
* InputAdapter is used to hide a SparkPlan from a subtree that support codegen.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.expressions._
import org.apache.spark.sql.catalyst.expressions.codegen.{CodegenContext, ExprCode, ExpressionCanonicalizer}
import org.apache.spark.sql.catalyst.plans.physical._
import org.apache.spark.sql.execution.metric.{LongSQLMetric, SQLMetrics}
import org.apache.spark.sql.execution.metric.SQLMetrics
import org.apache.spark.sql.types.LongType
import org.apache.spark.util.MutablePair
import org.apache.spark.util.random.PoissonSampler
Expand All @@ -42,14 +42,11 @@ case class Project(projectList: Seq[NamedExpression], child: SparkPlan)
}

override def doConsume(ctx: CodegenContext, child: SparkPlan, input: Seq[ExprCode]): String = {
val numRows = termForLongMetric(ctx, "numRows")
val exprs = projectList.map(x =>
ExpressionCanonicalizer.execute(BindReferences.bindReference(x, child.output)))
ctx.currentVars = input
val output = exprs.map(_.gen(ctx))
s"""
| // Projection
| $numRows.add(1);
| ${output.map(_.code).mkString("\n")}
|
| ${consume(ctx, output)}
Expand Down Expand Up @@ -84,18 +81,13 @@ case class Filter(condition: Expression, child: SparkPlan) extends UnaryNode wit
}

override def doConsume(ctx: CodegenContext, child: SparkPlan, input: Seq[ExprCode]): String = {
val numInputTerm = termForLongMetric(ctx, "numInputRows")
val numOutputTerm = termForLongMetric(ctx, "numOutputRows")
val expr = ExpressionCanonicalizer.execute(
BindReferences.bindReference(condition, child.output))
ctx.currentVars = input
val eval = expr.gen(ctx)
s"""
| // Filter
| $numInputTerm.add(1);
| ${eval.code}
| if (!${eval.isNull} && ${eval.value}) {
| $numOutputTerm.add(1);
| ${consume(ctx, ctx.currentVars)}
| }
""".stripMargin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,9 @@ class SQLMetricsSuite extends SparkFunSuite with SharedSQLContext {
test("WholeStageCodegen metrics") {
// Assume the execution plan is
// WholeStageCodegen(nodeId = 0, Range(nodeId = 2) -> Filter(nodeId = 1))
// TODO: update metrics in generated operators
val df = sqlContext.range(10).filter('id < 5)
testSparkPlanMetrics(df, 1, Map(
1L -> ("Filter", Map(
"number of input rows" -> 10L,
"number of output rows" -> 5L
)))
)
testSparkPlanMetrics(df, 1, Map.empty)
}

test("TungstenAggregate metrics") {
Expand Down

0 comments on commit 331b46d

Please sign in to comment.