Skip to content

Commit

Permalink
refactor: make swap_partitions_between_tables support vertica only
Browse files Browse the repository at this point in the history
  • Loading branch information
reata committed May 20, 2024
1 parent 94b550e commit 4573766
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
9 changes: 5 additions & 4 deletions sqllineage/core/parser/sqlfluff/extractors/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,13 @@ def _handle_select_statement_child_segments(
)
self._handle_column(segment)

@staticmethod
def _handle_swap_partition(segment: BaseSegment, holder: SubQueryLineageHolder):
def _handle_swap_partition(
self, segment: BaseSegment, holder: SubQueryLineageHolder
):
"""
A handler for swap_partitions_between_tables function
A handler for swap_partitions_between_tables function supported by vertica
"""
if segment.type == "select_clause":
if self.dialect == "vertica" and segment.type == "select_clause":
if select_clause_element := segment.get_child("select_clause_element"):
if function := select_clause_element.get_child("function"):
if (
Expand Down
13 changes: 0 additions & 13 deletions tests/sql/table/test_other_with_lineage.py
Original file line number Diff line number Diff line change
@@ -1,13 +0,0 @@
from ...helpers import assert_table_lineage_equal


def test_swapping_partitions():
"""
See https://www.vertica.com/docs/10.0.x/HTML/Content/Authoring/AdministratorsGuide/Partitions/SwappingPartitions.htm
for language specification
"""
assert_table_lineage_equal(
"SELECT swap_partitions_between_tables('staging', 'min-range-value', 'max-range-value', 'target')",
{"staging"},
{"target"},
)
14 changes: 14 additions & 0 deletions tests/sql/table/test_other_with_lineage_dialect_specific.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,17 @@ def test_alter_table_swap_partition(dialect: str):
dialect=dialect,
test_sqlparse=False,
)


@pytest.mark.parametrize("dialect", ["vertica"])
def test_swapping_partitions(dialect: str):
"""
See https://www.vertica.com/docs/10.0.x/HTML/Content/Authoring/AdministratorsGuide/Partitions/SwappingPartitions.htm
for language specification
"""
assert_table_lineage_equal(
"SELECT swap_partitions_between_tables('staging', 'min-range-value', 'max-range-value', 'target')",
{"staging"},
{"target"},
dialect=dialect,
)

0 comments on commit 4573766

Please sign in to comment.