class UDFHelper {

    public static String generateUDFClause(
        final String inTableName, final String functionName,
        final String outputCol, final String[] selectedCols, final String[] reservedCols) {
        final String selectedColsStr = TableUtil.columnsToSqlClause(selectedCols);

        // if outputCol is found in reservedCols, the one in reservedCols will not be output
        final String[] cleanedReservedCols = Arrays.stream(reservedCols)
            .filter(d -> !d.equals(outputCol))
            .toArray(String[]::new);

        StringBuilder sb = new StringBuilder();
        if (cleanedReservedCols.length > 0) {
            sb.append(TableUtil.columnsToSqlClause(cleanedReservedCols)).append(", ");
        }
        sb.append(functionName).append("(").append(selectedColsStr).append(") as `").append(outputCol).append("`");
        return String.format("SELECT %s FROM %s", sb.toString(), inTableName);
    }

}