Skip to content

Copy source before modifying it in GroupBy #972

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 4 commits into
base: main
Choose a base branch
from
Open
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
21 changes: 20 additions & 1 deletion api/py/ai/chronon/group_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import copy
import inspect
import json
import logging
Expand Down Expand Up @@ -515,7 +516,7 @@ def _normalize_source(source):

if not isinstance(sources, list):
sources = [sources]
sources = [_sanitize_columns(_normalize_source(source)) for source in sources]
sources = [_sanitize_columns(_normalize_source(_copy_source(source))) for source in sources]

deps = [dep for src in sources for dep in utils.get_dependencies(src, dependencies, lag=lag)]

Expand Down Expand Up @@ -557,3 +558,21 @@ def _normalize_source(source):
)
validate_group_by(group_by)
return group_by


def _copy_source(source: ttypes.Source) -> ttypes.Source:
# Hold a reference to the join in a join source so that the
# module name can be extracted from GC referrers later on
join = None
if isinstance(source, ttypes.JoinSource):
join = source.join
elif isinstance(source, ttypes.Source) and source.joinSource:
join = source.joinSource.join

source_copy = copy.deepcopy(source)

if isinstance(source_copy, ttypes.JoinSource):
source_copy.join = join
elif isinstance(source_copy, ttypes.Source) and source_copy.joinSource:
source_copy.joinSource.join = join
return source_copy