Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for new position parameter in Spark 3.1.0 RegExpReplace #1012

Merged
merged 2 commits into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ package com.nvidia.spark.rapids.shims.spark300

import java.time.ZoneId

import scala.collection.JavaConverters._

import com.nvidia.spark.rapids._
import com.nvidia.spark.rapids.spark300.RapidsShuffleManager

Expand All @@ -44,7 +42,7 @@ import org.apache.spark.sql.execution.exchange.{BroadcastExchangeExec, ShuffleEx
import org.apache.spark.sql.execution.joins.{BroadcastHashJoinExec, BroadcastNestedLoopJoinExec, HashJoin, SortMergeJoinExec}
import org.apache.spark.sql.execution.joins.ShuffledHashJoinExec
import org.apache.spark.sql.execution.python.WindowInPandasExec
import org.apache.spark.sql.rapids.{GpuFileSourceScanExec, GpuTimeSub, ShuffleManagerShimBase}
import org.apache.spark.sql.rapids.{GpuFileSourceScanExec, GpuStringReplace, GpuTimeSub, ShuffleManagerShimBase}
import org.apache.spark.sql.rapids.execution.{GpuBroadcastExchangeExecBase, GpuBroadcastNestedLoopJoinExecBase, GpuShuffleExchangeExecBase}
import org.apache.spark.sql.rapids.shims.spark300._
import org.apache.spark.sql.types._
Expand Down Expand Up @@ -231,6 +229,22 @@ class Spark300Shims extends SparkShims {

override def convertToGpu(): GpuExpression =
GpuLast(child.convertToGpu(), ignoreNulls.convertToGpu())
}),
GpuOverrides.expr[RegExpReplace](
"RegExpReplace support for string literal input patterns",
(a, conf, p, r) => new TernaryExprMeta[RegExpReplace](a, conf, p, r) {
override def tagExprForGpu(): Unit = {
if (!GpuOverrides.isLit(a.rep)) {
willNotWorkOnGpu("Only literal values are supported for replacement string")
}
if (GpuOverrides.isNullOrEmptyOrRegex(a.regexp)) {
willNotWorkOnGpu(
"Only non-null, non-empty String literals that are not regex patterns " +
"are supported by RegExpReplace on the GPU")
}
}
override def convertToGpu(lhs: Expression, regexp: Expression,
rep: Expression): GpuExpression = GpuStringReplace(lhs, regexp, rep)
})
).map(r => (r.getClassFor.asSubclass(classOf[Expression]), r)).toMap
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@

package com.nvidia.spark.rapids.shims.spark310

import java.time.ZoneId

import scala.collection.JavaConverters._

import com.nvidia.spark.rapids._
import com.nvidia.spark.rapids.shims.spark301.Spark301Shims
import com.nvidia.spark.rapids.spark310.RapidsShuffleManager
Expand All @@ -28,19 +24,17 @@ import org.apache.spark.SparkEnv
import org.apache.spark.sql.catalyst.encoders.ExpressionEncoder
import org.apache.spark.sql.catalyst.expressions._
import org.apache.spark.sql.catalyst.plans.JoinType
import org.apache.spark.sql.catalyst.rules.Rule
import org.apache.spark.sql.connector.read.Scan
import org.apache.spark.sql.execution._
import org.apache.spark.sql.execution.columnar.InMemoryTableScanExec
import org.apache.spark.sql.execution.datasources.HadoopFsRelation
import org.apache.spark.sql.execution.datasources.parquet.ParquetFileFormat
import org.apache.spark.sql.execution.datasources.v2.orc.OrcScan
import org.apache.spark.sql.execution.datasources.v2.parquet.ParquetScan
import org.apache.spark.sql.execution.joins.{BroadcastHashJoinExec, BroadcastNestedLoopJoinExec, HashJoin, SortMergeJoinExec}
import org.apache.spark.sql.execution.joins.ShuffledHashJoinExec
import org.apache.spark.sql.execution.joins.{BroadcastHashJoinExec, BroadcastNestedLoopJoinExec, HashJoin, ShuffledHashJoinExec, SortMergeJoinExec}
import org.apache.spark.sql.execution.python.WindowInPandasExec
import org.apache.spark.sql.internal.StaticSQLConf
import org.apache.spark.sql.rapids.{GpuFileSourceScanExec, ShuffleManagerShimBase}
import org.apache.spark.sql.rapids.{GpuFileSourceScanExec, GpuStringReplace, ShuffleManagerShimBase}
import org.apache.spark.sql.rapids.execution.GpuBroadcastNestedLoopJoinExecBase
import org.apache.spark.sql.rapids.shims.spark310._
import org.apache.spark.sql.types._
Expand Down Expand Up @@ -104,8 +98,39 @@ class Spark310Shims extends Spark301Shims {
}
}

