-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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 query diagnosis warning #1006
Conversation
@@ -895,6 +896,18 @@ public FeaturesConfig setMaxGroupingSets(int maxGroupingSets) | |||
return this; | |||
} | |||
|
|||
public boolean getQueryDiagnosisWarningEnable() |
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.
public boolean getQueryDiagnosisWarningEnable() | |
public boolean isEnableQueryDiagnosisWarning() |
.putAll( | ||
Stage.DIAGNOSTIC, | ||
new DeprecatedFunctionWarning(), | ||
new IntegerDivisionWarning()).build(); |
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.
Move .build();
to next line.
public final class DeprecatedFunctionWarning | ||
implements PlanSanityChecker.Checker | ||
{ | ||
private List<String> deprecatedFunctions = ImmutableList.of("json_array_get"); |
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.
We can change this to static final
variable.
private List<String> deprecatedFunctions = ImmutableList.of("json_array_get"); | |
private static final List<String> DEPRECATED_FUNCTIONS = ImmutableList.of("json_array_get"); |
protected Void visitFunctionCall(FunctionCall node, Void context) | ||
{ | ||
if (node.getName().getParts().stream().anyMatch(deprecatedFunctions::contains)) { | ||
warningCollector.add(new PrestoWarning(DREPRCATED_FUNCTION, "Detected use of deprecated function: json_array_get()")); |
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 avoid hardcoding the function name here? When we add a deprecated function later, we need to fix this line.
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'll try to detect the annotation "@deprecated" instead of hardcoding.
{ | ||
WarningCode warningCode = StandardWarningCode.DREPRCATED_FUNCTION.toWarningCode(); | ||
assertPlannerWarnings(queryRunner, | ||
"SELECT 123", |
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 would add a normal(=non-deprecated) function to this test.
assertPlannerWarnings(queryRunner, sql, ImmutableMap.of("enable_query_diagnosis_warning", "true"), expectedWarning); | ||
} | ||
|
||
private static void assertPlannerWarnings(LocalQueryRunner queryRunner, @Language("SQL") String sql, Map<String, String> sessionProperties, Optional<WarningCode> expectedWarning) |
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 change Optional<WarningCode>
to List<WarningCode>
for multiple warning case?
Superseded by #2446. Comments are addressed there. Thanks for the review. |
Enhance the warning system to report risky or error-prone query. This is similar to the warnings from a language compiler or static code analysis tool.
Current there are two rules:
IntegerDivisionWarning
In Hive,
SELECT 1/2
will return 0.5, but in Presto this will return 0.DeprecatedFunctionWarning
Some random thoughts that we can do using the warning system: