Github user felixcheung commented on a diff in the pull request:
https://github.com/apache/spark/pull/11336#discussion_r84189253
--- Diff: R/pkg/R/column.R ---
@@ -29,38 +31,66 @@ setOldClass("jobj")
#' @rdname column
#'
#' @slot jc reference to JVM SparkDataFrame column
+#' @slot df the parent SparkDataFrame of the Column object
#' @export
#' @note Column since 1.4.0
setClass("Column",
- slots = list(jc = "jobj"))
+ slots = list(jc = "jobj", df = "SparkDataFrameOrNull"))
#' A set of operations working with SparkDataFrame columns
#' @rdname columnfunctions
#' @name columnfunctions
NULL
-
-setMethod("initialize", "Column", function(.Object, jc) {
+setMethod("initialize", "Column", function(.Object, jc, df) {
.Object@jc <- jc
+
+ # Some Column objects don't have any referencing DataFrame. In such
case, df will be NULL.
+ if (missing(df)) {
+ df <- NULL
+ }
+ .Object@df <- df
.Object
})
+#' @rdname show
+setMethod("show", signature = "Column", function(object) {
+ MAX_ELEMENTS <- 20
+ head.df <- head(object, MAX_ELEMENTS)
+
+ if (length(head.df) == 0) {
+ colname <- callJMethod(object@jc, "toString")
+ cat(paste0(colname, "\n"))
+ cat(paste0("<Empty column>\n"))
+ } else {
+ show(head.df)
+ }
+ if (length(head.df) == MAX_ELEMENTS) {
+ cat(paste0("\b...\nDisplaying up to ", as.character(MAX_ELEMENTS), "
elements only."))
+ }
+})
+
+#' @rdname head
+setMethod("head",
+ signature = "Column",
--- End diff --
There are more than 1 in the file...
---
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]