Destutter mql

This commit is contained in:
kortschak 2014-06-28 12:58:03 +09:30
parent 3a673a333c
commit 913d567ae1
5 changed files with 18 additions and 18 deletions

View file

@ -66,7 +66,7 @@ func Repl(ts graph.TripleStore, queryLanguage string, cfg *config.Config) {
case "sexp":
ses = sexp.NewSexpSession(ts)
case "mql":
ses = mql.NewMqlSession(ts)
ses = mql.NewSession(ts)
case "gremlin":
fallthrough
default:

View file

@ -73,7 +73,7 @@ func (api *Api) ServeV1Query(w http.ResponseWriter, r *http.Request, params http
case "gremlin":
ses = gremlin.NewSession(api.ts, api.config.GremlinTimeout, false)
case "mql":
ses = mql.NewMqlSession(api.ts)
ses = mql.NewSession(api.ts)
default:
return FormatJson400(w, "Need a query language.")
}
@ -122,7 +122,7 @@ func (api *Api) ServeV1Shape(w http.ResponseWriter, r *http.Request, params http
case "gremlin":
ses = gremlin.NewSession(api.ts, api.config.GremlinTimeout, false)
case "mql":
ses = mql.NewMqlSession(api.ts)
ses = mql.NewSession(api.ts)
default:
return FormatJson400(w, "Need a query language.")
}

View file

@ -35,9 +35,9 @@ import (
// +---+
//
func buildTripleStore() *MqlSession {
func buildTripleStore() *Session {
ts := memstore.MakeTestingMemstore()
return NewMqlSession(ts)
return NewSession(ts)
}
func compareJsonInterfaces(actual interface{}, expected interface{}, path MqlPath, t *testing.T) {

View file

@ -25,7 +25,7 @@ type MqlPath string
type MqlResultPath string
type MqlQuery struct {
ses *MqlSession
ses *Session
it graph.Iterator
isRepeated map[MqlPath]bool
queryStructure map[MqlPath]map[string]interface{}
@ -100,7 +100,7 @@ func (p MqlPath) ToResultPathFromMap(resultMap map[MqlPath]string) MqlResultPath
return output
}
func NewMqlQuery(ses *MqlSession) *MqlQuery {
func NewMqlQuery(ses *Session) *MqlQuery {
var q MqlQuery
q.ses = ses
q.results = make([]interface{}, 0)

View file

@ -24,23 +24,23 @@ import (
"github.com/google/cayley/graph"
)
type MqlSession struct {
type Session struct {
ts graph.TripleStore
currentQuery *MqlQuery
debug bool
}
func NewMqlSession(ts graph.TripleStore) *MqlSession {
var m MqlSession
func NewSession(ts graph.TripleStore) *Session {
var m Session
m.ts = ts
return &m
}
func (m *MqlSession) ToggleDebug() {
func (m *Session) ToggleDebug() {
m.debug = !m.debug
}
func (m *MqlSession) GetQuery(input string, output_struct chan map[string]interface{}) {
func (m *Session) GetQuery(input string, output_struct chan map[string]interface{}) {
defer close(output_struct)
var mqlQuery interface{}
err := json.Unmarshal([]byte(input), &mqlQuery)
@ -61,7 +61,7 @@ func (m *MqlSession) GetQuery(input string, output_struct chan map[string]interf
output_struct <- output
}
func (m *MqlSession) InputParses(input string) (graph.ParseResult, error) {
func (m *Session) InputParses(input string) (graph.ParseResult, error) {
var x interface{}
err := json.Unmarshal([]byte(input), &x)
if err != nil {
@ -70,7 +70,7 @@ func (m *MqlSession) InputParses(input string) (graph.ParseResult, error) {
return graph.Parsed, nil
}
func (m *MqlSession) ExecInput(input string, c chan interface{}, limit int) {
func (m *Session) ExecInput(input string, c chan interface{}, limit int) {
defer close(c)
var mqlQuery interface{}
err := json.Unmarshal([]byte(input), &mqlQuery)
@ -102,7 +102,7 @@ func (m *MqlSession) ExecInput(input string, c chan interface{}, limit int) {
}
}
func (m *MqlSession) ToText(result interface{}) string {
func (m *Session) ToText(result interface{}) string {
tags := *(result.(*map[string]graph.TSVal))
out := fmt.Sprintln("****")
tagKeys := make([]string, len(tags))
@ -125,11 +125,11 @@ func (m *MqlSession) ToText(result interface{}) string {
return out
}
func (m *MqlSession) BuildJson(result interface{}) {
func (m *Session) BuildJson(result interface{}) {
m.currentQuery.treeifyResult(*(result.(*map[string]graph.TSVal)))
}
func (m *MqlSession) GetJson() (interface{}, error) {
func (m *Session) GetJson() (interface{}, error) {
m.currentQuery.buildResults()
if m.currentQuery.isError {
return nil, m.currentQuery.err
@ -138,7 +138,7 @@ func (m *MqlSession) GetJson() (interface{}, error) {
}
}
func (m *MqlSession) ClearJson() {
func (m *Session) ClearJson() {
// Since we create a new MqlQuery underneath every query, clearing isn't necessary.
return
}