@Inject public PrestoRetentionQueryExecutor( ProjectConfig projectConfig, QueryExecutorService executor, Metastore metastore, MaterializedViewService materializedViewService, UserPluginConfig userPluginConfig) { this.projectConfig = projectConfig; this.executor = executor; this.metastore = metastore; this.materializedViewService = materializedViewService; this.userMappingEnabled = userPluginConfig.getEnableUserMapping(); }
@Inject public PrestoFunnelQueryExecutor( ProjectConfig projectConfig, PrestoConfig prestoConfig, FastGenericFunnelQueryExecutor fastPrestoFunnelQueryExecutor, PrestoApproxFunnelQueryExecutor approxFunnelQueryExecutor, Metastore metastore, QueryExecutor executor, UserPluginConfig userPluginConfig) { super(projectConfig, metastore, executor); this.prestoConfig = prestoConfig; this.fastPrestoFunnelQueryExecutor = fastPrestoFunnelQueryExecutor; this.approxFunnelQueryExecutor = approxFunnelQueryExecutor; this.userMappingEnabled = userPluginConfig.getEnableUserMapping(); this.fastPrestoFunnelQueryExecutor.setTimeStampMapping(timeStampMapping); this.approxFunnelQueryExecutor.setTimeStampMapping(timeStampMapping); super.timeStampMapping = timeStampMapping; }
if (!userPluginConfig.getEnableUserMapping()) { Multibinder<UserPropertyMapper> userPropertyMappers = Multibinder.newSetBinder(binder, UserPropertyMapper.class); Multibinder<EventMapper> eventMappers = Multibinder.newSetBinder(binder, EventMapper.class);
.append(config.getEnableUserMapping() ? "coalesce(mapping._user, collection._user, collection._device_id) as _user" : "collection._user") .append(" from %s collection"); if (config.getEnableUserMapping() && getHasDeviceId(project, filter.collection)) { if (config.getEnableUserMapping()) { builder.append(" group by mapping._user, collection._user, collection._device_id"); } else {
if (userPluginConfig.getEnableUserMapping()) { binder.bind(UserMergeTableHook.class).asEagerSingleton();
public void merge(String project, Object user, Object anonymousId, Instant createdAt, Instant mergedAt) { if (!config.getEnableUserMapping()) { throw new RakamException(NOT_IMPLEMENTED); } GenericData.Record properties = new GenericData.Record(ANONYMOUS_USER_MAPPING_SCHEMA); properties.put(0, anonymousId); properties.put(1, user); properties.put(2, createdAt.toEpochMilli()); properties.put(3, mergedAt.toEpochMilli()); eventStore.store(new Event(project, ANONYMOUS_ID_MAPPING, null, null, properties)); } }
if (userPluginConfig.getEnableUserMapping()) { binder.bind(UserMergeTableHook.class).asEagerSingleton();
@JsonRequest @ApiOperation(value = "Merge user with anonymous id", authorizations = @Authorization(value = "write_key")) @ApiResponses(value = {@ApiResponse(code = 404, message = "User does not exist.")}) @Path("/merge") @IgnoreApi @AllowCookie public void mergeUser(RakamHttpRequest request, @BodyParam MergeRequest mergeRequest) { // TODO: what if a user sends real user ids instead of its previous anonymous id? if (!config.getEnableUserMapping()) { throw new RakamException("The feature is not supported", PRECONDITION_FAILED); } Object anonymousId = mergeRequest.anonymousId; DefaultFullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, wrappedBuffer(OK_MESSAGE)); setBrowser(request, response); if (anonymousId == null) { throw new RakamException("Anonymous id is required", BAD_REQUEST); } String project = apiKeyService.getProjectOfApiKey(mergeRequest.api.apiKey, WRITE_KEY); service.merge(project, mergeRequest.id, anonymousId, Instant.ofEpochMilli(mergeRequest.createdAt), Instant.ofEpochMilli(mergeRequest.mergedAt)); request.response(response).end(); }
if (userPluginConfig.getEnableUserMapping()) { throw new IllegalStateException("Clickhouse module doesn't support user mapping.");
public void merge(String project, Object user, Object anonymousId, Instant createdAt, Instant mergedAt) { if (!config.getEnableUserMapping()) { throw new RakamException(HttpResponseStatus.NOT_IMPLEMENTED); } GenericData.Record properties = new GenericData.Record(ANONYMOUS_USER_MAPPING_SCHEMA); properties.put(0, anonymousId); properties.put(1, user); properties.put(2, (int) Math.floorDiv(createdAt.getEpochSecond(), 86400)); properties.put(3, (int) Math.floorDiv(mergedAt.getEpochSecond(), 86400)); eventStore.store(new Event(project, ANONYMOUS_ID_MAPPING, null, null, properties)); }