Example #1
0
def sql_fields_cursor_get_page(
    connection: 'Connection',
    cursor: int,
    field_count: int,
    query_id=None,
) -> APIResult:
    """
    Retrieves the next query result page by cursor ID from `sql_fields`.

    :param connection: connection to Ignite server,
    :param cursor: cursor ID,
    :param field_count: a number of fields in a row,
    :param query_id: (optional) a value generated by client and returned as-is
     in response.query_id. When the parameter is omitted, a random value
     is generated,
    :return: API result data object. Contains zero status and a value
     of type dict with results on success, non-zero status and an error
     description otherwise.

     Value dict is of following format:

     * `data`: list, result values,
     * `more`: bool, True if more data is available for subsequent
       ‘sql_fields_cursor_get_page’ calls.
    """

    query_struct = Query(
        OP_QUERY_SQL_FIELDS_CURSOR_GET_PAGE,
        [
            ('cursor', Long),
        ],
        query_id=query_id,
    )

    _, send_buffer = query_struct.from_python({
        'cursor': cursor,
    })

    connection.send(send_buffer)

    response_struct = Response([
        ('data',
         StructArray([('field_{}'.format(i), AnyDataObject)
                      for i in range(field_count)])),
        ('more', Bool),
    ])
    response_class, recv_buffer = response_struct.parse(connection)
    response = response_class.from_buffer_copy(recv_buffer)

    result = APIResult(response)
    if result.status != 0:
        return result
    value = response_struct.to_python(response)
    result.value = {'data': [], 'more': value['more']}
    for row_dict in value['data']:
        row = []
        for field_key in sorted(row_dict.keys()):
            row.append(row_dict[field_key])
        result.value['data'].append(row)
    return result
Example #2
0
def __sql_fields_cursor_get_page(conn, cursor, field_count, query_id):
    query_struct = Query(
        OP_QUERY_SQL_FIELDS_CURSOR_GET_PAGE,
        [
            ('cursor', Long),
        ],
        query_id=query_id,
    )
    return query_perform(query_struct,
                         conn,
                         query_params={
                             'cursor': cursor,
                         },
                         response_config=[
                             ('data',
                              StructArray([(f'field_{i}', AnyDataObject)
                                           for i in range(field_count)])),
                             ('more', Bool),
                         ],
                         post_process_fun=__post_process_sql_fields_cursor)
Example #3
0
# For purposes of the foregoing, “Sell” means practicing any or all of the rights granted to you
# under the License to provide to third parties, for a fee or other consideration (including without
# limitation fees for hosting or consulting/ support services related to the Software), a product or
# service whose value derives, entirely or substantially, from the functionality of the Software.
# Any license notice or attribution required by the License must also include this Commons Clause
# License Condition notice.
#
# For purposes of the clause above, the “Licensor” is Copyright 2019 GridGain Systems, Inc.,
# the “License” is the Apache License, Version 2.0, and the Software is the GridGain Community
# Edition software provided with this notice.

from pyignite.datatypes import Int, Bool, String, Struct, StructArray

binary_fields_struct = StructArray([
    ('field_name', String),
    ('type_id', Int),
    ('field_id', Int),
])

body_struct = Struct([
    ('type_id', Int),
    ('type_name', String),
    ('affinity_key_field', String),
    ('binary_fields', binary_fields_struct),
    ('is_enum', Bool),
])

enum_struct = StructArray([
    ('literal', String),
    ('type_id', Int),
])