Created
August 27, 2020 03:14
-
-
Save wiserfirst/ce271e32393ae79d92f82a398f401363 to your computer and use it in GitHub Desktop.
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
def hello | |
src = File.open('/Users/wiser/Downloads/sample.avro', 'rb') | |
dst = File.open('/Users/wiser/Downloads/dest.avro', 'wb') | |
# p get_events(file) | |
data_reader = | |
Avro::DataFile::Reader.new(src, Avro::IO::DatumReader.new) | |
record = data_reader.first | |
schema = Avro::Schema.parse(data_reader.meta["avro.schema"]) | |
# Creates DatumWriter instance with required schema. | |
writer = Avro::IO::DatumWriter.new(schema) | |
# Below dw is equivalent to DataFileWriter instance in Java API | |
dw = Avro::DataFile::Writer.new(dst, writer, schema) | |
record["campaign_name"] = "Braze Currents sample Campaign" | |
record["timezone"] = "Sydney/Australia" | |
record["time"] = Time.now.to_i | |
record["external_user_id"] = SecureRandom.uuid | |
record["id"] = SecureRandom.uuid | |
record["dispatch_id"] = SecureRandom.uuid.gsub('-', '') | |
record["user_id"] = SecureRandom.uuid.gsub('-', '')[0..23] | |
record["email_address"] = "braze_currents1@example.com" | |
dw<< record | |
record["external_user_id"] = SecureRandom.uuid | |
record["id"] = SecureRandom.uuid | |
record["dispatch_id"] = SecureRandom.uuid.gsub('-', '') | |
record["user_id"] = SecureRandom.uuid.gsub('-', '')[0..23] | |
record["email_address"] = "braze_currents2@example.com" | |
dw<< record | |
dw.close | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment