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

Fix Dimension Serialization Problem with Nested Queries #15

Merged
merged 1 commit into from
Aug 31, 2016

Conversation

garyluoex
Copy link
Collaborator

@garyluoex garyluoex commented Aug 30, 2016

  • Modified DimensionToDefaultDimensionSpec serializer to serialize dimension to apiName if it is not the inner most query
  • Added helper hasInnerQuery to Util in serializer package to determine if current query is the inner most query or not
  • Added tests for DimensionToDefaultDimensionSpec


while (context != null) {
Object parent = context.getCurrentValue();
if (parent instanceof DruidQuery) {
Copy link
Collaborator

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();
}

Copy link
Collaborator Author

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.

Copy link
Contributor

@archolewa archolewa Aug 30, 2016

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.

<version>${maven-jar-plugin-version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Copy link
Collaborator

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?

return Optional.of(
((DruidQuery) parent)
return getDruidQuery(gen, druidQuery ->
druidQuery
.getDataSource()
.getPhysicalTables()
.iterator()
.next()
.getPhysicalColumnName(apiName)
Copy link
Collaborator

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

@garyluoex garyluoex force-pushed the NestedQueryDimensionSerialization branch 2 times, most recently from 8e388b0 to f9b58ed Compare August 31, 2016 05:09
@garyluoex garyluoex force-pushed the NestedQueryDimensionSerialization branch from f9b58ed to 3adb6fe Compare August 31, 2016 06:07
/**
* JSON tree walk to find the druid query context of the current context,
* returns the current context if current context is a druid query.
*
Copy link
Contributor

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.

@cdeszaq
Copy link
Collaborator

cdeszaq commented Aug 31, 2016

👍

@michael-mclawhorn
Copy link
Contributor

michael-mclawhorn commented Aug 31, 2016

👍 Once the build passes.

@michael-mclawhorn
Copy link
Contributor

Build is failing on one of the tests.

…tasource, added tests for corresponding serialization
@cdeszaq
Copy link
Collaborator

cdeszaq commented Aug 31, 2016

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.

@garyluoex garyluoex merged commit b4d1c71 into master Aug 31, 2016
@garyluoex garyluoex deleted the NestedQueryDimensionSerialization branch August 31, 2016 19:16
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.

4 participants