[patches] [PATCH 6/7] iproto: send SQL column meta on SELECT
Kirill Yukhin
kyukhin at tarantool.org
Thu Mar 1 09:59:56 MSK 2018
Hello Vlad,
On 28 фев 22:36, Vladislav Shpilevoy wrote:
> JDBC driver is a Java driver to connect to various databases and
> communicate with them using SQL. It requires some meta
> information on a SELECT from a server about each returned column:
> https://docs.oracle.com/javase/6/docs/api/java/sql/ResultSetMetaData.html
>
> Introduce new IPROTO codes in IPROTO_METADATA map with the needed
> meta and fetch it from SQL statement.
>
> Closes #2620
>
> Signed-off-by: Vladislav Shpilevoy <v.shpilevoy at tarantool.org>
> ---
> src/box/execute.c | 127 ++++++++++++++++++++++++++++++++++++++-------
> src/box/iproto_constants.h | 23 ++++++++
> src/box/lua/net_box.lua | 29 +++++++++--
> test/sql/iproto.result | 59 ++++++++++++++++++---
> test/sql/iproto.test.lua | 9 ++++
> 5 files changed, 220 insertions(+), 27 deletions(-)
>
> diff --git a/src/box/execute.c b/src/box/execute.c
> index 48d166b5b..859bd10ae 100644
> --- a/src/box/execute.c
> +++ b/src/box/execute.c
> @@ -506,6 +507,108 @@ sql_bind(const struct sql_request *request, struct sqlite3_stmt *stmt)
> return 0;
> }
>
> +/**
> + * Binary encoded MessagePack map. It is used to avoid multiple
> + * mp_sizeof_...() + mp_encode_uint() during column meta building.
> + * Select can contain very big amount of columns, so column meta
> + * building speed is important.
> + */
> +struct PACKED iproto_sql_column_meta_bin {
> + /** MP_MAP with key count. */
> + uint8_t m_header;
> + /** IPROTO_FIELD_FLAGS: MP_UINT8. */
> + uint8_t k_flags;
> + uint8_t m_flags;
> +};
> +
> +/** 0x80 - MessagePack map with 0 keys. */
> +static const struct iproto_sql_column_meta_bin iproto_sql_column_meta_bin = {
> + 0x80, IPROTO_FIELD_FLAGS, 0
> +};
> +
> +/**
> + * Encode meta information about a non-table column represented in
> + * a SELECT column list by a constant, or by a complex expression.
> + * It does not have any meta except an alias.
> + * @param out Output buffer.
> + * @param column Column meta.
> + *
> + * @retval 0 Success.
> + * @retval -1 Memory error.
> + */
> +static inline int
> +sql_ephemeral_column_meta_encode(struct obuf *out,
> + const struct sql_column_meta *column)
I think reference to artificial column as `ephemeral` is confusing,
since we recently introduced ephemeral spaces. Maybe use other word?
> +static inline int
> +sql_table_column_meta_encode(struct obuf *out,
> + const struct sql_column_meta *column)
> +{
> + assert(column->alias != NULL);
> + assert(column->name != NULL);
> + int alias_len = strlen(column->alias);
> + int name_len = strlen(column->name);
> + bool is_alias_eq_name =
> + alias_len == name_len &&
> + memcmp(column->name, column->alias, name_len) == 0;
> + struct iproto_sql_column_meta_bin header = iproto_sql_column_meta_bin;
> + size_t size = sizeof(header) + mp_sizeof_uint(IPROTO_FIELD_COLUMN) +
> + mp_sizeof_str(name_len);
> + if (! is_alias_eq_name) {
> + size += mp_sizeof_uint(IPROTO_FIELD_NAME) +
> + mp_sizeof_str(alias_len);
> + /* @Sa mp_encode_map(). */
I might be out of context, but what is @Sa?
--
Regard, Kirill Yukhin
More information about the Tarantool-patches
mailing list