Skip to content

Added --fix-header option #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Usage
[-m INTEGER] [-s INTEGER] [-k] [-r] [-e] [--verify-certs]
[--ca-certs CA_CERTS] [--client-cert CLIENT_CERT]
[--client-key CLIENT_KEY] [-v] [--debug]
[--fix-header]

Arguments:
-q, --query QUERY Query string in Lucene syntax. [required]
Expand All @@ -64,6 +65,7 @@ Usage
--client-key CLIENT_KEY Location of Client Cert Key.
-v, --version Show version and exit.
--debug Debug mode on.
--fix-header Replace . with _ and remove @ in the output csv header row.
-h, --help show this help message and exit

[ `Usage Examples <./docs/EXAMPLES.rst>`_ | `Release Changelog <./docs/HISTORY.rst>`_ ]
11 changes: 10 additions & 1 deletion es2csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ def next_scroll(scroll_id):

def flush_to_file(self, hit_list):
def to_keyvalue_pairs(source, ancestors=[], header_delimeter='.'):
# Use _ for Oracle database
if self.opts.fix_header == True:
header_delimeter = '_'

def is_list(arg):
return type(arg) is list

Expand All @@ -188,7 +192,12 @@ def is_dict(arg):
else:
[to_keyvalue_pairs(item, ancestors + [str(index)]) for index, item in enumerate(source)]
else:
header = header_delimeter.join(ancestors)
# Remove @ sign from ES's metadata column heads
if self.opts.fix_header == True:
header = header_delimeter.join(ancestors).replace('@', '')
else:
header = header_delimeter.join(ancestors)

if header not in self.csv_headers:
self.csv_headers.append(header)
try:
Expand Down
1 change: 1 addition & 0 deletions es2csv_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def main():
p.add_argument('--client-key', dest='client_key', default=None, type=str, help='Location of Client Cert Key.')
p.add_argument('-v', '--version', action='version', version='%(prog)s ' + __version__, help='Show version and exit.')
p.add_argument('--debug', dest='debug_mode', action='store_true', help='Debug mode on.')
p.add_argument('--fix-header', dest='fix_header', action='store_true', help='Replace . to _ and remove @ in the header row.')

if len(sys.argv) == 1:
p.print_help()
Expand Down