Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

sql: implement struct types #735

Closed
wants to merge 1 commit into from

Conversation

erizocosmico
Copy link
Contributor

Depends on #720

This PR implements struct types, which will be serialized to JSON
before being sent to the mysql client using the mysql wire proto.

Internally, structs are just map[string]interface{}, but they can
actually be anything that's convertible to that, because of the way
the Convert method of the struct type is implemented. That means,
the result of an UDF or a table that returns a struct may be an
actual Go struct and it will then be transformed into the internal
map. It does have a penalty, though, because structs require
encoding to JSON and then decoding into map[string]interface{}.
Structs have a schema, identical to a table schema, except their
Source will always be empty.

Resolution of columns has also been slightly change in order to
resolve getting fields from structs using the . operator, which
required some trade-offs in some rules, such as not erroring
anymore in qualify_columns when the table is not found. That
error was delegated to resolve_columns in order to make resolution
possible, as the syntax is a bit ambiguous.
The advantage of using dot is the fact that no changes have to be made
to the parser in order for it to work.

@erizocosmico erizocosmico requested a review from a team May 30, 2019 14:14
@erizocosmico erizocosmico self-assigned this May 30, 2019
@erizocosmico erizocosmico force-pushed the feature/structs branch 2 times, most recently from 47f3f6b to 345af2a Compare June 3, 2019 10:29
@erizocosmico
Copy link
Contributor Author

Rebased against master

@erizocosmico
Copy link
Contributor Author

Rebased

Copy link
Contributor

@agarciamontoro agarciamontoro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

This PR implements struct types, which will be serialized to JSON
before being sent to the mysql client using the mysql wire proto.

Internally, structs are just `map[string]interface{}`, but they can
actually be anything that's convertible to that, because of the way
the Convert method of the struct type is implemented. That means,
the result of an UDF or a table that returns a struct may be an
actual Go struct and it will then be transformed into the internal
map. It does have a penalty, though, because structs require
encoding to JSON and then decoding into `map[string]interface{}`.
Structs have a schema, identical to a table schema, except their
`Source` will always be empty.

Resolution of columns has also been slightly change in order to
resolve getting fields from structs using the `.` operator, which
required some trade-offs in some rules, such as not erroring
anymore in `qualify_columns` when the table is not found. That
error was delegated to `resolve_columns` in order to make resolution
possible, as the syntax is a bit ambiguous.
The advantage of using dot is the fact that no changes have to be made
to the parser in order for it to work.

Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy