Skip to content
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

Add SQL exprs needed for custom offset window #1575

Merged
merged 5 commits into from
Dec 21, 2024

Conversation

courtneyholcomb
Copy link
Contributor

This includes a CASE expression, an integer expression, an arithmetic expression, and some updates to the add time expression & window function expressions. These are all needed to build the following SQL column:

CASE
  WHEN ds__martian_day__first_value__offset + INTERVAL (ds__day__row_number - 1) day <= ds__martian_day__last_value__offset
    THEN ds__martian_day__first_value__offset + INTERVAL (ds__day__row_number - 1) day
  ELSE ds__martian_day__last_value__offset
  END AS metric_time__day

Note that the first commit is moving the sql_exprs file into metricflow-semantics, which is needed for a commit further up the stack.

@cla-bot cla-bot bot added the cla:yes label Dec 18, 2024
@courtneyholcomb courtneyholcomb added the Run Tests With Other SQL Engines Runs the test suite against the SQL engines in our target environment label Dec 18, 2024
@github-actions github-actions bot removed the Run Tests With Other SQL Engines Runs the test suite against the SQL engines in our target environment label Dec 18, 2024
@courtneyholcomb courtneyholcomb force-pushed the court/custom-offset1 branch 4 times, most recently from 4390e63 to e193228 Compare December 19, 2024 15:18
Copy link
Contributor

@WilliamDee WilliamDee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I'm not super familiar with using case when exprs, so I want to defer to @plypaul for that. But the other 2 looks good!



@dataclass(frozen=True, eq=False)
class SqlArithmeticExpression(SqlExpressionNode):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For potentially cleanup, seems like this can replace SqlRatioComputationExpression unless we want to explicitly have a node for that. But if we wanted to do that, i don't see why we wouldn't want to do it for other operations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered that but decided not to because the ratio expression has a bunch of extra logic related to casting & NULLIF, and I wasn't sure we would always want that for this node!

Comment on lines 1811 to 1812
parent_nodes += (when,)
parent_nodes += (then,)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: don't have to do it

parent_nodes += (when, then)

)

@classmethod
def id_prefix(cls) -> IdPrefix: # noqa: D102
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this PR as we can do a batch cleanup, but we can now use @override to avoid the D102 for many of the implemented methods.

def bind_parameter_set(self) -> SqlBindParameterSet: # noqa: D102
return SqlBindParameterSet()

def __repr__(self) -> str: # noqa: D105
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this PR as we can do a batch cleanup, but this can be moved to a common method in the base class.

sql=f"DATEADD({granularity.value}, {count_rendered}, {arg_rendered.sql})",
bind_parameter_set=arg_rendered.bind_parameter_set,
sql=f"DATEADD({granularity.value}, {count_sql}, {arg_rendered.sql})",
bind_parameter_set=SqlBindParameterSet.merge_iterable(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't need to be changed, but you can also do arg_rendered.bind_parameter_set.merge(count_rendered.bind_parameter_set)

This includes a CASE expression, an integer expression, and some updates to the add time expression & the window function expression.
Not totally relevant to this PR, but these seem to have been removed somehow.
@courtneyholcomb courtneyholcomb enabled auto-merge (squash) December 21, 2024 02:06
@courtneyholcomb courtneyholcomb merged commit 48e85f5 into main Dec 21, 2024
11 checks passed
@courtneyholcomb courtneyholcomb deleted the court/custom-offset1 branch December 21, 2024 02:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants