Last active
February 17, 2018 10:29
-
-
Save YordanGeorgiev/b230f2847bae294a6b80e58688a11dc6 to your computer and use it in GitHub Desktop.
[create dataframe with schema] how-to create a dataframe obj with schema in scala spark #scala #spark #dataframe
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
val spark = SparkSession.builder().getOrCreate() | |
import spark.implicits._ | |
val df = spark | |
.createDataFrame( | |
spark.sparkContext.parallelize( | |
Seq( | |
Row( | |
Map(("key1","val1") -> 1) | |
), | |
Row( | |
Map(("key1","val2") -> 2) | |
) | |
)), | |
StructType( | |
new StructType().add("server_rank_map", MapType( | |
new StructType() | |
.add("key_col", StringType , false) | |
.add("val_col" , StringType , false) | |
, IntegerType | |
) //eof MapType | |
) //eof add | |
) //eof schema | |
) //eof createDataFrame | |
df.printSchema() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment