@Override public int hashCode() { // Not relying on Enum hashcode String typeString = type == null ? null : type.getName(); return Objects.hash(typeString, field); }
@SuppressWarnings("unchecked") private static GroupOperation makeOperation(Object object) { try { Map<String, String> data = (Map<String, String>) object; String type = data.get(OPERATION_TYPE); Optional<GroupOperationType> operation = SUPPORTED_GROUP_OPERATIONS.stream().filter(t -> t.isMe(type)).findFirst(); // May or may not be present String field = data.get(OPERATION_FIELD); // May or may not be present String newName = data.get(OPERATION_NEW_NAME); // Unknown GroupOperations are ignored. return operation.isPresent() ? new GroupOperation(operation.get(), field, newName) : null; } catch (ClassCastException | NullPointerException e) { return null; } } }
/** * Get the {@link Type} of this FunctionCall. * * @param clazz {@link Type} class. * @return The {@link Type}. */ public Type getType(Class<SelectItem.Type> clazz) { if (type.toString().equalsIgnoreCase("count") && distinct) { return Type.COUNT_DISTINCT; } return Type.GROUP; }
/** * Returns the name of the result field to use for the given {@link GroupOperation}. If the operation * does specify a newName, it will be returned. Otherwise, a composite name containing the type of the * operation as well as the field name will be used (if provided). * * @param operation The operation to get the name for. * @return a String representing a name for the result of the operation. */ public static String getResultName(GroupOperation operation) { String name = operation.getNewName(); if (name != null) { return name; } GroupOperation.GroupOperationType type = operation.getType(); String field = operation.getField(); if (field == null) { return type.getName(); } return type.getName() + NAME_SEPARATOR + operation.getField(); }
private GroupOperationType getGroupOperationType(BQLBaseParser.FunctionCallContext context) { String functionName = context.qualifiedName().getText().toUpperCase(); return GroupOperationType.valueOf(functionName); }