Load only the required lookups for MSQ tasks#16358
Conversation
eb435a5 to
32c1fa4
Compare
kfaraz
left a comment
There was a problem hiding this comment.
Thanks for the changes, @Akshat-Jain ! Left some feedback.
ff669a7 to
0149079
Compare
|
Based on offline discussion, I have modified the approach to populate a new field The primary rationale behind this change is that it allows us to limit the scope of our changes to MSQ, since queryContext is a widely used field in a lot of areas. |
a2727b1 to
191eb42
Compare
| return LookupLoadingSpec.NONE; | ||
| } else if (lookupLoadingMode == LookupLoadingSpec.Mode.ONLY_REQUIRED) { | ||
| List<String> lookupsToLoad = (List<String>) getContext().get(PlannerContext.CTX_LOOKUPS_TO_LOAD); | ||
| if (lookupsToLoad == null) { |
There was a problem hiding this comment.
We should check for empty too.
There was a problem hiding this comment.
Technically ONLY_REQUIRED can use an empty list, so it's fine?
We could technically merge NONE and ONLY_REQUIRED from a functional point of view. but I like having them separate from a user consumption point of view.
Thoughts?
There was a problem hiding this comment.
Yes, exactly. Since we have decided to keep them distinct, ONLY_REQUIRED must always have a non-empty list.
The other alternative would be to get rid of the enum value NONE altogether and then the lists can be empty. But, as you said, I like having NONE too, as it clarifies the intent much better.
There was a problem hiding this comment.
Have made the change.
| } | ||
|
|
||
| /** | ||
| * Returns the lookup loading spec for a given task. |
There was a problem hiding this comment.
| * Returns the lookup loading spec for a given task. | |
| * Lookup loading spec for MSQ tasks. |
There was a problem hiding this comment.
It's not limited to MSQ tasks though? Right now we consume it only in MSQ, but there's no restriction to not use this for other tasks in future.
…nerContext's LookupLoadingSpec
|
@kfaraz @cryptoe Have made some changes in the latest commit bb4a093. Summarizing them here:
Hope this works? Appreciate your thoughts on these changes, thanks! |
adarshsanjeev
left a comment
There was a problem hiding this comment.
The calcite side changes look good to me
Why is this a problem? There is no harm in pointing to the same instance if the instance is immutable. |
@kfaraz We can't add any lookups to load to LookupLoadingSpec.NONE as that ends up updating the constant itself. What's the suggestion to deal with such issues? |
|
@kfaraz Have made the change to use |
Yes, this is what I had meant 🙂 . |
cryptoe
left a comment
There was a problem hiding this comment.
Minor changes.
Overall LGTM
Thanks @Akshat-Jain for the patch.
kfaraz
left a comment
There was a problem hiding this comment.
Changes look good to me.
My only concern is why we can't use Query.equals() in the test assertions anymore. All other comments are non-blockers and may be addressed later.
| List<String> lookupsToLoad = (List<String>) context.get(PlannerContext.CTX_LOOKUPS_TO_LOAD); | ||
| if (expectedLookupLoadingSpec != null) { | ||
| Assert.assertEquals(expectedLookupLoadingSpec.getMode().toString(), lookupLoadingMode); | ||
| if (expectedLookupLoadingSpec.getMode().equals(LookupLoadingSpec.Mode.ONLY_REQUIRED)) { | ||
| Assert.assertEquals(new ArrayList<>(expectedLookupLoadingSpec.getLookupsToLoad()), lookupsToLoad); | ||
| } else { | ||
| Assert.assertNull(lookupsToLoad); | ||
| } | ||
| } else { | ||
| Assert.assertEquals(LookupLoadingSpec.Mode.NONE.toString(), lookupLoadingMode); | ||
| Assert.assertNull(lookupsToLoad); | ||
| } | ||
| } |
There was a problem hiding this comment.
Rather than this if-else chain, we can just build a LookupLoadingSpec object from the values in the context and then do an equals check with the expected lookup loading spec. You would also need to override equals and hashCode in LookupLoadingSpec.
There was a problem hiding this comment.
I can try taking care of this in the next PR with compaction changes, hope that works.
With this PR changes, MSQ tasks (MSQControllerTask and MSQWorkerTask) only load the required lookups during querying and ingestion, based on the value of CTX_LOOKUPS_TO_LOAD key in the query context.
Description
With this PR changes, MSQ tasks (MSQControllerTask and MSQWorkerTask) only load the required lookups during querying and ingestion, based on the value of
CTX_LOOKUPS_TO_LOADkey in the query context.Test plan
Apart from adding unit tests, the following manual testing was done for the different lookup loading modes.
Lookup loading mode =
ONLY_REQUIREDI verified that only the required lookups were being loaded in the following operations:
LOOKUP()function.Lookup loading mode =
NONEI verified that no lookups were being loaded in the following operations:
LOOKUP()function.Lookup loading mode =
ALLThese are operations that aren't touched by this PR. I verified that all lookups were being loaded in the following operations:
This PR has: