From 797a939be45501fa8a5c1eb303df4ebc3c1e7c51 Mon Sep 17 00:00:00 2001 From: ErmiasG Date: Tue, 4 Jun 2024 14:08:23 +0200 Subject: [PATCH] [HWORKS-1197] Add support for case insensitive search on datasets api (#1530) --- .../common/dao/dataset/DatasetFacade.java | 6 +- .../dao/dataset/DatasetSharedWithFacade.java | 68 ++++--------------- .../common/dao/hdfs/inode/InodeFacade.java | 10 ++- 3 files changed, 27 insertions(+), 57 deletions(-) diff --git a/hopsworks-common/src/main/java/io/hops/hopsworks/common/dao/dataset/DatasetFacade.java b/hopsworks-common/src/main/java/io/hops/hopsworks/common/dao/dataset/DatasetFacade.java index 9b232c7b2e..057a2bf9c9 100644 --- a/hopsworks-common/src/main/java/io/hops/hopsworks/common/dao/dataset/DatasetFacade.java +++ b/hopsworks-common/src/main/java/io/hops/hopsworks/common/dao/dataset/DatasetFacade.java @@ -202,6 +202,8 @@ private void setFilter(Set filter, Query q) { private void setFilterQuery(AbstractFacade.FilterBy filterBy, Query q) { switch (Filters.valueOf(filterBy.getValue())) { case NAME: + case NAME_NEQ: + case NAME_LIKE: q.setParameter(filterBy.getField(), filterBy.getParam()); break; case ACCEPTED: @@ -259,7 +261,9 @@ public String toString() { } public enum Filters { - NAME("NAME", "d.name LIKE CONCAT(:name, '%') ", "name", " "), + NAME("NAME", "LOWER(d.name) LIKE LOWER(CONCAT(:name, '%')) ", "name", " "), + NAME_NEQ("NAME_NEQ", "LOWER(d.name) NOT LIKE LOWER(CONCAT(:name_not_eq, '%')) ", "name_not_eq", " "), + NAME_LIKE("NAME_LIKE", "LOWER(d.name) LIKE LOWER(CONCAT('%', :name_like, '%')) ", "name_like", " "), ACCEPTED("ACCEPTED", "true =:accepted ", "accepted", "true"),//return all if true SHARED("SHARED", "NOT :shared ", "shared", "true"),//return none if true SEARCHABLE("SEARCHABLE", "d.searchable =:searchable ", "searchable", "0"), diff --git a/hopsworks-common/src/main/java/io/hops/hopsworks/common/dao/dataset/DatasetSharedWithFacade.java b/hopsworks-common/src/main/java/io/hops/hopsworks/common/dao/dataset/DatasetSharedWithFacade.java index 2f38aab105..df9c75595b 100644 --- a/hopsworks-common/src/main/java/io/hops/hopsworks/common/dao/dataset/DatasetSharedWithFacade.java +++ b/hopsworks-common/src/main/java/io/hops/hopsworks/common/dao/dataset/DatasetSharedWithFacade.java @@ -16,19 +16,16 @@ package io.hops.hopsworks.common.dao.dataset; import io.hops.hopsworks.common.dao.AbstractFacade; -import io.hops.hopsworks.common.dao.hdfs.inode.InodeFacade; -import io.hops.hopsworks.persistence.entity.project.Project; import io.hops.hopsworks.persistence.entity.dataset.Dataset; import io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith; import io.hops.hopsworks.persistence.entity.dataset.DatasetType; +import io.hops.hopsworks.persistence.entity.project.Project; -import javax.ejb.EJB; import javax.ejb.Stateless; import javax.persistence.EntityManager; import javax.persistence.NoResultException; import javax.persistence.PersistenceContext; import javax.persistence.Query; -import java.util.Date; import java.util.List; import java.util.Set; @@ -38,8 +35,6 @@ public class DatasetSharedWithFacade extends AbstractFacade { @PersistenceContext(unitName = "kthfsPU") private EntityManager em; - @EJB - private InodeFacade inodeFacade; @Override protected EntityManager getEntityManager() { @@ -76,56 +71,37 @@ public CollectionInfo findAllDatasetByProject(Integer offset, Integer limit, Set "d.project = :project "); Query query = em.createQuery(queryStr, DatasetSharedWith.class).setParameter("project", project); Query queryCount = em.createQuery(queryCountStr, DatasetSharedWith.class).setParameter("project", project); - setFilter(filter, query, project); - setFilter(filter, queryCount, project); + setFilter(filter, query); + setFilter(filter, queryCount); setOffsetAndLim(offset, limit, query); return new CollectionInfo((Long) queryCount.getSingleResult(), query.getResultList()); } - private void setFilter(Set filter, Query q, Project project) { + private void setFilter(Set filter, Query q) { if (filter == null || filter.isEmpty()) { return; } for (FilterBy aFilter : filter) { - setFilterQuery(aFilter, q, project); + setFilterQuery(aFilter, q); } } - private void setFilterQuery(AbstractFacade.FilterBy filterBy, Query q, Project project) { + private void setFilterQuery(AbstractFacade.FilterBy filterBy, Query q) { switch (Filters.valueOf(filterBy.getValue())) { case NAME: + case NAME_NEQ: + case NAME_LIKE: q.setParameter(filterBy.getField(), filterBy.getParam()); break; case ACCEPTED: case PUBLIC: case SHARED: case SEARCHABLE: - case UNDER_CONSTRUCTION: q.setParameter(filterBy.getField(), getBooleanValue(filterBy.getParam())); break; case TYPE: q.setParameter(filterBy.getField(), getEnumValue(filterBy.getField(), filterBy.getValue(), DatasetType.class)); break; - case HDFS_USER: - q.setParameter(filterBy.getField(), inodeFacade.gethdfsUser(filterBy.getParam())); - break; - case USER_EMAIL: - q.setParameter(filterBy.getField(), inodeFacade.getUsers(filterBy.getParam(), project)); - break; - case ACCESS_TIME: - case ACCESS_TIME_GT: - case ACCESS_TIME_LT: - case MODIFICATION_TIME: - case MODIFICATION_TIME_GT: - case MODIFICATION_TIME_LT: - Date date = getDate(filterBy.getField(), filterBy.getParam()); - q.setParameter(filterBy.getField(), date.getTime()); - break; - case SIZE: - case SIZE_LT: - case SIZE_GT: - q.setParameter(filterBy.getField(), getIntValue(filterBy)); - break; default: break; } @@ -135,10 +111,8 @@ public enum Sorts { ID("ID", "d.dataset.id ", "ASC"), NAME("NAME", "LOWER(d.dataset.name) ", "ASC"), SEARCHABLE("SEARCHABLE", "d.dataset.searchable ", "ASC"), - MODIFICATION_TIME("MODIFICATION_TIME", "d.dataset.inode.modificationTime ", "ASC"), - ACCESS_TIME("ACCESS_TIME", "d.dataset.inode.accessTime ", "ASC"), PUBLIC("PUBLIC", "d.dataset.public ", "ASC"), - SIZE("SIZE", "d.dataset.inode.size ", "ASC"), + TYPE("TYPE", "d.dataset.dsType ", "ASC"); private final String value; @@ -175,30 +149,14 @@ public String toString() { } public enum Filters { - NAME("NAME", "d.dataset.name LIKE CONCAT(:name, '%') ", "name", " "), - USER_EMAIL("USER_EMAIL", "d.dataset.inode.hdfsUser =:user ", "user", " "), - HDFS_USER("HDFS_USER", "d.dataset.inode.hdfsUser =:hdfsUser ", "hdfsUser", " "), - UNDER_CONSTRUCTION("UNDER_CONSTRUCTION", "d.dataset.inode.underConstruction =:underConstruction ", - "underConstruction", "true"), + NAME("NAME", "LOWER(d.dataset.name) LIKE LOWER(CONCAT(:name, '%')) ", "name", " "), + NAME_NEQ("NAME_NEQ", "LOWER(d.dataset.name) NOT LIKE LOWER(CONCAT(:name_not_eq, '%')) ", "name_not_eq", " "), + NAME_LIKE("NAME_LIKE", "LOWER(d.dataset.name) LIKE LOWER(CONCAT('%', :name_like, '%')) ", "name_like", " "), ACCEPTED("ACCEPTED", "d.accepted =:accepted ", "accepted", "true"), SHARED("SHARED", "true =:shared ", "shared", "true"),//return all if true nothing if false SEARCHABLE("SEARCHABLE", "d.dataset.searchable =:searchable ", "searchable", "0"), TYPE("TYPE", "d.dataset.dsType =:dsType ", "dsType", "DATASET"), - PUBLIC("PUBLIC", "d.dataset.public =:public ", "public", "0"), - MODIFICATION_TIME("MODIFICATION_TIME", "d.dataset.inode.modificationTime =:modificationTime ", "modificationTime", - ""), - MODIFICATION_TIME_LT("MODIFICATION_TIME_LT", "d.dataset.inode.modificationTime <:modificationTime_lt ", - "modificationTime_lt", - ""), - MODIFICATION_TIME_GT("MODIFICATION_TIME_GT", "d.dataset.inode.modificationTime >:modificationTime_gt ", - "modificationTime_gt", - ""), - ACCESS_TIME("ACCESS_TIME", "d.dataset.inode.accessTime =:accessTime ", "accessTime", ""), - ACCESS_TIME_LT("ACCESS_TIME_LT", "d.dataset.inode.accessTime <:accessTime_lt ", "accessTime_lt", ""), - ACCESS_TIME_GT("ACCESS_TIME_GT", "d.dataset.inode.accessTime >:accessTime_gt ", "accessTime_gt", ""), - SIZE("SIZE", "d.dataset.inode.size =:size_eq ", "size_eq", "0"), - SIZE_LT("SIZE_LT", "d.dataset.inode.size <:size_lt ", "size_lt", "1"), - SIZE_GT("SIZE_GT", "d.dataset.inode.size >:size_gt ", "size_gt", "0"); + PUBLIC("PUBLIC", "d.dataset.public =:public ", "public", "0"); private final String value; private final String sql; diff --git a/hopsworks-common/src/main/java/io/hops/hopsworks/common/dao/hdfs/inode/InodeFacade.java b/hopsworks-common/src/main/java/io/hops/hopsworks/common/dao/hdfs/inode/InodeFacade.java index 82624e231b..32cecbe41c 100644 --- a/hopsworks-common/src/main/java/io/hops/hopsworks/common/dao/hdfs/inode/InodeFacade.java +++ b/hopsworks-common/src/main/java/io/hops/hopsworks/common/dao/hdfs/inode/InodeFacade.java @@ -276,6 +276,8 @@ private void setFilter(Set filter, Query q, P private void setFilterQuery(AbstractFacade.FilterBy filterBy, Query q, Project project) { switch (Filters.valueOf(filterBy.getValue())) { case NAME: + case NAME_NEQ: + case NAME_LIKE: q.setParameter(filterBy.getField(), filterBy.getParam()); break; case UNDER_CONSTRUCTION: @@ -301,6 +303,9 @@ private void setFilterQuery(AbstractFacade.FilterBy filterBy, Query q, Project p case SIZE_GT: q.setParameter(filterBy.getField(), getIntValue(filterBy)); break; + case TYPE: + q.setParameter(filterBy.getField(), filterBy.getParam().equalsIgnoreCase("dir")); + break; default: break; } @@ -365,7 +370,9 @@ public String toString() { } public enum Filters { - NAME("NAME", "i.inodePK.name LIKE CONCAT(:name, '%') ", "name", " "),//case + NAME("NAME", "LOWER(i.inodePK.name) LIKE LOWER(CONCAT(:name, '%')) ", "name", " "), + NAME_NEQ("NAME_NEQ", "LOWER(i.inodePK.name) NOT LIKE LOWER(CONCAT(:name_not_eq, '%')) ", "name_not_eq", " "), + NAME_LIKE("NAME_LIKE", "LOWER(i.inodePK.name) LIKE LOWER(CONCAT('%', :name_like, '%')) ", "name_like", " "), USER_EMAIL("USER_EMAIL", "i.hdfsUser =:user ", "user", " "), HDFS_USER("HDFS_USER", "i.hdfsUser =:hdfsUser ", "hdfsUser", " "), UNDER_CONSTRUCTION("UNDER_CONSTRUCTION", "i.underConstruction =:underConstruction ", "underConstruction", "true"), @@ -377,6 +384,7 @@ public enum Filters { ACCESS_TIME("ACCESS_TIME", "i.accessTime =:accessTime ", "accessTime", ""), ACCESS_TIME_LT("ACCESS_TIME_LT", "i.accessTime <:accessTime_lt ", "accessTime_lt", ""), ACCESS_TIME_GT("ACCESS_TIME_GT", "i.accessTime >:accessTime_gt ", "accessTime_gt", ""), + TYPE("TYPE", "i.dir =:is_dir ", "is_dir", "dir"), SIZE("SIZE", "i.size =:size_eq ", "size_eq", "0"), SIZE_LT("SIZE_LT", "i.size <:size_lt ", "size_lt", "1"), SIZE_GT("SIZE_GT", "i.size >:size_gt ", "size_gt", "0");