def add_many_columns(row): result = row_function(row) data = [] for i, data_type in enumerate(data_types): try: value = result[i] except TypeError as e: raise RuntimeError("UDF returned non-indexable value. Provided schema indicated an Indexable return type") except IndexError as e: raise RuntimeError("UDF return value did not match the number of items in the provided schema") cast_value = valid_data_types.cast(value, data_type) data.append(numpy_to_bson_friendly(cast_value)) # return json.dumps(data, cls=NumpyJSONEncoder) return data
def aggregate(acc, row): accumulator_wrapper = acc aggregator_row_function(accumulator_wrapper, row) acc_data = accumulator_wrapper._get_data() data = [] for i, data_type in enumerate(data_types): try: value = acc_data[i] except TypeError as e: raise RuntimeError("UDF returned non-indexable value. Provided schema indicated an Indexable return type") except IndexError as e: raise RuntimeError("UDF return value did not match the number of items in the provided schema") cast_value = valid_data_types.cast(value, data_type) data.append(cast_value) return data
def add_one_column(row): result = row_function(row) cast_value = valid_data_types.cast(result, data_type) return [numpy_to_bson_friendly(cast_value)]