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

    https://github.com/apache/spark/pull/7176#discussion_r33833159
  
    --- Diff: 
sql/catalyst/src/test/scala/org/apache/spark/sql/RandomDataGenerator.scala ---
    @@ -0,0 +1,95 @@
    +/*
    + * 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
    +
    +import java.sql.Timestamp
    +
    +import org.apache.spark.sql.types._
    +import org.scalacheck.{Arbitrary, Gen}
    +
    +/**
    + * Random data generators for Spark SQL DataTypes. These generators do not 
generate uniformly random
    + * values; instead, they're biased to return "interesting" values (such as 
maximum / minimum values)
    + * with higher probability.
    + */
    +object RandomDataGenerator {
    +
    +  /**
    +   * Returns a function which generates random values for the given 
[[DataType]], or `None` if no
    +   * random data generator is defined for that data type. The generated 
values will use an external
    +   * representation of the data type; for example, the random generator 
for [[DateType]] will return
    +   * instances of [[java.sql.Date]] and the generator for [[StructType]] 
will return a
    +   * [[org.apache.spark.Row]].
    +   *
    +   * @param dataType the type to generate values for
    +   * @param nullable whether null values should be generated
    +   * @return a ScalaCheck [[Gen]] which can be used to produce random 
values.
    +   */
    +  def forType(
    +      dataType: DataType,
    +      nullable: Boolean = true): Option[Gen[Any]] = {
    +    val valueGenerator: Option[Gen[Any]] = dataType match {
    +      case StringType => Some(Arbitrary.arbitrary[String])
    +      case BinaryType => 
Some(Gen.listOf(Arbitrary.arbitrary[Byte]).map(_.toArray))
    --- End diff --
    
    Note that I mapped a list into an Array instead of using 
`Arbitrary.arbitrary[Array[Byte]]` because the latter seems to run into a 
possible ScalaCheck NPE bug when we wrap the resulting generator to sometimes 
return nulls.  I've filed https://github.com/rickynils/scalacheck/issues/177 to 
try to investigate this upstream.  AFAIK the only downside to the workaround 
here is that we lose some of the failing test case minimization benefits that 
ScalaCheck provides.


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