-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
107 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package parser | ||
|
||
import "github.com/pg-sharding/lyx/lyx" | ||
|
||
type Parser interface { | ||
Parse(query string) (ParseState, string, error) | ||
|
||
Stmt() lyx.Node | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package parser | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/pg-sharding/lyx/lyx" | ||
) | ||
|
||
type CacheEntry struct { | ||
ps ParseState | ||
comm string | ||
} | ||
|
||
// Parser shared accross all relays. | ||
// caches parse result. | ||
type SharedParser struct { | ||
parseCache sync.Map | ||
|
||
mu sync.Mutex | ||
underlying Parser | ||
} | ||
|
||
// Stmt implements Parser. | ||
func (shp *SharedParser) Stmt() lyx.Node { | ||
return shp.underlying.Stmt() | ||
} | ||
|
||
var _ Parser = &SharedParser{} | ||
|
||
func (shp *SharedParser) Parse(query string) (ParseState, string, error) { | ||
ce, ok := shp.parseCache.Load(query) | ||
if ok { | ||
return ce.(CacheEntry).ps, ce.(CacheEntry).comm, nil | ||
} | ||
|
||
p := NewQParser() | ||
state, comm, err := p.Parse(query) | ||
|
||
if err == nil { | ||
shp.parseCache.Store(query, CacheEntry{ | ||
ps: state, | ||
comm: comm, | ||
}) | ||
} | ||
|
||
return state, comm, err | ||
} | ||
|
||
func NewSharedParser() Parser { | ||
return &SharedParser{ | ||
parseCache: sync.Map{}, | ||
underlying: NewQParser(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters