@Subscribe public void onCreateProject(SystemEvents.ProjectCreatedEvent event) { FieldType type = configManager.getConfig(event.project, USER_TYPE.name(), FieldType.class); if (type != null) { if (storage.isPresent()) { storage.get().createProjectIfNotExists(event.project, type.isNumeric()); } } } }
(id instanceof Integer ? FieldType.INTEGER : FieldType.STRING)); FieldType fieldType = configManager.setConfigOnce(project, USER_TYPE.name(), other); createProjectIfNotExists(project, fieldType.isNumeric()); columns = loadColumns(project);
if (!unchecked.isPresent() || !unchecked.get().isNumeric()) { ps.setString(1, userId.toString()); } else if (unchecked.get() == FieldType.LONG) {
.filter(field -> field.getType() != BINARY) .map(field -> { if (field.getType().isNumeric()) { return format("\"%1$s\": '|| COALESCE(cast(%1$s as varchar), 'null')||'", field.getName()); "\"" + prestoConfig.getColdStorageConnector() + "\"" + ".\"" + context.project + "\"." + checkCollection(entry.getKey()), checkTableColumn(projectConfig.getUserColumn()), userType.get().isNumeric() ? user : "'" + user + "'", beforeThisTime == null ? "" : format("and %s < from_iso8601_timestamp('%s')", checkTableColumn(projectConfig.getTimeColumn()), beforeThisTime.toString()))) .collect(Collectors.joining(" union all "));
public void incrementProperty(Connection conn, String project, Object userId, String property, double value) throws SQLException { Map<String, FieldType> columns = createMissingColumns(project, userId, ImmutableList.of(new SimpleImmutableEntry<>(property, new DoubleNode(value))), new CommitConnection(conn)); FieldType fieldType = columns.get(property); if (fieldType == null) { createColumn(project, userId, property, JsonHelper.numberNode(0)); } if (!fieldType.isNumeric()) { throw new RakamException(String.format("The property the is %s and it can't be incremented.", fieldType.name()), BAD_REQUEST); } String tableRef = checkTableColumn(stripName(property, "table column")); Statement statement = conn.createStatement(); ProjectCollection userTable = getUserTable(project, false); String table = checkProject(userTable.project, '"') + "." + checkCollection(userTable.collection); int execute = statement.executeUpdate("update " + table + " set " + tableRef + " = " + value + " + coalesce(" + tableRef + ", 0)"); if (execute == 0) { create(project, userId, JsonHelper.jsonObject().put(property, value)); } }
FieldType fieldType = configManager.setConfigOnce(project, USER_TYPE.name(), other); createProjectIfNotExists(project, fieldType.isNumeric());
throw new RakamException("_user field must be numeric or string.", BAD_REQUEST); final FieldType eventUserType = type.isNumeric() ? (type != INTEGER ? LONG : INTEGER) : STRING; type = configManager.setConfigOnce(project, USER_TYPE.name(), eventUserType);
.filter(field -> field.getType() != BINARY) .map(field -> { if (field.getType().isNumeric()) { return format("\"%1$s\": ', COALESCE(cast(%1$s as varchar), 'null'), '", field.getName()); format(" }') as json, _time from %s where _user = %s %s", ".\"" + project + "\"." + ValidationUtil.checkCollection(entry.getKey(), '`'), userType.get().isNumeric() ? user : "'" + user + "'", beforeThisTime == null ? "" : format("and _time < toDateTime('%s')", beforeThisTime.toString()))) .collect(Collectors.joining(" union all "));
String hashFunction = userColumn.get().getType().isNumeric() ? "intHash32" : "cityHash64"; properties = format("ENGINE = MergeTree(`$date`, %s(_user), (`$date`, %s(_user)), 8192)", hashFunction, hashFunction); } else {