Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions R/pkg/R/DataFrame.R
Original file line number Diff line number Diff line change
Expand Up @@ -3745,3 +3745,27 @@ setMethod("hint",
jdf <- callJMethod(x@sdf, "hint", name, parameters)
dataFrame(jdf)
})

#' alias
#'
#' @aliases alias,SparkDataFrame-method
#' @family SparkDataFrame functions
#' @rdname alias
#' @name alias
#' @export
#' @examples
#' \dontrun{
#' df <- alias(createDataFrame(mtcars), "mtcars")
#' avg_mpg <- alias(agg(groupBy(df, df$cyl), avg(df$mpg)), "avg_mpg")
#'
#' head(select(df, column("mtcars.mpg")))
#' head(join(df, avg_mpg, column("mtcars.cyl") == column("avg_mpg.cyl")))
#' }
#' @note alias(SparkDataFrame) since 2.3.0
setMethod("alias",
signature(object = "SparkDataFrame"),
function(object, data) {
stopifnot(is.character(data))
sdf <- callJMethod(object@sdf, "alias", data)
dataFrame(sdf)
})
16 changes: 8 additions & 8 deletions R/pkg/R/column.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,19 @@ createMethods <- function() {

createMethods()

#' alias
#'
#' Set a new name for a column
#'
#' @param object Column to rename
#' @param data new name to use
#'
#' @rdname alias
#' @name alias
#' @aliases alias,Column-method
#' @family colum_func
#' @export
#' @note alias since 1.4.0
#' @examples \dontrun{
#' df <- createDataFrame(iris)
#'
#' head(select(
#' df, alias(df$Sepal_Length, "slength"), alias(df$Petal_Length, "plength")
#' ))
#' }
#' @note alias(Column) since 1.4.0
setMethod("alias",
signature(object = "Column"),
function(object, data) {
Expand Down
11 changes: 11 additions & 0 deletions R/pkg/R/generics.R
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,17 @@ setGeneric("value", function(bcast) { standardGeneric("value") })
#' @export
setGeneric("agg", function (x, ...) { standardGeneric("agg") })

#' alias
#'
#' Returns a new SparkDataFrame or a Column with an alias set. Equivalent to SQL "AS" keyword.
#'
#' @name alias
#' @rdname alias
#' @param object x a SparkDataFrame or a Column
#' @param data new name to use
#' @return a SparkDataFrame or a Column
NULL

#' @rdname arrange
#' @export
setGeneric("arrange", function(x, col, ...) { standardGeneric("arrange") })
Expand Down
12 changes: 11 additions & 1 deletion R/pkg/inst/tests/testthat/test_sparkSQL.R
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,16 @@ test_that("select with column", {
expect_equal(columns(df4), c("name", "age"))
expect_equal(count(df4), 3)

# Test select with alias
df5 <- alias(df, "table")

expect_equal(columns(select(df5, column("table.name"))), "name")
expect_equal(columns(select(df5, "table.name")), "name")

# Test that stats::alias is not masked
expect_is(alias(aov(yield ~ block + N * P * K, npk)), "listof")


expect_error(select(df, c("name", "age"), "name"),
"To select multiple columns, use a character vector or list for col")
})
Expand Down Expand Up @@ -3387,7 +3397,7 @@ compare_list <- function(list1, list2) {

# This should always be the **very last test** in this test file.
test_that("No extra files are created in SPARK_HOME by starting session and making calls", {
skip_on_cran()
skip_on_cran() # skip because when run from R CMD check SPARK_HOME is not the current directory

# Check that it is not creating any extra file.
# Does not check the tempdir which would be cleaned up after.
Expand Down
4 changes: 3 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ install:
build_script:
- cmd: mvn -DskipTests -Psparkr -Phive -Phive-thriftserver package

environment:
NOT_CRAN: true

test_script:
- cmd: .\bin\spark-submit2.cmd --driver-java-options "-Dlog4j.configuration=file:///%CD:\=/%/R/log4j.properties" --conf spark.hadoop.fs.defaultFS="file:///" R\pkg\tests\run-all.R

Expand All @@ -56,4 +59,3 @@ notifications:
on_build_success: false
on_build_failure: false
on_build_status_changed: false

14 changes: 14 additions & 0 deletions assembly/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -226,5 +226,19 @@
<parquet.deps.scope>provided</parquet.deps.scope>
</properties>
</profile>

<!--
Pull in spark-hadoop-cloud and its associated JARs,
-->
<profile>
<id>hadoop-cloud</id>
<dependencies>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-hadoop-cloud_${scala.binary.version}</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
52 changes: 52 additions & 0 deletions core/src/test/scala/org/apache/spark/storage/BlockIdSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.spark.storage

import java.util.UUID

import org.apache.spark.SparkFunSuite

class BlockIdSuite extends SparkFunSuite {
Expand Down Expand Up @@ -67,6 +69,32 @@ class BlockIdSuite extends SparkFunSuite {
assertSame(id, BlockId(id.toString))
}

test("shuffle data") {
val id = ShuffleDataBlockId(4, 5, 6)
assertSame(id, ShuffleDataBlockId(4, 5, 6))
assertDifferent(id, ShuffleDataBlockId(6, 5, 6))
assert(id.name === "shuffle_4_5_6.data")
assert(id.asRDDId === None)
assert(id.shuffleId === 4)
assert(id.mapId === 5)
assert(id.reduceId === 6)
assert(!id.isShuffle)
assertSame(id, BlockId(id.toString))
}

test("shuffle index") {
val id = ShuffleIndexBlockId(7, 8, 9)
assertSame(id, ShuffleIndexBlockId(7, 8, 9))
assertDifferent(id, ShuffleIndexBlockId(9, 8, 9))
assert(id.name === "shuffle_7_8_9.index")
assert(id.asRDDId === None)
assert(id.shuffleId === 7)
assert(id.mapId === 8)
assert(id.reduceId === 9)
assert(!id.isShuffle)
assertSame(id, BlockId(id.toString))
}

test("broadcast") {
val id = BroadcastBlockId(42)
assertSame(id, BroadcastBlockId(42))
Expand Down Expand Up @@ -101,6 +129,30 @@ class BlockIdSuite extends SparkFunSuite {
assertSame(id, BlockId(id.toString))
}

test("temp local") {
val id = TempLocalBlockId(new UUID(5, 2))
assertSame(id, TempLocalBlockId(new UUID(5, 2)))
assertDifferent(id, TempLocalBlockId(new UUID(5, 3)))
assert(id.name === "temp_local_00000000-0000-0005-0000-000000000002")
assert(id.asRDDId === None)
assert(id.isBroadcast === false)
assert(id.id.getMostSignificantBits() === 5)
assert(id.id.getLeastSignificantBits() === 2)
assert(!id.isShuffle)
}

test("temp shuffle") {
val id = TempShuffleBlockId(new UUID(1, 2))
assertSame(id, TempShuffleBlockId(new UUID(1, 2)))
assertDifferent(id, TempShuffleBlockId(new UUID(1, 3)))
assert(id.name === "temp_shuffle_00000000-0000-0001-0000-000000000002")
assert(id.asRDDId === None)
assert(id.isBroadcast === false)
assert(id.id.getMostSignificantBits() === 1)
assert(id.id.getLeastSignificantBits() === 2)
assert(!id.isShuffle)
}

test("test") {
val id = TestBlockId("abc")
assertSame(id, TestBlockId("abc"))
Expand Down
Loading