Skip to content

Commit

Permalink
Merge branch 'main' into snow-1622249
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-bli committed Sep 13, 2024
2 parents 886e76b + 6a9edb1 commit f548585
Show file tree
Hide file tree
Showing 8 changed files with 1,219 additions and 13 deletions.
327 changes: 327 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 Expand Up @@ -4308,11 +4504,142 @@ public static Column from_unixtime(Column ut, String f) {
* [Row(SEQ8(0)=0),Row(SEQ8(0)=1), Row(SEQ8(0)=2)]
* }</pre>
*
* @return A sequence of monotonically increasing integers, with wrap-around * which happens after
* largest representable integer of integer width 8 byte.
* @since 1.15.0
*/
public static Column monotonically_increasing_id() {
return new Column(com.snowflake.snowpark.functions.monotonically_increasing_id());
}
/**
* Returns number of months between dates `start` and `end`.
*
* <p>A whole number is returned if both inputs have the same day of month or both are the last
* day of their respective months. Otherwise, the difference is calculated assuming 31 days per
* month.
*
* <p>For example:
*
* <pre>{@code
* {{{
* months_between("2017-11-14", "2017-07-14") // returns 4.0
* months_between("2017-01-01", "2017-01-10") // returns 0.29032258
* months_between("2017-06-01", "2017-06-16 12:00:00") // returns -0.5
* }}}
* }</pre>
*
* @param end A date, timestamp or string. If a string, the data must be in a format that can be
* cast to a timestamp, such as `yyyy-MM-dd` or `yyyy-MM-dd HH:mm:ss.SSSS`
* @param start A date, timestamp or string. If a string, the data must be in a format that can
* cast to a timestamp, such as `yyyy-MM-dd` or `yyyy-MM-dd HH:mm:ss.SSSS`
* @return A double, or null if either `end` or `start` were strings that could not be cast to a
* timestamp. Negative if `end` is before `start`
* @since 1.15.0
*/
public static Column months_between(String end, String start) {
return new Column(functions.months_between(end, start));
}

/**
* Locate the position of the first occurrence of substr column in the given string. Returns null
* if either of the arguments are null.
*
* <p>Example
*
* <pre>{@code
* SELECT id,
* string1,
* REGEXP_SUBSTR(string1, 'nevermore\\d') AS substring,
* REGEXP_INSTR( string1, 'nevermore\\d') AS position
* FROM demo1
* ORDER BY id;
*
* +----+-------------------------------------+------------+----------+
* | ID | STRING1 | SUBSTRING | POSITION |
* |----+-------------------------------------+------------+----------|
* | 1 | nevermore1, nevermore2, nevermore3. | nevermore1 | 1 |
* +----+-------------------------------------+------------+----------+
* }</pre>
*
* The position is not zero based, but 1 based index. Returns 0 if substr could not be found in
* str.
*
* @param str Column on which instr has to be applied
* @param substring Pattern to be retrieved
* @return A null if either of the arguments are null.
* @since 1.15.0
*/
public static Column instr(Column str, String substring) {
return new Column(com.snowflake.snowpark.functions.instr(str.toScalaColumn(), substring));
}

/**
* Given a timestamp like '2017-07-14 02:40:00.0', interprets it as a time in UTC, and renders
* that time as a timestamp in the given time zone. For example, 'GMT+1' would yield '2017-07-14
* 03:40:00.0'.
*
* <p>For Example
*
* <pre>{@code
* ALTER SESSION SET TIMEZONE = 'America/Los_Angeles';
* SELECT TO_TIMESTAMP_TZ('2024-04-05 01:02:03');
* +----------------------------------------+
* | TO_TIMESTAMP_TZ('2024-04-05 01:02:03') |
* |----------------------------------------|
* | 2024-04-05 01:02:03.000 -0700 |
* +----------------------------------------+
* }</pre>
*
* @param ts A date, timestamp or string. If a string, the data must be in a format that can be
* cast to a timestamp, such as `yyyy-MM-dd` or `yyyy-MM-dd HH:mm:ss.SSSS` A string detailing
* the time zone ID that the input should be adjusted to. It should be in the format of either
* region-based zone IDs or zone offsets. Region IDs must have the form 'area/city', such as
* 'America/Los_Angeles'. Zone offsets must be in the format '(+|-)HH:mm', for example
* '-08:00' or '+01:00'. Also 'UTC' and 'Z' are supported as aliases of '+00:00'. Other short
* names are not recommended to use because they can be ambiguous.
* @return A timestamp, or null if `ts` was a string that could not be cast to a timestamp or `tz`
* was an invalid value
* @since 1.15.0
*/
public static Column from_utc_timestamp(Column ts) {
return new Column(com.snowflake.snowpark.functions.from_utc_timestamp(ts.toScalaColumn()));
}

/**
* Given a timestamp like '2017-07-14 02:40:00.0', interprets it as a time in the given time zone,
* and renders that time as a timestamp in UTC. For example, 'GMT+1' would yield '2017-07-14
* 01:40:00.0'.
*
* @param ts A date, timestamp or string. If a string, the data must be in a format that can be
* cast to a timestamp, such as `yyyy-MM-dd` or `yyyy-MM-dd HH:mm:ss.SSSS` A string detailing
* the time zone ID that the input should be adjusted to. It should be in the format of either
* region-based zone IDs or zone offsets. Region IDs must have the form 'area/city', such as
* 'America/Los_Angeles'. Zone offsets must be in the format '(+|-)HH:mm', for example
* '-08:00' or '+01:00'. Also 'UTC' and 'Z' are supported as aliases of '+00:00'. Other short
* names are not recommended to use because they can be ambiguous.
* @return A timestamp, or null if `ts` was a string that could not be cast to a timestamp or `tz`
* was an invalid value
* @since 1.15.0
*/
public static Column to_utc_timestamp(Column ts) {
return new Column(com.snowflake.snowpark.functions.to_utc_timestamp(ts.toScalaColumn()));
}

/**
* Formats numeric column x to a format like '#,###,###.##', rounded to d decimal places with
* HALF_EVEN round mode, and returns the result as a string column.
*
* <p>If d is 0, the result has no decimal point or fractional part. If d is less than 0, the
* result will be null.
*
* @param x numeric column to be transformed
* @param d Amount of decimal for the number format
* @return Number casted to the specific string format
* @since 1.15.0
*/
public static Column format_number(Column x, Integer d) {
return new Column(com.snowflake.snowpark.functions.format_number(x.toScalaColumn(), d));
}

/* Returns a Column expression with values sorted in descending order.
*
Expand Down
Loading

0 comments on commit f548585

Please sign in to comment.