-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Since INTO queries need to have absolute information about the database to work, we need to create a loopback interface back to the cluster in order to perform them.
- Loading branch information
Daniel Morsing
committed
Oct 12, 2015
1 parent
f1e0c59
commit 3f77f68
Showing
5 changed files
with
198 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package tsdb | ||
|
||
import ( | ||
"errors" | ||
"github.com/influxdb/influxdb/influxql" | ||
"github.com/influxdb/influxdb/models" | ||
"time" | ||
) | ||
|
||
// convertRowToPoints will convert a query result Row into Points that can be written back in. | ||
// Used for INTO queries | ||
func convertRowToPoints(measurementName string, row *models.Row) ([]models.Point, error) { | ||
// figure out which parts of the result are the time and which are the fields | ||
timeIndex := -1 | ||
fieldIndexes := make(map[string]int) | ||
for i, c := range row.Columns { | ||
if c == "time" { | ||
timeIndex = i | ||
} else { | ||
fieldIndexes[c] = i | ||
} | ||
} | ||
|
||
if timeIndex == -1 { | ||
return nil, errors.New("error finding time index in result") | ||
} | ||
|
||
points := make([]models.Point, 0, len(row.Values)) | ||
for _, v := range row.Values { | ||
vals := make(map[string]interface{}) | ||
for fieldName, fieldIndex := range fieldIndexes { | ||
vals[fieldName] = v[fieldIndex] | ||
} | ||
|
||
p := models.NewPoint(measurementName, row.Tags, vals, v[timeIndex].(time.Time)) | ||
|
||
points = append(points, p) | ||
} | ||
|
||
return points, nil | ||
} | ||
|
||
func intoDB(stmt *influxql.SelectStatement) (string, error) { | ||
if stmt.Target.Measurement.Database != "" { | ||
return stmt.Target.Measurement.Database, nil | ||
} | ||
return "", errNoDatabaseInTarget | ||
} | ||
|
||
var errNoDatabaseInTarget = errors.New("no database in target") | ||
|
||
func intoRP(stmt *influxql.SelectStatement) string { return stmt.Target.Measurement.RetentionPolicy } | ||
func intoMeasurement(stmt *influxql.SelectStatement) string { return stmt.Target.Measurement.Name } |
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