Skip to content

Instantly share code, notes, and snippets.

@spark2ignite
Last active Aug 14, 2017
Embed
What would you like to do?
How we saved over $240K per year by replacing Mixpanel with Google BigQuery, Pub/Sub, Dataflow & Kubernetes (code snippet #4)
package com.jellybtn;
import com.google.api.services.bigquery.model.TableRow;
import com.google.cloud.dataflow.sdk.values.TupleTag;
import org.json.JSONObject;
public class MapPeople extends BaseMap {
MapPeople(TupleTag < TableRow > errorsTag) {
super(errorsTag);
}
@Override
String getType() {
return "people";
}
@Override
void map(JSONObject json, TableRow tableRow) {
if (json.has("$distinct_id")) {
tableRow.set("distinct_id", json.get("$distinct_id"));
}
if (json.has("$token")) {
tableRow.set("token", json.get("$token"));
}
if (json.has("$set")) {
tableRow.set("action", "set");
tableRow.set("properties", json.get("$set").toString());
} else if (json.has("$set_once")) {
tableRow.set("action", "set_once");
tableRow.set("properties", json.get("$set_once").toString());
} else if (json.has("$union")) {
tableRow.set("action", "union");
tableRow.set("properties", json.get("$union").toString());
}
}
}
@spark2ignite
Copy link
Author

spark2ignite commented Aug 14, 2017

ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment