-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement import-db command (#10040)
* implement import-db command * generate .dvc file * update * fix tests * pin dbt-fal * try to run on ci * use os.chdir * fix * revert * require dbt-core>=1.5 * add db config schema * remove platformdirs constraints * use logger.getChild * improve error messaging * rename cli flag --export-format to --output-format * use feature flag for db config * hide command from dvc commands list * refactor dependency._get * remove todo * refactor dependency._get * fix dbt installation check
- Loading branch information
Showing
19 changed files
with
831 additions
and
29 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,90 @@ | ||
import argparse | ||
|
||
from dvc.cli import completion | ||
from dvc.cli.command import CmdBase | ||
from dvc.cli.utils import append_doc_link | ||
from dvc.log import logger | ||
|
||
logger = logger.getChild(__name__) | ||
|
||
|
||
class CmdImportDb(CmdBase): | ||
def run(self): | ||
if not (self.args.sql or self.args.model): | ||
raise argparse.ArgumentTypeError("Either of --sql or --model is required.") | ||
|
||
self.repo.imp_db( | ||
url=self.args.url, | ||
rev=self.args.rev, | ||
project_dir=self.args.project_dir, | ||
sql=self.args.sql, | ||
model=self.args.model, | ||
profile=self.args.profile, | ||
target=self.args.target, | ||
output_format=self.args.output_format, | ||
out=self.args.out, | ||
force=self.args.force, | ||
) | ||
return 0 | ||
|
||
|
||
def add_parser(subparsers, parent_parser): | ||
IMPORT_HELP = ( | ||
"Download file or directory tracked by DVC or by Git " | ||
"into the workspace, and track it." | ||
) | ||
|
||
import_parser = subparsers.add_parser( | ||
"import-db", | ||
parents=[parent_parser], | ||
description=append_doc_link(IMPORT_HELP, "import"), | ||
add_help=False, | ||
) | ||
import_parser.add_argument( | ||
"--url", help="Location of DVC or Git repository to download from" | ||
) | ||
import_parser.add_argument( | ||
"--rev", | ||
nargs="?", | ||
help="Git revision (e.g. SHA, branch, tag)", | ||
metavar="<commit>", | ||
) | ||
import_parser.add_argument( | ||
"--project-dir", nargs="?", help="Subdirectory to the dbt project location" | ||
) | ||
|
||
group = import_parser.add_mutually_exclusive_group() | ||
group.add_argument( | ||
"--sql", | ||
help="SQL query", | ||
) | ||
group.add_argument( | ||
"--model", | ||
help="Model name to download", | ||
) | ||
import_parser.add_argument("--profile", help="Profile to use") | ||
import_parser.add_argument("--target", help="Target to use") | ||
import_parser.add_argument( | ||
"--output-format", | ||
default="csv", | ||
const="csv", | ||
nargs="?", | ||
choices=["csv", "json"], | ||
help="Export format", | ||
) | ||
import_parser.add_argument( | ||
"-o", | ||
"--out", | ||
nargs="?", | ||
help="Destination path to download files to", | ||
metavar="<path>", | ||
).complete = completion.FILE | ||
import_parser.add_argument( | ||
"-f", | ||
"--force", | ||
action="store_true", | ||
default=False, | ||
help="Override destination file or folder if exists.", | ||
) | ||
|
||
import_parser.set_defaults(func=CmdImportDb) |
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.