Skip to content

Commit

Permalink
Integrate sqlfluff as dbt cli command
Browse files Browse the repository at this point in the history
  • Loading branch information
ismailsimsek committed Oct 22, 2024
1 parent 3d3c0ba commit 20b0925
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
4 changes: 0 additions & 4 deletions opendbt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from dbt.cli.main import dbtRunner as DbtCliRunner
from dbt.cli.main import dbtRunnerResult
from dbt.contracts.graph.manifest import Manifest
from dbt.contracts.results import RunResult
from dbt.exceptions import DbtRuntimeError

from opendbt.dbt import patch_dbt
Expand Down Expand Up @@ -52,8 +51,6 @@ def run(args: list) -> dbtRunnerResult:
return result

# print query for user to run and see the failing rows
rer: RunResult

_exception = result.exception if result.exception else None
if (_exception is None and hasattr(result.result, 'results') and result.result.results and
len(result.result.results) > 0 and result.result.results[0].message
Expand All @@ -65,7 +62,6 @@ def run(args: list) -> dbtRunnerResult:
if _exception:
raise _exception
else:
print("HERRREEEE")
return result


Expand Down
12 changes: 6 additions & 6 deletions opendbt/dbt/shared/task/sqlfluff.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, args, config, manifest):
# args=dbt.utils.args_to_dict(self.args),
args={},
)
self.results = CatalogArtifact.from_results(
self.result = CatalogArtifact.from_results(
nodes={},
sources={},
generated_at=datetime.utcnow(),
Expand All @@ -53,8 +53,8 @@ def __init__(self, args, config, manifest):
def lint(self) -> CatalogArtifact:
os.chdir(self.config.project_root)
lint_result: LintingResult = self.linter.lint_paths(paths=(self.config.project_root,))
self.results.errors = lint_result.get_violations()
self.results.exception = Exception(f"Linting {lint_result.num_violations()} errors found!")
self.result.errors = lint_result.get_violations()
self.result.exception = Exception(f"Linting {lint_result.num_violations()} errors found!")
for error in lint_result.as_records():
filepath = Path(error['filepath'])
violations: list = error['violations']
Expand All @@ -63,17 +63,17 @@ def lint(self) -> CatalogArtifact:
for violation in violations:
print(f" {violation}")
# print(f"Code:{violation['code']} Line:{violation['start_line_no']}, LinePos:{violation['start_line_pos']} {violation['description']}")
return self.results
return self.result

def fix(self) -> CatalogArtifact:
os.chdir(self.config.project_root)
lnt, formatter = commands.get_linter_and_formatter(cfg=self.sqlfluff_config)
lint_result: LintingResult = lnt.lint_paths(
_: LintingResult = lnt.lint_paths(
paths=(self.config.project_root,),
fix=True,
apply_fixes=True
)
return self.results
return self.result

@classmethod
def interpret_results(self, results: Optional[CatalogResults]) -> bool:
Expand Down

0 comments on commit 20b0925

Please sign in to comment.