/** * Get the type family of the requested field. * @param name The name of the field. * @return The type family or Option.absent() if no family was found/determined. */ private Optional<SqlTypeFamily> getSqlTypeFamily(final String name) { if (fields.containsKey(name)) { final ViewFieldType field = fields.get(name); try { return Optional.of(SqlTypeFamily.valueOf(field.getTypeFamily())); } catch (final IllegalArgumentException ex) { // return absent } } return Optional.absent(); }
private void validateDimensions(List<ReflectionDimensionField> fieldList, Map<String, ViewFieldType> schemaMap) { if (fieldList == null) { return; } for (ReflectionDimensionField reflectionField : fieldList) { // A field must exist in the schema Preconditions.checkArgument(schemaMap.containsKey(reflectionField.getName()), String.format("dimension field contains a field [%s] that does exist in the dataset", reflectionField.getName())); ViewFieldType fieldType = schemaMap.get(reflectionField.getName()); // We let ANY type pass primarily because pre-1.5 datasets may have valid fields marked as ANY. Preconditions.checkArgument(!Arrays.asList(SqlTypeFamily.ARRAY.name(), SqlTypeFamily.MAP.name()).contains(fieldType.getTypeFamily()), String.format("dimension field cannot have field [%s] of type list, map or union", reflectionField.getName())); } }
private void validateFields(List<ReflectionField> fieldList, Map<String, ViewFieldType> schemaMap, String fieldName, Boolean mustBePrimitive) { if (fieldList == null) { return; } for (ReflectionField reflectionField : fieldList) { // A field must exist in the schema Preconditions.checkArgument(schemaMap.containsKey(reflectionField.getName()), String.format("%s field contains a field name [%s] that does not exist in the dataset", fieldName, reflectionField.getName())); if (mustBePrimitive) { ViewFieldType fieldType = schemaMap.get(reflectionField.getName()); // We let ANY type pass primarily because pre-1.5 datasets may have valid fields marked as ANY. Preconditions.checkArgument(!Arrays.asList(SqlTypeFamily.ARRAY.name(), SqlTypeFamily.MAP.name()).contains(fieldType.getTypeFamily()), String.format("%s field cannot have field [%s] of type list, map or union", fieldName, reflectionField.getName())); } } }
private void validateMeasures(List<ReflectionMeasureField> fieldList, Map<String, ViewFieldType> schemaMap, String fieldName) { if (fieldList == null) { return; } for (ReflectionMeasureField measureField : fieldList) { // A field must exist in the schema Preconditions.checkArgument(schemaMap.containsKey(measureField.getName()), String.format("%s field contains a field name [%s] that does not exist in the dataset", fieldName, measureField.getName())); ViewFieldType fieldType = schemaMap.get(measureField.getName()); // We let ANY type pass primarily because pre-1.5 datasets may have valid fields marked as ANY. Preconditions.checkArgument(!Arrays.asList(SqlTypeFamily.ARRAY.name(), SqlTypeFamily.MAP.name()).contains(fieldType.getTypeFamily()), String.format("%s field cannot have field [%s] of type list, map or union", fieldName, measureField.getName())); final SqlTypeFamily family; try { family = SqlTypeFamily.valueOf(fieldType.getTypeFamily()); } catch (RuntimeException ex) { throw UserException.validationError().message("Field %s cannot be configured as measure due to unexpected type of %s." ).build(logger); } final List<MeasureType> measures = AccelerationUtils.selfOrEmpty(measureField.getMeasureTypeList()) .stream() .map(ReflectionValidator::toSqlMeasureType) .collect(Collectors.toList()); // validate field types AccelCreateReflectionHandler.validate(fieldName, family, measures); } }