Created
October 24, 2022 13:20
-
-
Save d4rkc0de/6618f361e89c8b688129806bc53779e7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Cucmumber datatable to spark dataframe | |
import scala.collection.convert.ImplicitConversions.`collection AsScalaIterable` | |
import io.cucumber.datatable.DataTable | |
import org.apache.spark.sql.DataFrame | |
def dataTableToDataframe(table: DataTable): DataFrame = { | |
import sparkSession.implicits._ | |
val columns: Seq[String] = table.cells().head.toSeq | |
val data = table.cells().drop(1).toSeq.map(r => r.toList) | |
data.toDF().select(columns.indices.map(i => col("value")(i).alias(columns(i))): _*) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment