当前位置: 首页>>代码示例>>Golang>>正文


Golang parser.ParseSelectQuery函数代码示例

本文整理汇总了Golang中parser.ParseSelectQuery函数的典型用法代码示例。如果您正苦于以下问题:Golang ParseSelectQuery函数的具体用法?Golang ParseSelectQuery怎么用?Golang ParseSelectQuery使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ParseSelectQuery函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: CreateContinuousQuery

func (self *ClusterConfiguration) CreateContinuousQuery(db string, query string) error {
	self.continuousQueriesLock.Lock()
	defer self.continuousQueriesLock.Unlock()

	if self.continuousQueries == nil {
		self.continuousQueries = map[string][]*ContinuousQuery{}
	}

	if self.parsedContinuousQueries == nil {
		self.parsedContinuousQueries = map[string]map[uint32]*parser.SelectQuery{}
	}

	maxId := uint32(0)
	for _, query := range self.continuousQueries[db] {
		if query.Id > maxId {
			maxId = query.Id
		}
	}

	selectQuery, err := parser.ParseSelectQuery(query)
	if err != nil {
		return fmt.Errorf("Failed to parse continuous query: %s", query)
	}

	queryId := maxId + 1
	if self.parsedContinuousQueries[db] == nil {
		self.parsedContinuousQueries[db] = map[uint32]*parser.SelectQuery{queryId: selectQuery}
	} else {
		self.parsedContinuousQueries[db][queryId] = selectQuery
	}
	self.continuousQueries[db] = append(self.continuousQueries[db], &ContinuousQuery{queryId, query})

	return nil
}
开发者ID:nkts,项目名称:golang-devops-stuff,代码行数:34,代码来源:cluster_configuration.go

示例2: TestEqualityFiltering

func (self *FilteringSuite) TestEqualityFiltering(c *C) {
	queryStr := "select * from t where column_one = 100 and column_two <> 6;"
	query, err := parser.ParseSelectQuery(queryStr)
	c.Assert(err, IsNil)

	series, err := common.StringToSeriesArray(`
[
 {
   "points": [
     {"values": [{"int64_value": 100},{"int64_value": 5 }], "timestamp": 1381346631, "sequence_number": 1},
     {"values": [{"int64_value": 100},{"int64_value": 6 }], "timestamp": 1381346631, "sequence_number": 1},
     {"values": [{"int64_value": 90 },{"int64_value": 15}], "timestamp": 1381346632, "sequence_number": 1}
   ],
   "name": "t",
   "fields": ["column_one", "column_two"]
 }
]
`)
	c.Assert(err, IsNil)
	result, err := Filter(query, series[0])
	c.Assert(err, IsNil)
	c.Assert(result, NotNil)
	c.Assert(result.Points, HasLen, 1)
	c.Assert(*result.Points[0].Values[0].Int64Value, Equals, int64(100))
	c.Assert(*result.Points[0].Values[1].Int64Value, Equals, int64(5))
}
开发者ID:johntdyer,项目名称:golang-devops-stuff,代码行数:26,代码来源:filtering_test.go

示例3: TestPropagateErrorsProperly

func (self *DatastoreSuite) TestPropagateErrorsProperly(c *C) {
	cleanup(nil)
	db := newDatastore(c)
	defer cleanup(db)
	mock := `
  {
    "points": [
      {
        "values": [
          {
            "int64_value": 3
          }
        ],
        "sequence_number": 1
      }
    ],
    "name": "foo",
    "fields": ["value"]
  }`
	pointTime := time.Now().Unix()
	series := stringToSeries(mock, pointTime, c)
	err := db.WriteSeriesData("test", series)
	c.Assert(err, IsNil)
	q, err := parser.ParseSelectQuery("select value from foo;")
	c.Assert(err, IsNil)
	yield := func(series *protocol.Series) error {
		return fmt.Errorf("Whatever")
	}
	user := &MockUser{}
	err = db.ExecuteQuery(user, "test", q, yield, nil)
	c.Assert(err, ErrorMatches, "Whatever")
}
开发者ID:johann8384,项目名称:influxdb,代码行数:32,代码来源:datastore_test.go

