Skip to content

Add default configuration for select query 'fromNext' parameter#3986

Merged
fjy merged 4 commits intoapache:masterfrom
jon-wei:fromnext
Mar 2, 2017
Merged

Add default configuration for select query 'fromNext' parameter#3986
fjy merged 4 commits intoapache:masterfrom
jon-wei:fromnext

Conversation

@jon-wei
Copy link
Copy Markdown
Contributor

@jon-wei jon-wei commented Mar 1, 2017

This PR adds a configuration option that sets a default value for the fromNext property of the SelectQuery's pagingSpec.

If fromNext is omitted, the value set by druid.query.select.enableFromNextDefault will be used.

This is a continuation of #2767 by @navis, based on the discussion in that thread (see #2767 (comment))

Comment thread docs/content/querying/select-query.md Outdated
}
```

Note that specifying the `fromNext` option in the `pagingSpec` overrides the default value set by `druid.query.select.enableFromNextDefault` in the server configuration. See [Server configuration](#server-configuration) for more details.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These docs, taken as a whole, are kind of confusing. The paragraph above (starting with "Note that in the second query") discusses fromNext in a tone that suggests it's off by default, but then the next section says it's on by default.

Could you reword these docs and the example json to make more sense given that fromNext defaults to true?

I think the only reason anyone would want fromNext to default to false is for compatibility with query tools that don't understand fromNext, and the docs should reflect that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I rewrote part of the docs to better explain the query pagination and fromNext, with mention of backwards compatibility

private final Map<String, Integer> pagingIdentifiers;
private final int threshold;
private final boolean fromNext;
private final Boolean fromNext;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Make this boolean and resolve the default fromNext in the constructor, that way it'll be consistent for the entire query when it's forwarded from the broker to the data nodes. (If you don't do this, then when the cluster's data nodes are partially updated, it'll be in a weird state where fromNext is false on some data nodes and true on others for the same query, making it impossible to get correct behavior)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You might have to @JacksonInject the config to get this to work.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

cool, changed this to resolve fromNext in the constructor

if (offset == null) {
offset = PagingOffset.toOffset(0, descending);
} else if (fromNext) {
} else if (shouldApplyFromNext(defaultFromNext)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This can change back to the old logic when fromNext becomes a boolean again.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

reverted


public class SelectQueryConfig
{
public static String CTX_KEY_ENABLE_FROM_NEXT_DEFAULT = "enableFromNextDefault";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This isn't a context key so it's misleading for it to start with CTX_KEY_. It seems like it's only used in the tests, so IMO it doesn't really need to be a constant at all. But if you want it to be, then please give it another name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

renamed, removed the "CTX_KEY_" portion

}

public byte[] getCacheKey()
public byte[] getCacheKey(boolean defaultFromNext)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This can change back to the old logic when fromNext becomes a boolean again.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

reverted

@jon-wei
Copy link
Copy Markdown
Contributor Author

jon-wei commented Mar 1, 2017

@gianm I reverted the boolean-related changes in PagingSpec; the changes where I create a SelectQueryConfig supplier in the various unit test suites and SelectQueryToolChest were related to the older patch where I resolved fromNext later and not in the constructor, but I decided to leave these in, I think they could be useful if we add more select config options later on, and I feel like they do no harm there

Copy link
Copy Markdown
Contributor

@gianm gianm left a comment

Choose a reason for hiding this comment

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

Looks good other than the annotations.

private final Supplier<SelectQueryConfig> configSupplier;

@JsonCreator
@Inject
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You want this injected by Jackson, not a Guice injector, so remove the @Inject annotation and add @JacksonInject to the configSupplier. Check out JavaScriptExtractionFn for an example.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

got it, thanks, fixed this

Arrays.<String>asList("index"),
null,
new PagingSpec(null, 3),
new PagingSpec(null, 3, null),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Might as well make this new PagingSpec(null, 3, true).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I made that null intentionally for testing that it would grab the default value from the config

@gianm gianm closed this Mar 1, 2017
@gianm gianm reopened this Mar 1, 2017
Copy link
Copy Markdown
Contributor

@gianm gianm left a comment

Choose a reason for hiding this comment

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

👍 after travis

@fjy
Copy link
Copy Markdown
Contributor

fjy commented Mar 2, 2017

👍

This was the PR I thought I was merging before accidentally merging #3989

@fjy fjy merged commit 5fb1638 into apache:master Mar 2, 2017
@jon-wei jon-wei deleted the fromnext branch October 6, 2017 22:19
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.

3 participants