{"action":"created","issue":{"url":"https://api.github.com/repos/apache/spark/issues/9256","labels_url":"https://api.github.com/repos/apache/spark/issues/9256/labels{/name}","comments_url":"https://api.github.com/repos/apache/spark/issues/9256/comments","events_url":"https://api.github.com/repos/apache/spark/issues/9256/events","html_url":"https://github.com/apache/spark/pull/9256","id":113111044,"number":9256,"title":"[SPARK-2629][STREAMING] Basic implementation of trackStateByKey [WIP]","user":{"login":"tdas","id":663212,"avatar_url":"https://avatars.githubusercontent.com/u/663212?v=3","gravatar_id":"","url":"https://api.github.com/users/tdas","html_url":"https://github.com/tdas","followers_url":"https://api.github.com/users/tdas/followers","following_url":"https://api.github.com/users/tdas/following{/other_user}","gists_url":"https://api.github.com/users/tdas/gists{/gist_id}","starred_url":"https://api.github.com/users/tdas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tdas/subscriptions","organizations_url":"https://api.github.com/users/tdas/orgs","repos_url":"https://api.github.com/users/tdas/repos","events_url":"https://api.github.com/users/tdas/events{/privacy}","received_events_url":"https://api.github.com/users/tdas/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-10-23T22:30:04Z","updated_at":"2015-11-05T18:12:54Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/9256","html_url":"https://github.com/apache/spark/pull/9256","diff_url":"https://github.com/apache/spark/pull/9256.diff","patch_url":"https://github.com/apache/spark/pull/9256.patch"},"body":"Current updateStateByKey provides stateful processing in Spark Streaming. It allows the user to maintain per-key state and manage that state using an updateFunction. The updateFunction is called for each key, and it uses new data and existing state of the key, to generate an updated state. However, based on community feedback, we have learnt the following lessons.\r\n* Need for more optimized state management that does not scan every key\r\n* Need to make it easier to implement common use cases - (a) timeout of idle data, (b) returning items other than state\r\n\r\nThe high level idea that of this PR\r\n* Introduce a new API trackStateByKey that, allows the user to update per-key state, and emit arbitrary records. The new API is necessary as this will have significantly different semantics than the existing updateStateByKey API. This API will have direct support for timeouts.\r\n* Internally, the system will keep the state data as a map/list within the partitions of the state RDDs. The new data RDDs will be partitioned appropriately, and for all the key-value data, it will lookup the map/list in the state RDD partition and create a new list/map of updated state data. The new state RDD partition will be created based on the update data and if necessary, with old data.\r\nHere is the detailed design doc. Please take a look and provide feedback as comments.\r\nhttps://docs.google.com/document/d/1NoALLyd83zGs1hNGMm0Pc5YOVgiPpMHugGMk6COqxxE/edit#heading=h.ph3w0clkd4em\r\n\r\nThis is still WIP. Major things left to be done. \r\n- [x] Implement basic functionality of state tracking, with initial RDD and timeouts\r\n- [x] Unit tests for state tracking\r\n- [x] Unit tests for initial RDD and timeout\r\n- [ ] Unit tests for TrackStateRDD\r\n       - [x] state creating, updating, removing\r\n       - [ ] emitting\r\n       - [ ] checkpointing\r\n- [ ] Misc unit tests for State, TrackStateSpec, etc.\r\n- [ ] Update docs and experimental tags"},"comment":{"url":"https://api.github.com/repos/apache/spark/issues/comments/154141796","html_url":"https://github.com/apache/spark/pull/9256#issuecomment-154141796","issue_url":"https://api.github.com/repos/apache/spark/issues/9256","id":154141796,"user":{"login":"rxin","id":323388,"avatar_url":"https://avatars.githubusercontent.com/u/323388?v=3","gravatar_id":"","url":"https://api.github.com/users/rxin","html_url":"https://github.com/rxin","followers_url":"https://api.github.com/users/rxin/followers","following_url":"https://api.github.com/users/rxin/following{/other_user}","gists_url":"https://api.github.com/users/rxin/gists{/gist_id}","starred_url":"https://api.github.com/users/rxin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rxin/subscriptions","organizations_url":"https://api.github.com/users/rxin/orgs","repos_url":"https://api.github.com/users/rxin/repos","events_url":"https://api.github.com/users/rxin/events{/privacy}","received_events_url":"https://api.github.com/users/rxin/received_events","type":"User","site_admin":false},"created_at":"2015-11-05T18:12:54Z","updated_at":"2015-11-05T18:12:54Z","body":"@tdas can you also build an example file so we can look at the example itself?\r\n"}}