示例4: TestFilteringWithGroupBy

func (self *FilteringSuite) TestFilteringWithGroupBy(c *C) {
	queryStr := "select sum(column_one) from t group by column_two where column_one = 85;"
	query, err := parser.ParseSelectQuery(queryStr)
	c.Assert(err, IsNil)

	series, err := common.StringToSeriesArray(`
[
 {
   "points": [
     {"values": [{"int64_value": 100},{"int64_value": 5 }], "timestamp": 1381346631, "sequence_number": 1},
     {"values": [{"int64_value": 85},{"int64_value": 6 }], "timestamp": 1381346631, "sequence_number": 1},
     {"values": [{"int64_value": 90 },{"int64_value": 15}], "timestamp": 1381346632, "sequence_number": 1}
   ],
   "name": "t",
   "fields": ["column_one", "column_two"]
 }
]
`)
	c.Assert(err, IsNil)
	result, err := Filter(query, series[0])
	c.Assert(err, IsNil)
	c.Assert(result, NotNil)
	c.Assert(result.Points, HasLen, 1)
	c.Assert(result.Fields, HasLen, 2)
}
开发者ID:johntdyer,项目名称:golang-devops-stuff,代码行数:25,代码来源:filtering_test.go

示例5: handleQuery

func (self *ProtobufRequestHandler) handleQuery(request *protocol.Request, conn net.Conn) {
	nextPointMap := make(map[string]*NextPoint)
	assignNextPointTimesAndSend := func(series *protocol.Series) error {
		response := createResponse(nextPointMap, series, request.Id)
		return self.WriteResponse(conn, response)
	}
	// the query should always parse correctly since it was parsed at the originating server.
	query, _ := parser.ParseSelectQuery(*request.Query)
	var user common.User
	if *request.IsDbUser {
		user = self.clusterConfig.GetDbUser(*request.Database, *request.UserName)
	} else {
		user = self.clusterConfig.GetClusterAdmin(*request.UserName)
	}

	var response *protocol.Response
	var ringFilter func(database, series *string, time *int64) bool

	if user == nil {
		errorMsg := fmt.Sprintf("Cannot find user %s", *request.UserName)
		response = &protocol.Response{ErrorMessage: &errorMsg}
		goto response
	}

	if request.RingLocationsToQuery != nil {
		ringFilter = self.clusterConfig.GetRingFilterFunction(*request.Database, *request.RingLocationsToQuery)
	}
	self.db.ExecuteQuery(user, *request.Database, query, assignNextPointTimesAndSend, ringFilter)

	response = &protocol.Response{Type: &endStreamResponse, RequestId: request.Id}
response:
	self.WriteResponse(conn, response)
}
开发者ID:nkts,项目名称:golang-devops-stuff,代码行数:33,代码来源:protobuf_request_handler.go

示例6: CreateContinuousQuery

func (s *RaftServer) CreateContinuousQuery(db string, query string) error {
	selectQuery, err := parser.ParseSelectQuery(query)
	if err != nil {
		return fmt.Errorf("Failed to parse continuous query: %s", query)
	}

	if !selectQuery.IsValidContinuousQuery() {
		return fmt.Errorf("Continuous queries with a group by clause must include time(...) as one of the elements")
	}

	duration, err := selectQuery.GetGroupByClause().GetGroupByTime()
	if err != nil {
		return fmt.Errorf("Couldn't get group by time for continuous query: %s", err)
	}

	// if there are already-running queries, we need to initiate a backfill
	if duration != nil && !s.clusterConfig.LastContinuousQueryRunTime().IsZero() {
		zeroTime := time.Time{}
		currentBoundary := time.Now().Truncate(*duration)
		go s.runContinuousQuery(db, selectQuery, zeroTime, currentBoundary)
	} else {
		// TODO: make continuous queries backfill for queries that don't have a group by time
	}

	command := NewCreateContinuousQueryCommand(db, query)
	_, err = s.doOrProxyCommand(command, "create_cq")
	return err
}
开发者ID:rramos,项目名称:influxdb,代码行数:28,代码来源:raft_server.go

