def test_join_feature(self): tables = [rows.import_from_csv('tests/data/to-merge-1.csv'), rows.import_from_csv('tests/data/to-merge-2.csv'), rows.import_from_csv('tests/data/to-merge-3.csv'),] merged = rows.join(keys=('id', 'username'), tables=tables) expected = rows.import_from_csv('tests/data/merged.csv') self.assert_table_equal(merged, expected)
def join(input_encoding, output_encoding, input_locale, output_locale, verify_ssl, order_by, keys, sources, destination): # TODO: may use sys.stdout.encoding if output_file = '-' output_encoding = output_encoding or DEFAULT_OUTPUT_ENCODING keys = [key.strip() for key in keys.split(',')] if input_locale is not None: with rows.locale_context(input_locale): tables = [_import_table(source, encoding=input_encoding, verify_ssl=verify_ssl) for source in sources] else: tables = [_import_table(source, encoding=input_encoding, verify_ssl=verify_ssl) for source in sources] result = rows.join(keys, tables) if order_by is not None: order_by = _get_field_names(order_by, result.field_names, permit_not=True) # TODO: use complete list of `order_by` fields result.order_by(order_by[0].replace('^', '-')) if output_locale is not None: with rows.locale_context(output_locale): export_to_uri(result, destination, encoding=output_encoding) else: export_to_uri(result, destination, encoding=output_encoding)
def join(input_encoding, output_encoding, input_locale, output_locale, verify_ssl, order_by, keys, sources, destination): # TODO: may use sys.stdout.encoding if output_file = '-' output_encoding = output_encoding or DEFAULT_OUTPUT_ENCODING keys = [key.strip() for key in keys.split(',')] if input_locale is not None: with rows.locale_context(input_locale): tables = [ _import_table(source, encoding=input_encoding, verify_ssl=verify_ssl) for source in sources ] else: tables = [ _import_table(source, encoding=input_encoding, verify_ssl=verify_ssl) for source in sources ] result = rows.join(keys, tables) if order_by is not None: order_by = _get_field_names(order_by, result.fields.keys(), permit_not=True) # TODO: use complete list of `order_by` fields result.order_by(order_by[0].replace('^', '-')) if output_locale is not None: with rows.locale_context(output_locale): export_to_uri(destination, result, encoding=output_encoding) else: export_to_uri(destination, result, encoding=output_encoding)
def test_join_feature(self): tables = [ rows.import_from_csv('tests/data/to-merge-1.csv'), rows.import_from_csv('tests/data/to-merge-2.csv'), rows.import_from_csv('tests/data/to-merge-3.csv'), ] merged = rows.join(keys=('id', 'username'), tables=tables) expected = rows.import_from_csv('tests/data/merged.csv') self.assert_table_equal(merged, expected)
def join(input_encoding, output_encoding, input_locale, output_locale, keys, sources, destination): keys = [key.strip() for key in keys.split(',')] with rows.locale_context(input_locale): tables = [import_from_uri(source) for source in sources] result = rows.join(keys, tables) with rows.locale_context(output_locale): export_to_uri(destination, result)
def join( input_encoding, output_encoding, input_locale, output_locale, verify_ssl, order_by, fields, fields_exclude, keys, sources, destination, ): export_fields = _get_import_fields(fields, fields_exclude) keys = make_header(keys.split(","), permit_not=False) if input_locale is not None: with rows.locale_context(input_locale): tables = [ _import_table(source, encoding=input_encoding, verify_ssl=verify_ssl) for source in sources ] else: tables = [ _import_table(source, encoding=input_encoding, verify_ssl=verify_ssl) for source in sources ] result = rows.join(keys, tables) if order_by is not None: order_by = _get_field_names(order_by, result.field_names, permit_not=True) # TODO: use complete list of `order_by` fields result.order_by(order_by[0].replace("^", "-")) if export_fields is None: export_fields = _get_export_fields(result.field_names, fields_exclude) # TODO: may use sys.stdout.encoding if output_file = '-' output_encoding = output_encoding or DEFAULT_OUTPUT_ENCODING if output_locale is not None: with rows.locale_context(output_locale): export_to_uri( result, destination, encoding=output_encoding, export_fields=export_fields, ) else: export_to_uri( result, destination, encoding=output_encoding, export_fields=export_fields )