spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From JoshRosen <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-9393] [SQL] Fix several error-handling ...
Date Tue, 28 Jul 2015 02:30:29 GMT
Github user JoshRosen commented on a diff in the pull request:

    https://github.com/apache/spark/pull/7710#discussion_r35609591
  
    --- 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 {
    --- End diff --
    
    Also note that there's quite a bit of code redundancy in this test suite but I'm not super
motivated to clean it up since I don't expect that it will ever need to change.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message