mirror of
https://github.com/chaisql/chai.git
synced 2025-10-05 23:57:01 +08:00
stream: clone stream before execution
This commit is contained in:
@@ -127,6 +127,12 @@ type TypeOf struct {
|
||||
Expr expr.Expr
|
||||
}
|
||||
|
||||
func (t *TypeOf) Clone() expr.Expr {
|
||||
return &TypeOf{
|
||||
Expr: expr.Clone(t.Expr),
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TypeOf) Eval(env *environment.Environment) (types.Value, error) {
|
||||
v, err := t.Expr.Eval(env)
|
||||
if err != nil {
|
||||
@@ -175,6 +181,14 @@ func NewCount(e expr.Expr) *Count {
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Count) Clone() expr.Expr {
|
||||
return &Count{
|
||||
Expr: expr.Clone(t.Expr),
|
||||
wildcard: t.wildcard,
|
||||
Count: t.Count,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Count) Eval(env *environment.Environment) (types.Value, error) {
|
||||
d, ok := env.GetRow()
|
||||
if !ok {
|
||||
@@ -250,6 +264,12 @@ type Min struct {
|
||||
Expr expr.Expr
|
||||
}
|
||||
|
||||
func (t *Min) Clone() expr.Expr {
|
||||
return &Min{
|
||||
Expr: expr.Clone(t.Expr),
|
||||
}
|
||||
}
|
||||
|
||||
// Eval extracts the min value from the given object and returns it.
|
||||
func (m *Min) Eval(env *environment.Environment) (types.Value, error) {
|
||||
r, ok := env.GetRow()
|
||||
@@ -354,6 +374,12 @@ type Max struct {
|
||||
Expr expr.Expr
|
||||
}
|
||||
|
||||
func (t *Max) Clone() expr.Expr {
|
||||
return &Max{
|
||||
Expr: expr.Clone(t.Expr),
|
||||
}
|
||||
}
|
||||
|
||||
// Eval extracts the max value from the given object and returns it.
|
||||
func (m *Max) Eval(env *environment.Environment) (types.Value, error) {
|
||||
r, ok := env.GetRow()
|
||||
@@ -453,6 +479,12 @@ type Sum struct {
|
||||
Expr expr.Expr
|
||||
}
|
||||
|
||||
func (t *Sum) Clone() expr.Expr {
|
||||
return &Sum{
|
||||
Expr: expr.Clone(t.Expr),
|
||||
}
|
||||
}
|
||||
|
||||
// Eval extracts the sum value from the given object and returns it.
|
||||
func (s *Sum) Eval(env *environment.Environment) (types.Value, error) {
|
||||
r, ok := env.GetRow()
|
||||
@@ -564,6 +596,12 @@ type Avg struct {
|
||||
Expr expr.Expr
|
||||
}
|
||||
|
||||
func (t *Avg) Clone() expr.Expr {
|
||||
return &Avg{
|
||||
Expr: expr.Clone(t.Expr),
|
||||
}
|
||||
}
|
||||
|
||||
// Eval extracts the average value from the given object and returns it.
|
||||
func (s *Avg) Eval(env *environment.Environment) (types.Value, error) {
|
||||
r, ok := env.GetRow()
|
||||
@@ -651,6 +689,12 @@ type Len struct {
|
||||
Expr expr.Expr
|
||||
}
|
||||
|
||||
func (t *Len) Clone() expr.Expr {
|
||||
return &Len{
|
||||
Expr: expr.Clone(t.Expr),
|
||||
}
|
||||
}
|
||||
|
||||
// Eval extracts the average value from the given object and returns it.
|
||||
func (s *Len) Eval(env *environment.Environment) (types.Value, error) {
|
||||
val, err := s.Expr.Eval(env)
|
||||
@@ -694,6 +738,16 @@ type Coalesce struct {
|
||||
Exprs []expr.Expr
|
||||
}
|
||||
|
||||
func (c *Coalesce) Clone() expr.Expr {
|
||||
var clone Coalesce
|
||||
clone.Exprs = make([]expr.Expr, 0, len(c.Exprs))
|
||||
for _, e := range c.Exprs {
|
||||
clone.Exprs = append(clone.Exprs, expr.Clone(e))
|
||||
}
|
||||
|
||||
return &clone
|
||||
}
|
||||
|
||||
func (c *Coalesce) Eval(e *environment.Environment) (types.Value, error) {
|
||||
for _, exp := range c.Exprs {
|
||||
v, err := exp.Eval(e)
|
||||
@@ -717,6 +771,10 @@ func (c *Coalesce) Params() []expr.Expr {
|
||||
|
||||
type Now struct{}
|
||||
|
||||
func (n *Now) Clone() expr.Expr {
|
||||
return &Now{}
|
||||
}
|
||||
|
||||
func (n *Now) Eval(env *environment.Environment) (types.Value, error) {
|
||||
tx := env.GetTx()
|
||||
if tx == nil {
|
||||
|
Reference in New Issue
Block a user