public static JDBCType jdbcType(FieldType type) { if (type.equals(FieldType.BOOLEAN)) { return JDBCType.BOOLEAN; } if (type.equals(LONG) || type.equals(TIMESTAMP)) { return JDBCType.BIGINT; } if (type.equals(FieldType.INTEGER)) { return JDBCType.INTEGER; } if (type.equals(FieldType.DOUBLE)) { return JDBCType.DOUBLE; } if (type.equals(FieldType.DATE)) { return JDBCType.INTEGER; } if (type.equals(FieldType.STRING)) { return VARBINARY; } return null; }
private void checkFields(List<SchemaField> fields) { SchemaField[] collisions = fields.stream() .filter(newField -> constantFields.stream() .anyMatch(f -> f.getName().equals(newField.getName()) && !f.getType().equals(newField.getType()))) .toArray(SchemaField[]::new); checkState(collisions.length == 0, "Module field collides with existing field that has another type exists: ", Arrays.toString(collisions)); collisions = dependentFields.values().stream() .flatMap(col -> col.stream()) .filter(field -> fields.stream().anyMatch(f -> f.getName().equals(field.getName()) && !f.getType().equals(field.getType()))) .toArray(SchemaField[]::new); checkState(collisions.length == 0, "Fields already exist in dependency table: ", Arrays.toString(collisions)); }
private void addModuleField(Set<SchemaField> fields, SchemaField newField) { Iterator<SchemaField> iterator = fields.iterator(); while (iterator.hasNext()) { SchemaField field = iterator.next(); if (field.getName().equals(newField.getName())) { if (field.getType().equals(newField.getType())) { return; } else { iterator.remove(); break; } } } fields.add(newField); }
.anyMatch(e -> e.getValue().stream().anyMatch(z -> z.getType().equals(STRING)));
public HashSet<SchemaField> checkNewFields(String collection, Set<SchemaField> newFields) { HashSet<SchemaField> fields = new HashSet<>(newFields); Iterator<SchemaField> it = fields.iterator(); while (it.hasNext()) { SchemaField newField = it.next(); if (fieldDependency.dependentFields.containsKey(newField)) { it.remove(); } if (newField.getName().startsWith("_")) { for (Map.Entry<String, List<SchemaField>> entry : fieldDependency.dependentFields.entrySet()) { Optional<SchemaField> collision = entry.getValue().stream() .filter(e -> e.getName().equals(newField.getName()) && !e.getType().equals(e.getType())) .findAny(); if (collision.isPresent()) { throw new RakamException(format("Field %s.%s collides with one of the magic field with type %s", collection, newField.getName(), collision.get().getType()), BAD_REQUEST); } } } if (newField.getName().equals("$server_time")) { throw new RakamException("$server_time is reserved as a system attribute", BAD_REQUEST); } } fieldDependency.constantFields.forEach(field -> addModuleField(fields, field)); fieldDependency.dependentFields.forEach((fieldName, field) -> addConditionalModuleField(fields, fieldName, field)); return fields; }
private boolean check(String project, String collection, SchemaField existing, SchemaField moduleField) { if (existing.getName().equals(moduleField.getName())) { if (!existing.getType().equals(moduleField.getType())) { throw new IllegalStateException(format("Module field '%s' type does not match existing field in event of project %s.%s. Existing type: %s, Module field type: %s. \n" + "Please change the schema manually of disable the module.", existing.getName(), project, collection, existing.getType(), moduleField.getType())); } return true; } return false; } }
.filter(f -> fields.stream().anyMatch(field -> field.getName().equals(f.getName()) && !f.getType().equals(field.getType()))) .collect(Collectors.toList());
Optional<SchemaField> existing = fields.stream().filter(e -> e.getName().equals(newField.getName())).findAny(); if (existing.isPresent()) { if (!existing.get().getType().equals(newField.getType())) { throw new IllegalStateException(String.format("Multiple entries with same key for collection %s field %s: %s,%s", collection, newField.getName(), newField.getType(), existing.get().getType()));
for (FieldType fieldType : tableInfo.getFieldTypes()) { // if this is a foreign field and its foreign-id field is the same as the other's id FieldType foreignIdField = fieldType.getForeignIdField(); if (fieldType.isForeign() && foreignIdField.equals(joinedQueryBuilder.tableInfo.getIdField())) { joinInfo.localField = fieldType; joinInfo.remoteField = foreignIdField; return; } } // if this other field is a foreign field and its foreign-id field is our id for (FieldType fieldType : joinedQueryBuilder.tableInfo.getFieldTypes()) { if (fieldType.isForeign() && fieldType.getForeignIdField().equals(idField)) { joinInfo.localField = idField; joinInfo.remoteField = fieldType; return; } }