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

Indicate what fields are getting ignored when adding configs #8514

Merged
merged 17 commits into from
Apr 27, 2022

Conversation

saurabhd336
Copy link
Contributor

@saurabhd336 saurabhd336 commented Apr 12, 2022

This PR adds "unrecognizedProperties" to POST /tables/, PUT /tables/{tableName} and POST /tables/validate. This field will be a flattened map of json keys to values that will let the API users know when certain field(s) in the input config json are being ignored.

@saurabhd336
Copy link
Contributor Author

GH Issue: #8318

@KKcorps KKcorps requested a review from npawar April 13, 2022 10:35
@codecov-commenter
Copy link

codecov-commenter commented Apr 13, 2022

Codecov Report

Merging #8514 (00d6277) into master (b0144cf) will decrease coverage by 1.04%.
The diff coverage is 84.44%.

@@             Coverage Diff              @@
##             master    #8514      +/-   ##
============================================
- Coverage     70.65%   69.61%   -1.05%     
+ Complexity     4314     4313       -1     
============================================
  Files          1692     1693       +1     
  Lines         88751    88786      +35     
  Branches      13468    13470       +2     
============================================
- Hits          62708    61806     -902     
- Misses        21657    22611     +954     
+ Partials       4386     4369      -17     
Flag Coverage Δ
integration1 27.31% <35.55%> (+0.07%) ⬆️
integration2 ?
unittests1 66.93% <68.18%> (+<0.01%) ⬆️
unittests2 14.17% <51.11%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...inot/controller/api/resources/SuccessResponse.java 100.00% <ø> (ø)
...ain/java/org/apache/pinot/spi/utils/JsonUtils.java 67.06% <68.18%> (+0.10%) ⬆️
...ontroller/api/resources/ConfigSuccessResponse.java 100.00% <100.00%> (ø)
...oller/api/resources/PinotTableRestletResource.java 50.67% <100.00%> (+0.49%) ⬆️
...apache/pinot/common/helix/ExtraInstanceConfig.java 0.00% <0.00%> (-100.00%) ⬇️
...t/core/plan/StreamingInstanceResponsePlanNode.java 0.00% <0.00%> (-100.00%) ⬇️
...ore/operator/streaming/StreamingResponseUtils.java 0.00% <0.00%> (-100.00%) ⬇️
...ager/realtime/PeerSchemeSplitSegmentCommitter.java 0.00% <0.00%> (-100.00%) ⬇️
...ator/streaming/StreamingSelectionOnlyOperator.java 0.00% <0.00%> (-90.00%) ⬇️
...he/pinot/core/plan/StreamingSelectionPlanNode.java 0.00% <0.00%> (-88.89%) ⬇️
... and 113 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 89836a5...00d6277. Read the comment docs.

@saurabhd336 saurabhd336 changed the title Indicate what fields are getting ignored when adding configs (WIP) Indicate what fields are getting ignored when adding configs Apr 14, 2022
@saurabhd336 saurabhd336 force-pushed the configJsonIgnoreNotify branch 10 times, most recently from 8980030 to 55f7d2b Compare April 21, 2022 06:44
Copy link
Contributor

@Jackie-Jiang Jackie-Jiang left a comment

Choose a reason for hiding this comment

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

This is awesome! I can see it improve user experience drastically!

import java.util.Map;

public final class ConfigSuccessResponse extends SuccessResponse {
private final Map<String, Object> _unparseableProps;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest renaming the field, same for other places

Suggested change
private final Map<String, Object> _unparseableProps;
private final Map<String, Object> _ unrecognizedProperties;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack


public static <T> T stringToObject(String jsonString, Class<T> valueType)
throws IOException {
return DEFAULT_READER.forType(valueType).readValue(jsonString);
}

public static <T> JsonPojoWithUnparsableProps<T> stringToObjectAndUnparseableProps(String jsonString, Class<T> klass)
Copy link
Contributor

Choose a reason for hiding this comment

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

Name the second parameter valueType for consistency

Copy link
Contributor

Choose a reason for hiding this comment

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

(optional) I feel returning a Pair<T, Map<String, Object>> should be enough

Copy link
Contributor Author

@saurabhd336 saurabhd336 Apr 22, 2022

Choose a reason for hiding this comment

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

Ack on https://github.com/apache/pinot/pull/8514/files#r855450400
#2 The Pair class defined within the project expects 'T' to be extending Serializable, which would mean changing the base response classes. Other Pair implementations would need dependencies. Leaving it as it is for now.. Will revisit.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use org.apache.commons.lang3.tuple.Pair? I think we should already have the dependency

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack

int _primitiveIntegerField;
String _stringField;
Long _longField;
Klass _classField;
Copy link
Contributor

Choose a reason for hiding this comment

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

(minor) I think we use Clazz in most of the places

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack

}

