Github user JoshRosen commented on a diff in the pull request:

    https://github.com/apache/spark/pull/7710#discussion_r35609535
  
    --- Diff: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/ScriptTransformationSuite.scala
 ---
    @@ -0,0 +1,123 @@
    +/*
    + * 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.hive.execution
    +
    +import org.apache.hadoop.hive.serde2.`lazy`.LazySimpleSerDe
    +import org.scalatest.exceptions.TestFailedException
    +
    +import org.apache.spark.TaskContext
    +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, 
AttributeReference}
    +import org.apache.spark.sql.execution.{UnaryNode, SparkPlan, SparkPlanTest}
    +import org.apache.spark.sql.hive.test.TestHive
    +import org.apache.spark.sql.types.StringType
    +
    +class ScriptTransformationSuite extends SparkPlanTest {
    +
    +  override def sqlContext: SQLContext = TestHive
    +
    +  private val noSerdeIOSchema = HiveScriptIOSchema(
    +    inputRowFormat = Seq.empty,
    +    outputRowFormat = Seq.empty,
    +    inputSerdeClass = None,
    +    outputSerdeClass = None,
    +    inputSerdeProps = Seq.empty,
    +    outputSerdeProps = Seq.empty,
    +    schemaLess = false
    +  )
    +
    +  private val serdeIOSchema = noSerdeIOSchema.copy(
    +    inputSerdeClass = 
Some(s"'${classOf[LazySimpleSerDe].getCanonicalName}"),
    +    outputSerdeClass = 
Some(s"'${classOf[LazySimpleSerDe].getCanonicalName}")
    +  )
    +
    +  test("cat without SerDe") {
    +    val rowsDf = Seq("a", "b", "c").map(Tuple1.apply).toDF("a")
    +    checkAnswer(
    +      rowsDf,
    +      (child: SparkPlan) => new ScriptTransformation(
    +        input = Seq(rowsDf.col("a").expr),
    +        script = "cat",
    +        output = Seq(AttributeReference("a", StringType)()),
    +        child = child,
    +        ioschema = noSerdeIOSchema
    +      )(TestHive),
    +      rowsDf.collect())
    +  }
    +
    +  test("cat with LazySimpleSerDe") {
    +    val rowsDf = Seq("a", "b", "c").map(Tuple1.apply).toDF("a")
    +    checkAnswer(
    +      rowsDf,
    +      (child: SparkPlan) => new ScriptTransformation(
    +        input = Seq(rowsDf.col("a").expr),
    +        script = "cat",
    +        output = Seq(AttributeReference("a", StringType)()),
    +        child = child,
    +        ioschema = serdeIOSchema
    +      )(TestHive),
    +      rowsDf.collect())
    +  }
    +
    +  test("script transformation should not swallow errors from upstream 
operators (no serde)") {
    +    val rowsDf = Seq("a", "b", "c").map(Tuple1.apply).toDF("a")
    +    val e = intercept[TestFailedException] {
    +      checkAnswer(
    +        rowsDf,
    +        (child: SparkPlan) => new ScriptTransformation(
    +          input = Seq(rowsDf.col("a").expr),
    +          script = "cat",
    +          output = Seq(AttributeReference("a", StringType)()),
    +          child = ExceptionInjectingOperator(child),
    +          ioschema = noSerdeIOSchema
    +        )(TestHive),
    +        rowsDf.collect())
    +    }
    +    assert(e.getMessage().contains("intentional exception"))
    +  }
    +
    +  test("script transformation should not swallow errors from upstream 
operators (with serde)") {
    +    val rowsDf = Seq("a", "b", "c").map(Tuple1.apply).toDF("a")
    +    val e = intercept[TestFailedException] {
    +      checkAnswer(
    +        rowsDf,
    +        (child: SparkPlan) => new ScriptTransformation(
    +          input = Seq(rowsDf.col("a").expr),
    +          script = "cat",
    +          output = Seq(AttributeReference("a", StringType)()),
    +          child = ExceptionInjectingOperator(child),
    +          ioschema = serdeIOSchema
    +        )(TestHive),
    +        rowsDf.collect())
    +    }
    +    assert(e.getMessage().contains("intentional exception"))
    +  }
    +}
    +
    +private case class ExceptionInjectingOperator(child: SparkPlan) extends 
UnaryNode {
    +  override protected def doExecute(): RDD[InternalRow] = {
    +    child.execute().map { x =>
    +      assert(TaskContext.get() != null) // Make sure that TaskContext is 
defined.
    +      Thread.sleep(1000) // This sleep gives the external process time to 
start.
    --- End diff --
    
    This was necessary in order to trigger certain timing-related bugs.  This 
shouldn't lead to test flakiness, though, but it might hypothetically lead to 
false-negatives if someone were to break this code again in the future.  The 
idea here is to give the external child process time to start so that it has a 
chance to hang.


---
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]

Reply via email to