示例7: TestCanWriteAndRetrievePoints

func (self *DatastoreSuite) TestCanWriteAndRetrievePoints(c *C) {
	cleanup(nil)
	db := newDatastore(c)
	defer cleanup(db)
	mock := `
  {
    "points": [
      {
        "values": [
          {
            "int64_value": 3
          }
        ],
        "sequence_number": 1
      },
      {
        "values": [
          {
            "int64_value": 2
          }
        ],
        "sequence_number": 2
      }
    ],
    "name": "foo",
    "fields": ["value"]
  }`
	pointTime := time.Now().Unix()
	series := stringToSeries(mock, pointTime, c)
	err := db.WriteSeriesData("test", series)
	c.Assert(err, IsNil)
	q, errQ := parser.ParseSelectQuery("select value from foo;")
	c.Assert(errQ, IsNil)
	resultSeries := []*protocol.Series{}
	yield := func(series *protocol.Series) error {
		resultSeries = append(resultSeries, series)
		return nil
	}
	user := &MockUser{}
	err = db.ExecuteQuery(user, "test", q, yield, nil)
	c.Assert(err, IsNil)
	// we should get the actual data and the end of series data
	// indicator , i.e. a series with no points
	c.Assert(resultSeries, HasLen, 2)
	c.Assert(resultSeries[0].Points, HasLen, 2)
	c.Assert(resultSeries[0].Fields, HasLen, 1)
	c.Assert(*resultSeries[0].Points[0].SequenceNumber, Equals, uint64(2))
	c.Assert(*resultSeries[0].Points[1].SequenceNumber, Equals, uint64(1))
	c.Assert(*resultSeries[0].Points[0].GetTimestampInMicroseconds(), Equals, pointTime*1000000)
	c.Assert(*resultSeries[0].Points[1].GetTimestampInMicroseconds(), Equals, pointTime*1000000)
	c.Assert(*resultSeries[0].Points[0].Values[0].Int64Value, Equals, int64(2))
	c.Assert(*resultSeries[0].Points[1].Values[0].Int64Value, Equals, int64(3))
	c.Assert(resultSeries[1].Points, HasLen, 0)
	c.Assert(resultSeries[1].Fields, HasLen, 0)
	c.Assert(resultSeries, Not(DeepEquals), series)
}
开发者ID:johann8384,项目名称:influxdb,代码行数:56,代码来源:datastore_test.go

示例8: TestCanSelectFromARegex

func (self *DatastoreSuite) TestCanSelectFromARegex(c *C) {
	cleanup(nil)
	db := newDatastore(c)
	defer cleanup(db)

	mock := `{
    "points":[
      {"values":[{"int64_value":3},{"string_value":"paul"}],"sequence_number":2},
      {"values":[{"int64_value":1},{"string_value":"todd"}],"sequence_number":1}],
      "name":"user_things",
      "fields":["count", "name"]
    }`
	series := stringToSeries(mock, time.Now().Unix(), c)
	err := db.WriteSeriesData("foobar", series)
	c.Assert(err, IsNil)
	user := &MockUser{}
	results := executeQuery(user, "foobar", "select count, name from user_things;", db, c)
	c.Assert(results[0], DeepEquals, series)

	mock = `{
    "points":[{"values":[{"double_value":10.1}],"sequence_number":23}],
    "name":"response_times",
    "fields":["ms"]
  }`
	responseSeries := stringToSeries(mock, time.Now().Unix(), c)
	err = db.WriteSeriesData("foobar", responseSeries)
	c.Assert(err, IsNil)
	results = executeQuery(user, "foobar", "select ms from response_times;", db, c)
	c.Assert(results[0], DeepEquals, responseSeries)

	mock = `{
    "points":[{"values":[{"string_value":"NY"}],"sequence_number":23}, {"values":[{"string_value":"CO"}],"sequence_number":20}],
    "name":"other_things",
    "fields":["state"]
  }`
	otherSeries := stringToSeries(mock, time.Now().Unix(), c)
	err = db.WriteSeriesData("foobar", otherSeries)
	c.Assert(err, IsNil)
	results = executeQuery(user, "foobar", "select state from other_things;", db, c)
	c.Assert(results[0], DeepEquals, otherSeries)

	q, errQ := parser.ParseSelectQuery("select * from /.*things/;")
	c.Assert(errQ, IsNil)
	resultSeries := make([]*protocol.Series, 0)
	yield := func(series *protocol.Series) error {
		if len(series.Points) > 0 {
			resultSeries = append(resultSeries, series)
		}
		return nil
	}
	err = db.ExecuteQuery(user, "foobar", q, yield, nil)
	c.Assert(err, IsNil)
	c.Assert(resultSeries, HasLen, 2)
	c.Assert(resultSeries[0], DeepEquals, otherSeries)
	c.Assert(resultSeries[1], DeepEquals, series)
}
开发者ID:johann8384,项目名称:influxdb,代码行数:56,代码来源:datastore_test.go

