I am new to spark/scala world. I have two sources of data
Traffic data which has URLs and hostnames
Attribute data which defines rules on the traffic urls. The rules are regex patterns to match the domain name. There could be one or many rules for one attribute-id.
If an URL meets criteria I have to assign an attribute-id. Each row in the traffic can match zero or more attribute conditions
A sample input
traffic-data
visitor_id | url
1000-abc10 | www.motor.com/index.html
2000-fe30a | www.lifestyle.com/cooking/pasta.html
`attribute-data
attribute_id | rule | describtion
101 | motor.com, auto*.com, vehicles.com | "vehicles"
102 | motor.com | "auto site"
Expected output:
visitor_id | attribute_id
1000-abc10 | 101
1000-abc10 | 202
I tried the following :
val traffic_df = spark.read.parquet(<traffic-path>).as[Traffic]
val attribute_df = spark.read.parquet(<attribute-path>).as[Attribute]
traffic_df.map(row => attribute_df.map(r => TrafficAttribute(row.visitor_id, r.attribute_id)))