dssysolyatin commented on code in PR #4926:
URL: https://github.com/apache/calcite/pull/4926#discussion_r3264009161
##########
core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java:
##########
@@ -6423,6 +6254,35 @@ public void setOriginal(SqlNode expr, SqlNode original) {
final LambdaNamespace ns =
getNamespaceOrThrow(lambdaExpr).unwrap(LambdaNamespace.class);
+ // Check for duplicate lambda parameter names
+ final SqlNameMatcher nameMatcher = catalogReader.nameMatcher();
+ final List<SqlNode> params = lambdaExpr.getParameters();
+ for (int i = 0; i < params.size(); i++) {
+ final String paramName = ((SqlIdentifier) params.get(i)).getSimple();
+ // Check within the same lambda: (x, x) -> ...
+ for (int j = i + 1; j < params.size(); j++) {
+ final String otherName = ((SqlIdentifier) params.get(j)).getSimple();
+ if (nameMatcher.matches(paramName, otherName)) {
+ throw newValidationError(params.get(j),
+ RESOURCE.duplicateLambdaParameter(otherName));
+ }
+ }
Review Comment:
```
final Set<String> seen = catalogReader.nameMatcher().createSet();
for (SqlNode param : lambdaExpr.getParameters()) {
final String name = ((SqlIdentifier) param).getSimple();
if (!seen.add(name)) {
throw newValidationError(param,
RESOURCE.duplicateLambdaParameter(name));
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]