示例9: TestCanWriteAndRetrievePointsWithAlias

func (self *DatastoreSuite) TestCanWriteAndRetrievePointsWithAlias(c *C) {
	cleanup(nil)
	db := newDatastore(c)
	defer cleanup(db)
	mock := `
  {
    "points": [
      {
        "values": [
          {
            "int64_value": 3
          }
        ],
        "sequence_number": 1
      },
      {
        "values": [
          {
            "int64_value": 2
          }
        ],
        "sequence_number": 2
      }
    ],
    "name": "foo",
    "fields": ["value"]
  }`
	pointTime := time.Now().Unix()
	series := stringToSeries(mock, pointTime, c)
	err := db.WriteSeriesData("test", series)
	c.Assert(err, IsNil)
	q, errQ := parser.ParseSelectQuery("select * from foo as f1 inner join foo as f2;")
	c.Assert(errQ, IsNil)
	resultSeries := map[string][]*protocol.Series{}
	yield := func(series *protocol.Series) error {
		resultSeries[*series.Name] = append(resultSeries[*series.Name], series)
		return nil
	}
	user := &MockUser{}
	err = db.ExecuteQuery(user, "test", q, yield, nil)
	c.Assert(err, IsNil)
	// we should get the actual data and the end of series data
	// indicator , i.e. a series with no points
	c.Assert(resultSeries, HasLen, 2)
	c.Assert(resultSeries["f1"], HasLen, 2)
	c.Assert(resultSeries["f1"][0].Points, HasLen, 2)
	c.Assert(resultSeries["f1"][1].Points, HasLen, 0)
	c.Assert(resultSeries["f2"], HasLen, 2)
	c.Assert(resultSeries["f2"][0].Points, HasLen, 2)
	c.Assert(resultSeries["f2"][1].Points, HasLen, 0)
}
开发者ID:johann8384,项目名称:influxdb,代码行数:51,代码来源:datastore_test.go

示例10: executeQuery

func executeQuery(user common.User, database, query string, db Datastore, c *C) []*protocol.Series {
	q, errQ := parser.ParseSelectQuery(query)
	c.Assert(errQ, IsNil)
	resultSeries := []*protocol.Series{}
	yield := func(series *protocol.Series) error {
		// ignore time series which have no data, this includes
		// end of series indicator
		if len(series.Points) > 0 {
			resultSeries = append(resultSeries, series)
		}
		return nil
	}
	err := db.ExecuteQuery(user, database, q, yield, nil)
	c.Assert(err, IsNil)
	return resultSeries
}
开发者ID:johann8384,项目名称:influxdb,代码行数:16,代码来源:datastore_test.go

示例11: handleQuery

