Skip to content

Commit

Permalink
Release v0.2.9
Browse files Browse the repository at this point in the history
Add temporary table.
  • Loading branch information
mithrandie committed Jul 10, 2017
2 parents 9ed22e3 + 2fb4d03 commit e36aa2c
Show file tree
Hide file tree
Showing 25 changed files with 6,531 additions and 6,124 deletions.
1 change: 1 addition & 0 deletions docs/_includes/side_menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<li><a href="{{ '/reference/variable.html' | relative_url }}">Variable</a></li>
<li><a href="{{ '/reference/row-value.html' | relative_url }}">Row Value</a></li>
<li><a href="{{ '/reference/cursor.html' | relative_url }}">Cursor</a></li>
<li><a href="{{ '/reference/temporary-table.html' | relative_url }}">Temporary Table</a></li>
<li><a href="{{ '/reference/control-flow.html' | relative_url }}">Control Flow</a></li>
<li><a href="{{ '/reference/transaction.html' | relative_url }}">Transaction Management</a></li>
<li><a href="{{ '/reference/built-in.html' | relative_url }}">Built-in Commands</a></li>
Expand Down
26 changes: 26 additions & 0 deletions docs/_posts/2006-01-02-temporary-table.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
layout: default
title: Temporary Table - Reference Manual - csvq
category: reference
---

# Temporary Table

A Temporary Table is a temporary view that can be used in a procedure.
You can refer, insert, update, or delete temporary tables.

