Created
May 8, 2019 06:54
-
-
Save zygm0nt/9a102a3c3fe73836246c118c5376bcad to your computer and use it in GitHub Desktop.
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
scala> case class Category( | |
| path: String, | |
| id: String, | |
| name: Option[String] = None | |
| ) | |
defined class Category | |
scala> case class BaseItem(id: ItemId, | |
| userId: Option[String], | |
| category: Option[Category], | |
| itemType: String, | |
| endDate: Option[Long], | |
| metaItemMap: Map[String, String]) | |
<console>:13: error: not found: type ItemId | |
case class BaseItem(id: ItemId, | |
^ | |
scala> type ItemId = String | |
defined type alias ItemId | |
scala> case class BaseItem(id: ItemId, | |
| userId: Option[String], | |
| category: Option[Category], | |
| itemType: String, | |
| endDate: Option[Long], | |
| metaItemMap: Map[String, String]) | |
defined class BaseItem | |
scala> case class KafkaItemMessage(timestamp: Long, item: BaseItem) | |
defined class KafkaItemMessage | |
scala> val collection = Seq(KafkaItemMessage(1L, BaseItem("1", Some("A"), Some(Category("A", "b", Some("c"))), "SELL", Some(2L), Map("k" -> "v", "a" -> "b")))) | |
collection: Seq[KafkaItemMessage] = List(KafkaItemMessage(1,BaseItem(1,Some(A),Some(Category(A,b,Some(c))),SELL,Some(2),Map(k -> v, a -> b)))) | |
scala> collection.toDS() | |
res0: org.apache.spark.sql.Dataset[KafkaItemMessage] = [timestamp: bigint, item: struct<id: string, userId: string ... 4 more fields>] | |
scala> res0.registerTempTable("some_tmp_table") | |
warning: there was one deprecation warning; re-run with -deprecation for details | |
scala> spark.sql("describe some_tmp_table") | |
res2: org.apache.spark.sql.DataFrame = [col_name: string, data_type: string ... 1 more field] | |
scala> res2.toString | |
res3: String = [col_name: string, data_type: string ... 1 more field] | |
scala> res2.show() | |
+---------+--------------------+-------+ | |
| col_name| data_type|comment| | |
+---------+--------------------+-------+ | |
|timestamp| bigint| null| | |
| item|struct<id:string,...| null| | |
+---------+--------------------+-------+ | |
scala> res2.show(false) | |
+---------+------------------------------------------------------------------------------------------------------------------------------------------------+-------+ | |
|col_name |data_type |comment| | |
+---------+------------------------------------------------------------------------------------------------------------------------------------------------+-------+ | |
|timestamp|bigint |null | | |
|item |struct<id:string,userId:string,category:struct<path:string,id:string,name:string>,itemType:string,endDate:bigint,metaItemMap:map<string,string>>|null | | |
+---------+------------------------------------------------------------------------------------------------------------------------------------------------+-------+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment