Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIT-2227 Add new overloads for com.snowflake.snowpark.functions.pow function #158

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
196 changes: 196 additions & 0 deletions src/main/java/com/snowflake/snowpark_java/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,202 @@ public static Column pow(Column l, Column r) {
return new Column(com.snowflake.snowpark.functions.pow(l.toScalaColumn(), r.toScalaColumn()));
}

/**
* Returns a number (l) raised to the specified power (r).
*
* <p>Example:
*
* <pre>{@code
* DataFrame df = session.sql("select * from (values (0.1, 2), (2, 3), (2, 0.5), (2, -1)) as T(base, exponent)");
* df.select(col("base"), col("exponent"), pow(col("base"), "exponent").as("result")).show();
*
* ----------------------------------------------
* |"BASE" |"EXPONENT" |"RESULT" |
* ----------------------------------------------
* |0.1 |2.0 |0.010000000000000002 |
* |2.0 |3.0 |8.0 |
* |2.0 |0.5 |1.4142135623730951 |
* |2.0 |-1.0 |0.5 |
* ----------------------------------------------
* }</pre>
*
* @param l The numeric column representing the base.
* @param r The name of the numeric column representing the exponent.
* @return A column containing the result of raising {@code l} to the power of {@code r}.
* @since 1.15.0
*/
public static Column pow(Column l, String r) {
return new Column(com.snowflake.snowpark.functions.pow(l.toScalaColumn(), r));
}

/**
* Returns a number (l) raised to the specified power (r).
*
* <p>Example:
*
* <pre>{@code
* DataFrame df = session.sql("select * from (values (0.1, 2), (2, 3), (2, 0.5), (2, -1)) as T(base, exponent)");
* df.select(col("base"), col("exponent"), pow("base", col("exponent")).as("result")).show();
*
* ----------------------------------------------
* |"BASE" |"EXPONENT" |"RESULT" |
* ----------------------------------------------
* |0.1 |2.0 |0.010000000000000002 |
* |2.0 |3.0 |8.0 |
* |2.0 |0.5 |1.4142135623730951 |
* |2.0 |-1.0 |0.5 |
* ----------------------------------------------
* }</pre>
*
* @param l The name of the numeric column representing the base.
* @param r The numeric column representing the exponent.
* @return A column containing the result of raising {@code l} to the power of {@code r}.
* @since 1.15.0
*/
public static Column pow(String l, Column r) {
return new Column(com.snowflake.snowpark.functions.pow(l, r.toScalaColumn()));
}

/**
* Returns a number (l) raised to the specified power (r).
*
* <p>Example:
*
* <pre>{@code
* DataFrame df = session.sql("select * from (values (0.1, 2), (2, 3), (2, 0.5), (2, -1)) as T(base, exponent)");
* df.select(col("base"), col("exponent"), pow("base", "exponent").as("result")).show();
*
* ----------------------------------------------
* |"BASE" |"EXPONENT" |"RESULT" |
* ----------------------------------------------
* |0.1 |2.0 |0.010000000000000002 |
* |2.0 |3.0 |8.0 |
* |2.0 |0.5 |1.4142135623730951 |
* |2.0 |-1.0 |0.5 |
* ----------------------------------------------
* }</pre>
*
* @param l The name of the numeric column representing the base.
* @param r The name of the numeric column representing the exponent.
* @return A column containing the result of raising {@code l} to the power of {@code r}.
* @since 1.15.0
*/
public static Column pow(String l, String r) {
return new Column(com.snowflake.snowpark.functions.pow(l, r));
}

/**
* Returns a number (l) raised to the specified power (r).
*
* <p>Example:
*
* <pre>{@code
* DataFrame df = session.sql("select * from (values (0.5), (2), (2.5), (4)) as T(base)");
* df.select(col("base"), lit(2.0).as("exponent"), pow(col("base"), 2.0).as("result")).show();
*
* ----------------------------------
* |"BASE" |"EXPONENT" |"RESULT" |
* ----------------------------------
* |0.5 |2.0 |0.25 |
* |2.0 |2.0 |4.0 |
* |2.5 |2.0 |6.25 |
* |4.0 |2.0 |16.0 |
* ----------------------------------
* }</pre>
*
* @param l The numeric column representing the base.
* @param r The value of the exponent.
* @return A column containing the result of raising {@code l} to the power of {@code r}.
* @since 1.15.0
*/
public static Column pow(Column l, Double r) {
return new Column(com.snowflake.snowpark.functions.pow(l.toScalaColumn(), r));
}