## Declare Temporary Table
{: #declare}

```sql
DECLARE table_name TABLE [(column_name [, column_name ...])] FOR select_query;
```

_table_name_
: [identifier]({{ '/reference/statement.html#parsing' | relative_url }})

_column_name_
: [identifier]({{ '/reference/statement.html#parsing' | relative_url }})

_select_query_
: [Select Query]({{ '/reference/select-query.html' | relative_url }})
1 change: 1 addition & 0 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ title: Reference Manual - csvq
* [Variable]({{ '/reference/variable.html' | relative_url }})
* [Row Value]({{ '/reference/row-value.html' | relative_url }})
* [Cursor]({{ '/reference/cursor.html' | relative_url }})
* [Temporary Table]({{ '/reference/temporary-table.html' | relative_url }})
* [Control Flow]({{ '/reference/control-flow.html' | relative_url }})
* [Transaction Management]({{ '/reference/transaction.html' | relative_url }})
* [Built-in Commands]({{ '/reference/built-in.html' | relative_url }})
Expand Down
6 changes: 5 additions & 1 deletion docs/sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</url>
<url>
<loc>https://mithrandie.github.io/csvq/reference.html</loc>
<lastmod>2017-07-05T21:28:49+00:00</lastmod>
<lastmod>2017-07-10T05:11:55+00:00</lastmod>
</url>
<url>
<loc>https://mithrandie.github.io/csvq/reference/install.html</loc>
Expand Down Expand Up @@ -68,6 +68,10 @@
<loc>https://mithrandie.github.io/csvq/reference/cursor.html</loc>
<lastmod>2017-06-29T17:08:49+00:00</lastmod>
</url>
<url>
<loc>https://mithrandie.github.io/csvq/reference/temporary-table.html</loc>
<lastmod>2017-07-10T05:11:55+00:00</lastmod>
</url>
<url>
<loc>https://mithrandie.github.io/csvq/reference/control-flow.html</loc>
<lastmod>2017-07-06T20:38:36+00:00</lastmod>
Expand Down
4 changes: 2 additions & 2 deletions lib/action/calc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"strconv"
"strings"

"errors"
"github.com/mithrandie/csvq/lib/cmd"
"github.com/mithrandie/csvq/lib/parser"
"github.com/mithrandie/csvq/lib/query"
Expand All @@ -14,10 +15,9 @@ func Calc(expr string) error {

q := "select " + expr + " from stdin"

parser.SetDebugLevel(0, true)
program, err := parser.Parse(q)
if err != nil {
return err
return errors.New("syntax error")
}
selectEntity, _ := program[0].(parser.SelectQuery).SelectEntity.(parser.SelectEntity)

Expand Down
2 changes: 1 addition & 1 deletion lib/action/calc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var calcTests = []struct {
{
Stdin: "foo",
Input: "from",
Error: "syntax error: unexpected FROM",
Error: "syntax error",
},
{
Stdin: "",
Expand Down
2 changes: 1 addition & 1 deletion lib/action/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var executeTests = []struct {
{
Name: "Query Execution Error",
Input: "select from",
Error: "syntax error: unexpected FROM",
Error: "syntax error: unexpected from [L:1 C:8]",
},
}

Expand Down
30 changes: 18 additions & 12 deletions lib/parser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,12 +567,12 @@ func (sq Subquery) String() string {

type Comparison struct {
LHS Expression
Operator Token
Operator string
RHS Expression
}

func (c Comparison) String() string {
s := []string{c.LHS.String(), c.Operator.Literal, c.RHS.String()}
s := []string{c.LHS.String(), c.Operator, c.RHS.String()}
return joinWithSpace(s)
}

Expand Down Expand Up @@ -641,24 +641,24 @@ func (i In) String() string {
type All struct {
All string
LHS Expression
Operator Token
Operator string
Values Expression
}

func (a All) String() string {
s := []string{a.LHS.String(), a.Operator.Literal, a.All, a.Values.String()}
s := []string{a.LHS.String(), a.Operator, a.All, a.Values.String()}
return joinWithSpace(s)
}

type Any struct {
Any string
LHS Expression
Operator Token
Operator string
Values Expression
}

func (a Any) String() string {
s := []string{a.LHS.String(), a.Operator.Literal, a.Any, a.Values.String()}
s := []string{a.LHS.String(), a.Operator, a.Any, a.Values.String()}
return joinWithSpace(s)
}

Expand Down Expand Up @@ -761,14 +761,14 @@ func (f Function) String() string {

type Table struct {
Object Expression
As Token
As string
Alias Expression
}

func (t Table) String() string {
s := []string{t.Object.String()}
if !t.As.IsEmpty() {
s = append(s, t.As.Literal)
if 0 < len(t.As) {
s = append(s, t.As)
}
if t.Alias != nil {
s = append(s, t.Alias.String())
Expand Down Expand Up @@ -834,14 +834,14 @@ func (jc JoinCondition) String() string {

type Field struct {
Object Expression
As Token
As string
Alias Expression
}

func (f Field) String() string {
s := []string{f.Object.String()}
if !f.As.IsEmpty() {
s = append(s, f.As.Literal)
if 0 < len(f.As) {
s = append(s, f.As)
}
if f.Alias != nil {
s = append(s, f.Alias.String())
Expand Down Expand Up @@ -1348,6 +1348,12 @@ func (e CursorStatus) String() string {
return joinWithSpace(s)
}

type TableDeclaration struct {
Table Identifier
Fields []Expression
Query Expression
}

type TransactionControl struct {
Token int
}
Expand Down
34 changes: 17 additions & 17 deletions lib/parser/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ func TestSelectEntity_String(t *testing.T) {
Where: "where",
Filter: Comparison{
LHS: Identifier{Literal: "column"},
Operator: Token{Token: COMPARISON_OP, Literal: ">"},
Operator: ">",
RHS: Integer{literal: "1"},
},
},
Expand All @@ -511,7 +511,7 @@ func TestSelectEntity_String(t *testing.T) {
Having: "having",
Filter: Comparison{
LHS: Identifier{Literal: "column"},
Operator: Token{Token: COMPARISON_OP, Literal: ">"},
Operator: ">",
RHS: Integer{literal: "1"},
},
},
Expand Down Expand Up @@ -545,7 +545,7 @@ func TestSelectClause_String(t *testing.T) {
},
Field{
Object: Identifier{Literal: "column2"},
As: Token{Token: AS, Literal: "as"},
As: "as",
Alias: Identifier{Literal: "alias"},
},
},
Expand Down Expand Up @@ -575,7 +575,7 @@ func TestWhereClause_String(t *testing.T) {
Where: "where",
Filter: Comparison{
LHS: Identifier{Literal: "column"},
Operator: Token{Token: COMPARISON_OP, Literal: ">"},
Operator: ">",
RHS: Integer{literal: "1"},
},
}
Expand Down Expand Up @@ -604,7 +604,7 @@ func TestHavingClause_String(t *testing.T) {
Having: "having",
Filter: Comparison{
LHS: Identifier{Literal: "column"},
Operator: Token{Token: COMPARISON_OP, Literal: ">"},
Operator: ">",
RHS: Integer{literal: "1"},
},
}
Expand Down Expand Up @@ -820,7 +820,7 @@ func TestSubquery_String(t *testing.T) {
func TestComparison_String(t *testing.T) {
e := Comparison{
LHS: Identifier{Literal: "column"},
Operator: Token{Token: COMPARISON_OP, Literal: ">"},
Operator: ">",
RHS: Integer{literal: "1"},
}
expect := "column > 1"
Expand Down Expand Up @@ -924,7 +924,7 @@ func TestAll_String(t *testing.T) {
},
},
},
Operator: Token{Token: COMPARISON_OP, Literal: ">"},
Operator: ">",
Values: Subquery{
Query: SelectQuery{
SelectEntity: SelectEntity{
Expand Down Expand Up @@ -961,7 +961,7 @@ func TestAny_String(t *testing.T) {
},
},
},
Operator: Token{Token: COMPARISON_OP, Literal: ">"},
Operator: ">",
Values: Subquery{
Query: SelectQuery{
SelectEntity: SelectEntity{
Expand Down Expand Up @@ -1136,7 +1136,7 @@ func TestFunction_String(t *testing.T) {
func TestTable_String(t *testing.T) {
e := Table{
Object: Identifier{Literal: "table"},
As: Token{Token: AS, Literal: "as"},
As: "as",
Alias: Identifier{Literal: "alias"},
}
expect := "table as alias"
Expand All @@ -1156,7 +1156,7 @@ func TestTable_String(t *testing.T) {
func TestTable_Name(t *testing.T) {
e := Table{
Object: Identifier{Literal: "table.csv"},
As: Token{Token: AS, Literal: "as"},
As: "as",
Alias: Identifier{Literal: "alias"},
}
expect := "alias"
Expand Down Expand Up @@ -1234,7 +1234,7 @@ func TestJoinCondition_String(t *testing.T) {
Literal: "on",
On: Comparison{
LHS: Identifier{Literal: "column"},
Operator: Token{Token: COMPARISON_OP, Literal: ">"},
Operator: ">",
RHS: Integer{literal: "1"},
},
}
Expand All @@ -1259,7 +1259,7 @@ func TestJoinCondition_String(t *testing.T) {
func TestField_String(t *testing.T) {
e := Field{
Object: Identifier{Literal: "column"},
As: Token{Token: AS, Literal: "as"},
As: "as",
Alias: Identifier{Literal: "alias"},
}
expect := "column as alias"
Expand All @@ -1279,7 +1279,7 @@ func TestField_String(t *testing.T) {
func TestField_Name(t *testing.T) {
e := Field{
Object: Identifier{Literal: "column"},
As: Token{Token: AS, Literal: "as"},
As: "as",
Alias: Identifier{Literal: "alias"},
}
expect := "alias"
Expand Down Expand Up @@ -1399,7 +1399,7 @@ func TestCase_String(t *testing.T) {
Then: "then",
Condition: Comparison{
LHS: Identifier{Literal: "column"},
Operator: Token{Token: COMPARISON_OP, Literal: ">"},
Operator: ">",
RHS: Integer{literal: "1"},
},
Result: String{literal: "A"},
Expand All @@ -1418,7 +1418,7 @@ func TestCaseWhen_String(t *testing.T) {
Then: "then",
Condition: Comparison{
LHS: Identifier{Literal: "column"},
Operator: Token{Token: COMPARISON_OP, Literal: ">"},
Operator: ">",
RHS: Integer{literal: "1"},
},
Result: String{literal: "abcde"},
Expand Down Expand Up @@ -1741,7 +1741,7 @@ func TestUpdateQuery_String(t *testing.T) {
Where: "where",
Filter: Comparison{
LHS: Identifier{Literal: "column3"},
Operator: Token{Token: COMPARISON_OP, Literal: "="},
Operator: "=",
RHS: NewInteger(3),
},
},
Expand Down Expand Up @@ -1802,7 +1802,7 @@ func TestDeleteQuery_String(t *testing.T) {
Where: "where",
Filter: Comparison{
LHS: Identifier{Literal: "column1"},
Operator: Token{Token: COMPARISON_OP, Literal: "="},
Operator: "=",
RHS: NewInteger(1),
},
},
Expand Down
17 changes: 13 additions & 4 deletions lib/parser/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,41 @@ package parser

import (
"errors"
"fmt"
)

type Lexer struct {
Scanner
program []Statement
token Token
err error
}

func (l *Lexer) Lex(lval *yySymType) int {
token, literal, quoted, err := l.Scan()
tok, err := l.Scan()
if err != nil {
l.Error(err.Error())
}

lval.token = Token{Token: token, Literal: literal, Quoted: quoted}
return token
lval.token = tok
l.token = lval.token
return tok.Token
}

func (l *Lexer) Error(e string) {
l.err = errors.New(e)
if 0 < l.token.Token {
l.err = errors.New(fmt.Sprintf("%s: unexpected %s [L:%d C:%d]", e, l.token.Literal, l.token.Line, l.token.Char))
} else {
l.err = errors.New(fmt.Sprintf("%s [L:%d C:%d]", e, l.token.Line, l.token.Char))
}
}

type Token struct {
Token int
Literal string
Quoted bool
Line int
Char int
}

func (t *Token) IsEmpty() bool {
Expand Down
Loading

0 comments on commit e36aa2c

Please sign in to comment.