Github user marmbrus commented on a diff in the pull request: https://github.com/apache/spark/pull/448#discussion_r11813558 --- Diff: sql/core/src/main/scala/org/apache/spark/sql/SchemaRDD.scala --- @@ -313,4 +314,46 @@ class SchemaRDD( } } } + + /** + * Creates SchemaRDD by applying own schema to child RDD. Typically used to wrap results of base + * RDD functions that do not change schema. + * + * @param childRDD RDD derived from this one and has same schema + * + * @group schema + */ + private def applySchema(childRDD: RDD[Row]): SchemaRDD = + new SchemaRDD(sqlContext, SparkLogicalPlan(ExistingRdd(logicalPlan.output, childRDD))) + + // ======================================================================= + // Base RDD functions that do NOT change schema + // ======================================================================= + + override def coalesce(numPartitions: Int, shuffle: Boolean = false): SchemaRDD = + applySchema(super.coalesce(numPartitions, shuffle)) + + override def distinct(numPartitions: Int): SchemaRDD = + applySchema(super.distinct(numPartitions)) + + override def filter(f: Row => Boolean): SchemaRDD = + applySchema(super.filter(f)) + + override def intersection(other: RDD[Row]): SchemaRDD = + applySchema(super.intersection(other)) + + override def intersection(other: RDD[Row], partitioner: Partitioner): SchemaRDD = + applySchema(super.intersection(other, partitioner)) + + override def intersection(other: RDD[Row], numPartitions: Int): SchemaRDD = + applySchema(super.intersection(other, numPartitions)) + + override def sample(withReplacement: Boolean, fraction: Double, seed: Int): SchemaRDD = --- End diff -- Yeah, you are going to end up getting the same thing. I'd say we drop this one and leave the other. Right now it probably doesn't matter, but the other one is lazy and gives the optimizer a chance to possibly improve things before actually executing.
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. ---