-
Notifications
You must be signed in to change notification settings - Fork 96
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
Fix Dimension Serialization Problem with Nested Queries #15
Conversation
d1bb540
to
868af8c
Compare
|
||
while (context != null) { | ||
Object parent = context.getCurrentValue(); | ||
if (parent instanceof DruidQuery) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we extract the "tree walk to find the next level up" into it's own method? Both of the helper methods in this class are currently doing that work. Optional<DruidQuery>
may be a useful return type to use, since it may let us keep things clean.
Here's one (untested) idea:
public <T> Optional<T> withContainingQuery(JsonGenerator gen, Function<DruidQuery, T> success) {
JsonStreamContext context = gen.getOutputContext();
while (context != null) {
Object parent = context.getCurrentValue();
if (parent instanceof DruidQuery) {
return Optional.of(success.apply((DruidQuery) parent));
}
context = context.getParent();
}
return Optional.empty();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am amazed by how much line reduction this implementation provides, however I am a bit worried about the readability reduction associated with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see how this reduces readability any. Personally, I generally find it more readable when things are broken out into helper methods, especially if there is duplication.
First, the helper methods abstract away some of the "how" and replace it with "what." I find this good for two reasons: One, I generally find the "what" more interesting than the "how" when I'm starting to dig into some code. Two, I generally find it easier to understand the "how" when I already know the "what," then I do to derive the "what" from the "how."
Second, this makes it immediately clear that this code is identical both here and in the other helper method. Without this method, I would have to read the two code blocks very closely in order to confirm that they are doing the same thing (as opposed to very subtly different things). That in and of itself is a huge readability bonus.
Though the success
variable could probably stand to be renamed. Perhaps something like queryTransform
? I'd have to dig in a bit more to get enough context to provide a better suggestion.
868af8c
to
90c44c0
Compare
<version>${maven-jar-plugin-version}</version> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it was mistakenly pulled in. I think this is already on master
, right?
90c44c0
to
91d81d3
Compare
ba1d4f9
to
8ba60cb
Compare
return Optional.of( | ||
((DruidQuery) parent) | ||
return getDruidQuery(gen, druidQuery -> | ||
druidQuery | ||
.getDataSource() | ||
.getPhysicalTables() | ||
.iterator() | ||
.next() | ||
.getPhysicalColumnName(apiName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can actually all be unwrapped since it can fit on 1 line now
8e388b0
to
f9b58ed
Compare
f9b58ed
to
3adb6fe
Compare
/** | ||
* JSON tree walk to find the druid query context of the current context, | ||
* returns the current context if current context is a druid query. | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Javadoc is incorrect. This query returns the mapped value of the druid query under the success function if the current context if the current context is a druid query.
3adb6fe
to
5e3060d
Compare
5e3060d
to
3b003e8
Compare
👍 |
3b003e8
to
4861ef4
Compare
👍 Once the build passes. |
Build is failing on one of the tests. |
…tasource, added tests for corresponding serialization
4861ef4
to
b4d1c71
Compare
I'm pretty sure the build is failing due to load during tests caused by a too-tight wait period. Since nothing else relevant to this PR is failing, marking this as mergeable. |
DimensionToDefaultDimensionSpec
serializer to serialize dimension to apiName if it is not the inner most queryhasInnerQuery
toUtil
in serializer package to determine if current query is the inner most query or notDimensionToDefaultDimensionSpec