org.rakam.collection.Event类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.1k)|赞(0)|评价(0)|浏览(100)

本文整理了Java中org.rakam.collection.Event类的一些代码示例,展示了Event类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Event类的具体详情如下:
包路径:org.rakam.collection.Event
类名称:Event

Event介绍

暂无

代码示例

代码示例来源:origin: rakam-io/rakam

@Test
public void testSimpleWithoutProject()
    throws Exception {
  Event.EventContext api = Event.EventContext.apiKey(apiKeys.writeKey());
  byte[] bytes = mapper.writeValueAsBytes(ImmutableMap.of(
      "collection", "test",
      "api", api,
      "properties", ImmutableMap.of()));
  Event event = mapper.readValue(bytes, Event.class);
  assertEquals("test", event.project());
  assertEquals("test", event.collection());
  assertEquals(api, event.api());
  assertEquals(eventBuilder
      .createEvent("test", ImmutableMap.of()).properties(), event.properties());
}

代码示例来源:origin: rakam-io/rakam

public String process(String project, Supplier<User> user, SendEventAction sendEventAction) {
  new Event(project, sendEventAction.collection, null, null, null);
  return null;
}

代码示例来源:origin: rakam-io/rakam

@Override
public void set(String attr, Object value) {
  try {
    event.properties().put(attr, value);
  } catch (AvroRuntimeException e) {
    List<SchemaField> fields = metastore.getOrCreateCollectionFields(event.project(), event.collection(),
        ImmutableSet.of(new SchemaField(attr, attrValue.fieldType)));
    List<Schema.Field> oldFields = event.properties().getSchema().getFields();
    for (Schema.Field field : event.properties().getSchema().getFields()) {
      record.put(field.name(), event.getAttribute(field.name()));
    AvroUtil.put(event.properties(), attr, attrValue.value);
    event.properties(record, fields);

代码示例来源:origin: rakam-io/rakam

private String getPartitionKey(Event event) {
  Object user = event.getAttribute("_user");
  return event.project() + "|" + (user == null ? event.collection() : user.toString());
}

代码示例来源:origin: rakam-io/rakam

@Override
  public User get() {
    if (user == null) {
      String userAttr = event.getAttribute("_user");
      if (userAttr != null) {
        user = userStorage.getUser(new RequestContext(event.project(), null), userAttr).join();
      }
    }
    return user;
  }
};

代码示例来源:origin: rakam-io/rakam

@Override
public List<Cookie> map(Event event, RequestParams requestParams, InetAddress sourceAddress, HttpHeaders responseHeaders) {
  List<CollectionStreamHolder> streamHolder = lists.get(event.project());
        if (item.collection != null && !item.collection.equals(event.collection())) {
          continue;
        if (!item.filter.test(event.properties())) {
          continue;

代码示例来源:origin: rakam-io/rakam

@Test()
public void testUnknownReferrer() throws Exception {
  ReferrerEventMapper mapper = new ReferrerEventMapper();
  FieldDependencyBuilder builder = new FieldDependencyBuilder();
  mapper.addFieldDependency(builder);
  builder.build();
  List<SchemaField> fields = builder.build().dependentFields.get("_referrer");
  ImmutableList<Schema.Field> build = ImmutableList.<Schema.Field>builder()
      .addAll(fields.stream()
          .map(AvroUtil::generateAvroField).collect(Collectors.toList()))
      .add(new Schema.Field("_referrer", Schema.create(NULL), null, null))
      .build();
  GenericData.Record properties = new GenericData.Record(Schema.createRecord(build));
  properties.put("_referrer", "http://test.com");
  Event event = new Event("testproject", "testcollection", null, null, properties);
  List<Cookie> resp = mapper.map(event, EventMapper.RequestParams.EMPTY_PARAMS, InetAddress.getLocalHost(), null);
  assertNull(resp);
  assertNull(event.getAttribute("_referrer_source"));
  assertNull(event.getAttribute("_referrer_term"));
  assertEquals("unknown", event.getAttribute("_referrer_medium"));
  assertEquals("test.com", event.getAttribute("_referrer_domain"));
  assertEquals("", event.getAttribute("_referrer_path"));
}

代码示例来源:origin: rakam-io/rakam

public void store(Event event, boolean partitionCheckDone) {
  GenericRecord record = event.properties();
  try (Connection connection = connectionPool.getConnection()) {
    Schema schema = event.properties().getSchema();
    PreparedStatement ps = connection.prepareStatement(getQuery(event.project(), event.collection(), schema));
    bindParam(connection, ps, event.schema(), record);
    ps.executeUpdate();
  } catch (SQLException e) {
    // check_violation -> https://www.postgresql.org/docs/8.2/static/errcodes-appendix.html
    if (version.getVersion() == PG10 && !partitionCheckDone && "23514".equals(e.getSQLState())) {
      generateMissingPartitions(event.project(), event.collection(), ImmutableList.of(event), 0);
      store(event, true);
    } else {
      throw new RuntimeException(e);
    }
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: rakam-io/rakam

public <T> T getAttribute(String attr) {
  return (T) properties().get(attr);
}

代码示例来源:origin: rakam-io/rakam

@Test(dataProvider = "google-ips")
public void testEventMapper(Map<String, Object> props, InetAddress address)
    throws Exception {
  MaxmindGeoIPEventMapper mapper = new MaxmindGeoIPEventMapper(new MaxmindGeoIPModuleConfig());
  FieldDependencyBuilder builder = new FieldDependencyBuilder();
  mapper.addFieldDependency(builder);
  ImmutableList<Schema.Field> build = ImmutableList.<Schema.Field>builder()
      .addAll(builder.build().dependentFields.get("_ip").stream()
          .map(AvroUtil::generateAvroField).collect(Collectors.toList()))
      .add(new Schema.Field("_ip", Schema.create(NULL), null, null))
      .build();
  Record properties = new Record(Schema.createRecord(build));
  props.forEach(properties::put);
  Event event = new Event("testproject", "testcollection", null, null, properties);
  List<Cookie> resp = mapper.map(event, EventMapper.RequestParams.EMPTY_PARAMS, address, null);
  assertTrue(resp == null);
  assertTrue(event.properties().getSchema().getField("_country_code") != null);
  assertTrue(event.properties().getSchema().getField("_city") != null);
  assertTrue(event.properties().getSchema().getField("_timezone") != null);
  assertTrue(event.getAttribute("_latitude") instanceof Double);
  assertTrue(event.properties().getSchema().getField("_region") != null);
  assertTrue(event.getAttribute("_longitude") instanceof Double);
  GenericData.get().validate(properties.getSchema(), properties);
}

代码示例来源:origin: rakam-io/rakam

@Override
public List<Cookie> map(Event event, RequestParams extraProperties, InetAddress sourceAddress, HttpHeaders responseHeaders) {
  final List<AutomationRule> automationRules = service.list(event.project());
  if (automationRules == null) {
    return null;
    if (event.collection().equals(scenarioStep.collection) && scenarioStep.filterPredicate.test(event)) {
          action.getAction().process(event.project(), supplier, action.value);

代码示例来源:origin: rakam-io/rakam

private ByteBuf getBuffer(Event event) {
    DatumWriter writer = new FilteredRecordWriter(event.properties().getSchema(), GenericData.get());
    ByteBuf buffer = DEFAULT.buffer(100);
    buffer.writeByte(2);

    BinaryEncoder encoder = EncoderFactory.get()
        .directBinaryEncoder(new ByteBufOutputStream(buffer), null);

    try {
      encoder.writeString(event.collection());

      writer.write(event.properties(), encoder);
    } catch (Exception e) {
      throw new RuntimeException("Couldn't serialize event", e);
    }

    return buffer;
  }
}

代码示例来源:origin: rakam-io/rakam

PreparedStatement ps = connection.prepareStatement(getQuery(lastEvent.project(),
    collection, lastEvent.properties().getSchema()));
  GenericRecord properties = event.properties();
  bindParam(connection, ps, lastEvent.schema(), properties);
  ps.addBatch();
  if (i > 0 && i % 5000 == 0) {
        generateMissingPartitions(event.project(), collection, eventsForCollection, 0);
        ps.cancel();
        connection.rollback();
    generateMissingPartitions(lastEvent.project(), collection, eventsForCollection, 0);
    ps.cancel();
    connection.rollback();

代码示例来源:origin: rakam-io/rakam

generator.writeString(event.collection());
List<SchemaField> fields = event.schema();
for (SchemaField field : fields) {
  generator.writeFieldName("properties." + field.getName());
  Object value = event.getAttribute(field.getName());
  if (value == null) {
    generator.writeNull();

代码示例来源:origin: rakam-io/rakam

@Override
public List<Cookie> map(Event event, RequestParams extraProperties, InetAddress sourceAddress, HttpHeaders responseHeaders) {
  GenericRecord properties = event.properties();
  Object time = properties.get(projectConfig.getTimeColumn());
  if (time == null) {
    long serverTime = Instant.now().getEpochSecond();
    properties.put(projectConfig.getTimeColumn(), serverTime * 1000);
  } else if (time instanceof Number && event.api() != null && event.api().uploadTime != null) {
    // match server time and client time and get an estimate
    long fixedTime = ((Number) time).longValue() + ((Instant.now().getEpochSecond() - (event.api().uploadTime / 1000)) * 1000);
    properties.put(projectConfig.getTimeColumn(), fixedTime);
  }
  return null;
}

代码示例来源:origin: rakam-io/rakam

@Override
public Object get(String attr) {
  return event.getAttribute(attr);
}

代码示例来源:origin: org.rakam/rakam-clickhouse

private ByteBuffer getBuffer(Event event)
{
  SharedByteArrayOutputStream buffer = new SharedByteArrayOutputStream(event.properties().getSchema().getFields().size() * 8);
  LittleEndianDataOutputStream out = new LittleEndianDataOutputStream(buffer);
  GenericRecord record = event.properties();
  Object time = record.get("_time");
  try {
    int size = event.schema().size();
    writeVarInt(size, out);
    writeValue(time == null ? 0 : ((int) (((long) time) / 86400000)), DATE, out);
    for (int i = 0; i < size; i++) {
      writeValue(record.get(i), event.schema().get(i).getType(), out);
    }
  }
  catch (IOException e) {
    throw Throwables.propagate(e);
  }
  return buffer.toByteBuffer();
}

代码示例来源:origin: rakam-io/rakam

@Override
public String collection() {
  return event.collection();
}

代码示例来源:origin: rakam-io/rakam

@Override
public CompletableFuture<List<Cookie>> mapAsync(Event event, RequestParams requestParams, InetAddress sourceAddress, HttpHeaders responseHeaders) {
  return mapInternal(event.project(), new EventsProxy() {
    @Override
    public Event.EventContext api() {
      return event.api();
    }
    @Override
    public String project() {
      return event.project();
    }
    @Override
    public Iterator<EventProxy> events() {
      return Iterators.singletonIterator(new ListEventProxy(event));
    }
  }, requestParams, sourceAddress, responseHeaders);
}

代码示例来源:origin: rakam-io/rakam

private Event getLastEvent(List<Event> eventsForCollection) {
  Event event = eventsForCollection.get(0);
  for (int i = 1; i < eventsForCollection.size(); i++) {
    Event newEvent = eventsForCollection.get(i);
    if (newEvent.schema().size() > event.schema().size()) {
      event = newEvent;
    }
  }
  return event;
}

相关文章