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

tree: allow string concat with any non-array type (anynonarray approach) #43143

Closed
wants to merge 1 commit into from

Conversation

otan
Copy link
Contributor

@otan otan commented Dec 13, 2019

Refs #41872. This method solves the problem with heavy edits to the
type system.

Previously, the || concat operator only worked on string pairs. Postgres
supports concatenation between strings and any other non-array type. This
patch adds support for that as well.

To support this, we add another heuristic to the overload detection to
prefer omitting "Any" if possible. Furthermore, we add a new
AnyNonArray type constant to types.go to encode not being able to
append to arrays.

Release note (sql change): the concatenation operator || is now usable
between strings and any other non-array type.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@otan
Copy link
Contributor Author

otan commented Dec 13, 2019

The remaining test failure b'hello' || 'world' differs between sql/concat and opt/no-opt -- seemingly due to constant folding for the sql case. This is because of the String + Any // vice versa being introduced. Any ideas @jordanlewis before I do a deeper dive? So close haha, but could be a fundamental problem with how we deal with types :)

--- FAIL: TestEval (0.53s)
    --- FAIL: TestEval/opt (0.04s)
        --- FAIL: TestEval/opt/concat (0.00s)
            datadriven.go:154:
                testdata/eval/concat:18: b'hello' || 'world'
                expected:
                '\x68656c6c6f776f726c64'

                found:
                e'\'\\x68656c6c6f\'world'
    --- FAIL: TestEval/no-opt (0.04s)
        --- FAIL: TestEval/no-opt/concat (0.00s)
            datadriven.go:154:
                testdata/eval/concat:18: b'hello' || 'world'
                expected:
                '\x68656c6c6f776f726c64'

                found:
                e'\'\\x68656c6c6f\'world'
    --- FAIL: TestEval/sql (0.35s)
        --- FAIL: TestEval/sql/concat (0.00s)
            datadriven.go:154:
                testdata/eval/concat:18: b'hello' || 'world'
                expected:
                '\x68656c6c6f776f726c64'

                found:
                'helloworld'
    --- FAIL: TestEval/vectorized (0.11s)
        --- FAIL: TestEval/vectorized/concat (0.00s)
            datadriven.go:154:
                testdata/eval/concat:18: b'hello' || 'world'
                expected:
                '\x68656c6c6f776f726c64'

                found:
                'helloworld'

@otan
Copy link
Contributor Author

otan commented Dec 14, 2019

looks like optimiser makes some assumptions about types: TestTypingBinaryAssumptions - so we have two ways of evaluating types?!

Previously, the || concat operator only worked on string pairs. Postgres
supports concatenation between strings and any other non-array type. This
patch adds support for that as well.

To support this, we add another heuristic to the overload detection to
prefer omitting "Any" if possible. Furthermore, we add a new
`AnyNonArray` type constant to types.go to encode not being able to
append to arrays.

Release note (sql change): the concatenation operator || is now usable
between strings and any other non-array type.
@otan otan changed the title tree: allow string concat with any non-array type tree: allow string concat with any non-array type (init approach) Dec 16, 2019
@otan otan changed the title tree: allow string concat with any non-array type (init approach) tree: allow string concat with any non-array type Dec 16, 2019
@otan
Copy link
Contributor Author

otan commented Dec 16, 2019

let's try #43190.

@otan
Copy link
Contributor Author

otan commented Dec 16, 2019

image

@otan otan closed this Dec 16, 2019
@rafiss rafiss changed the title tree: allow string concat with any non-array type tree: allow string concat with any non-array type (anynonarray approach) Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants