本文整理汇总了Golang中parser.NewQuerySpec函数的典型用法代码示例。如果您正苦于以下问题:Golang NewQuerySpec函数的具体用法?Golang NewQuerySpec怎么用?Golang NewQuerySpec使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewQuerySpec函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestShouldQuerySequentially
func (self *CoordinatorSuite) TestShouldQuerySequentially(c *C) {
end := time.Now().Truncate(24 * time.Hour)
start := end.Add(-7 * 24 * time.Hour)
shard := cluster.NewShard(1, start, end, cluster.SHORT_TERM, false, nil)
shards := []*cluster.ShardData{shard}
coordinator := NewCoordinatorImpl(&configuration.Configuration{
ClusterMaxResponseBufferSize: 1000,
}, nil, nil)
queries := map[string]bool{
"list series": false,
"select count(foo) from /.*bar.*/ group by time(1d)": true,
"select count(foo) from bar": true,
"select foo from bar": true,
"select count(foo) from bar group by baz": true,
"select count(foo) from bar group by time(1d)": false,
"select count(foo) from bar group by time(3d)": true,
}
for query, result := range queries {
fmt.Printf("Testing %s\n", query)
parsedQuery, err := parser.ParseQuery(query)
c.Assert(err, IsNil)
c.Assert(parsedQuery, HasLen, 1)
querySpec := parser.NewQuerySpec(nil, "", parsedQuery[0])
c.Assert(coordinator.shouldQuerySequentially(shards, querySpec), Equals, result)
}
}
示例2: handleQuery
func (self *ProtobufRequestHandler) handleQuery(request *protocol.Request, conn net.Conn) {
// the query should always parse correctly since it was parsed at the originating server.
queries, err := parser.ParseQuery(*request.Query)
if err != nil || len(queries) < 1 {
log.Error("Error parsing query: ", err)
errorMsg := fmt.Sprintf("Cannot find user %s", *request.UserName)
response := &protocol.Response{Type: &endStreamResponse, ErrorMessage: &errorMsg, RequestId: request.Id}
self.WriteResponse(conn, response)
return
}
query := queries[0]
var user common.User
if *request.IsDbUser {
user = self.clusterConfig.GetDbUser(*request.Database, *request.UserName)
} else {
user = self.clusterConfig.GetClusterAdmin(*request.UserName)
}
if user == nil {
errorMsg := fmt.Sprintf("Cannot find user %s", *request.UserName)
response := &protocol.Response{Type: &accessDeniedResponse, ErrorMessage: &errorMsg, RequestId: request.Id}
self.WriteResponse(conn, response)
return
}
shard := self.clusterConfig.GetLocalShardById(*request.ShardId)
querySpec := parser.NewQuerySpec(user, *request.Database, query)
responseChan := make(chan *protocol.Response)
if querySpec.IsDestructiveQuery() {
go shard.HandleDestructiveQuery(querySpec, request, responseChan, true)
} else {
go shard.Query(querySpec, responseChan)
}
for {
response := <-responseChan
response.RequestId = request.Id
self.WriteResponse(conn, response)
if response.GetType() == protocol.Response_END_STREAM || response.GetType() == protocol.Response_ACCESS_DENIED {
return
}
}
}
示例3: RunQuery
func (self *CoordinatorImpl) RunQuery(user common.User, database string, queryString string, seriesWriter SeriesWriter) (err error) {
log.Info("Query: db: %s, u: %s, q: %s", database, user.GetName(), queryString)
// don't let a panic pass beyond RunQuery
defer common.RecoverFunc(database, queryString, nil)
q, err := parser.ParseQuery(queryString)
if err != nil {
return err
}
for _, query := range q {
querySpec := parser.NewQuerySpec(user, database, query)
if query.DeleteQuery != nil {
if err := self.clusterConfiguration.CreateCheckpoint(); err != nil {
return err
}
if err := self.runDeleteQuery(querySpec, seriesWriter); err != nil {
return err
}
continue
}
if query.DropQuery != nil {
if err := self.DeleteContinuousQuery(user, database, uint32(query.DropQuery.Id)); err != nil {
return err
}
continue
}
if query.IsListQuery() {
if query.IsListSeriesQuery() {
self.runListSeriesQuery(querySpec, seriesWriter)
} else if query.IsListContinuousQueriesQuery() {
queries, err := self.ListContinuousQueries(user, database)
if err != nil {
return err
}
for _, q := range queries {
if err := seriesWriter.Write(q); err != nil {
return err
}
}
}
continue
}
if query.DropSeriesQuery != nil {
err := self.runDropSeriesQuery(querySpec, seriesWriter)
if err != nil {
return err
}
continue
}
selectQuery := query.SelectQuery
if selectQuery.IsContinuousQuery() {
return self.CreateContinuousQuery(user, database, queryString)
}
if err := self.checkPermission(user, querySpec); err != nil {
return err
}
return self.runQuery(querySpec, seriesWriter)
}
seriesWriter.Close()
return nil
}
示例4: RunQuery
func (self *CoordinatorImpl) RunQuery(user common.User, database string, queryString string, seriesWriter SeriesWriter) (err error) {
log.Debug("COORD: RunQuery: ", queryString)
// don't let a panic pass beyond RunQuery
defer recoverFunc(database, queryString)
q, err := parser.ParseQuery(queryString)
if err != nil {
return err
}
for _, query := range q {
querySpec := parser.NewQuerySpec(user, database, query)
if query.DeleteQuery != nil {
if err := self.runDeleteQuery(querySpec, seriesWriter); err != nil {
return err
}
continue
}
if query.DropQuery != nil {
if err := self.DeleteContinuousQuery(user, database, uint32(query.DropQuery.Id)); err != nil {
return err
}
continue
}
if query.IsListQuery() {
if query.IsListSeriesQuery() {
self.runListSeriesQuery(querySpec, seriesWriter)
} else if query.IsListContinuousQueriesQuery() {
queries, err := self.ListContinuousQueries(user, database)
if err != nil {
return err
}
for _, q := range queries {
if err := seriesWriter.Write(q); err != nil {
return err
}
}
}
continue
}
if query.DropSeriesQuery != nil {
err := self.runDropSeriesQuery(querySpec, seriesWriter)
if err != nil {
return err
}
continue
}
selectQuery := query.SelectQuery
if selectQuery.IsContinuousQuery() {
return self.CreateContinuousQuery(user, database, queryString)
}
return self.runQuery(query, user, database, seriesWriter)
}
seriesWriter.Close()
return nil
}
示例5: runQuery
// This should only get run for SelectQuery types
func (self *CoordinatorImpl) runQuery(query *parser.Query, user common.User, database string, seriesWriter SeriesWriter) error {
querySpec := parser.NewQuerySpec(user, database, query)
return self.runQuerySpec(querySpec, seriesWriter)
}