/**
* Returns a number (l) raised to the specified power (r).
*
* <p>Example:
*
* <pre>{@code
* DataFrame df = session.sql("select * from (values (0.5), (2), (2.5), (4)) as T(base)");
* df.select(col("base"), lit(2.0).as("exponent"), pow("base", 2.0).as("result")).show();
*
* ----------------------------------
* |"BASE" |"EXPONENT" |"RESULT" |
* ----------------------------------
* |0.5 |2.0 |0.25 |
* |2.0 |2.0 |4.0 |
* |2.5 |2.0 |6.25 |
* |4.0 |2.0 |16.0 |
* ----------------------------------
* }</pre>
*
* @param l The name of the numeric column representing the base.
* @param r The value of the exponent.
* @return A column containing the result of raising {@code l} to the power of {@code r}.
* @since 1.15.0
*/
public static Column pow(String l, Double r) {
return new Column(com.snowflake.snowpark.functions.pow(l, r));
}

/**
* Returns a number (l) raised to the specified power (r).
*
* <p>Example:
*
* <pre>{@code
* DataFrame df = session.sql("select * from (values (0.5), (2), (2.5), (4)) as T(exponent)");
* df.select(lit(2.0).as("base"), col("exponent"), pow(2.0, col("exponent")).as("result")).show();
*
* --------------------------------------------
* |"BASE" |"EXPONENT" |"RESULT" |
* --------------------------------------------
* |2.0 |0.5 |1.4142135623730951 |
* |2.0 |2.0 |4.0 |
* |2.0 |2.5 |5.656854249492381 |
* |2.0 |4.0 |16.0 |
* --------------------------------------------
* }</pre>
*
* @param l The value of the base.
* @param r The numeric column representing the exponent.
* @return A column containing the result of raising {@code l} to the power of {@code r}.
* @since 1.15.0
*/
public static Column pow(Double l, Column r) {
return new Column(com.snowflake.snowpark.functions.pow(l, r.toScalaColumn()));
}

/**
* Returns a number (l) raised to the specified power (r).
*
* <p>Example:
*
* <pre>{@code
* DataFrame df = session.sql("select * from (values (0.5), (2), (2.5), (4)) as T(exponent)");
* df.select(lit(2.0).as("base"), col("exponent"), pow(2.0, "exponent").as("result")).show();
*
* --------------------------------------------
* |"BASE" |"EXPONENT" |"RESULT" |
* --------------------------------------------
* |2.0 |0.5 |1.4142135623730951 |
* |2.0 |2.0 |4.0 |
* |2.0 |2.5 |5.656854249492381 |
* |2.0 |4.0 |16.0 |
* --------------------------------------------
* }</pre>
*
* @param l The value of the base.
* @param r The name of the numeric column representing the exponent.
* @return A column containing the result of raising {@code l} to the power of {@code r}.
* @since 1.15.0
*/
public static Column pow(Double l, String r) {
return new Column(com.snowflake.snowpark.functions.pow(l, r));
}

/**
* Rounds the numeric values of the given column {@code e} to the {@code scale} decimal places
* using the half away from zero rounding mode.
Expand Down
186 changes: 186 additions & 0 deletions src/main/scala/com/snowflake/snowpark/functions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,192 @@ object functions {
*/
def pow(l: Column, r: Column): Column = builtin("pow")(l, r)

/**
* Returns a number (l) raised to the specified power (r).
*
* Example:
* {{{
* val df = session.sql(
* "select * from (values (0.1, 2), (2, 3), (2, 0.5), (2, -1)) as T(base, exponent)")
* df.select(col("base"), col("exponent"), pow(col("base"), "exponent").as("result")).show()
*
* ----------------------------------------------
* |"BASE" |"EXPONENT" |"RESULT" |
* ----------------------------------------------
* |0.1 |2.0 |0.010000000000000002 |
* |2.0 |3.0 |8.0 |
* |2.0 |0.5 |1.4142135623730951 |
* |2.0 |-1.0 |0.5 |
* ----------------------------------------------
* }}}
*
* @param l The numeric column representing the base.
* @param r The name of the numeric column representing the exponent.
* @return A column containing the result of raising `l` to the power of `r`.
* @group num_func
* @since 1.15.0
*/
def pow(l: Column, r: String): Column = pow(l, col(r))

/**
* Returns a number (l) raised to the specified power (r).
*
* Example:
* {{{
* val df = session.sql(
* "select * from (values (0.1, 2), (2, 3), (2, 0.5), (2, -1)) as T(base, exponent)")
* df.select(col("base"), col("exponent"), pow("base", col("exponent")).as("result")).show()
*
* ----------------------------------------------
* |"BASE" |"EXPONENT" |"RESULT" |
* ----------------------------------------------
* |0.1 |2.0 |0.010000000000000002 |
* |2.0 |3.0 |8.0 |
* |2.0 |0.5 |1.4142135623730951 |
* |2.0 |-1.0 |0.5 |
* ----------------------------------------------
* }}}
*
* @param l The name of the numeric column representing the base.
* @param r The numeric column representing the exponent.
* @return A column containing the result of raising `l` to the power of `r`.
* @group num_func
* @since 1.15.0
*/
def pow(l: String, r: Column): Column = pow(col(l), r)

