This repository was archived by the owner on Jan 28, 2021. It is now read-only.
This repository was archived by the owner on Jan 28, 2021. It is now read-only.
Pass session around #36
Closed
Description
We should have a Session
to pass around to all nodes that need to be evaluated. With this session, we can pass dependencies around (such as the repository pool for gitquery) and any other dependencies that are needed elsewhere in the code along with user data, if any.
Possible use cases for this:
- request-scoped metrics
- dependency injection
- passing of session data
Any thoughts? /cc @ajnavarro @mcarmonaa @jfontan
Proposal:
A way of implementing this in a way that's not very disruptive to the current API would be the following:
- Implement a
Session
type. It could either be a concrete type or an interface with a base implementation that can be extended to provide extra features (this option could be really powerful for gitquery).
type SessionData struct { /* yada yada */ }
type Session interface {
Data() SessionData
// yada yada
}
type BaseSession struct {
data SessionData
}
func (s BaseSession) Data() SessionData {
return s.data
}
// another file or even another package
type CustomSession struct {
BaseSession
mything MyType
}
// inside an UDF, for example
customSess, ok := session.(*CustomSession)
if ok {
customSess.mything.foo()
}
- Change the signature of
Expression.Eval
toEval(Session, Row) (interface{}, error)
- Change the signature of
Node.RowIter
toRowIter(Session) (RowIter, error)
- Change the signature of
AggregationExpression.Update
toUpdate(session Session, buffer, row Row) error
- Change the signature of
AggregationExpression.Merge
toMerge(session Session, buffer, partial Row) error
- Change the signature of
Aggregation.Update
toUpdate(Session, Row) (Row, error)
- Change the signature of
Aggregation.Merge
toMerge(Session, Row)
- Change the signature of
Aggregation.Eval
toEval(Session) (interface{}, error)
(and make it return an error, while we are at it
That's about all the places that would need the session passed around. Then it's the job of whoever calls these methods to provide them the session and so on.