func (self *ProtobufRequestHandler) handleQuery(request *protocol.Request, conn net.Conn) {
	nextPointMap := make(map[string]*protocol.Point)
	assignNextPointTimesAndSend := func(series *protocol.Series) error {
		pointCount := len(series.Points)
		if pointCount <= 1 {
			if nextPoint := nextPointMap[*series.Name]; nextPoint != nil {
				series.Points = append(series.Points, nextPoint)
			}
			response := &protocol.Response{Type: &queryResponse, Series: series, RequestId: request.Id}

			self.WriteResponse(conn, response)
			return nil
		}
		oldNextPoint := nextPointMap[*series.Name]
		nextPoint := series.Points[pointCount-1]
		series.Points[pointCount-1] = nil
		if oldNextPoint != nil {
			copy(series.Points[1:], series.Points[0:])
			series.Points[0] = oldNextPoint
		} else {
			series.Points = series.Points[:len(series.Points)-1]
		}

		response := &protocol.Response{Series: series, Type: &queryResponse, RequestId: request.Id}
		if nextPoint != nil {
			response.NextPointTime = nextPoint.Timestamp
			nextPointMap[*series.Name] = nextPoint
		}
		err := self.WriteResponse(conn, response)
		return err
	}
	// the query should always parse correctly since it was parsed at the originating server.
	query, _ := parser.ParseSelectQuery(*request.Query)
	user := self.clusterConfig.GetDbUser(*request.Database, *request.UserName)

	var ringFilter func(database, series *string, time *int64) bool
	if request.RingLocationsToQuery != nil {
		ringFilter = self.clusterConfig.GetRingFilterFunction(*request.Database, *request.RingLocationsToQuery)
	}
	self.db.ExecuteQuery(user, *request.Database, query, assignNextPointTimesAndSend, ringFilter)

	response := &protocol.Response{Type: &endStreamResponse, RequestId: request.Id}
	self.WriteResponse(conn, response)
}
开发者ID:ronaldevers,项目名称:influxdb,代码行数:44,代码来源:protobuf_request_handler.go

示例12: TestBreaksLargeResultsIntoMultipleBatches

func (self *DatastoreSuite) TestBreaksLargeResultsIntoMultipleBatches(c *C) {
	cleanup(nil)
	db := newDatastore(c)
	defer cleanup(db)

	mock := `{
    "points":[
      {"values":[{"double_value":23.1},{"string_value":"paul"}],"sequence_number":2},
      {"values":[{"double_value":56.8},{"string_value":"todd"}],"sequence_number":1}],
      "name":"user_things",
      "fields":["response_time","name"]
  }`
	series := stringToSeries(mock, time.Now().Unix(), c)
	sequence := 0
	writtenPoints := 0
	for i := 0; i < 50000; i++ {
		for _, p := range series.Points {
			sequence += 1
			s := uint64(sequence)
			p.SequenceNumber = &s
		}
		writtenPoints += 2
		err := db.WriteSeriesData("foobar", series)
		c.Assert(err, IsNil)
	}

	q, errQ := parser.ParseSelectQuery("select * from user_things limit 0;")
	c.Assert(errQ, IsNil)
	resultSeries := make([]*protocol.Series, 0)
	yield := func(series *protocol.Series) error {
		resultSeries = append(resultSeries, series)
		return nil
	}
	user := &MockUser{}
	err := db.ExecuteQuery(user, "foobar", q, yield, nil)
	c.Assert(err, IsNil)
	c.Assert(len(resultSeries), InRange, 2, 20)
	pointCount := 0
	for _, s := range resultSeries {
		pointCount += len(s.Points)
	}
	c.Assert(pointCount, Equals, writtenPoints)
}
开发者ID:johann8384,项目名称:influxdb,代码行数:43,代码来源:datastore_test.go

示例13: handleQuery

