Skip to content

Commit

Permalink
add java doc
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-bli committed Nov 14, 2023
1 parent aa976e1 commit 283e17b
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/main/java/com/snowflake/snowpark_java/DataFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -1312,10 +1312,73 @@ public DataFrame join(
JavaUtils.columnArrayToSeq(Column.toScalaColumnArray(orderBy))));
}

/**
* Joins the current DataFrame with the output of the specified table function `func`.
*
* <p> Pre-defined table functions can be found in `TableFunctions` class.
*
* <p> For example:
*
* <pre>{@code
* df.join(TableFunctions.flatten(
* Functions.parse_json(df.col("col")),
* "path", true, true, "both"
* ));
* }</pre>
*
* <p> Or load any Snowflake builtin table function via TableFunction Class.
*
* <pre>{@code
* Map<String, Column> args = new HashMap<>();
* args.put("input", Functions.parse_json(df.col("a")));
* df.join(new TableFunction("flatten").call(args));
* }</pre>
*
* @since 1.10.0
* @param func Column object, which can be one of the values in the TableFunctions class or
* an object that you create from the `new TableFunction("name").call()`.
* @return The result DataFrame
*/
public DataFrame join(Column func) {
return new DataFrame(this.df.join(func.toScalaColumn()));
}

/**
* Joins the current DataFrame with the output of the specified table function `func`.
*
* <p>To specify a PARTITION BY or ORDER BY clause, use the `partitionBy` and `orderBy` arguments.
*
* <p> Pre-defined table functions can be found in `TableFunctions` class.
*
* <p> For example:
*
* <pre>{@code
* df.join(TableFunctions.flatten(
* Functions.parse_json(df.col("col1")),
* "path", true, true, "both"
* ),
* new Column[] {df.col("col2")},
* new Column[] {df.col("col1")}
* );
* }</pre>
*
* <p> Or load any Snowflake builtin table function via TableFunction Class.
*
* <pre>{@code
* Map<String, Column> args = new HashMap<>();
* args.put("input", Functions.parse_json(df.col("col1")));
* df.join(new TableFunction("flatten").call(args),
* new Column[] {df.col("col2")},
* new Column[] {df.col("col1")});
* }</pre>
*
* @since 1.10.0
* @param func Column object, which can be one of the values in the TableFunctions class or
* an object that you create from the `new TableFunction("name").call()`.
* @param partitionBy An array of columns partitioned by.
* @param orderBy An array of columns ordered by.
* @return The result DataFrame
*/
public DataFrame join(Column func, Column[] partitionBy, Column[] orderBy) {
return new DataFrame(
this.df.join(
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/snowflake/snowpark_java/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,23 @@ public DataFrame tableFunction(TableFunction func, Map<String, Column> args) {
func.getScalaTableFunction(), JavaUtils.javaStringColumnMapToScala(scalaArgs)));
}

/**
* Creates a new DataFrame from the given table function and arguments.
*
* <p>Example
*
* <pre>{@code
* session.tableFunction(TableFunctions.flatten(
* Functions.parse_json(df.col("col")),
* "path", true, true, "both"
* ));
* }</pre>
*
* @since 1.10.0
* @param func Column object, which can be one of the values in the TableFunctions class or
* an object that you create from the `new TableFunction("name").call()`.
* @return The result DataFrame
*/
public DataFrame tableFunction(Column func) {
return new DataFrame(session.tableFunction(func.toScalaColumn()));
}
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/snowflake/snowpark_java/TableFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,25 @@ public String funcName() {
return func.funcName();
}

/**
* Create a Column reference by passing arguments in the TableFunction object.
*
* @param args A list of Column objects representing the arguments of the given table function
* @return A Column reference
* @since 1.10.0
*/
public Column call(Column... args) {
return new Column(this.func.apply(JavaUtils.columnArrayToSeq(Column.toScalaColumnArray(args))));
}

/**
* Create a Column reference by passing arguments in the TableFunction object.
*
* @param args function arguments map of the given table function. Some functions, like flatten,
* have named parameters. use this map to assign values to the corresponding parameters.
* @return A Column reference
* @since 1.10.0
*/
public Column call(Map<String, Column> args) {
Map<String, com.snowflake.snowpark.Column> scalaArgs = new HashMap<>();
for (Map.Entry<String, Column> entry : args.entrySet()) {
Expand Down

0 comments on commit 283e17b

Please sign in to comment.