mirror of
https://github.com/chaisql/chai.git
synced 2025-10-17 05:00:46 +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 {
|
||||
|
@@ -56,6 +56,18 @@ type ScalarFunction struct {
|
||||
params []expr.Expr
|
||||
}
|
||||
|
||||
func (sf *ScalarFunction) Clone() expr.Expr {
|
||||
exprs := make([]expr.Expr, 0, len(sf.params))
|
||||
for _, e := range sf.params {
|
||||
exprs = append(exprs, expr.Clone(e))
|
||||
}
|
||||
|
||||
return &ScalarFunction{
|
||||
def: sf.def,
|
||||
params: exprs,
|
||||
}
|
||||
}
|
||||
|
||||
// Eval returns a row.Value based on the given environment and the underlying function
|
||||
// definition.
|
||||
func (sf *ScalarFunction) Eval(env *environment.Environment) (types.Value, error) {
|
||||
|
@@ -15,6 +15,12 @@ type Lower struct {
|
||||
Expr expr.Expr
|
||||
}
|
||||
|
||||
func (s *Lower) Clone() expr.Expr {
|
||||
return &Lower{
|
||||
Expr: expr.Clone(s.Expr),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Lower) Eval(env *environment.Environment) (types.Value, error) {
|
||||
val, err := s.Expr.Eval(env)
|
||||
if err != nil {
|
||||
@@ -55,6 +61,12 @@ type Upper struct {
|
||||
Expr expr.Expr
|
||||
}
|
||||
|
||||
func (s *Upper) Clone() expr.Expr {
|
||||
return &Upper{
|
||||
Expr: expr.Clone(s.Expr),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Upper) Eval(env *environment.Environment) (types.Value, error) {
|
||||
val, err := s.Expr.Eval(env)
|
||||
if err != nil {
|
||||
@@ -101,6 +113,18 @@ type Trim struct {
|
||||
|
||||
type TrimFunc func(string, string) string
|
||||
|
||||
func (s *Trim) Clone() expr.Expr {
|
||||
exprs := make([]expr.Expr, len(s.Expr))
|
||||
for i := range s.Expr {
|
||||
exprs[i] = expr.Clone(s.Expr[i])
|
||||
}
|
||||
return &Trim{
|
||||
Expr: exprs,
|
||||
TrimFunc: s.TrimFunc,
|
||||
Name: s.Name,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Trim) Eval(env *environment.Environment) (types.Value, error) {
|
||||
if len(s.Expr) > 2 {
|
||||
return nil, fmt.Errorf("misuse of string function %v()", s.Name)
|
||||
|
Reference in New Issue
Block a user