/** * Helper method to validate that the target types are of one data type, and get that data type * * @return the DataType of the target types */ @Nullable private AttributeType.DataType<?> validateAndGetTargetDataType() { AttributeType.DataType<?> dataType = null; for (Type type : targetTypes()) { // check if the selected type is a attribute type if (!type.isAttributeType()) throw GraqlQueryException.mustBeAttributeType(type.label()); AttributeType<?> attributeType = type.asAttributeType(); if (dataType == null) { // check if the attribute type has data-type LONG or DOUBLE dataType = attributeType.dataType(); if (!dataType.equals(AttributeType.DataType.LONG) && !dataType.equals(AttributeType.DataType.DOUBLE)) { throw GraqlQueryException.attributeMustBeANumber(dataType, attributeType.label()); } } else { // check if all the attribute types have the same data-type if (!dataType.equals(attributeType.dataType())) { throw GraqlQueryException.attributesWithDifferentDataTypes(query.of().get()); } } } return dataType; }
private Thing putInstance() { Type type = use(TYPE); if (type.isEntityType()) { return type.asEntityType().create(); } else if (type.isRelationshipType()) { return type.asRelationshipType().create(); } else if (type.isAttributeType()) { return type.asAttributeType().create(use(VALUE)); } else if (type.label().equals(Schema.MetaSchema.THING.getLabel())) { throw GraqlQueryException.createInstanceOfMetaConcept(var, type); } else { throw CommonUtil.unreachableStatement("Can't recognize type " + type); } }