-
Notifications
You must be signed in to change notification settings - Fork 50
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
Add option to preserve the original ordering of columns #75
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,7 @@ def __init__( | |
debugging_map=False, | ||
sanitize_names=False, | ||
ignore_invalid_lines=False, | ||
keep_input_sort_order=False, | ||
): | ||
self.input_format = input_format | ||
self.infer_mode = infer_mode | ||
|
@@ -113,7 +114,7 @@ def __init__( | |
# If CSV, preserve the original ordering because 'bq load` matches the | ||
# CSV column with the respective schema entry using the position of the | ||
# column in the schema. | ||
self.sorted_schema = (input_format in {'json', 'dict'}) | ||
self.sorted_schema = (input_format in {'json', 'dict'}) and not keep_input_sort_order | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you run
|
||
|
||
self.line_number = 0 | ||
self.error_logs = [] | ||
|
@@ -1042,6 +1043,12 @@ def main(): | |
' This can be fetched with:' | ||
' `bq show --schema <project_id>:<dataset>:<table_name>', | ||
default=None) | ||
parser.add_argument( | ||
'--keep-input-sort-order', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use |
||
help='Preserve the original ordering of columns from input instead of sorting alphabetically.' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. break long line < 80 columns |
||
' This only only impacts `input_format` of json or dict', | ||
action='store_true' | ||
) | ||
args = parser.parse_args() | ||
|
||
# Configure logging. | ||
|
@@ -1056,6 +1063,7 @@ def main(): | |
debugging_map=args.debugging_map, | ||
sanitize_names=args.sanitize_names, | ||
ignore_invalid_lines=args.ignore_invalid_lines, | ||
keep_input_sort_order=args.keep_input_sort_order | ||
) | ||
existing_schema_map = read_existing_schema_from_file( | ||
args.existing_schema_path) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use
preserve_input_sort_order