-
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.
feat(influx_tools): Add export to parquet files
- Loading branch information
Showing
5 changed files
with
832 additions
and
123 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package parquet | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"flag" | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
"go.uber.org/zap" | ||
|
||
"github.com/influxdata/influxdb/cmd/influx_tools/server" | ||
) | ||
|
||
// Command represents the program execution for "store query". | ||
type Command struct { | ||
// Standard input/output, overridden for testing. | ||
Stderr io.Writer | ||
Logger *zap.Logger | ||
|
||
server server.Interface | ||
} | ||
|
||
// NewCommand returns a new instance of the export Command. | ||
func NewCommand(server server.Interface) *Command { | ||
return &Command{ | ||
Stderr: os.Stderr, | ||
server: server, | ||
} | ||
} | ||
|
||
// Run executes the export command using the specified args. | ||
func (cmd *Command) Run(args []string) (err error) { | ||
var ( | ||
configPath string | ||
database string | ||
rp string | ||
measurement string | ||
output string | ||
dryRun bool | ||
) | ||
|
||
cwd, err := os.Getwd() | ||
if err != nil { | ||
return fmt.Errorf("getting current working directory failed: %w", err) | ||
} | ||
|
||
flags := flag.NewFlagSet("export", flag.ContinueOnError) | ||
flags.StringVar(&configPath, "config", "", "Config file") | ||
flags.StringVar(&database, "database", "", "Database name") | ||
flags.StringVar(&rp, "rp", "", "Retention policy name") | ||
flags.StringVar(&measurement, "measurement", "*", "Measurement name") | ||
flags.StringVar(&output, "output", cwd, "Output directory for parquet files") | ||
flags.BoolVar(&dryRun, "print-only", false, "Print plan to stderr and exit") | ||
|
||
if err := flags.Parse(args); err != nil { | ||
return err | ||
} | ||
|
||
if database == "" { | ||
return errors.New("database is required") | ||
} | ||
|
||
if err := cmd.server.Open(configPath); err != nil { | ||
return err | ||
} | ||
defer cmd.server.Close() | ||
|
||
cfg := &config{ | ||
Database: database, | ||
RP: rp, | ||
Measurement: measurement, | ||
Output: output, | ||
Stderr: cmd.Stderr, | ||
} | ||
exp, err := newExporter(cmd.server, cfg) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := exp.open(); err != nil { | ||
return err | ||
} | ||
defer exp.close() | ||
|
||
exp.printPlan() | ||
|
||
if dryRun { | ||
return nil | ||
} | ||
|
||
return exp.export(context.Background()) | ||
} |
Oops, something went wrong.