Skip to content

Commit dc41313

Browse files
committed
[SPARK-8218][SQL] Binary log math function update.
Some minor updates based on after merging #6725. Author: Reynold Xin <[email protected]> Closes #6871 from rxin/log and squashes the following commits: ab51542 [Reynold Xin] Use JVM log 76fc8de [Reynold Xin] Fixed arg. a7c1522 [Reynold Xin] [SPARK-8218][SQL] Binary log math function update.
1 parent 207a98c commit dc41313

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

python/pyspark/sql/functions.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,18 +404,23 @@ def when(condition, value):
404404
return Column(jc)
405405

406406

407-
@since(1.4)
408-
def log(col, base=math.e):
407+
@since(1.5)
408+
def log(arg1, arg2=None):
409409
"""Returns the first argument-based logarithm of the second argument.
410410
411-
>>> df.select(log(df.age, 10.0).alias('ten')).map(lambda l: str(l.ten)[:7]).collect()
411+
If there is only one argument, then this takes the natural logarithm of the argument.
412+
413+
>>> df.select(log(10.0, df.age).alias('ten')).map(lambda l: str(l.ten)[:7]).collect()
412414
['0.30102', '0.69897']
413415
414416
>>> df.select(log(df.age).alias('e')).map(lambda l: str(l.e)[:7]).collect()
415417
['0.69314', '1.60943']
416418
"""
417419
sc = SparkContext._active_spark_context
418-
jc = sc._jvm.functions.log(base, _to_java_column(col))
420+
if arg2 is None:
421+
jc = sc._jvm.functions.log(_to_java_column(arg1))
422+
else:
423+
jc = sc._jvm.functions.log(arg1, _to_java_column(arg2))
419424
return Column(jc)
420425

421426

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/math.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ case class Pow(left: Expression, right: Expression)
260260

261261
case class Logarithm(left: Expression, right: Expression)
262262
extends BinaryMathExpression((c1, c2) => math.log(c2) / math.log(c1), "LOG") {
263+
264+
/**
265+
* Natural log, i.e. using e as the base.
266+
*/
263267
def this(child: Expression) = {
264268
this(EulerNumber(), child)
265269
}

0 commit comments

Comments
 (0)