Skip to content

Commit 3f22c8d

Browse files
committed
Merge pull request apache#195 from cafreeman/sparkr-sql
New 1.3 repo and updates to `column.R`
2 parents 8a676b1 + e8639c3 commit 3f22c8d

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

pkg/R/column.R

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ column <- function(jc) {
2626
# TODO: change Dsl to functions once update spark-sql
2727
# A helper function to create a column from name
2828
col <- function(x) {
29-
column(callJStatic("org.apache.spark.sql.Dsl", "col", x))
29+
column(callJStatic("org.apache.spark.sql.functions", "col", x))
3030
}
3131

3232
# TODO(davies): like, rlike, startwith, substr, getField, getItem
@@ -38,7 +38,7 @@ operators <- list(
3838
)
3939

4040
functions <- c("min", "max", "sum", "avg", "mean", "count", "abs", "sqrt",
41-
"first", "last", "asc", "desc", "lower", "upper", "sumDistinct",
41+
"first", "last", "lower", "upper", "sumDistinct",
4242
"isNull", "isNotNull")
4343

4444
createOperator <- function(op) {
@@ -65,7 +65,7 @@ createFunction <- function(name) {
6565
setMethod(name,
6666
signature(x = "Column"),
6767
function(x) {
68-
jc <- callJStatic("org.apache.spark.sql.Dsl", name, x@jc)
68+
jc <- callJStatic("org.apache.spark.sql.functions", name, x@jc)
6969
column(jc)
7070
})
7171
}
@@ -77,8 +77,6 @@ createMethods <- function() {
7777

7878
setGeneric("avg", function(x) { standardGeneric("avg") })
7979
setGeneric("last", function(x) { standardGeneric("last") })
80-
setGeneric("asc", function(x) { standardGeneric("asc") })
81-
setGeneric("desc", function(x) { standardGeneric("desc") })
8280
setGeneric("lower", function(x) { standardGeneric("lower") })
8381
setGeneric("upper", function(x) { standardGeneric("upper") })
8482
setGeneric("isNull", function(x) { standardGeneric("isNull") })
@@ -92,6 +90,24 @@ createMethods <- function() {
9290

9391
createMethods()
9492

93+
setGeneric("asc", function(x) { standardGeneric("asc") })
94+
95+
setMethod("asc",
96+
signature(x = "Column"),
97+
function(x) {
98+
jc <- callJMethod(x@jc, "asc")
99+
column(jc)
100+
})
101+
102+
setGeneric("desc", function(x) { standardGeneric("desc") })
103+
104+
setMethod("desc",
105+
signature(x = "Column"),
106+
function(x) {
107+
jc <- callJMethod(x@jc, "desc")
108+
column(jc)
109+
})
110+
95111
setMethod("alias",
96112
signature(object = "Column"),
97113
function(object, data) {
@@ -117,7 +133,7 @@ setGeneric("approxCountDistinct", function(x, ...) { standardGeneric("approxCoun
117133
setMethod("approxCountDistinct",
118134
signature(x = "Column"),
119135
function(x, rsd = 0.95) {
120-
jc <- callJStatic("org.apache.spark.sql.Dsl", "approxCountDistinct", x@jc, rsd)
136+
jc <- callJStatic("org.apache.spark.sql.functions", "approxCountDistinct", x@jc, rsd)
121137
column(jc)
122138
})
123139

@@ -129,7 +145,7 @@ setMethod("countDistinct",
129145
jcol <- lapply(list(...), function (x) {
130146
x@jc
131147
})
132-
jc <- callJStatic("org.apache.spark.sql.Dsl", "countDistinct", x@jc, listToSeq(jcol))
148+
jc <- callJStatic("org.apache.spark.sql.functions", "countDistinct", x@jc, listToSeq(jcol))
133149
column(jc)
134150
})
135151

pkg/inst/tests/test_sparkSQL.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ test_that("schema(), dtypes(), columns(), names() return the correct values/form
166166
df <- jsonFile(sqlCtx, jsonPath)
167167
testSchema <- schema(df)
168168
expect_true(length(testSchema$fields()) == 2)
169-
expect_true(testSchema$fields()[[1]]$dataType.toString() == "IntegerType")
169+
expect_true(testSchema$fields()[[1]]$dataType.toString() == "LongType")
170170
expect_true(testSchema$fields()[[2]]$dataType.simpleString() == "string")
171171
expect_true(testSchema$fields()[[1]]$name() == "age")
172172

pkg/src/build.sbt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ libraryDependencies ++= Seq(
2929
val excludeHadoop = ExclusionRule(organization = "org.apache.hadoop")
3030
val sbtYarnFlag = scala.util.Properties.envOrElse("USE_YARN", "")
3131
val defaultHadoopVersion = "1.0.4"
32-
val defaultSparkVersion = "1.3.0"
32+
val defaultSparkVersion = "1.3.0-SNAPSHOT-sparkr"
3333
val hadoopVersion = scala.util.Properties.envOrElse("SPARK_HADOOP_VERSION", defaultHadoopVersion)
3434
val sparkVersion = scala.util.Properties.envOrElse("SPARK_VERSION", defaultSparkVersion)
3535
libraryDependencies ++= Seq(
@@ -53,6 +53,7 @@ libraryDependencies ++= Seq(
5353
}
5454

5555
resolvers ++= Seq(
56+
"SparkR 1.3 Snapshots" at "https://s3-us-west-2.amazonaws.com/sparkr-dep-1.3/release",
5657
"Apache Staging" at "https://repository.apache.org/content/repositories/staging/",
5758
"Typesafe" at "http://repo.typesafe.com/typesafe/releases",
5859
"Scala Tools Snapshots" at "http://scala-tools.org/repo-snapshots/",

0 commit comments

Comments
 (0)