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

    https://github.com/apache/spark/pull/8597#discussion_r38742967
  
    --- Diff: 
sql/hive/src/test/scala/org/apache/spark/sql/sources/hadoopFsRelationSuites.scala
 ---
    @@ -100,6 +104,87 @@ abstract class HadoopFsRelationTest extends QueryTest 
with SQLTestUtils {
         }
       }
     
    +  test("test all data types") {
    +    withTempDir { file =>
    +      file.delete()
    +
    +      // Create the schema.
    +      val struct =
    +        StructType(
    +          StructField("f1", FloatType, true) ::
    +            StructField("f2", ArrayType(BooleanType), true) :: Nil)
    +      val dataTypes =
    +        Seq(
    +          StringType, BinaryType, NullType, BooleanType,
    +          ByteType, ShortType, IntegerType, LongType,
    +          FloatType, DoubleType, DecimalType(25, 5), DecimalType(6, 5),
    +          DateType, TimestampType,
    +          ArrayType(IntegerType), MapType(StringType, LongType), struct,
    +          new MyDenseVectorUDT())
    +      val fields = dataTypes.zipWithIndex.map { case (dataType, index) =>
    +        StructField(s"col$index", dataType, true)
    +      }
    +      val schema = StructType(fields)
    +
    +      // Create a RDD for the schema
    +      val rdd =
    +        sqlContext.sparkContext.parallelize((1 to 100), 10).flatMap { i =>
    +          val row1 = Row(
    +            s"str${i}: test save.",
    +            s"binary${i}: test save.".getBytes("UTF-8"),
    +            null,
    +            i % 2 == 0,
    +            i.toByte,
    +            i.toShort,
    +            i,
    +            Long.MaxValue - i.toLong,
    +            (i + 0.25).toFloat,
    +            (i + 0.75),
    +            BigDecimal(Long.MaxValue.toString + ".12345"),
    +            new java.math.BigDecimal(s"${i % 9 + 1}" + ".23456"),
    +            new Date(i),
    +            new Timestamp(i),
    +            (1 to i).toSeq,
    +            (0 to i).map(j => s"map_key_$j" -> (Long.MaxValue - j)).toMap,
    +            Row((i - 0.25).toFloat, Seq(true, false, null)),
    +            new MyDenseVector(Array(1.1, 2.1, 3.1)))
    +          val row2 = Row.fromSeq(Seq.fill(dataTypes.length)(null))
    +          row1 :: row2 :: Nil
    +        }
    +      val df = sqlContext.createDataFrame(rdd, schema)
    +
    +      // All columns that have supported data types of this source.
    +      val supportedColumns = schema.fields.filter { field =>
    +        supportsDataType(field.dataType)
    +      }.map { field =>
    +        field.name
    +      }
    --- End diff --
    
    Nit: Can be simplified a little bit:
    
    ```scala
    val supportedColumns = schema.collect {
      case StructField(name, dataType) if supportsDataType(dataType) => name
    }
    ```


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