Skip to content

Commit

Permalink
Revert "updating the default string to gson object for mongodb to big…
Browse files Browse the repository at this point in the history
…query da…" (GoogleCloudPlatform#1850)

This reverts commit bf05990.
  • Loading branch information
Polber authored and asthamohta committed Sep 15, 2024
1 parent 3f96cd5 commit 0f487b8
Showing 1 changed file with 3 additions and 12 deletions.
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

0 comments on commit 0f487b8

Please sign in to comment.