-
Notifications
You must be signed in to change notification settings - Fork 995
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
MongoDbToBigQuery - ISO standard for date and time #2132
Open
OreOreDa
wants to merge
5
commits into
GoogleCloudPlatform:main
Choose a base branch
from
OreOreDa:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
306c28a
MongoDbToBigQuery - ISO standard for date and time
OreOreDa fc7c64b
set paramater default to true
OreOreDa 1660181
parameter update
OreOreDa e046b7a
Merge branch 'GoogleCloudPlatform:main' into main
OreOreDa 5d0614a
uuid update
OreOreDa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
set paramater default to true
- Loading branch information
commit fc7c64b0b5ceed91bedd9dfc0255a829349d491c
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,7 +79,7 @@ public class MongoDbUtils implements Serializable { | |
|
||
private static final Gson GSON = new Gson(); | ||
|
||
private static final JsonWriterSettings JSON_WRITER_SETTINGS = | ||
private static final JsonWriterSettings JSON_WRITER_SETTINGS_ISO_FORMAT = | ||
JsonWriterSettings.builder() | ||
.dateTimeConverter(new JsonDateTimeConverter()) | ||
.timestampConverter(new JsonTimestampConverter()) | ||
|
@@ -133,7 +133,7 @@ public static Document getMongoDbDocument(String uri, String dbName, String coll | |
} | ||
|
||
public static TableRow getTableSchema( | ||
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. Could you please add a unit test for legacy / iso time format? |
||
Document document, String userOption, Boolean useLegacyTimeFormat) { | ||
Document document, String userOption, Boolean useIsoTimeFormat) { | ||
TableRow row = new TableRow(); | ||
LocalDateTime localDate = LocalDateTime.now(ZoneId.of("UTC")); | ||
if (userOption.equals("FLATTEN")) { | ||
|
@@ -155,9 +155,9 @@ public static TableRow getTableSchema( | |
break; | ||
case "org.bson.Document": | ||
String data = | ||
useLegacyTimeFormat | ||
? GSON.toJson(value) | ||
: ((Document) value).toJson(JSON_WRITER_SETTINGS); | ||
useIsoTimeFormat | ||
? ((Document) value).toJson(JSON_WRITER_SETTINGS_ISO_FORMAT) | ||
: GSON.toJson(value); | ||
row.set(key, data); | ||
break; | ||
default: | ||
|
@@ -167,9 +167,9 @@ public static TableRow getTableSchema( | |
row.set("timestamp", localDate.format(TIMEFORMAT)); | ||
} else if (userOption.equals("JSON")) { | ||
JsonObject sourceDataJsonObject = | ||
useLegacyTimeFormat | ||
? GSON.toJsonTree(document).getAsJsonObject() | ||
: GSON.fromJson(document.toJson(JSON_WRITER_SETTINGS), JsonObject.class); | ||
useIsoTimeFormat | ||
? GSON.fromJson(document.toJson(JSON_WRITER_SETTINGS_ISO_FORMAT), JsonObject.class) | ||
: GSON.toJsonTree(document).getAsJsonObject(); | ||
|
||
// Convert to a Map | ||
Map<String, Object> sourceDataMap = | ||
|
@@ -180,7 +180,9 @@ public static TableRow getTableSchema( | |
.set("timestamp", localDate.format(TIMEFORMAT)); | ||
} else { | ||
String sourceData = | ||
useLegacyTimeFormat ? GSON.toJson(document) : document.toJson(JSON_WRITER_SETTINGS); | ||
useIsoTimeFormat | ||
? document.toJson(JSON_WRITER_SETTINGS_ISO_FORMAT) | ||
: GSON.toJson(document); | ||
|
||
row.set("id", document.get("_id").toString()) | ||
.set("source_data", sourceData) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The description is "use legacy time format" but the option name is "useIsoTimeFormat". The helpText (default is true) is also not true. Please fix.