Skip to content
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
Closed
@erizocosmico

Description

@erizocosmico

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 to Eval(Session, Row) (interface{}, error)
  • Change the signature of Node.RowIter to RowIter(Session) (RowIter, error)
  • Change the signature of AggregationExpression.Update to Update(session Session, buffer, row Row) error
  • Change the signature of AggregationExpression.Merge to Merge(session Session, buffer, partial Row) error
  • Change the signature of Aggregation.Update to Update(Session, Row) (Row, error)
  • Change the signature of Aggregation.Merge to Merge(Session, Row)
  • Change the signature of Aggregation.Eval to Eval(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.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestproposalproposal for new additions or changes

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions