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 query diagnosis warning #1006

Closed
wants to merge 1 commit into from
Closed

Add query diagnosis warning #1006

wants to merge 1 commit into from

Conversation

oneonestar
Copy link
Member

@oneonestar oneonestar commented Jun 15, 2019

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:

  1. IntegerDivisionWarning
    In Hive, SELECT 1/2 will return 0.5, but in Presto this will return 0.

  2. DeprecatedFunctionWarning


Some random thoughts that we can do using the warning system:

  • Allow Connector to throw warnings on potential bad performance / incompatible type casing query. Such as "Too many partitions" or "unsupported types".
  • Allow UDF to be marked as deprecated and issue a warning.
  • Warning level.
  • "Treat warnings as errors" session property.

@cla-bot cla-bot bot added the cla-signed label Jun 15, 2019
@oneonestar oneonestar changed the title Add query diagnosis warning. Add query diagnosis warning Jun 17, 2019
@@ -895,6 +896,18 @@ public FeaturesConfig setMaxGroupingSets(int maxGroupingSets)
return this;
}

public boolean getQueryDiagnosisWarningEnable()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public boolean getQueryDiagnosisWarningEnable()
public boolean isEnableQueryDiagnosisWarning()

.putAll(
Stage.DIAGNOSTIC,
new DeprecatedFunctionWarning(),
new IntegerDivisionWarning()).build();
Copy link
Member

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");
Copy link
Member

@ebyhr ebyhr Oct 14, 2019

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.

Suggested change
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()"));
Copy link
Member

@ebyhr ebyhr Oct 14, 2019

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.

Copy link
Member Author

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",
Copy link
Member

@ebyhr ebyhr Oct 14, 2019

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)
Copy link
Member

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?

@oneonestar
Copy link
Member Author

Superseded by #2446. Comments are addressed there. Thanks for the review.

@oneonestar oneonestar closed this Jan 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants