chrislusf / gleam

Fast, efficient, and scalable distributed map/reduce system, DAG execution, in memory or on disk, written in pure Go, runs standalone or distributedly.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: Query To AST parser

robinportigliatti opened this issue · comments

Hello,

How would you parse a query to an AST using sql/ast ?

I tried to find a parse method but couldn't.

The code would look something like:

    query := "SELECT * FROM users WHERE age > 30"

    stmt, err := ast.Parse(query)
    if err != nil {
        fmt.Println("Erreur d'analyse :", err)
        return
    }

    fmt.Printf("AST: %#v\n", stmt)

Robin,

I guess that's it ?

package main

import (
    "fmt"
 	"github.com/chrislusf/gleam/sql/parser"
)

func main() {
	sql := "SELECT * FROM users WHERE age > 30"

	p := parser.New()
	tree, err := p.ParseOneStmt(sql, "", "")
	if err != nil {
		fmt.Printf("error")
		return 
	}

    fmt.Printf("AST: %#v\n", tree)

 }