Comments (9)
I'm not familiar with this code but the key is not lic but (lic, f(trip)) and so it is likely to be intended. Values are separately sorted and split. @sryza ?
from aas.
As far as I can tell, for this line
implicit val ordering: Ordering[(K,S)] = Ordering.by(_._1)
K is lic, S is f(trip). Ordering by(_._1) means to order by K , which is lic, right ? Did I miss something here?
from aas.
It should apply to the repartition and sort of presess
which is not keyed by lic but a different tuple.
from aas.
val presess = rdd.map {
case (lic, trip) => {
((lic, secondaryKeyFunc(trip)), trip)
}
}
val partitioner = new FirstKeyPartitioner[K, S](numPartitions)
implicit val ordering: Ordering[(K,S)] = Ordering.by(_._1)
presess.repartitionAndSortWithinPartitions(partitioner).mapPartitions(groupSorted(_, splitFunc))
Here is what I understand.
presess is RDD of ((lic, secondaryKeyFunc(trip)), trip) . The key is composite key includes lic and timestamp of the trip. The value is the trip.
implicit val ordering: Ordering[(K,S)] = Ordering.by(_._1)
This line indicates how we want to sort by the key, which is by the first element of the tuple( lic , timestamp) , which is lic in this case.
As I tried to run the code with small set of taxi data, I found that the data are not ordered by the pickup time.
from aas.
My reading is that the code in its present form is correct. In this case, secondaryKeyFunc
returns the pickup time of the trip, so the tuples in presess are ((lic, pickup time), trip). The given Ordering
orders on the first element of the outer tuple, which is the (lic, pickup time) inner tuple. Scala tuples have a natural lexicographic ordering, so the records will first be ordered by license, but within each license, will be ordered by pickup time. Which is the intended behavior. @yaominator does that conflict with what you're observing?
CC @jwills who wrote this code originally.
from aas.
Here is the mock data I am using for testing purpose
medallion,hack_license,vendor_id,rate_code,store_and_fwd_flag,pickup_datetime,dropoff_datetime,passenger_count,trip_time_in_secs,trip_distance,pickup_longitude,pickup_latitude,dropoff_longitude,dropoff_latitude
89D227B655E5C82AECF13C3F540D4CF4,BA96DE419E711691B9445D6A6307C170,CMT,1,N,2013-01-01 15:11:42,2013-01-01 15:18:10,4,382,1.00,-73.978165,40.757977,-73.989838,40.751171
89D227B655E5C82AECF13C3F540D4CF4,BA96DE419E711691B9445D6A6307C170,CMT,1,N,2013-01-01 15:11:49,2013-01-01 15:18:10,4,382,1.00,-73.978165,40.757977,-73.989838,40.751171
89D227B655E5C82AECF13C3F540D4CF4,BA96DE419E711691B9445D6A6307C170,CMT,1,N,2013-01-01 15:11:46,2013-01-01 15:18:10,4,382,1.00,-73.978165,40.757977,-73.989838,40.751171
I added a line to print out the trip
--- a/ch08-geotime/src/main/scala/com/cloudera/datascience/geotime/RunGeoTime.scala
+++ b/ch08-geotime/src/main/scala/com/cloudera/datascience/geotime/RunGeoTime.scala
@@ -101,7 +101,9 @@ object RunGeoTime extends Serializable {
def secondaryKeyFunc(trip: Trip) = trip.pickupTime.getMillis
val sessions = groupByKeyAndSortValues(taxiDone, secondaryKeyFunc, split, 30)
sessions.cache()
+ sessions.values.foreach( trip => trip.toList.foreach(println))
What I got is
16/02/02 17:07:48 INFO BlockManagerInfo: Added rdd_26_17 in memory on localhost:64693 (size: 17.5 KB, free: 529.8 MB)
Trip(2013-01-01T15:11:42.000-05:00,2013-01-01T15:18:10.000-05:00,{"x":-73.978165,"y":40.757977},{"x":-73.989838,"y":40.751171})
Trip(2013-01-01T15:11:49.000-05:00,2013-01-01T15:18:10.000-05:00,{"x":-73.978165,"y":40.757977},{"x":-73.989838,"y":40.751171})
Trip(2013-01-01T15:11:46.000-05:00,2013-01-01T15:18:10.000-05:00,{"x":-73.978165,"y":40.757977},{"x":-73.989838,"y":40.751171})
As you can see, it is not ordered by pick up time. Keep the same order as is in the text file.
from aas.
I tried running the code on @yaominator 's data sample and hit the incorrect behavior as well. It looks my analysis of what was going on was incorrect, because, by the contract of repartionAndSortWithinPartitions, the given ordering only applies to keys, which are the (lic, pickup time) tuples. The ordering overrides the natural lexicographic tuple ordering to only look at the first element.
I've pushed a fix here: 5d0514c.
This code isn't included in the text of the book, so I don't think we need an accompanying change there.
from aas.
works great !!! +1
from aas.
Awesome
from aas.
Related Issues (20)
- Pyspark implementation of these HOT 1
- Chapter 9: Getting the Data: 403 Forbidden results HOT 7
- Chapter 10 LeftOuterShuffleRegionJoin issue HOT 6
- Importing projects into IntelliJ HOT 2
- [ch-03] match Error with function: buildArtistAlias HOT 3
- transform RDD [(String, String)] to DATASET [ (String, String)] HOT 1
- Ch 03: audioscrobbler data not available HOT 2
- NullPointerException in chapter9 HOT 1
- how to work around "next on empty iterator"in chapter 9th? HOT 11
- ValueError: cannot decompress PACKBITS in chapter11 HOT 4
- [Question] Chapter 3 - Use the CROSS JOIN syntax to allow cartesian products between these relations HOT 4
- java.lang.NoClassDefFoundError: scala/reflect/internal/Trees HOT 1
- [Question] Chapter 2 - about function "scoreMatchData" HOT 5
- but which data set to download from https://ti.arc.nasa.gov HOT 1
- Increased maven memory for build project HOT 1
- Chapter 1, page 46 HOT 13
- Chapter 3. Recommending Music and the Audioscrobbler Dataset HOT 2
- Chapter 3: Convert PySpark DataFrame to Pandas HOT 4
- Chapter 3: ROC HOT 4
- Where is the code for AA with PySpark Book by Akash Tandon? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aas.