Github user davies commented on a diff in the pull request:

    https://github.com/apache/spark/pull/6981#discussion_r34932464
  
    --- Diff: python/pyspark/sql/functions.py ---
    @@ -652,6 +652,153 @@ def ntile(n):
         return Column(sc._jvm.functions.ntile(int(n)))
     
     
    +@since(1.5)
    +def date_format(dateCol, format):
    +    """
    +    Converts a date/timestamp/string to a value of string in the format 
specified by the date
    +    format given by the second argument.
    +
    +    A pattern could be for instance `dd.MM.yyyy` and could return a string 
like '18.03.1993'. All
    +    pattern letters of the Java class `java.text.SimpleDateFormat` can be 
used.
    +
    +    NOTE: Use when ever possible specialized functions like `year`. These 
benefit from a
    +    specialized implementation.
    +
    +    >>> df0 = sqlContext.createDataFrame([('2015-04-08',)], ['a'])
    +
    +    >>> df0.select(date_format('a', 'MM/dd/yyy').alias('date')).collect()
    +    [Row(date=u'04/08/2015')]
    +    """
    +    sc = SparkContext._active_spark_context
    +    return Column(sc._jvm.functions.date_format(dateCol, format))
    +
    +
    +@since(1.5)
    +def year(col):
    +    """
    +    Extract the year of a given date as integer.
    +    >>> df0 = sqlContext.createDataFrame([('2015-04-08',)], ['a'])
    +
    +    >>> df0.select(year('a').alias('year')).collect()
    +    [Row(year=2015)]
    +    """
    +    sc = SparkContext._active_spark_context
    +    return Column(sc._jvm.functions.year(col))
    +
    +
    +@since(1.5)
    +def quarter(col):
    +    """
    +    Extract the quarter of a given date as integer.
    +    >>> df0 = sqlContext.createDataFrame([('2015-04-08',)], ['a'])
    +
    +    >>> df0.select(quarter('a').alias('quarter')).collect()
    +    [Row(quarter=2)]
    +    """
    +    sc = SparkContext._active_spark_context
    +    return Column(sc._jvm.functions.quarter(col))
    +
    +
    +@since(1.5)
    +def month(col):
    +    """
    +    Extract the month of a given date as integer.
    +    >>> df0 = sqlContext.createDataFrame([('2015-04-08',)], ['a'])
    +
    +    >>> df0.select(month('a').alias('month')).collect()
    +    [Row(month=4)]
    +   """
    +    sc = SparkContext._active_spark_context
    +    return Column(sc._jvm.functions.month(col))
    +
    +
    +@since(1.5)
    +def day(col):
    +    """
    +    Extract the day of the month of a given date as integer.
    +    >>> sqlContext.createDataFrame([('2015-04-08',)], 
['a']).select(day('a').alias('day')).collect()
    +    [Row(day=8)]
    +    """
    +    sc = SparkContext._active_spark_context
    +    return Column(sc._jvm.functions.day(col))
    +
    +
    +@since(1.5)
    +def day_of_month(col):
    +    """
    +    Extract the day of the month of a given date as integer.
    +    >>> df0 = sqlContext.createDataFrame([('2015-04-08',)], ['a'])
    +    >>> df0.select(day_of_month('a').alias('day')).collect()
    +    [Row(day=8)]
    +    """
    +    sc = SparkContext._active_spark_context
    +    return Column(sc._jvm.functions.day_of_month(col))
    +
    +
    +@since(1.5)
    +def day_in_year(col):
    +    """
    +    Extract the day of the year of a given date as integer.
    +    >>> df0 = sqlContext.createDataFrame([('2015-04-08',)], ['a'])
    +    >>> df0.select(day_in_year('a').alias('day')).collect()
    +    [Row(day=98)]
    +    """
    +    sc = SparkContext._active_spark_context
    +    return Column(sc._jvm.functions.day_in_year(col))
    +
    +
    +@since(1.5)
    +def hour(col):
    +    """
    +    Extract the hours of a given date as integer.
    +    >>> df0 = sqlContext.createDataFrame([('2015-04-08 13:08:15',)], ['a'])
    +
    +    >>> df0.select(hour('a').alias('hour')).collect()
    +    [Row(hour=13)]
    +    """
    +    sc = SparkContext._active_spark_context
    +    return Column(sc._jvm.functions.hour(col))
    +
    +
    +@since(1.5)
    +def minute(col):
    +    """
    +    Extract the minutes of a given date as integer.
    +    >>> df0 = sqlContext.createDataFrame([('2015-04-08 13:08:15',)], ['a'])
    +
    +    >>> df0.select(minute('a').alias('minute')).collect()
    +    [Row(minute=8)]
    +    """
    +    sc = SparkContext._active_spark_context
    +    return Column(sc._jvm.functions.minute(col))
    +
    +
    +@since(1.5)
    +def second(col):
    +    """
    +    Extract the seconds of a given date as integer.
    +    >>> df0 = sqlContext.createDataFrame([('2015-04-08 13:08:15',)], ['a'])
    +
    +    >>> df0.select(second('a').alias('second')).collect()
    +    [Row(second=15)]
    +    """
    +    sc = SparkContext._active_spark_context
    +    return Column(sc._jvm.functions.second(col))
    +
    +
    +@since(1.5)
    +def week_of_year(col):
    +    """
    +    Extract the week number of a given date as integer.
    +    >>> df0 = sqlContext.createDataFrame([('2015-04-08',)], ['a'])
    --- End diff --
    
    a empty line above this line (to separate doc string and doc tests)


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to