-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Annotate semanticException factories as format methods #15963
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,8 @@ | |
| import com.google.common.collect.LinkedHashMultimap; | ||
| import com.google.common.collect.Multimap; | ||
| import com.google.common.collect.Streams; | ||
| import com.google.errorprone.annotations.FormatMethod; | ||
| import com.google.errorprone.annotations.FormatString; | ||
| import io.trino.Session; | ||
| import io.trino.execution.warnings.WarningCollector; | ||
| import io.trino.metadata.FunctionResolver; | ||
|
|
@@ -761,7 +763,7 @@ protected Type visitDereferenceExpression(DereferenceExpression node, StackableA | |
| for (RowType.Field rowField : rowType.getFields()) { | ||
| if (fieldName.equalsIgnoreCase(rowField.getName().orElse(null))) { | ||
| if (foundFieldName) { | ||
| throw semanticException(AMBIGUOUS_NAME, field, "Ambiguous row field reference: " + fieldName); | ||
| throw semanticException(AMBIGUOUS_NAME, field, "Ambiguous row field reference: %s", fieldName); | ||
| } | ||
| foundFieldName = true; | ||
| rowFieldType = rowField.getType(); | ||
|
|
@@ -1248,7 +1250,7 @@ protected Type visitFunctionCall(FunctionCall node, StackableAstVisitorContext<C | |
| Expression expression = arguments.get(0); | ||
| Type expressionType = process(expression, context); | ||
| if (!(expressionType instanceof VarcharType)) { | ||
| throw semanticException(TYPE_MISMATCH, node, format("Expected expression of varchar, but '%s' has %s type", expression, expressionType.getDisplayName())); | ||
| throw semanticException(TYPE_MISMATCH, node, "Expected expression of varchar, but '%s' has %s type", expression, expressionType.getDisplayName()); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1488,7 +1490,7 @@ else if (frame.getType() == GROUPS) { | |
| } | ||
| } | ||
| else { | ||
| throw semanticException(NOT_SUPPORTED, frame, "Unsupported frame type: " + frame.getType()); | ||
| throw semanticException(NOT_SUPPORTED, frame, "Unsupported frame type: %s", frame.getType()); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -2415,7 +2417,7 @@ protected Type visitLambdaExpression(LambdaExpression node, StackableAstVisitorC | |
|
|
||
| if (types.size() != lambdaArguments.size()) { | ||
| throw semanticException(INVALID_PARAMETER_USAGE, node, | ||
| format("Expected a lambda that takes %s argument(s) but got %s", types.size(), lambdaArguments.size())); | ||
| "Expected a lambda that takes %s argument(s) but got %s", types.size(), lambdaArguments.size()); | ||
| } | ||
|
|
||
| ImmutableList.Builder<Field> fields = ImmutableList.builder(); | ||
|
|
@@ -2550,7 +2552,7 @@ public Type visitJsonValue(JsonValue node, StackableAstVisitorContext<Context> c | |
| !isDateTimeType(returnedType) || | ||
| returnedType.equals(INTERVAL_DAY_TIME) || | ||
| returnedType.equals(INTERVAL_YEAR_MONTH)) { | ||
| throw semanticException(TYPE_MISMATCH, node, "Invalid return type of function JSON_VALUE: " + node.getReturnedType().get()); | ||
| throw semanticException(TYPE_MISMATCH, node, "Invalid return type of function JSON_VALUE: %s", node.getReturnedType().get()); | ||
| } | ||
|
|
||
| JsonPathAnalysis pathAnalysis = jsonPathAnalyses.get(NodeRef.of(node)); | ||
|
|
@@ -2797,7 +2799,7 @@ private ResolvedFunction getInputFunction(Type type, JsonFormat format, Node nod | |
| if (isStringType(type)) { | ||
| yield VARBINARY_TO_JSON; | ||
| } | ||
| throw semanticException(TYPE_MISMATCH, node, format("Cannot read input of type %s as JSON using formatting %s", type, format)); | ||
| throw semanticException(TYPE_MISMATCH, node, "Cannot read input of type %s as JSON using formatting %s", type, format); | ||
| } | ||
| case UTF8 -> VARBINARY_UTF8_TO_JSON; | ||
| case UTF16 -> VARBINARY_UTF16_TO_JSON; | ||
|
|
@@ -2822,23 +2824,23 @@ private ResolvedFunction getOutputFunction(Type type, JsonFormat format, Node no | |
| if (isStringType(type)) { | ||
| yield JSON_TO_VARBINARY; | ||
| } | ||
| throw semanticException(TYPE_MISMATCH, node, format("Cannot output JSON value as %s using formatting %s", type, format)); | ||
| throw semanticException(TYPE_MISMATCH, node, "Cannot output JSON value as %s using formatting %s", type, format); | ||
| } | ||
| case UTF8 -> { | ||
| if (!VARBINARY.equals(type)) { | ||
| throw semanticException(TYPE_MISMATCH, node, format("Cannot output JSON value as %s using formatting %s", type, format)); | ||
| throw semanticException(TYPE_MISMATCH, node, "Cannot output JSON value as %s using formatting %s", type, format); | ||
| } | ||
| yield JSON_TO_VARBINARY_UTF8; | ||
| } | ||
| case UTF16 -> { | ||
| if (!VARBINARY.equals(type)) { | ||
| throw semanticException(TYPE_MISMATCH, node, format("Cannot output JSON value as %s using formatting %s", type, format)); | ||
| throw semanticException(TYPE_MISMATCH, node, "Cannot output JSON value as %s using formatting %s", type, format); | ||
| } | ||
| yield JSON_TO_VARBINARY_UTF16; | ||
| } | ||
| case UTF32 -> { | ||
| if (!VARBINARY.equals(type)) { | ||
| throw semanticException(TYPE_MISMATCH, node, format("Cannot output JSON value as %s using formatting %s", type, format)); | ||
| throw semanticException(TYPE_MISMATCH, node, "Cannot output JSON value as %s using formatting %s", type, format); | ||
| } | ||
| yield JSON_TO_VARBINARY_UTF32; | ||
| } | ||
|
|
@@ -3129,7 +3131,8 @@ private void coerceType(StackableAstVisitorContext<Context> context, Expression | |
| coerceType(expression, actualType, expectedType, message); | ||
| } | ||
|
|
||
| private Type coerceToSingleType(StackableAstVisitorContext<Context> context, Node node, String message, Expression first, Expression second) | ||
| @FormatMethod | ||
| private Type coerceToSingleType(StackableAstVisitorContext<Context> context, Node node, @FormatString String message, Expression first, Expression second) | ||
| { | ||
| Type firstType = UNKNOWN; | ||
| if (first != null) { | ||
|
|
@@ -3155,7 +3158,7 @@ private Type coerceToSingleType(StackableAstVisitorContext<Context> context, Nod | |
| return superType; | ||
| } | ||
|
|
||
| throw semanticException(TYPE_MISMATCH, node, message, firstType, secondType); | ||
| throw semanticException(TYPE_MISMATCH, node, "%s", format(message, firstType, secondType)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it because one
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can, but looks like it gets confused by them being different types. I wasn't sure if this is a bug or a weird corner case.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it doesn't look like we were doing anything wrong here
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The actual message is: Thing is, the message is the same but the message arguments passed to |
||
| } | ||
|
|
||
| private Type coerceToSingleType(StackableAstVisitorContext<Context> context, String description, List<Expression> expressions) | ||
|
|
@@ -3176,12 +3179,12 @@ private Type coerceToSingleType(StackableAstVisitorContext<Context> context, Str | |
| for (Type type : types) { | ||
| Optional<Type> newSuperType = typeCoercion.getCommonSuperType(superType, type); | ||
| if (newSuperType.isEmpty()) { | ||
| throw semanticException(TYPE_MISMATCH, Iterables.get(typeExpressions.get(type), 0).getNode(), format( | ||
| throw semanticException(TYPE_MISMATCH, Iterables.get(typeExpressions.get(type), 0).getNode(), | ||
| "%s must be the same type or coercible to a common type. Cannot find common type between %s and %s, all types (without duplicates): %s", | ||
| description, | ||
| superType, | ||
| type, | ||
| typeExpressions.keySet())); | ||
| typeExpressions.keySet()); | ||
| } | ||
| superType = newSuperType.get(); | ||
| } | ||
|
|
@@ -3192,12 +3195,12 @@ private Type coerceToSingleType(StackableAstVisitorContext<Context> context, Str | |
|
|
||
| if (!type.equals(superType)) { | ||
| if (!typeCoercion.canCoerce(type, superType)) { | ||
| throw semanticException(TYPE_MISMATCH, Iterables.get(coercionCandidates, 0).getNode(), format( | ||
| throw semanticException(TYPE_MISMATCH, Iterables.get(coercionCandidates, 0).getNode(), | ||
| "%s must be the same type or coercible to a common type. Cannot find common type between %s and %s, all types (without duplicates): %s", | ||
| description, | ||
| superType, | ||
| type, | ||
| typeExpressions.keySet())); | ||
| typeExpressions.keySet()); | ||
| } | ||
| addOrReplaceExpressionsCoercion(coercionCandidates, type, superType); | ||
| } | ||
|
|
@@ -3460,7 +3463,7 @@ public static void analyzeExpressionWithoutSubqueries( | |
| plannerContext, | ||
| accessControl, | ||
| (node, ignored) -> { | ||
| throw semanticException(errorCode, node, message); | ||
| throw semanticException(errorCode, node, "%s", message); | ||
| }, | ||
| session, | ||
| TypeProvider.empty(), | ||
|
|
@@ -3582,7 +3585,7 @@ public static ExpressionAnalyzer createWithoutSubqueries( | |
| session, | ||
| TypeProvider.empty(), | ||
| parameters, | ||
| node -> semanticException(errorCode, node, message), | ||
| node -> semanticException(errorCode, node, "%s", message), | ||
| warningCollector, | ||
| isDescribe); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.