Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for InfluxDB retention policies
Because of the behaviour of the InfluxDB query 'SHOW MEASUREMENTS' where it is not specified which measurements belong to which retention policy, it was impossible to extract a measure from other than the default RP. This commit removes a redundant check for the presence of a measurement when doing migration of a single measurement and modifies the generated influx queries for schema exploration in order to properly select a measurement in a specified RP. Passing the name of the measurement as "retention_policy"."measurement name" now exports the proper data
- Loading branch information
1 parent
4090f30
commit 3d60065
Showing
11 changed files
with
305 additions
and
42 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,97 @@ | ||
package influx | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/timescale/outflux/internal/extraction/config" | ||
"github.com/timescale/outflux/internal/idrf" | ||
) | ||
|
||
func TestBuildMeasurementName(t *testing.T) { | ||
testCases := []struct { | ||
in string | ||
exp string | ||
}{ | ||
{in: "measure", exp: `"measure"`}, | ||
{in: "rp.measure", exp: `"rp"."measure"`}, | ||
{in: "rp.measure name", exp: `"rp"."measure name"`}, | ||
{in: "rp name.measure.name", exp: `"rp name"."measure.name"`}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
out := buildMeasurementName(tc.in) | ||
if out != tc.exp { | ||
t.Errorf("expected: %s, got: %s", tc.exp, out) | ||
} | ||
} | ||
} | ||
|
||
func TestBuildProjection(t *testing.T) { | ||
testCases := []struct { | ||
in []*idrf.Column | ||
exp string | ||
}{ | ||
{in: []*idrf.Column{{Name: "col1"}}, exp: `"col1"`}, | ||
{in: []*idrf.Column{{Name: "col 1"}}, exp: `"col 1"`}, | ||
{in: []*idrf.Column{{Name: "col 1"}, {Name: "col 2"}}, exp: `"col 1", "col 2"`}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
out := buildProjection(tc.in) | ||
if out != tc.exp { | ||
t.Errorf("expected: %s, got: %s", tc.exp, out) | ||
} | ||
} | ||
} | ||
|
||
func TestBuildSelectCommand(t *testing.T) { | ||
testCases := []struct { | ||
measure string | ||
columns []*idrf.Column | ||
from string | ||
to string | ||
limit uint64 | ||
exp string | ||
}{ | ||
{ | ||
measure: "m", | ||
columns: []*idrf.Column{{Name: "col1"}}, | ||
exp: `SELECT "col1" FROM "m"`, | ||
}, { | ||
measure: "rp.m", | ||
columns: []*idrf.Column{{Name: "col1"}, {Name: "col 2"}}, | ||
from: "a", | ||
exp: `SELECT "col1", "col 2" FROM "rp"."m" WHERE time >= 'a'`, | ||
}, { | ||
measure: "m", | ||
columns: []*idrf.Column{{Name: "col1"}}, | ||
to: "b", | ||
exp: `SELECT "col1" FROM "m" WHERE time <= 'b'`, | ||
}, { | ||
measure: "m", | ||
columns: []*idrf.Column{{Name: "col1"}}, | ||
from: "a", | ||
to: "b", | ||
exp: `SELECT "col1" FROM "m" WHERE time >= 'a' AND time <= 'b'`, | ||
}, { | ||
measure: "m", | ||
columns: []*idrf.Column{{Name: "col1"}}, | ||
limit: 11, | ||
exp: `SELECT "col1" FROM "m" LIMIT 11`, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
config := &config.MeasureExtraction{ | ||
Measure: tc.measure, | ||
From: tc.from, | ||
To: tc.to, | ||
Limit: tc.limit, | ||
} | ||
|
||
out := buildSelectCommand(config, tc.columns) | ||
if out != tc.exp { | ||
t.Errorf("expected: %s, got: %s", tc.exp, out) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.