-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-12393] [SparkR] Add read.text and write.text for SparkR #10348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -549,6 +549,10 @@ setGeneric("write.parquet", function(x, path) { standardGeneric("write.parquet") | |
| #' @export | ||
| setGeneric("saveAsParquetFile", function(x, path) { standardGeneric("saveAsParquetFile") }) | ||
|
|
||
| #' @rdname write.text | ||
| #' @export | ||
| setGeneric("write.text", function(x, path) { standardGeneric("write.text") }) | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't read.text be added too?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found all functions in SQLContext.R did not use
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is historical legacy:) (you can find same cases in context.R.) I guess that because we did not implement SparkContext and SQLContext as S4 classes. If there is no strong reason, we can keep it as is. |
||
| #' @rdname schema | ||
| #' @export | ||
| setGeneric("schema", function(x) { standardGeneric("schema") }) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1481,6 +1481,27 @@ test_that("read/write Parquet files", { | |
| unlink(parquetPath4) | ||
| }) | ||
|
|
||
| test_that("read/write text files", { | ||
| # Test write.df and read.df | ||
| df <- read.df(sqlContext, jsonPath, "text") | ||
| expect_is(df, "DataFrame") | ||
| expect_equal(colnames(df), c("value")) | ||
| expect_equal(count(df), 3) | ||
| textPath <- tempfile(pattern = "textPath", fileext = ".txt") | ||
| write.df(df, textPath, "text", mode="overwrite") | ||
|
|
||
| # Test write.text and read.text | ||
| textPath2 <- tempfile(pattern = "textPath2", fileext = ".txt") | ||
| write.text(df, textPath2) | ||
| df2 <- read.text(sqlContext, c(textPath, textPath2)) | ||
| expect_is(df2, "DataFrame") | ||
| expect_equal(colnames(df2), c("value")) | ||
| expect_equal(count(df2), count(df) * 2) | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should unlink(textPath) and unlink(textPath2)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for catching this, I will update it. |
||
| unlink(textPath) | ||
| unlink(textPath2) | ||
| }) | ||
|
|
||
| test_that("describe() and summarize() on a DataFrame", { | ||
| df <- read.json(sqlContext, jsonPath) | ||
| stats <- describe(df, "age") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might want to add the DataFrame must have a column with the name "value" I recall there is a similar doc clarification in Scala recently.