Skip to content

Commit

Permalink
Clean-up, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marmbrus committed Oct 9, 2014
1 parent 763af15 commit 654b926
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ package object debug {
}
}

/**
* :: DeveloperApi ::
* Helper functions for checking that runtime types match a given schema.
*/
@DeveloperApi
object TypeCheck {
def typeCheck(data: Any, schema: DataType): Unit = (data, schema) match {
case (null, _) =>
Expand All @@ -159,13 +164,20 @@ package object debug {
}
}

case class TypeCheck(child: SparkPlan) extends SparkPlan {
/**
* :: DeveloperApi ::
* Augments SchemaRDDs with debug methods.
*/
@DeveloperApi
private[sql] case class TypeCheck(child: SparkPlan) extends SparkPlan {
import TypeCheck._
//def otherCopyArgs = null :: Nil

override def nodeName = ""

override def makeCopy(args: Array[Object]): this.type = TypeCheck(args(0).asInstanceOf[SparkPlan]).asInstanceOf[this.type]
/* Only required when defining this class in a REPL.
override def makeCopy(args: Array[Object]): this.type =
TypeCheck(args(0).asInstanceOf[SparkPlan]).asInstanceOf[this.type]
*/

def output = child.output

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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.execution.debug

import org.scalatest.FunSuite

import org.apache.spark.sql.TestData._
import org.apache.spark.sql.test.TestSQLContext._

class DebuggingSuite extends FunSuite {
test("SchemaRDD.debug()") {
testData.debug()
}

test("SchemaRDD.typeCheck()") {
testData.typeCheck()
}
}

0 comments on commit 654b926

Please sign in to comment.