/**
* Returns a number (l) raised to the specified power (r).
*
* Example:
* {{{
* val df = session.sql(
* "select * from (values (0.1, 2), (2, 3), (2, 0.5), (2, -1)) as T(base, exponent)")
* df.select(col("base"), col("exponent"), pow("base", "exponent").as("result")).show()
*
* ----------------------------------------------
* |"BASE" |"EXPONENT" |"RESULT" |
* ----------------------------------------------
* |0.1 |2.0 |0.010000000000000002 |
* |2.0 |3.0 |8.0 |
* |2.0 |0.5 |1.4142135623730951 |
* |2.0 |-1.0 |0.5 |
* ----------------------------------------------
* }}}
*
* @param l The name of the numeric column representing the base.
* @param r The name of the numeric column representing the exponent.
* @return A column containing the result of raising `l` to the power of `r`.
* @group num_func
* @since 1.15.0
*/
def pow(l: String, r: String): Column = pow(col(l), col(r))

/**
* Returns a number (l) raised to the specified power (r).
*
* Example:
* {{{
* val df = session.sql("select * from (values (0.5), (2), (2.5), (4)) as T(base)")
* df.select(col("base"), lit(2.0).as("exponent"), pow(col("base"), 2.0).as("result")).show()
*
* ----------------------------------
* |"BASE" |"EXPONENT" |"RESULT" |
* ----------------------------------
* |0.5 |2.0 |0.25 |
* |2.0 |2.0 |4.0 |
* |2.5 |2.0 |6.25 |
* |4.0 |2.0 |16.0 |
* ----------------------------------
* }}}
*
* @param l The numeric column representing the base.
* @param r The value of the exponent.
* @return A column containing the result of raising `l` to the power of `r`.
* @group num_func
* @since 1.15.0
*/
def pow(l: Column, r: Double): Column = pow(l, lit(r))

/**
* Returns a number (l) raised to the specified power (r).
*
* Example:
* {{{
* val df = session.sql("select * from (values (0.5), (2), (2.5), (4)) as T(base)")
* df.select(col("base"), lit(2.0).as("exponent"), pow("base", 2.0).as("result")).show()
*
* ----------------------------------
* |"BASE" |"EXPONENT" |"RESULT" |
* ----------------------------------
* |0.5 |2.0 |0.25 |
* |2.0 |2.0 |4.0 |
* |2.5 |2.0 |6.25 |
* |4.0 |2.0 |16.0 |
* ----------------------------------
* }}}
*
* @param l The name of the numeric column representing the base.
* @param r The value of the exponent.
* @return A column containing the result of raising `l` to the power of `r`.
* @group num_func
* @since 1.15.0
*/
def pow(l: String, r: Double): Column = pow(col(l), r)

/**
* Returns a number (l) raised to the specified power (r).
*
* Example:
* {{{
* val df = session.sql("select * from (values (0.5), (2), (2.5), (4)) as T(exponent)")
* df.select(lit(2.0).as("base"), col("exponent"), pow(2.0, col("exponent")).as("result"))
* .show()
*
* --------------------------------------------
* |"BASE" |"EXPONENT" |"RESULT" |
* --------------------------------------------
* |2.0 |0.5 |1.4142135623730951 |
* |2.0 |2.0 |4.0 |
* |2.0 |2.5 |5.656854249492381 |
* |2.0 |4.0 |16.0 |
* --------------------------------------------
* }}}
*
* @param l The value of the base.
* @param r The numeric column representing the exponent.
* @return A column containing the result of raising `l` to the power of `r`.
* @group num_func
* @since 1.15.0
*/
def pow(l: Double, r: Column): Column = pow(lit(l), r)

/**
* Returns a number (l) raised to the specified power (r).
*
* Example:
* {{{
* val df = session.sql("select * from (values (0.5), (2), (2.5), (4)) as T(exponent)")
* df.select(lit(2.0).as("base"), col("exponent"), pow(2.0, "exponent").as("result")).show()
*
* --------------------------------------------
* |"BASE" |"EXPONENT" |"RESULT" |
* --------------------------------------------
* |2.0 |0.5 |1.4142135623730951 |
* |2.0 |2.0 |4.0 |
* |2.0 |2.5 |5.656854249492381 |
* |2.0 |4.0 |16.0 |
* --------------------------------------------
* }}}
*
* @param l The value of the base.
* @param r The name of the numeric column representing the exponent.
* @return A column containing the result of raising `l` to the power of `r`.
* @group num_func
* @since 1.15.0
*/
def pow(l: Double, r: String): Column = pow(l, col(r))

/**
* Rounds the numeric values of the given column `e` to the `scale` decimal places using the
* half away from zero rounding mode.
Expand Down
Loading
Loading