Skip to content

Commit 11b351c

Browse files
committed
add tests and remove pu
1 parent db331c9 commit 11b351c

File tree

7 files changed

+26
-32
lines changed

7 files changed

+26
-32
lines changed

python/pyspark/sql/functions.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,6 @@ def _():
138138
'bitwiseNOT': 'Computes bitwise not.',
139139
}
140140

141-
_functions_1_5 = {
142-
'e': 'Returns the double value that is closer than any other to e, the base of the natural ' +
143-
'logarithms.',
144-
'pi': 'Returns the double value that is closer than any other to pi, the ratio of the ' +
145-
'circumference of a circle to its diameter.'
146-
}
147-
148141
# math functions that take two arguments as input
149142
_binary_mathfunctions = {
150143
'atan2': 'Returns the angle theta from the conversion of rectangular coordinates (x, y) to' +
@@ -195,14 +188,11 @@ def _():
195188
globals()[_name] = since(1.4)(_create_binary_mathfunction(_name, _doc))
196189
for _name, _doc in _window_functions.items():
197190
globals()[_name] = since(1.4)(_create_window_function(_name, _doc))
198-
for _name, _doc in _functions_1_5.items():
199-
globals()[_name] = since(1.5)(_create_function(_name, _doc))
200191
del _name, _doc
201192
__all__ += _functions.keys()
202193
__all__ += _functions_1_4.keys()
203194
__all__ += _binary_mathfunctions.keys()
204195
__all__ += _window_functions.keys()
205-
__all__ += _functions_1_5.keys()
206196
__all__.sort()
207197

208198

@@ -358,24 +348,6 @@ def randn(seed=None):
358348
return Column(jc)
359349

360350

361-
@since(1.5)
362-
def e():
363-
"""Returns the double value that is closer than any other to e, the base of the natural
364-
logarithms.
365-
"""
366-
import math
367-
return Column(math.e)
368-
369-
370-
@since(1.5)
371-
def pi():
372-
"""Returns the double value that is closer than any other to pi, the ratio of the circumference
373-
of a circle to its diameter.
374-
"""
375-
import math
376-
return Column(math.pi)
377-
378-
379351
@since(1.4)
380352
def sparkPartitionId():
381353
"""A column for partition ID of the Spark task.

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ object FunctionRegistry {
106106
expression[Cbrt]("cbrt"),
107107
expression[Ceil]("ceil"),
108108
expression[Cos]("cos"),
109-
expression[E]("e"),
109+
expression[EulerNumber]("e"),
110110
expression[Exp]("exp"),
111111
expression[Expm1]("expm1"),
112112
expression[Floor]("floor"),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ abstract class BinaryMathExpression(f: (Double, Double) => Double, name: String)
129129
////////////////////////////////////////////////////////////////////////////////////////////////////
130130
////////////////////////////////////////////////////////////////////////////////////////////////////
131131

132-
case class E() extends LeafMathExpression(math.E, "E")
132+
case class EulerNumber() extends LeafMathExpression(math.E, "E")
133133

134134
case class Pi() extends LeafMathExpression(math.Pi, "PI")
135135

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MathFunctionsSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class MathFunctionsSuite extends SparkFunSuite with ExpressionEvalHelper {
8989
}
9090

9191
test("e") {
92-
testLeaf(E, math.E)
92+
testLeaf(EulerNumber, math.E)
9393
}
9494

9595
test("pi") {

sql/core/src/main/scala/org/apache/spark/sql/functions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ object functions {
951951
* @group math_funcs
952952
* @since 1.5.0
953953
*/
954-
def e(): Column = E()
954+
def e(): Column = EulerNumber()
955955

956956
/**
957957
* Computes the exponential of the given value.

sql/core/src/test/scala/org/apache/spark/sql/DataFrameFunctionsSuite.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,17 @@ class DataFrameFunctionsSuite extends QueryTest {
8585
}
8686
}
8787

88+
test("constant function") {
89+
checkAnswer(
90+
testData2.select(e()).limit(1),
91+
Row(scala.math.E)
92+
)
93+
checkAnswer(
94+
testData2.select(pi()).limit(1),
95+
Row(scala.math.Pi)
96+
)
97+
}
98+
8899
test("bitwiseNOT") {
89100
checkAnswer(
90101
testData2.select(bitwiseNOT($"a")),

sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,17 @@ class SQLQuerySuite extends QueryTest with BeforeAndAfterAll with SQLTestUtils {
145145
Seq(Row("1"), Row("2")))
146146
}
147147

148+
test("constant functions") {
149+
checkAnswer(
150+
sql("SELECT E()"),
151+
Row(scala.math.E)
152+
)
153+
checkAnswer(
154+
sql("SELECT PI()"),
155+
Row(scala.math.Pi)
156+
)
157+
}
158+
148159
test("SPARK-3176 Added Parser of SQL ABS()") {
149160
checkAnswer(
150161
sql("SELECT ABS(-1.3)"),

0 commit comments

Comments
 (0)