def exprs310: Map[Class[_ <: Expression], ExprRule[_ <: Expression]] = Seq(
GpuOverrides.expr[RegExpReplace](
"RegExpReplace support for string literal input patterns",
(a, conf, p, r) => new ExprMeta[RegExpReplace](a, conf, p, r) {
override def tagExprForGpu(): Unit = {
if (!GpuOverrides.isLit(a.rep)) {
willNotWorkOnGpu("Only literal values are supported for replacement string")
}
if (GpuOverrides.isNullOrEmptyOrRegex(a.regexp)) {
willNotWorkOnGpu(
"Only non-null, non-empty String literals that are not regex patterns " +
"are supported by RegExpReplace on the GPU")
}
if (!a.pos.foldable) {
willNotWorkOnGpu("Only foldable expressions are supported for the " +
"starting search position")
}
val posEval = a.pos.eval()
if (posEval.asInstanceOf[Int] != 1) {
willNotWorkOnGpu("Only a search starting position of 1 is supported")
}
}
override def convertToGpu(): GpuExpression = {
GpuStringReplace(
childExprs(0).convertToGpu(),
childExprs(1).convertToGpu(),
childExprs(2).convertToGpu())
}
})
).map(r => (r.getClassFor.asSubclass(classOf[Expression]), r)).toMap

override def getExprs: Map[Class[_ <: Expression], ExprRule[_ <: Expression]] = {
super.exprs301
super.exprs301 ++ exprs310
}

override def getExecs: Map[Class[_ <: SparkPlan], ExecRule[_ <: SparkPlan]] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1594,22 +1594,6 @@ object GpuOverrides {
override def convertToGpu(lhs: Expression, rhs: Expression): GpuExpression =
GpuLike(lhs, rhs, a.escapeChar)
}),
expr[RegExpReplace](
"RegExpReplace support for string literal input patterns",
(a, conf, p, r) => new TernaryExprMeta[RegExpReplace](a, conf, p, r) {
override def tagExprForGpu(): Unit = {
if (!isLit(a.rep)) {
willNotWorkOnGpu("Only literal values are supported for replacement string")
}
if (isNullOrEmptyOrRegex(a.regexp)) {
willNotWorkOnGpu(
"Only non-null, non-empty String literals that are not regex patterns " +
"are supported by RegExpReplace on the GPU")
}
}
override def convertToGpu(lhs: Expression, regexp: Expression,
rep: Expression): GpuExpression = GpuStringReplace(lhs, regexp, rep)
}),
expr[Length](
"String character length",
(a, conf, p, r) => new UnaryExprMeta[Length](a, conf, p, r) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,23 @@ import org.apache.hadoop.fs.Path
import org.apache.spark.{SparkContext, TaskContext}
import org.apache.spark.internal.Logging
import org.apache.spark.sql.execution.SQLExecution
import org.apache.spark.sql.execution.datasources.{BasicWriteTaskStats, WriteTaskStats}
import org.apache.spark.sql.execution.datasources.WriteTaskStats
import org.apache.spark.sql.execution.metric.{SQLMetric, SQLMetrics}
import org.apache.spark.sql.vectorized.ColumnarBatch
import org.apache.spark.util.SerializableConfiguration

/**
* Simple metrics collected during an instance of [[GpuFileFormatDataWriter]].
* These were first introduced in https://github.com/apache/spark/pull/18159 (SPARK-20703).
*/
case class BasicColumnarWriteTaskStats(
numPartitions: Int,
numFiles: Int,
numBytes: Long,
numRows: Long)
extends WriteTaskStats


/**
* Simple metrics collected during an instance of [[GpuFileFormatDataWriter]].
* This is the columnar version of
Expand Down Expand Up @@ -104,15 +116,15 @@ class BasicColumnarWriteTaskStatsTracker(hadoopConf: Configuration)
"This could be due to the output format not writing empty files, " +
"or files being not immediately visible in the filesystem.")
}
BasicWriteTaskStats(numPartitions, numFiles, numBytes, numRows)
BasicColumnarWriteTaskStats(numPartitions, numFiles, numBytes, numRows)
}
}


/**
* Simple [[ColumnarWriteJobStatsTracker]] implementation that's serializable,
* capable ofinstantiating [[BasicColumnarWriteTaskStatsTracker]] on executors and processing the
* `BasicWriteTaskStats` they produce by aggregating the metrics and posting them
* `BasicColumnarWriteTaskStats` they produce by aggregating the metrics and posting them
* as DriverMetricUpdates.
*/
class BasicColumnarWriteJobStatsTracker(
Expand All @@ -131,7 +143,7 @@ class BasicColumnarWriteJobStatsTracker(
var totalNumBytes: Long = 0L
var totalNumOutput: Long = 0L

val basicStats = stats.map(_.asInstanceOf[BasicWriteTaskStats])
val basicStats = stats.map(_.asInstanceOf[BasicColumnarWriteTaskStats])

basicStats.foreach { summary =>
numPartitions += summary.numPartitions
Expand Down