Ejemplo n.º 1
0
def test_cast_values():
    selectColumns = [{'id': '353',
                      'name': 'name',
                      'columnType': 'STRING'},
                     {'id': '354',
                      'name': 'foo',
                      'columnType': 'STRING'},
                     {'id': '355',
                      'name': 'x',
                      'columnType': 'DOUBLE'},
                     {'id': '356',
                      'name': 'n',
                      'columnType': 'INTEGER'},
                     {'id': '357',
                      'name': 'bonk',
                      'columnType': 'BOOLEAN'}]

    row = ('Finklestein', 'bat', '3.14159', '65535', 'true')
    assert cast_values(row, selectColumns)==['Finklestein', 'bat', 3.14159, 65535, True]

    ## group by
    selectColumns = [{'name': 'bonk',
                      'columnType': 'BOOLEAN'},
                     {'name': 'COUNT(name)',
                      'columnType': 'INTEGER'},
                     {'name': 'AVG(x)',
                      'columnType': 'DOUBLE'},
                     {'name': 'SUM(n)',
                      'columnType': 'INTEGER'}]
    row = ('true', '211', '1.61803398875', '1421365')
    assert cast_values(row, selectColumns)==[True, 211, 1.61803398875, 1421365]
def test_cast_values():
    selectColumns = [{'id': '353',
                      'name': 'name',
                      'columnType': 'STRING'},
                     {'id': '354',
                      'name': 'foo',
                      'columnType': 'STRING'},
                     {'id': '355',
                      'name': 'x',
                      'columnType': 'DOUBLE'},
                     {'id': '356',
                      'name': 'n',
                      'columnType': 'INTEGER'},
                     {'id': '357',
                      'name': 'bonk',
                      'columnType': 'BOOLEAN'},
                     {'id': '358',
                      'name': 'boom',
                      'columnType': 'LINK'}]

    row = ('Finklestein', 'bat', '3.14159', '65535', 'true', 'https://www.synapse.org/')
    assert_equals(cast_values(row, selectColumns),
                  ['Finklestein', 'bat', 3.14159, 65535, True, 'https://www.synapse.org/'])

    # group by
    selectColumns = [{'name': 'bonk',
                      'columnType': 'BOOLEAN'},
                     {'name': 'COUNT(name)',
                      'columnType': 'INTEGER'},
                     {'name': 'AVG(x)',
                      'columnType': 'DOUBLE'},
                     {'name': 'SUM(n)',
                      'columnType': 'INTEGER'}]
    row = ('true', '211', '1.61803398875', '1421365')
    assert_equals(cast_values(row, selectColumns), [True, 211, 1.61803398875, 1421365])
Ejemplo n.º 3
0
def test_cast_values():
    selectColumns = [{
        'id': '353',
        'name': 'name',
        'columnType': 'STRING'
    }, {
        'id': '354',
        'name': 'foo',
        'columnType': 'STRING'
    }, {
        'id': '355',
        'name': 'x',
        'columnType': 'DOUBLE'
    }, {
        'id': '356',
        'name': 'n',
        'columnType': 'INTEGER'
    }, {
        'id': '357',
        'name': 'bonk',
        'columnType': 'BOOLEAN'
    }, {
        'id': '358',
        'name': 'boom',
        'columnType': 'LINK'
    }]

    row = ('Finklestein', 'bat', '3.14159', '65535', 'true',
           'https://www.synapse.org/')
    assert cast_values(row, selectColumns) == [
        'Finklestein', 'bat', 3.14159, 65535, True, 'https://www.synapse.org/'
    ]

    ## group by
    selectColumns = [{
        'name': 'bonk',
        'columnType': 'BOOLEAN'
    }, {
        'name': 'COUNT(name)',
        'columnType': 'INTEGER'
    }, {
        'name': 'AVG(x)',
        'columnType': 'DOUBLE'
    }, {
        'name': 'SUM(n)',
        'columnType': 'INTEGER'
    }]
    row = ('true', '211', '1.61803398875', '1421365')
    assert cast_values(row,
                       selectColumns) == [True, 211, 1.61803398875, 1421365]
def test_cast_values__unknown_column_type():
    selectColumns = [{'id': '353',
                      'name': 'name',
                      'columnType': 'INTEGER'},
                     {'id': '354',
                      'name': 'foo',
                      'columnType': 'DEFINTELY_NOT_A_EXISTING_TYPE'},
                     ]

    row = ('123', 'othervalue')
    assert (
        cast_values(row, selectColumns) ==
        [123, 'othervalue']
    )
def test_cast_values__list_type():
    selectColumns = [{'id': '354',
                      'name': 'foo',
                      'columnType': 'STRING_LIST'},
                     {'id': '356',
                      'name': 'n',
                      'columnType': 'INTEGER_LIST'},
                     {'id': '357',
                      'name': 'bonk',
                      'columnType': 'BOOLEAN_LIST'},
                     {'id': '358',
                      'name': 'boom',
                      'columnType': 'DATE_LIST'}]
    now_millis = int(round(time.time() * 1000))
    row = ('["foo", "bar"]', '[1,2,3]', '[true, false]', '[' + str(now_millis) + ']')
    assert (
        cast_values(row, selectColumns) ==
        [["foo", "bar"], [1, 2, 3], [True, False], [from_unix_epoch_time(now_millis)]]
    )