@AfterMethod public void tearDownMethod() throws Exception { metastore.deleteProject("test"); eventDeserializer.cleanCache(); eventBuilder.cleanCache(); }
@Override public Event deserialize(JsonParser jp, DeserializationContext ctx) throws IOException { Object project = ctx.getAttribute("project"); Object masterKey = ctx.getAttribute("master_key"); return deserializeWithProject( jp, project != null ? project.toString() : null, null, Boolean.TRUE.equals(masterKey)); }
type = getTypeForUnknown(jp); newFields.add(newField); avroSchema = createNewSchema(avroSchema, newField); field = avroSchema.getField(newField.getName()); record.put(field.pos(), getValue(jp, type, field, true, project, collection)); } else { record.put(field.pos(), getValue(jp, type, field, false, project, collection)); (field.pos() >= rakamSchema.size() ? newFields.get(field.pos() - rakamSchema.size()) : rakamSchema.get(field.pos())).getType(); Object value = getValue(jp, type, field, false, project, collection); record.put(field.pos(), value);
private Object getValue(JsonParser jp, FieldType type, Schema.Field field, boolean passInitialToken, String project, String collection) throws IOException { if (type == null) { return getValueOfMagicField(jp); if (type.isArray()) { Schema actualSchema = field.schema().getTypes().get(1); Object value = getValue(jp, type.getArrayElementType(), null, false, project, collection); if(value == null) { LOGGER.warn(new RuntimeException(jp.getValueAsString()), String.format("Error while parsing %s field", type.name())); Object value; if (t.isScalarValue()) { value = getValue(jp, type.getMapValueType(), null, false, project, collection); } else { value = JsonHelper.encode(jp.readValueAsTree()); value = getValue(jp, type.getMapValueType(), null, false, project, collection); objects.add(getValue(jp, type.getArrayElementType(), null, false, project, collection));
if (t == JsonToken.START_OBJECT) { while (t == JsonToken.START_OBJECT) { Map.Entry<List<SchemaField>, GenericData.Record> entry = jsonEventDeserializer.parseProperties(project, collection, parser, true); events.add(new Event(project, collection, null, entry.getKey(), entry.getValue())); t = parser.nextToken(); Map.Entry<List<SchemaField>, GenericData.Record> entry = jsonEventDeserializer.parseProperties(project, collection, parser, true); events.add(new Event(project, collection, null, entry.getKey(), entry.getValue()));
type = getTypeForUnknown(jp); } else { type = MAP_STRING; return MAP_STRING; type = getTypeForUnknown(jp); if (type == null) {
public Object getValue(FieldType type, JsonParser jp) throws IOException { if (type == null) { return getValueOfMagicField(jp);
@BeforeSuite public void setUp() throws Exception { FieldDependencyBuilder.FieldDependency fieldDependency = new FieldDependencyBuilder().build(); apiKeyService = new InMemoryApiKeyService(); metastore = new InMemoryMetastore(apiKeyService); SchemaChecker schemaChecker = new SchemaChecker(metastore, fieldDependency); eventDeserializer = new JsonEventDeserializer(metastore, apiKeyService, new TestingConfigManager(), schemaChecker, new ProjectConfig(), fieldDependency); EventListDeserializer eventListDeserializer = new EventListDeserializer(apiKeyService, eventDeserializer); mapper = JsonHelper.getMapper(); mapper.registerModule(new SimpleModule() .addDeserializer(Event.class, eventDeserializer) .addDeserializer(EventList.class, eventListDeserializer)); eventBuilder = new EventBuilder("test", metastore); }
properties = parseProperties(project, collection, jp, masterKey); properties = parseProperties(project, collection, fakeJp, masterKey); } else { throw new JsonMappingException(jp, "properties is null");
public void store(String jsonRaw) throws IOException { if (jsonEventDeserializer == null) { throw new RakamException("Event store is not supported.", BAD_REQUEST); } JsonParser jp = JsonHelper.getMapper().getFactory().createParser(jsonRaw); JsonToken t = jp.nextToken(); if (t != JsonToken.START_ARRAY) { throw new RakamException("The script didn't return an array", BAD_REQUEST); } t = jp.nextToken(); List<Event> list = new ArrayList<>(); for (; t == START_OBJECT; t = jp.nextToken()) { list.add(jsonEventDeserializer.deserializeWithProject(jp, project, Event.EventContext.empty(), true)); } EventCollectionHttpService.mapEvent(eventMapperSet, eventMapper -> eventMapper.mapAsync(new EventList(Event.EventContext.empty(), list), EMPTY_PARAMS, localhost, HttpHeaders.EMPTY_HEADERS)); int[] ints = eventStore.storeBatch(list); if (ints.length > 0) { logger.error(format("Failed to save events: %s", Arrays.stream(ints).boxed().map(i -> i + "").collect(Collectors.joining(", ")))); } } }
list.add(eventDeserializer.deserializeWithProject(jp, project, context, masterKey));