Skip to content

Commit

Permalink
Support non-lower case variables in functions
Browse files Browse the repository at this point in the history
  • Loading branch information
losipiuk committed Jan 28, 2025
1 parent 798eb19 commit 9318bc3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
import static io.trino.sql.analyzer.TypeSignatureTranslator.toTypeSignature;
import static java.lang.String.format;
import static java.util.Collections.nCopies;
import static java.util.Locale.ENGLISH;
import static java.util.Objects.requireNonNull;
import static java.util.function.Predicate.not;

Expand Down Expand Up @@ -629,6 +630,8 @@ public Context newScope()
private static String identifierValue(Identifier name)
{
// TODO: this should use getCanonicalValue()
return name.getValue();
// stop-gap: lowercasing for now to match what is happening during analysis;
// otherwise we do not support non-lowercase variables in functions.
return name.getValue().toLowerCase(ENGLISH);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import static io.trino.sql.relational.Expressions.call;
import static io.trino.sql.relational.Expressions.constantNull;
import static io.trino.sql.relational.Expressions.field;
import static java.util.Locale.ENGLISH;
import static java.util.Objects.requireNonNull;

public final class SqlRoutinePlanner
Expand Down Expand Up @@ -360,7 +361,9 @@ private static IrBlock block(List<IrStatement> statements)
private static String identifierValue(Identifier name)
{
// TODO: this should use getCanonicalValue()
return name.getValue();
// stop-gap: lowercasing for now to match what is happening during analysis;
// otherwise we do not support non-lowercase variables in functions.
return name.getValue().toLowerCase(ENGLISH);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6652,6 +6652,19 @@ SELECT my_pow(2, 8)
"""))
.matches("VALUES 256");

assertThat(query(
"""
WITH
FUNCTION fun_with_uppercase_var()
RETURNS int
BEGIN
DECLARE R int DEFAULT 7;
RETURN R;
END
SELECT fun_with_uppercase_var()
"""))
.matches("VALUES 7");

// invoke function on data from connector to prevent constant folding on the coordinator
assertThat(query(
"""
Expand Down

0 comments on commit 9318bc3

Please sign in to comment.