private static Stream<Map.Entry<String, Object>> flatten(Map.Entry<String, Object> entry) {

Copy link
Contributor

Choose a reason for hiding this comment

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

(nit) remove empty line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack

Copy link
Contributor

@npawar npawar left a comment

Choose a reason for hiding this comment

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

looking good so far! minior comments

@@ -492,18 +498,22 @@ public SuccessResponse updateTableConfig(
@ApiOperation(value = "Validate table config for a table",
notes = "This API returns the table config that matches the one you get from 'GET /tables/{tableName}'."
+ " This allows us to validate table config before apply.")
public String checkTableConfig(
public ObjectNode checkTableConfig(
Copy link
Contributor

Choose a reason for hiding this comment

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

should we take this opportunity to also wrap this into a ConfigValidationResponse object?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I checked this. But it's getting a little tricky to do it in a backward compatible way. Since ConfigSuccessResponse extends SuccesResponse while this function returns a custom object..



@JsonIgnoreProperties(ignoreUnknown = true)
public class TestClass {
Copy link
Contributor

Choose a reason for hiding this comment

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

should this just be inside JsonUtilsTest? It's very non-generic to be by itself

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Jackson is not able to work with inner classes. Hence had added it here.
Renamed to something more relevant

ControllerTestUtils
.sendPostRequest(StringUtil.join("/", ControllerTestUtils.getControllerBaseApiUrl(), "tables", "validate"),
offlineTableConfig.toJsonString());
ControllerTestUtils.sendPostRequest(
Copy link
Contributor

Choose a reason for hiding this comment

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

would be nice to have couple of tests in validate.

  1. validation success, but unparseable props
  2. validation failed
    to make sure both these experiences are unaffected by this change
    (optional) test case in add and update too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added unrecognizedProperties tests for add, update and validate table APIs.
Validation failed tests already exist for all APIs.

Copy link
Contributor

@npawar npawar left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@Jackie-Jiang Jackie-Jiang left a comment

Choose a reason for hiding this comment

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

LGTM. Only minor comments


public static <T> T stringToObject(String jsonString, Class<T> valueType)
throws IOException {
return DEFAULT_READER.forType(valueType).readValue(jsonString);
}

public static <T> Pair<T, Map<String, Object>> stringToObjectAndUnparseableProps(String jsonString,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest renaming

Suggested change
public static <T> Pair<T, Map<String, Object>> stringToObjectAndUnparseableProps(String jsonString,
public static <T> Pair<T, Map<String, Object>> stringToObjectAndUnrecognizedProperties(String jsonString,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack

@@ -273,6 +274,20 @@ public void testFlatten()
}
}

@Test
public void testUnparseableJson() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest renaming

Suggested change
public void testUnparseableJson() throws Exception {
public void testUnrecognizedProperties() throws Exception {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack

String tableConfigStr,
@ApiParam(value = "comma separated list of validation type(s) to skip. supported types: (ALL|TASK|UPSERT)")
@QueryParam("validationTypesToSkip") @Nullable String typesToSkip, @Context HttpHeaders httpHeaders,
@Context Request request) {
// TODO introduce a table config ctor with json string.
Pair<TableConfig, Map<String, Object>> tableConfigAndUnparsedProps;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest renaming

Suggested change
Pair<TableConfig, Map<String, Object>> tableConfigAndUnparsedProps;
Pair<TableConfig, Map<String, Object>> tableConfigAndUnrecognizedProperties;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack

@npawar npawar merged commit b38a59b into apache:master Apr 27, 2022
npawar pushed a commit that referenced this pull request May 3, 2022
This PR is a follow up of #8514. It adds the "unrecognizedProperties" fields to /schemas and /tableConfigs APIs
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.

None yet

4 participants