{"issue":{"milestone":null,"title":"[FRG-53] support for state-saving across user-defined routine invocations","created_at":"2011-12-30T03:50:27Z","user":{"login":"dynamobi-build","id":1123017,"url":"https://api.github.com/users/dynamobi-build","avatar_url":"https://secure.gravatar.com/avatar/cb215b3d786be20761071a562a56af64?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"cb215b3d786be20761071a562a56af64"},"labels":[{"name":"FRG","url":"https://api.github.com/repos/dynamobi/dynamobi/labels/FRG","color":"1f8f0d"},{"name":"Runtime","url":"https://api.github.com/repos/dynamobi/dynamobi/labels/Runtime","color":"886eef"}],"updated_at":"2011-12-30T03:50:36Z","state":"closed","id":2686378,"pull_request":{"patch_url":null,"html_url":null,"diff_url":null},"closed_at":"2011-12-30T03:50:27Z","html_url":"https://github.com/dynamobi/dynamobi/issues/817","body":"<b><i>[reporter=\"jvs\", created=\"Tue, 21 Feb 2006 15:12:09 -0500 (GMT-05:00)\"]</i></b>\nIt is often useful to be able to maintain state across invocations of a UDR.  The most common case is when precompilation is used as an optimization.  For example, a UDF may take a regular expression as a literal parameter, compile an instance of java.util.regex.Matcher, and use it to process another parameter for each invocation.  Another use is for writing non-deterministic UDR's (e.g. a random-number generator UDF which needs to use the same underlying java.util.Random object across invocations).<br/>\n<br/>\nThe SQL standard external routine mechanism only allows binding to a static method, without any notion of context across invocations.  Static data members are not a good solution because (a) they can be accessed from multiple threads, so they require synchronization, and (b) they can result in memory bloat since a UDR class which maintains a map or pool has no information about when an object is no longer needed (other than garbage collector memory pressure if something like a SoftHashMap is used).<br/>\n<br/>\nThe proposed feature is to enhance Farrago's runtime system to address this requirement, because Farrago has the best notion of what's going on during execution.  To the UDR, it would look something like thread-local storage:  the ability to set an Object value, load the current value, and receive a notification to deallocate any associated resources (when query execution completes).  The actual interface remains to be defined; it will be a  class with static methods.  FarragoRuntimeContext would take care of context-switching by setting a real thread-local before each UDR invocation, so that each usage of a UDR within a particular running instance of a SQL statement would see its own private state.  For example, in the following query,<br/>\n<br/>\nselect rand() as x, rand() as y<br/>\nfrom t;<br/>\n<br/>\nthe two rand usages would have independent state (as would any executions of the same cached query from other sessions).<br/>\n<br/>\nNote that reliance on this feature would make a UDR implementation dependent on Farrago (i.e. not portable to other SQL implementations).<br/>\n","number":817,"url":"https://api.github.com/repos/dynamobi/dynamobi/issues/817","comments":5,"assignee":null},"comment":{"created_at":"2011-12-30T03:50:36Z","user":{"login":"dynamobi-build","id":1123017,"url":"https://api.github.com/users/dynamobi-build","avatar_url":"https://secure.gravatar.com/avatar/cb215b3d786be20761071a562a56af64?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"cb215b3d786be20761071a562a56af64"},"updated_at":"2011-12-30T03:50:36Z","id":3310489,"body":"<b><i>[author=\"jvs\", created=\"Tue, 7 Mar 2006 21:20:53 -0500 (GMT-05:00)\"]</i></b>\nA feature to satisfy Sunny's request is available in eigenchange 5725.","url":"https://api.github.com/repos/dynamobi/dynamobi/issues/comments/3310489"},"action":"created"}