本文整理汇总了Golang中github.com/influxdb/influxdb/parser.QuerySpec.Database方法的典型用法代码示例。如果您正苦于以下问题:Golang QuerySpec.Database方法的具体用法?Golang QuerySpec.Database怎么用?Golang QuerySpec.Database使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/influxdb/influxdb/parser.QuerySpec
的用法示例。
在下文中一共展示了QuerySpec.Database方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Query
func (self *Shard) Query(querySpec *parser.QuerySpec, processor cluster.QueryProcessor) error {
if querySpec.IsListSeriesQuery() {
return self.executeListSeriesQuery(querySpec, processor)
} else if querySpec.IsDeleteFromSeriesQuery() {
return self.executeDeleteQuery(querySpec, processor)
}
seriesAndColumns := querySpec.SelectQuery().GetReferencedColumns()
if !self.hasReadAccess(querySpec) {
return errors.New("User does not have access to one or more of the series requested.")
}
for series, columns := range seriesAndColumns {
if regex, ok := series.GetCompiledRegex(); ok {
seriesNames := self.metaStore.GetSeriesForDatabaseAndRegex(querySpec.Database(), regex)
for _, name := range seriesNames {
if !querySpec.HasReadAccess(name) {
continue
}
err := self.executeQueryForSeries(querySpec, name, columns, processor)
if err != nil {
return err
}
}
} else {
err := self.executeQueryForSeries(querySpec, series.Name, columns, processor)
if err != nil {
return err
}
}
}
return nil
}
示例2: runListSeriesQuery
func (self *Coordinator) runListSeriesQuery(querySpec *parser.QuerySpec, p engine.Processor) error {
allSeries := self.clusterConfiguration.MetaStore.GetSeriesForDatabase(querySpec.Database())
matchingSeries := allSeries
if q := querySpec.Query().GetListSeriesQuery(); q.HasRegex() {
matchingSeries = nil
regex := q.GetRegex()
for _, s := range allSeries {
if !regex.MatchString(s) {
continue
}
matchingSeries = append(matchingSeries, s)
}
}
name := "list_series_result"
fields := []string{"name"}
points := make([]*protocol.Point, len(matchingSeries), len(matchingSeries))
for i, s := range matchingSeries {
fieldValues := []*protocol.FieldValue{{StringValue: proto.String(s)}}
points[i] = &protocol.Point{Values: fieldValues}
}
seriesResult := &protocol.Series{Name: &name, Fields: fields, Points: points}
_, err := p.Yield(seriesResult)
return err
}
示例3: executeListSeriesQuery
func (self *LevelDbShard) executeListSeriesQuery(querySpec *parser.QuerySpec, processor cluster.QueryProcessor) error {
it := self.db.NewIterator(self.readOptions)
defer it.Close()
database := querySpec.Database()
seekKey := append(DATABASE_SERIES_INDEX_PREFIX, []byte(querySpec.Database()+"~")...)
it.Seek(seekKey)
dbNameStart := len(DATABASE_SERIES_INDEX_PREFIX)
for it = it; it.Valid(); it.Next() {
key := it.Key()
if len(key) < dbNameStart || !bytes.Equal(key[:dbNameStart], DATABASE_SERIES_INDEX_PREFIX) {
break
}
dbSeries := string(key[dbNameStart:])
parts := strings.Split(dbSeries, "~")
if len(parts) > 1 {
if parts[0] != database {
break
}
name := parts[1]
shouldContinue := processor.YieldPoint(&name, nil, nil)
if !shouldContinue {
return nil
}
}
}
return nil
}
示例4: getShardsToMatchQuery
func (self *ClusterConfiguration) getShardsToMatchQuery(querySpec *parser.QuerySpec) ([]*ShardData, error) {
self.shardLock.RLock()
defer self.shardLock.RUnlock()
seriesNames, fromRegex := querySpec.TableNamesAndRegex()
db := querySpec.Database()
if fromRegex != nil {
seriesNames = self.MetaStore.GetSeriesForDatabaseAndRegex(db, fromRegex)
}
uniqueShards := make(map[uint32]*ShardData)
for _, name := range seriesNames {
if fs := self.MetaStore.GetFieldsForSeries(db, name); len(fs) == 0 {
return nil, fmt.Errorf("Couldn't find series: %s", name)
}
space := self.getShardSpaceToMatchSeriesName(db, name)
if space == nil {
continue
}
for _, shard := range space.shards {
uniqueShards[shard.id] = shard
}
}
shards := make([]*ShardData, 0, len(uniqueShards))
for _, shard := range uniqueShards {
shards = append(shards, shard)
}
SortShardsByTimeDescending(shards)
return shards, nil
}
示例5: executeArrayQuery
func (self *Shard) executeArrayQuery(querySpec *parser.QuerySpec, processor engine.Processor) error {
seriesAndColumns := querySpec.SelectQuery().GetReferencedColumns()
for series, columns := range seriesAndColumns {
if regex, ok := series.GetCompiledRegex(); ok {
seriesNames := self.metaStore.GetSeriesForDatabaseAndRegex(querySpec.Database(), regex)
for _, name := range seriesNames {
if !querySpec.HasReadAccess(name) {
continue
}
err := self.executeQueryForSeries(querySpec, name, columns, processor)
if err != nil {
return err
}
}
} else {
err := self.executeQueryForSeries(querySpec, series.Name, columns, processor)
if err != nil {
return err
}
}
}
return nil
}
示例6: executeQueryForSeries
func (self *Shard) executeQueryForSeries(querySpec *parser.QuerySpec, seriesName string, columns []string, processor engine.Processor) error {
fields, err := self.getFieldsForSeries(querySpec.Database(), seriesName, columns)
if err != nil {
log.Error("Error looking up fields for %s: %s", seriesName, err)
return err
}
if querySpec.IsSinglePointQuery() {
log.Debug("Running single query for series %s, fields %v", seriesName, fields)
return self.executeSinglePointQuery(querySpec, seriesName, fields, processor)
}
startTime := querySpec.GetStartTime()
endTime := querySpec.GetEndTime()
query := querySpec.SelectQuery()
aliases := query.GetTableAliases(seriesName)
fieldNames, iterators := self.getIterators(fields, startTime, endTime, query.Ascending)
seriesOutgoing := &protocol.Series{Name: protocol.String(seriesName), Fields: fieldNames, Points: make([]*protocol.Point, 0, self.pointBatchSize)}
pi := NewPointIterator(iterators, fields, querySpec.GetStartTime(), querySpec.GetEndTime(), query.Ascending)
defer pi.Close()
for pi.Valid() {
p := pi.Point()
seriesOutgoing.Points = append(seriesOutgoing.Points, p)
if len(seriesOutgoing.Points) >= self.pointBatchSize {
ok, err := yieldToProcessor(seriesOutgoing, processor, aliases)
if !ok || err != nil {
log.Debug("Stopping processing.")
if err != nil {
log.Error("Error while processing data: %v", err)
return err
}
}
seriesOutgoing = &protocol.Series{Name: protocol.String(seriesName), Fields: fieldNames, Points: make([]*protocol.Point, 0, self.pointBatchSize)}
}
pi.Next()
}
if err := pi.Error(); err != nil {
return err
}
//Yield remaining data
if ok, err := yieldToProcessor(seriesOutgoing, processor, aliases); !ok || err != nil {
log.Debug("Stopping processing remaining points...")
if err != nil {
log.Error("Error while processing data: %v", err)
return err
}
}
log.Debug("Finished running query %s", query.GetQueryString())
return nil
}
示例7: runDeleteQuery
func (self *CoordinatorImpl) runDeleteQuery(querySpec *parser.QuerySpec, seriesWriter SeriesWriter) error {
user := querySpec.User()
db := querySpec.Database()
if ok, err := self.permissions.AuthorizeDeleteQuery(user, db); !ok {
return err
}
querySpec.RunAgainstAllServersInShard = true
return self.runQuerySpec(querySpec, seriesWriter)
}
示例8: executeDropSeriesQuery
func (self *LevelDbShard) executeDropSeriesQuery(querySpec *parser.QuerySpec, processor cluster.QueryProcessor) error {
database := querySpec.Database()
series := querySpec.Query().DropSeriesQuery.GetTableName()
err := self.dropSeries(database, series)
if err != nil {
return err
}
self.compact()
return nil
}
示例9: expandRegex
func (self *Coordinator) expandRegex(spec *parser.QuerySpec) {
q := spec.SelectQuery()
if q == nil {
return
}
f := func(r *regexp.Regexp) []string {
return self.clusterConfiguration.MetaStore.GetSeriesForDatabaseAndRegex(spec.Database(), r)
}
parser.RewriteMergeQuery(q, f)
}
示例10: runDropSeriesQuery
func (self *Coordinator) runDropSeriesQuery(querySpec *parser.QuerySpec) error {
user := querySpec.User()
db := querySpec.Database()
series := querySpec.Query().DropSeriesQuery.GetTableName()
if ok, err := self.permissions.AuthorizeDropSeries(user, db, series); !ok {
return err
}
err := self.raftServer.DropSeries(db, series)
if err != nil {
return err
}
return nil
}
示例11: runListSeriesQuery
func (self *Coordinator) runListSeriesQuery(querySpec *parser.QuerySpec, p engine.Processor) error {
allSeries := self.clusterConfiguration.MetaStore.GetSeriesForDatabase(querySpec.Database())
matchingSeries := allSeries
q := querySpec.Query().GetListSeriesQuery()
if q.HasRegex() {
matchingSeries = nil
regex := q.GetRegex()
for _, s := range allSeries {
if !regex.MatchString(s) {
continue
}
matchingSeries = append(matchingSeries, s)
}
}
name := "list_series_result"
var fields []string
points := make([]*protocol.Point, len(matchingSeries))
if q.IncludeSpaces {
fields = []string{"name", "space"}
spaces := self.clusterConfiguration.GetShardSpacesForDatabase(querySpec.Database())
for i, s := range matchingSeries {
spaceName := ""
for _, sp := range spaces {
if sp.MatchesSeries(s) {
spaceName = sp.Name
break
}
}
fieldValues := []*protocol.FieldValue{
{StringValue: proto.String(s)},
{StringValue: proto.String(spaceName)},
}
points[i] = &protocol.Point{Values: fieldValues}
}
} else {
fields = []string{"name"}
for i, s := range matchingSeries {
fieldValues := []*protocol.FieldValue{
{StringValue: proto.String(s)},
}
points[i] = &protocol.Point{Values: fieldValues}
}
}
seriesResult := &protocol.Series{Name: &name, Fields: fields, Points: points}
_, err := p.Yield(seriesResult)
return err
}
示例12: executeSinglePointQuery
func (self *Shard) executeSinglePointQuery(querySpec *parser.QuerySpec, name string, columns []string, p engine.Processor) error {
fields, err := self.getFieldsForSeries(querySpec.Database(), name, columns)
if err != nil {
log.Error("Error looking up fields for %s: %s", name, err)
return err
}
query := querySpec.SelectQuery()
fieldCount := len(fields)
fieldNames := make([]string, 0, fieldCount)
point := &protocol.Point{Values: make([]*protocol.FieldValue, 0, fieldCount)}
timestamp := common.TimeToMicroseconds(query.GetStartTime())
sequenceNumber, err := query.GetSinglePointQuerySequenceNumber()
if err != nil {
return err
}
// set the timestamp and sequence number
point.SequenceNumber = &sequenceNumber
point.SetTimestampInMicroseconds(timestamp)
for _, field := range fields {
sk := newStorageKey(field.Id, timestamp, sequenceNumber)
data, err := self.db.Get(sk.bytes())
if err != nil {
return err
}
if data == nil {
continue
}
fieldValue := &protocol.FieldValue{}
err = proto.Unmarshal(data, fieldValue)
if err != nil {
return err
}
fieldNames = append(fieldNames, field.Name)
point.Values = append(point.Values, fieldValue)
}
result := &protocol.Series{Name: &name, Fields: fieldNames, Points: []*protocol.Point{point}}
if len(result.Points) > 0 {
_, err := p.Yield(result)
return err
}
return nil
}
示例13: runDropSeriesQuery
func (self *CoordinatorImpl) runDropSeriesQuery(querySpec *parser.QuerySpec, seriesWriter SeriesWriter) error {
user := querySpec.User()
db := querySpec.Database()
series := querySpec.Query().DropSeriesQuery.GetTableName()
if ok, err := self.permissions.AuthorizeDropSeries(user, db, series); !ok {
return err
}
defer seriesWriter.Close()
fmt.Println("DROP series")
err := self.raftServer.DropSeries(db, series)
if err != nil {
return err
}
fmt.Println("DROP returning nil")
return nil
}
示例14: createRequest
func (self *ShardData) createRequest(querySpec *parser.QuerySpec) *p.Request {
queryString := querySpec.GetQueryStringWithTimeCondition()
user := querySpec.User()
userName := user.GetName()
database := querySpec.Database()
isDbUser := !user.IsClusterAdmin()
return &p.Request{
Type: p.Request_QUERY.Enum(),
ShardId: &self.id,
Query: &queryString,
UserName: &userName,
Database: &database,
IsDbUser: &isDbUser,
}
}
示例15: runListSeriesQuery
func (self *CoordinatorImpl) runListSeriesQuery(querySpec *parser.QuerySpec, seriesWriter SeriesWriter) error {
series := self.clusterConfiguration.MetaStore.GetSeriesForDatabase(querySpec.Database())
name := "list_series_result"
fields := []string{"name"}
points := make([]*protocol.Point, len(series), len(series))
for i, s := range series {
fieldValues := []*protocol.FieldValue{{StringValue: proto.String(s)}}
points[i] = &protocol.Point{Values: fieldValues}
}
seriesResult := &protocol.Series{Name: &name, Fields: fields, Points: points}
seriesWriter.Write(seriesResult)
seriesWriter.Close()
return nil
}