-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38f24a6
commit c1d3730
Showing
5 changed files
with
101 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
common/core/src/main/java/zingg/common/core/util/ListConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package zingg.common.core.util; | ||
|
||
import scala.collection.JavaConverters; | ||
import scala.collection.Seq; | ||
|
||
import java.util.List; | ||
|
||
public class ListConverter<C> { | ||
public Seq<C> convertListToSeq(List<C> inputList) { | ||
return JavaConverters.asScalaIteratorConverter(inputList.iterator()) | ||
.asScala() | ||
.toSeq(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
spark/client/src/main/java/zingg/spark/client/util/ExtendedFunction.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package zingg.spark.client.util | ||
|
||
import org.apache.spark.sql.functions.{col, collect_list, concat_ws} | ||
import org.apache.spark.sql.{Dataset, Row} | ||
|
||
class ExtendedFunction { | ||
def TransposeDF(df: Dataset[Row], columns: Seq[String], pivotCol: String): Dataset[Row] = { | ||
val columnsValue = columns.map(x => "'" + x + "', " + x) | ||
val stackCols = columnsValue.mkString(",") | ||
val df_1 = df.selectExpr(pivotCol, "stack(" + columns.size + "," + stackCols + ")") | ||
.select(pivotCol, "col0", "col1") | ||
|
||
val final_df = df_1.groupBy(col("col0")).pivot(pivotCol).agg(concat_ws("", collect_list(col("col1")))) | ||
.withColumnRenamed("col0", pivotCol) | ||
final_df | ||
} | ||
|
||
} |