Skip to content

Commit

Permalink
Release v1.8.3
Browse files Browse the repository at this point in the history
- Fix the following bugs.
  - RETURN statement does not return a value in IF and WHILE statements.
  - NOW Function returns different time from the specification in user-defined functions.
  • Loading branch information
mithrandie committed Feb 17, 2019
2 parents 5aee9b5 + 116be92 commit d545f2a
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 26 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,9 @@
## Release v1.8.3 (2019-02-17)

- Fix the following bugs.
- RETURN statement does not return a value in IF and WHILE statements.
- NOW Function returns different time from the specification in user-defined functions.

## Release v1.8.2 (2019-02-13)

- Fix the following bug.
Expand Down
6 changes: 6 additions & 0 deletions docs/changelog.md
Expand Up @@ -5,6 +5,12 @@ title: Change Log - csvq

# Change Log

## Release v1.8.3 (2019-02-17)

- Fix the following bugs.
- RETURN statement does not return a value in IF and WHILE statements.
- NOW Function returns different time from the specification in user-defined functions.

## Release v1.8.2 (2019-02-13)

- Fix the following bug.
Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Expand Up @@ -13,8 +13,8 @@ In the multiple operations, you can use variables, cursors, temporary tables, an

## Latest Release

[v1.8.2](https://github.com/mithrandie/csvq/releases/tag/v1.8.2)
: Released on February 13, 2019
[v1.8.3](https://github.com/mithrandie/csvq/releases/tag/v1.8.3)
: Released on February 17, 2019

[Change Log]({{ '/changelog.html' | relative_url }})

Expand Down
4 changes: 3 additions & 1 deletion lib/query/filter.go
Expand Up @@ -106,12 +106,14 @@ func (f *Filter) Merge(filter *Filter) {
}

func (f *Filter) CreateChildScope() *Filter {
return NewFilter(
child := NewFilter(
append(VariableScopes{NewVariableMap()}, f.Variables...),
append(TemporaryViewScopes{{}}, f.TempViews...),
append(CursorScopes{{}}, f.Cursors...),
append(UserDefinedFunctionScopes{{}}, f.Functions...),
)
child.Now = f.Now
return child
}

func (f *Filter) ResetCurrentScope() {
Expand Down
24 changes: 17 additions & 7 deletions lib/query/procedure.go
Expand Up @@ -78,7 +78,11 @@ func (proc *Procedure) NewChildProcedure() *Procedure {

func (proc *Procedure) ExecuteChild(statements []parser.Statement) (StatementFlow, error) {
child := proc.NewChildProcedure()
return child.Execute(statements)
flow, err := child.Execute(statements)
if child.ReturnVal != nil {
proc.ReturnVal = child.ReturnVal
}
return flow, err
}

func (proc *Procedure) Execute(statements []parser.Statement) (StatementFlow, error) {
Expand Down Expand Up @@ -486,11 +490,14 @@ func (proc *Procedure) While(stmt parser.While) (StatementFlow, error) {
return Error, err
}

if f == Break {
switch f {
case Break:
return Terminate, nil
}
if f == Exit {
case Exit:
return Exit, nil
case Return:
proc.ReturnVal = childProc.ReturnVal
return Return, nil
}
}
return Terminate, nil
Expand Down Expand Up @@ -526,11 +533,14 @@ func (proc *Procedure) WhileInCursor(stmt parser.WhileInCursor) (StatementFlow,
return Error, err
}

if f == Break {
switch f {
case Break:
return Terminate, nil
}
if f == Exit {
case Exit:
return Exit, nil
case Return:
proc.ReturnVal = childProc.ReturnVal
return Return, nil
}
}

Expand Down
98 changes: 83 additions & 15 deletions lib/query/procedure_test.go
Expand Up @@ -885,11 +885,12 @@ func TestProcedure_ExecuteStatement(t *testing.T) {
}

var procedureIfStmtTests = []struct {
Name string
Stmt parser.If
ResultFlow StatementFlow
Result string
Error string
Name string
Stmt parser.If
ResultFlow StatementFlow
ReturnValue value.Primary
Result string
Error string
}{
{
Name: "If Statement",
Expand Down Expand Up @@ -983,6 +984,18 @@ var procedureIfStmtTests = []struct {
},
Error: "[L:- C:-] field notexist does not exist",
},
{
Name: "If Statement Return Value",
Stmt: parser.If{
Condition: parser.NewTernaryValue(ternary.TRUE),
Statements: []parser.Statement{
parser.Return{Value: parser.NewStringValue("1")},
},
},
ResultFlow: Return,
ReturnValue: value.NewString("1"),
Result: "",
},
}

func TestProcedure_IfStmt(t *testing.T) {
Expand All @@ -995,6 +1008,7 @@ func TestProcedure_IfStmt(t *testing.T) {
r, w, _ := os.Pipe()
Stdout = w

proc.ReturnVal = nil
flow, err := proc.IfStmt(v.Stmt)

w.Close()
Expand All @@ -1017,6 +1031,9 @@ func TestProcedure_IfStmt(t *testing.T) {
if flow != v.ResultFlow {
t.Errorf("%s: result flow = %q, want %q", v.Name, flow, v.ResultFlow)
}
if !reflect.DeepEqual(proc.ReturnVal, v.ReturnValue) {
t.Errorf("%s: return = %t, want %t", v.Name, proc.ReturnVal, v.ReturnValue)
}
if string(log) != v.Result {
t.Errorf("%s: result = %q, want %q", v.Name, string(log), v.Result)
}
Expand Down Expand Up @@ -1198,11 +1215,12 @@ func TestProcedure_Case(t *testing.T) {
}

var procedureWhileTests = []struct {
Name string
Stmt parser.While
ResultFlow StatementFlow
Result string
Error string
Name string
Stmt parser.While
ResultFlow StatementFlow
ReturnValue value.Primary
Result string
Error string
}{
{
Name: "While Statement",
Expand Down Expand Up @@ -1400,13 +1418,39 @@ var procedureWhileTests = []struct {
},
Error: "[L:- C:-] field notexist does not exist",
},
{
Name: "While Statement Return Value",
Stmt: parser.While{
Condition: parser.Comparison{
LHS: parser.Variable{Name: "while_test"},
RHS: parser.NewIntegerValueFromString("3"),
Operator: "<",
},
Statements: []parser.Statement{
parser.Return{Value: parser.NewStringValue("1")},
parser.VariableSubstitution{
Variable: parser.Variable{Name: "while_test"},
Value: parser.Arithmetic{
LHS: parser.Variable{Name: "while_test"},
RHS: parser.NewIntegerValueFromString("1"),
Operator: '+',
},
},
parser.Print{Value: parser.Variable{Name: "while_test"}},
parser.TransactionControl{Token: parser.COMMIT},
},
},
ResultFlow: Return,
ReturnValue: value.NewString("1"),
},
}

func TestProcedure_While(t *testing.T) {
cmd.GetFlags().SetQuiet(true)
proc := NewProcedure()

for _, v := range procedureWhileTests {
proc.ReturnVal = nil
if _, err := proc.Filter.Variables[0].Get(parser.Variable{Name: "while_test"}); err != nil {
proc.Filter.Variables[0].Add(parser.Variable{Name: "while_test"}, value.NewInteger(0))
}
Expand Down Expand Up @@ -1444,18 +1488,22 @@ func TestProcedure_While(t *testing.T) {
if flow != v.ResultFlow {
t.Errorf("%s: result flow = %q, want %q", v.Name, flow, v.ResultFlow)
}
if !reflect.DeepEqual(proc.ReturnVal, v.ReturnValue) {
t.Errorf("%s: return = %t, want %t", v.Name, proc.ReturnVal, v.ReturnValue)
}
if string(log) != v.Result {
t.Errorf("%s: result = %q, want %q", v.Name, string(log), v.Result)
}
}
}

var procedureWhileInCursorTests = []struct {
Name string
Stmt parser.WhileInCursor
ResultFlow StatementFlow
Result string
Error string
Name string
Stmt parser.WhileInCursor
ResultFlow StatementFlow
ReturnValue value.Primary
Result string
Error string
}{
{
Name: "While In Cursor",
Expand Down Expand Up @@ -1608,6 +1656,23 @@ var procedureWhileInCursorTests = []struct {
},
Error: "[L:- C:-] field notexist does not exist",
},
{
Name: "While In Cursor Return Value",
Stmt: parser.WhileInCursor{
Variables: []parser.Variable{
{Name: "var1"},
{Name: "var2"},
},
Cursor: parser.Identifier{Literal: "cur"},
Statements: []parser.Statement{
parser.Return{Value: parser.NewStringValue("1")},
parser.Print{Value: parser.Variable{Name: "var1"}},
parser.TransactionControl{Token: parser.COMMIT},
},
},
ResultFlow: Return,
ReturnValue: value.NewString("1"),
},
}

func TestProcedure_WhileInCursor(t *testing.T) {
Expand Down Expand Up @@ -1655,6 +1720,9 @@ func TestProcedure_WhileInCursor(t *testing.T) {
if flow != v.ResultFlow {
t.Errorf("%s: result flow = %q, want %q", v.Name, flow, v.ResultFlow)
}
if !reflect.DeepEqual(proc.ReturnVal, v.ReturnValue) {
t.Errorf("%s: return = %t, want %t", v.Name, proc.ReturnVal, v.ReturnValue)
}
if string(log) != v.Result {
t.Errorf("%s: result = %q, want %q", v.Name, string(log), v.Result)
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/urfave/cli"
)

var version = "v1.8.2"
var version = "v1.8.3"

func main() {
var proc *query.Procedure
Expand Down

0 comments on commit d545f2a

Please sign in to comment.