Skip to content

Refactor SplitPart expression #1415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -639,16 +639,6 @@ def strtok_sql(self, expression: local_expression.StrTok) -> str:

return f"SPLIT_PART({expr_name}, '{delimiter}', {part_num})"

def splitpart_sql(self, expression: local_expression.SplitPart) -> str:
"""
:param expression: local_expression.SplitPart expression to be parsed
:return: Converted expression (SPLIT_PART) compatible with Databricks
"""
expr_name = self.sql(expression.this)
delimiter = self.sql(expression.expression)
part_num = self.sql(expression.args["partNum"])
return f"SPLIT_PART({expr_name}, {delimiter}, {part_num})"

def transaction_sql(self, expression: exp.Transaction) -> str:
"""
Skip begin command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ class TryToTimestamp(Func):
arg_types = {"this": True, "format": False}


class SplitPart(Func):
arg_types = {"this": True, "expression": False, "partNum": False}


class StrTok(Func):
arg_types = {"this": True, "expression": False, "partNum": False}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _parse_date_add(args: list) -> exp.DateAdd:
return exp.DateAdd(this=seq_get(args, 2), expression=seq_get(args, 1), unit=seq_get(args, 0))


def _parse_split_part(args: list) -> local_expression.SplitPart:
def _parse_split_part(args: list) -> exp.SplitPart:
if len(args) != 3:
err_msg = f"Error Parsing args `{args}`. Number of args must be 3, given {len(args)}"
raise ParseError(err_msg)
Expand All @@ -107,7 +107,7 @@ def _parse_split_part(args: list) -> local_expression.SplitPart:
part_num_if = exp.If(this=cond, true=exp.Literal.number(1), false=part_num_literal)

part_num = part_num_if if part_num_if is not None else part_num_literal
return local_expression.SplitPart(this=seq_get(args, 0), expression=seq_get(args, 1), partNum=part_num)
return exp.SplitPart(this=seq_get(args, 0), delimiter=seq_get(args, 1), part_index=part_num)


def _div0_to_if(args: list) -> exp.If:
Expand Down