Github user kanzhang commented on a diff in the pull request:
https://github.com/apache/spark/pull/448#discussion_r11816864
--- 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 --
Isn't the base impl lazy also (till compute() is called)? It's kind of hard
to tell the difference for users. What's your thinking in keeping the base
implementation around (not overriding it)?
---
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.
---