Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_build_input_rows_with_array(self):
data = [(1, 'a'), (2, 'b'), (3, ['c', 'd', 'e'])]
result = _build_input_rows(data)
expected = [TStringRow(cols=[TStringValue(str_val='1', is_null=None),
TStringValue(str_val='a', is_null=None)]),
TStringRow(cols=[TStringValue(str_val='2', is_null=None),
TStringValue(str_val='b', is_null=None)]),
TStringRow(cols=[TStringValue(str_val='3', is_null=None),
TStringValue(str_val='{c,d,e}',
is_null=None)])]
assert result == expected
def test_build_input_rows(self):
data = [(1, 'a'), (2, 'b')]
result = _build_input_rows(data)
expected = [TStringRow(cols=[TStringValue(str_val='1', is_null=None),
TStringValue(str_val='a', is_null=None)]),
TStringRow(cols=[TStringValue(str_val='2', is_null=None),
TStringValue(str_val='b', is_null=None)])]
assert result == expected
table_name: str
data: Iterable of tuples
Each element of `data` should be a row to be inserted
See Also
--------
load_table
load_table_arrow
load_table_columnar
Examples
--------
>>> data = [(1, 'a'), (2, 'b'), (3, 'c')]
>>> con.load_table('bar', data)
"""
input_data = _build_input_rows(data)
self._client.load_table(self._session, table_name, input_data)
return self.load_table_arrow(table_name, data)
elif method == 'columnar':
return self.load_table_columnar(table_name, data)
elif method != 'rows':
raise TypeError("Method must be one of {{'infer', 'arrow', "
"'columnar', 'rows'}}. Got {} instead"
.format(method))
if isinstance(data, pd.DataFrame):
# We need to convert a Pandas dataframe to a list of tuples before
# loading row wise
data = data.itertuples(index=preserve_index, name=None)
input_data = _build_input_rows(data)
self._client.load_table(self._session, table_name, input_data)