Skip to content
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

Revert "updating the default string to gson object for mongodb to bigquery da…" #1850

Merged
merged 1 commit into from
Sep 10, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import com.google.api.services.bigquery.model.TableRow;
import com.google.api.services.bigquery.model.TableSchema;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoCollection;
Expand All @@ -39,7 +37,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import javax.script.Invocable;
Expand Down Expand Up @@ -84,7 +81,7 @@ public static TableSchema getTableFieldSchema(
});
} else {
bigquerySchemaFields.add(new TableFieldSchema().setName("id").setType("STRING"));
bigquerySchemaFields.add(new TableFieldSchema().setName("source_data").setType("JSON"));
bigquerySchemaFields.add(new TableFieldSchema().setName("source_data").setType("STRING"));
}
bigquerySchemaFields.add(new TableFieldSchema().setName("timestamp").setType("TIMESTAMP"));
TableSchema bigquerySchema = new TableSchema().setFields(bigquerySchemaFields);
Expand Down Expand Up @@ -148,14 +145,8 @@ public static TableRow getTableSchema(Document document, String userOption) {
} else {
LocalDateTime localdate = LocalDateTime.now(ZoneId.of("UTC"));
String sourceData = GSON.toJson(document);
JsonObject sourceDataJsonObject = GSON.toJsonTree(document).getAsJsonObject();

// Convert to a Map
Map<String, Object> sourceDataMap =
GSON.fromJson(sourceDataJsonObject, new TypeToken<Map<String, Object>>() {}.getType());

row.set("id", document.get("_id").toString())
.set("source_data", sourceDataMap)
.set("source_data", sourceData)
.set("timestamp", localdate.format(TIMEFORMAT));
}
return row;
Expand Down Expand Up @@ -204,7 +195,7 @@ public static TableSchema getTableFieldSchemaForUDF(
});
} else {
bigquerySchemaFields.add(new TableFieldSchema().setName("id").setType("STRING"));
bigquerySchemaFields.add(new TableFieldSchema().setName("source_data").setType("JSON"));
bigquerySchemaFields.add(new TableFieldSchema().setName("source_data").setType("STRING"));
}

bigquerySchemaFields.add(new TableFieldSchema().setName("timestamp").setType("TIMESTAMP"));
Expand Down
Loading