0001 #
0002 # Licensed to the Apache Software Foundation (ASF) under one or more
0003 # contributor license agreements. See the NOTICE file distributed with
0004 # this work for additional information regarding copyright ownership.
0005 # The ASF licenses this file to You under the Apache License, Version 2.0
0006 # (the "License"); you may not use this file except in compliance with
0007 # the License. You may obtain a copy of the License at
0008 #
0009 # http://www.apache.org/licenses/LICENSE-2.0
0010 #
0011 # Unless required by applicable law or agreed to in writing, software
0012 # distributed under the License is distributed on an "AS IS" BASIS,
0013 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014 # See the License for the specific language governing permissions and
0015 # limitations under the License.
0016 #
0017
0018 # window.R - Utility functions for defining window in DataFrames
0019
0020 #' windowPartitionBy
0021 #'
0022 #' Creates a WindowSpec with the partitioning defined.
0023 #'
0024 #' @param col A column name or Column by which rows are partitioned to
0025 #' windows.
0026 #' @param ... Optional column names or Columns in addition to col, by
0027 #' which rows are partitioned to windows.
0028 #'
0029 #' @rdname windowPartitionBy
0030 #' @name windowPartitionBy
0031 #' @aliases windowPartitionBy,character-method
0032 #' @examples
0033 #' \dontrun{
0034 #' ws <- orderBy(windowPartitionBy("key1", "key2"), "key3")
0035 #' df1 <- select(df, over(lead("value", 1), ws))
0036 #'
0037 #' ws <- orderBy(windowPartitionBy(df$key1, df$key2), df$key3)
0038 #' df1 <- select(df, over(lead("value", 1), ws))
0039 #' }
0040 #' @note windowPartitionBy(character) since 2.0.0
0041 setMethod("windowPartitionBy",
0042 signature(col = "character"),
0043 function(col, ...) {
0044 windowSpec(
0045 callJStatic("org.apache.spark.sql.expressions.Window",
0046 "partitionBy",
0047 col,
0048 list(...)))
0049 })
0050
0051 #' @rdname windowPartitionBy
0052 #' @name windowPartitionBy
0053 #' @aliases windowPartitionBy,Column-method
0054 #' @note windowPartitionBy(Column) since 2.0.0
0055 setMethod("windowPartitionBy",
0056 signature(col = "Column"),
0057 function(col, ...) {
0058 jcols <- lapply(list(col, ...), function(c) {
0059 c@jc
0060 })
0061 windowSpec(
0062 callJStatic("org.apache.spark.sql.expressions.Window",
0063 "partitionBy",
0064 jcols))
0065 })
0066
0067 #' windowOrderBy
0068 #'
0069 #' Creates a WindowSpec with the ordering defined.
0070 #'
0071 #' @param col A column name or Column by which rows are ordered within
0072 #' windows.
0073 #' @param ... Optional column names or Columns in addition to col, by
0074 #' which rows are ordered within windows.
0075 #'
0076 #' @rdname windowOrderBy
0077 #' @name windowOrderBy
0078 #' @aliases windowOrderBy,character-method
0079 #' @examples
0080 #' \dontrun{
0081 #' ws <- windowOrderBy("key1", "key2")
0082 #' df1 <- select(df, over(lead("value", 1), ws))
0083 #'
0084 #' ws <- windowOrderBy(df$key1, df$key2)
0085 #' df1 <- select(df, over(lead("value", 1), ws))
0086 #' }
0087 #' @note windowOrderBy(character) since 2.0.0
0088 setMethod("windowOrderBy",
0089 signature(col = "character"),
0090 function(col, ...) {
0091 windowSpec(
0092 callJStatic("org.apache.spark.sql.expressions.Window",
0093 "orderBy",
0094 col,
0095 list(...)))
0096 })
0097
0098 #' @rdname windowOrderBy
0099 #' @name windowOrderBy
0100 #' @aliases windowOrderBy,Column-method
0101 #' @note windowOrderBy(Column) since 2.0.0
0102 setMethod("windowOrderBy",
0103 signature(col = "Column"),
0104 function(col, ...) {
0105 jcols <- lapply(list(col, ...), function(c) {
0106 c@jc
0107 })
0108 windowSpec(
0109 callJStatic("org.apache.spark.sql.expressions.Window",
0110 "orderBy",
0111 jcols))
0112 })