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

add validation for upsert tables #6149

Merged
merged 3 commits into from
Oct 16, 2020
Merged

Conversation

yupeng9
Copy link
Contributor

@yupeng9 yupeng9 commented Oct 15, 2020

Description

Part of a series of PRs for #4261
Check this doc out for the new design

@codecov-io
Copy link

codecov-io commented Oct 15, 2020

Codecov Report

Merging #6149 into master will increase coverage by 6.29%.
The diff coverage is 60.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6149      +/-   ##
==========================================
+ Coverage   66.44%   72.74%   +6.29%     
==========================================
  Files        1075     1231     +156     
  Lines       54773    58072    +3299     
  Branches     8168     8572     +404     
==========================================
+ Hits        36396    42245    +5849     
+ Misses      15700    13037    -2663     
- Partials     2677     2790     +113     
Flag Coverage Δ
#integration 45.09% <49.14%> (?)
#unittests 63.93% <38.09%> (?)

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

Impacted Files Coverage Δ
...ot/broker/broker/AllowAllAccessControlFactory.java 100.00% <ø> (ø)
.../helix/BrokerUserDefinedMessageHandlerFactory.java 52.83% <0.00%> (-13.84%) ⬇️
...ava/org/apache/pinot/client/AbstractResultSet.java 53.33% <0.00%> (-3.81%) ⬇️
.../main/java/org/apache/pinot/client/Connection.java 44.44% <0.00%> (-4.40%) ⬇️
.../org/apache/pinot/client/ResultTableResultSet.java 24.00% <0.00%> (-10.29%) ⬇️
...not/common/assignment/InstancePartitionsUtils.java 78.57% <ø> (+5.40%) ⬆️
.../apache/pinot/common/exception/QueryException.java 90.27% <ø> (+5.55%) ⬆️
...pinot/common/function/AggregationFunctionType.java 98.27% <ø> (-1.73%) ⬇️
.../pinot/common/function/DateTimePatternHandler.java 83.33% <ø> (ø)
...ot/common/function/FunctionDefinitionRegistry.java 88.88% <ø> (+44.44%) ⬆️
... and 982 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 a910f5d...8704e55. Read the comment docs.

@@ -230,6 +234,38 @@ private static void validateIngestionConfig(@Nullable IngestionConfig ingestionC
}
}

/**
* Validates the upsert-related configurations
*
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add some javadoc on the checks performed here

Comment on lines 246 to 248
if (schema.getPrimaryKeyColumns() == null || schema.getPrimaryKeyColumns().isEmpty()) {
throw new IllegalStateException("Upsert table must have primary key columns in the schema.");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (schema.getPrimaryKeyColumns() == null || schema.getPrimaryKeyColumns().isEmpty()) {
throw new IllegalStateException("Upsert table must have primary key columns in the schema.");
}
Preconditions.checkState(CollectionUtils.isNotEmpty(schema.getPrimaryKeyColumns()), "Upsert table must have primary key columns in the schema");

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 saw some checks in this class use precondition, others use IllegalStateException. Shall we make it consistent? @icefury71

Copy link
Contributor

Choose a reason for hiding this comment

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

Will do so in my next pass

Comment on lines 250 to 253
if (tableConfig.getRoutingConfig() == null || !tableConfig.getRoutingConfig().getInstanceSelectorType()
.equalsIgnoreCase(RoutingConfig.REPLICA_GROUP_INSTANCE_SELECTOR_TYPE)) {
throw new IllegalStateException("Upsert table must use replicaGroup as the routing config.");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This can potentially have NPE

Suggested change
if (tableConfig.getRoutingConfig() == null || !tableConfig.getRoutingConfig().getInstanceSelectorType()
.equalsIgnoreCase(RoutingConfig.REPLICA_GROUP_INSTANCE_SELECTOR_TYPE)) {
throw new IllegalStateException("Upsert table must use replicaGroup as the routing config.");
}
Preconditions.checkState(tableConfig.getRoutingConfig() != null && RoutingConfig.REPLICA_GROUP_INSTANCE_SELECTOR_TYPE. equalsIgnoreCase(tableConfig.getRoutingConfig().getInstanceSelectorType()), "Upsert table must use replica-group based routing")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why? this seems the same rewrite.

Copy link
Contributor

Choose a reason for hiding this comment

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

tableConfig.getRoutingConfig().getInstanceSelectorType() might be null

Copy link
Contributor Author

Choose a reason for hiding this comment

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

then it's the same :)

Comment on lines 258 to 261
if (streamConfig.getConsumerTypes().size() != 1
|| streamConfig.getConsumerTypes().get(0) != StreamConfig.ConsumerType.LOWLEVEL) {
throw new IllegalStateException("Upsert table must use low-level streaming consumer type.");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (streamConfig.getConsumerTypes().size() != 1
|| streamConfig.getConsumerTypes().get(0) != StreamConfig.ConsumerType.LOWLEVEL) {
throw new IllegalStateException("Upsert table must use low-level streaming consumer type.");
}
Preconditions.checkState(streamConfig.hasLowLevelConsumerType() && !streamConfig.hasHighLevelConsumerType(), ""Upsert table must use low-level streaming consumer type");

}
}
// check type type is realtime
if (tableConfig.getTableType() != TableType.REALTIME) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use precondition, also recommend reorder the checks in this order: upsert mode -> primary key -> table type -> consumer type -> routing type, which IMO is more intuitive

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sgtm

@icefury71
Copy link
Contributor

Can you add unit test for this as well please ? Look at TableConfigUtilsTest

}
}
// check type type is realtime
if (tableConfig.getTableType() != TableType.REALTIME) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: do this in the beginning ?

@yupeng9
Copy link
Contributor Author

yupeng9 commented Oct 15, 2020

@icefury71 @Jackie-Jiang thanks for the review. Comments addressed.

return;
}
// check table type is realtime
if (tableConfig.getTableType() != TableType.REALTIME) {
Copy link
Contributor

Choose a reason for hiding this comment

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

(nit) Use precondition for this as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@Jackie-Jiang Jackie-Jiang merged commit 1750548 into apache:master Oct 16, 2020
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.

4 participants