Skip to content

Add support for 'when' field in redis.lookup block#397

Closed
ZdravkoDonev-redis wants to merge 1 commit into
datayoga-io:mainfrom
ZdravkoDonev-redis:main
Closed

Add support for 'when' field in redis.lookup block#397
ZdravkoDonev-redis wants to merge 1 commit into
datayoga-io:mainfrom
ZdravkoDonev-redis:main

Conversation

@ZdravkoDonev-redis

Copy link
Copy Markdown
Contributor

In order to reduce latency, we can avoid doing lookups altogether by looking in some of the fields in the input data and deciding whether we should doo a lookup in advance. Thus with this commit, a 'when' field is introduced to support this functionality

In order to reduce latency, we can avoid doing lookups altogether by looking in some of the fields in the input data and deciding whether we should doo a lookup in advance. Thus with this commit, a 'when' field is introduced to support this functionality

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds conditional execution support to the redis.lookup block through a new when field, allowing lookups to be skipped based on input data conditions to reduce latency.

Key Changes:

  • Added when configuration field supporting JMESPath and SQL expressions
  • Modified lookup execution logic to evaluate conditions and skip lookups when conditions are false
  • Added comprehensive integration tests for both JMESPath and SQL condition languages

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
core/src/datayoga_core/blocks/redis/lookup/block.py Implements conditional lookup logic with when expression compilation and evaluation
core/src/datayoga_core/blocks/redis/lookup/block.schema.json Adds schema definition for the optional when field with expression and language properties
integration-tests/test_redis_lookup.py Adds parameterized test validating when condition functionality for both expression languages
integration-tests/resources/jobs/tests/redis_lookup_with_when_jmespath.dy.yaml Job configuration demonstrating JMESPath when condition usage
integration-tests/resources/jobs/tests/redis_lookup_with_when_sql.dy.yaml Job configuration demonstrating SQL when condition usage
integration-tests/resources/data/lookup_with_nulls.csv Test data file with records having null/empty branch_id values for condition testing
core/pyproject.toml Adds redis and testcontainers as dev dependencies

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"job_name",
[("tests.redis_lookup_with_when_jmespath"),
("tests.redis_lookup_with_when_sql")])
def test_redis_lookup_with_when_condition(job_name: str):

Copilot AI Dec 21, 2025

Copy link

Choose a reason for hiding this comment

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

The test function lacks coverage for error handling scenarios when the when condition evaluation fails. Consider adding test cases for malformed expressions or invalid condition syntax to ensure the error handling in block.py (lines 61-63) works correctly.

Copilot uses AI. Check for mistakes.
3,set_key,branch_3
4,sorted_set_key,branch_4
5,list_key,

Copilot AI Dec 21, 2025

Copy link

Choose a reason for hiding this comment

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

The CSV file contains an empty line at the end which may cause unexpected behavior during parsing. Remove the trailing empty line to ensure consistent data processing.

Suggested change

Copilot uses AI. Check for mistakes.
condition_result = self.when_expression.search(record)
should_lookup = bool(condition_result)
if not should_lookup:
logger.debug(f"Skipping lookup for record {idx} due to when condition")

Copilot AI Dec 21, 2025

Copy link

Choose a reason for hiding this comment

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

The debug message could be more informative by including the condition result or expression details to aid in troubleshooting. Consider adding the evaluated condition value to the log message.

Suggested change
logger.debug(f"Skipping lookup for record {idx} due to when condition")
logger.debug(f"Skipping lookup for record {idx} due to when condition evaluated as {condition_result!r}")

Copilot uses AI. Check for mistakes.

@spicy-sauce spicy-sauce left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi Zdravko,
The CI is failing partly because this PR has main as both the head and base branch, which prevents the auto-commit workflows (generate-docs, generate-jsonschemas) from pushing changes back.

Could you push your changes to a feature branch (e.g., add-redis-lookup-when-field) and create a new PR from there to main?

Note: There's also a separate CI issue with a pymssql/setuptools_scm dependency conflict that we'll need to fix on our end.

@ZdravkoDonev-redis

Copy link
Copy Markdown
Contributor Author

Hi Zdravko, The CI is failing partly because this PR has main as both the head and base branch, which prevents the auto-commit workflows (generate-docs, generate-jsonschemas) from pushing changes back.

Could you push your changes to a feature branch (e.g., add-redis-lookup-when-field) and create a new PR from there to main?

Note: There's also a separate CI issue with a pymssql/setuptools_scm dependency conflict that we'll need to fix on our end.

Hi, Yossi! :)

Sure I'll do that today. And will try to resolve the copilot comments as well.

@ZdravkoDonev-redis

Copy link
Copy Markdown
Contributor Author

Closed in favor of - #398

@ZdravkoDonev-redis

Copy link
Copy Markdown
Contributor Author

@spicy-sauce Please have a look at the new PR - #398

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants