Last active
August 14, 2017 11:41
-
-
Save spark2ignite/35b78bb689060eb630468e0e8616b70f to your computer and use it in GitHub Desktop.
How we saved over $240K per year by replacing Mixpanel with Google BigQuery, Pub/Sub, Dataflow & Kubernetes (code snippet #4)
This file contains hidden or 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
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()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ok