func (self *ProtobufRequestHandler) handleQuery(request *protocol.Request, conn net.Conn) {
	nextPointMap := make(map[string]*NextPoint)
	assignNextPointTimesAndSend := func(series *protocol.Series) error {
		response := createResponse(nextPointMap, series, request.Id)
		return self.WriteResponse(conn, response)
	}
	// the query should always parse correctly since it was parsed at the originating server.
	query, _ := parser.ParseSelectQuery(*request.Query)
	user := self.clusterConfig.GetDbUser(*request.Database, *request.UserName)

	var ringFilter func(database, series *string, time *int64) bool
	if request.RingLocationsToQuery != nil {
		ringFilter = self.clusterConfig.GetRingFilterFunction(*request.Database, *request.RingLocationsToQuery)
	}
	self.db.ExecuteQuery(user, *request.Database, query, assignNextPointTimesAndSend, ringFilter)

	response := &protocol.Response{Type: &endStreamResponse, RequestId: request.Id}
	self.WriteResponse(conn, response)
}
开发者ID:schmurfy,项目名称:influxdb,代码行数:19,代码来源:protobuf_request_handler.go

示例14: TestCheckReadAccess

func (self *DatastoreSuite) TestCheckReadAccess(c *C) {
	cleanup(nil)
	db := newDatastore(c)
	defer cleanup(db)

	mock := `{
    "points":[
      {"values":[{"int64_value":3},{"string_value":"paul"}],"sequence_number":2},
      {"values":[{"int64_value":1},{"string_value":"todd"}],"sequence_number":1}],
      "name":"user_things",
      "fields":["count", "name"]
    }`
	series := stringToSeries(mock, time.Now().Unix(), c)
	err := db.WriteSeriesData("foobar", series)
	c.Assert(err, IsNil)

	mock = `{
    "points":[{"values":[{"string_value":"NY"}],"sequence_number":23}, {"values":[{"string_value":"CO"}],"sequence_number":20}],
    "name":"other_things",
    "fields":["state"]
  }`
	otherSeries := stringToSeries(mock, time.Now().Unix(), c)
	err = db.WriteSeriesData("foobar", otherSeries)

	user := &MockUser{
		dbCannotRead: map[string]bool{"other_things": true},
	}
	q, errQ := parser.ParseSelectQuery("select * from /.*things/;")
	c.Assert(errQ, IsNil)
	resultSeries := make([]*protocol.Series, 0)
	yield := func(series *protocol.Series) error {
		if len(series.Points) > 0 {
			resultSeries = append(resultSeries, series)
		}
		return nil
	}
	err = db.ExecuteQuery(user, "foobar", q, yield, nil)
	c.Assert(err, ErrorMatches, ".*one or more.*")
	c.Assert(len(resultSeries), Equals, 1)
	c.Assert(*resultSeries[0].Name, Equals, "user_things")
	c.Assert(resultSeries[0], DeepEquals, series)
}
开发者ID:johann8384,项目名称:influxdb,代码行数:42,代码来源:datastore_test.go

示例15: TestDeletingData

func (self *DatastoreSuite) TestDeletingData(c *C) {
	cleanup(nil)
	db := newDatastore(c)
	defer cleanup(db)
	mock := `
  {
    "points": [
      {
        "values": [
          {
            "int64_value": 3
          }
        ],
        "sequence_number": 1
      }
    ],
    "name": "foo",
    "fields": ["value"]
  }`
	pointTime := time.Now().Unix()
	series := stringToSeries(mock, pointTime, c)
	err := db.WriteSeriesData("test", series)
	c.Assert(err, IsNil)
	q, err := parser.ParseSelectQuery("select value from foo;")
	c.Assert(err, IsNil)
	yield := func(series *protocol.Series) error {
		if len(series.Points) > 0 {
			panic("Series contains points")
		}
		return nil
	}
	c.Assert(db.DropDatabase("test"), IsNil)
	user := &MockUser{}
	err = db.ExecuteQuery(user, "test", q, yield, nil)

	// we don't have an error any more on query for fields that don't exist.
	// This is because of the clustering. Some servers could have some fields
	// while others don't. To be expected.
	// c.Assert(err, ErrorMatches, ".*Field value doesn't exist.*")
	c.Assert(err, IsNil)
}
开发者ID:johann8384,项目名称:influxdb,代码行数:41,代码来源:datastore_test.go


注:本文中的parser.ParseSelectQuery函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。