MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestTranspile_ArrayUpperInRangeFunction

Function TestTranspile_ArrayUpperInRangeFunction

transpiler/transpiler_test.go:3994–4040  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3992}
3993
3994func TestTranspile_ArrayUpperInRangeFunction(t *testing.T) {
3995 // Test that array_upper inside a FROM-clause function (RangeFunction) is properly
3996 // transformed to len() with the dimension argument stripped. This is the exact
3997 // pattern used by the pgx driver for type resolution.
3998 tr := New(DefaultConfig())
3999
4000 tests := []struct {
4001 name string
4002 input string
4003 contains string
4004 excludes string
4005 }{
4006 {
4007 name: "array_upper in generate_series FROM clause",
4008 input: "SELECT s.r FROM generate_series(1, array_upper(current_schemas(false), 1)) AS s(r)",
4009 contains: "len(current_schemas(false))",
4010 excludes: "array_upper",
4011 },
4012 {
4013 name: "array_upper in SELECT expression",
4014 input: "SELECT array_upper(ARRAY[1,2,3], 1)",
4015 contains: "len(ARRAY[1, 2, 3])",
4016 excludes: "array_upper",
4017 },
4018 {
4019 name: "array_length dimension arg stripped",
4020 input: "SELECT array_length(ARRAY[1,2,3], 1)",
4021 contains: "len(ARRAY[1, 2, 3])",
4022 excludes: "array_length",
4023 },
4024 }
4025
4026 for _, tt := range tests {
4027 t.Run(tt.name, func(t *testing.T) {
4028 result, err := tr.Transpile(tt.input)
4029 if err != nil {
4030 t.Fatalf("Transpile(%q) error: %v", tt.input, err)
4031 }
4032 if tt.contains != "" && !strings.Contains(result.SQL, tt.contains) {
4033 t.Errorf("Transpile(%q) = %q, should contain %q", tt.input, result.SQL, tt.contains)
4034 }
4035 if tt.excludes != "" && strings.Contains(result.SQL, tt.excludes) {
4036 t.Errorf("Transpile(%q) = %q, should NOT contain %q", tt.input, result.SQL, tt.excludes)
4037 }
4038 })
4039 }
4040}
4041
4042func TestTranspile_CtidToRowid(t *testing.T) {
4043 tests := []struct {

Callers

nothing calls this directly

Calls 4

TranspileMethod · 0.80
NewFunction · 0.70
DefaultConfigFunction · 0.70
RunMethod · 0.65

Tested by

no test coverage detected