/** * Returns a SQL string of the format {@code MAP((k1, v1), (k2, v2), (k3, v3), ...)} representing a map literal */ default String getMapArgumentString(Map<Object, Object> map, TestType mapKeyType, TestType mapValueType) { return "MAP" + "(" + map.entrySet() .stream() .map(entry -> "(" + getFunctionCallArgumentString(entry.getKey(), mapKeyType) + ", " + getFunctionCallArgumentString(entry.getValue(), mapValueType) + ")") .collect(Collectors.joining(", ")) + ")"; }
/** * Returns a SQL string of the format {@code MAP((k1, v1), (k2, v2), (k3, v3), ...)} representing a map literal */ default String getMapArgumentString(Map<Object, Object> map, TestType mapKeyType, TestType mapValueType) { return "MAP" + "(" + map.entrySet() .stream() .map(entry -> "(" + getFunctionCallArgumentString(entry.getKey(), mapKeyType) + ", " + getFunctionCallArgumentString(entry.getValue(), mapValueType) + ")") .collect(Collectors.joining(", ")) + ")"; }
/** * Returns a SQL string of the format {@code ARRAY(ele1, ele2, ele3, ...)} representing an array literal */ default String getArrayArgumentString(List<Object> array, TestType arrayElementType) { return "ARRAY" + "(" + array.stream() .map(element -> getFunctionCallArgumentString(element, arrayElementType)) .collect(Collectors.joining(", ")) + ")"; }
/** * Returns a SQL string of the format {@code ARRAY(ele1, ele2, ele3, ...)} representing an array literal */ default String getArrayArgumentString(List<Object> array, TestType arrayElementType) { return "ARRAY" + "(" + array.stream() .map(element -> getFunctionCallArgumentString(element, arrayElementType)) .collect(Collectors.joining(", ")) + ")"; }
/** * Returns a SQL string of the format {@code STRUCT(f1, f2, f3, ...)} representing a struct literal */ default String getStructArgumentString(Row struct, List<TestType> structFieldTypes) { List<Object> structFields = struct.getFields(); return "STRUCT" + "(" + IntStream.range(0, structFields.size()) .mapToObj(idx -> getFunctionCallArgumentString(structFields.get(idx), structFieldTypes.get(idx))) .collect(Collectors.joining(", ")) + ")"; } }
/** * Returns a SQL string of the format {@code STRUCT(f1, f2, f3, ...)} representing a struct literal */ default String getStructArgumentString(Row struct, List<TestType> structFieldTypes) { List<Object> structFields = struct.getFields(); return "STRUCT" + "(" + IntStream.range(0, structFields.size()) .mapToObj(idx -> getFunctionCallArgumentString(structFields.get(idx), structFieldTypes.get(idx))) .collect(Collectors.joining(", ")) + ")"; } }
/** * Returns SQL function call string of the format {@code functionName(argument1, argument2, argument3, ...)} */ default String getSqlFunctionCallString(FunctionCall functionCall) { return functionCall.getFunctionName() + "(" + IntStream.range(0, functionCall.getParameters().size()) .mapToObj(idx -> getFunctionCallArgumentString(functionCall.getParameters().get(idx), functionCall.getInferredParameterTypes().get(idx))) .collect(Collectors.joining(", ")) + ")"; }
/** * Returns SQL function call string of the format {@code functionName(argument1, argument2, argument3, ...)} */ default String getSqlFunctionCallString(FunctionCall functionCall) { return functionCall.getFunctionName() + "(" + IntStream.range(0, functionCall.getParameters().size()) .mapToObj(idx -> getFunctionCallArgumentString(functionCall.getParameters().get(idx), functionCall.getInferredParameterTypes().get(idx))) .collect(Collectors.joining(", ")) + ")"; }