Java Code Examples for org.apache.atlas.model.discovery.SearchParameters#FilterCriteria
The following examples show how to use
org.apache.atlas.model.discovery.SearchParameters#FilterCriteria .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestEntitiesREST.java From atlas with Apache License 2.0 | 6 votes |
@Test public void testSearchByMultiSystemAttributes() throws Exception { searchParameters = new SearchParameters(); searchParameters.setTypeName("_ALL_ENTITY_TYPES"); SearchParameters.FilterCriteria fc = new SearchParameters.FilterCriteria(); SearchParameters.FilterCriteria subFc1 = new SearchParameters.FilterCriteria(); SearchParameters.FilterCriteria subFc2 = new SearchParameters.FilterCriteria(); subFc1.setAttributeName(MODIFICATION_TIMESTAMP_PROPERTY_KEY); subFc1.setOperator(SearchParameters.Operator.LT); subFc1.setAttributeValue(String.valueOf(System.currentTimeMillis())); subFc2.setAttributeName(TIMESTAMP_PROPERTY_KEY); subFc2.setOperator(SearchParameters.Operator.LT); subFc2.setAttributeValue(String.valueOf(System.currentTimeMillis())); fc.setCriterion(Arrays.asList(subFc1, subFc2)); fc.setCondition(AND); searchParameters.setEntityFilters(fc); AtlasSearchResult res = discoveryREST.searchWithParameters(searchParameters); Assert.assertNotNull(res.getEntities()); Assert.assertTrue(res.getEntities().size() > 5); }
Example 2
Source File: EntitySearchProcessorTest.java From atlas with Apache License 2.0 | 6 votes |
@Test(dependsOnMethods = "searchWithNEQ_stringAttr") public void searchWithNEQ_doubleAttr() throws AtlasBaseException { SearchParameters params = new SearchParameters(); params.setTypeName(HIVE_TABLE_TYPE); SearchParameters.FilterCriteria filterCriteria = getSingleFilterCondition("retention", SearchParameters.Operator.NEQ, "5"); params.setEntityFilters(filterCriteria); params.setLimit(20); SearchContext context = new SearchContext(params, typeRegistry, graph, indexer.getVertexIndexKeys()); EntitySearchProcessor processor = new EntitySearchProcessor(context); List<AtlasVertex> vertices = processor.execute(); assertEquals(vertices.size(), 1); List<String> nameList = new ArrayList<>(); for (AtlasVertex vertex : vertices) { nameList.add((String) entityRetriever.toAtlasEntityHeader(vertex, Collections.singleton("name")).getAttribute("name")); } assertTrue(nameList.contains("hive_Table_Null_tableType")); }
Example 3
Source File: EntitySearchProcessorTest.java From atlas with Apache License 2.0 | 6 votes |
@Test(dependsOnMethods = "searchWithNEQ_stringAttr") public void searchWithNEQ_pipeSeperatedAttr() throws AtlasBaseException { SearchParameters params = new SearchParameters(); params.setTypeName(HIVE_TABLE_TYPE); SearchParameters.FilterCriteria filterCriteria = getSingleFilterCondition("__classificationNames", SearchParameters.Operator.NEQ, METRIC_CLASSIFICATION); params.setEntityFilters(filterCriteria); params.setLimit(20); SearchContext context = new SearchContext(params, typeRegistry, graph, indexer.getVertexIndexKeys()); EntitySearchProcessor processor = new EntitySearchProcessor(context); List<AtlasVertex> vertices = processor.execute(); assertEquals(vertices.size(), 7); List<String> nameList = new ArrayList<>(); for (AtlasVertex vertex : vertices) { nameList.add((String) entityRetriever.toAtlasEntityHeader(vertex, Collections.singleton("name")).getAttribute("name")); } assertTrue(nameList.contains("hive_Table_Null_tableType")); }
Example 4
Source File: EntitySearchProcessorTest.java From atlas with Apache License 2.0 | 6 votes |
@Test(priority = -1) public void searchWithNEQ_stringAttr() throws AtlasBaseException { String expectedEntityName = "hive_Table_Null_tableType"; createDummyEntity(expectedEntityName,HIVE_TABLE_TYPE); SearchParameters params = new SearchParameters(); params.setTypeName(HIVE_TABLE_TYPE); SearchParameters.FilterCriteria filterCriteria = getSingleFilterCondition("tableType", SearchParameters.Operator.NEQ, "Managed"); params.setEntityFilters(filterCriteria); params.setLimit(20); SearchContext context = new SearchContext(params, typeRegistry, graph, indexer.getVertexIndexKeys()); EntitySearchProcessor processor = new EntitySearchProcessor(context); List<AtlasVertex> vertices = processor.execute(); assertEquals(vertices.size(), 3); List<String> nameList = new ArrayList<>(); for (AtlasVertex vertex : vertices) { nameList.add((String) entityRetriever.toAtlasEntityHeader(vertex, Collections.singleton("name")).getAttribute("name")); } assertTrue(nameList.contains(expectedEntityName)); }
Example 5
Source File: AtlasAuditService.java From atlas with Apache License 2.0 | 6 votes |
private SearchParameters.FilterCriteria getNonEmptyFilter(SearchParameters.FilterCriteria auditFilter) throws AtlasBaseException { SearchParameters.FilterCriteria outCriteria = new SearchParameters.FilterCriteria(); outCriteria.setCriterion(new ArrayList<>()); if(auditFilter != null) { outCriteria.setCondition(auditFilter.getCondition()); List<SearchParameters.FilterCriteria> givenFilterCriterion = auditFilter.getCriterion(); for (SearchParameters.FilterCriteria each : givenFilterCriterion) { if (StringUtils.isNotEmpty(each.getAttributeName()) && !AtlasAuditEntryDTO.getAttributes().contains(each.getAttributeName())) { throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_ATTRIBUTE, each.getAttributeName(), "Atlas Audit Entry"); } addParameterIfValueNotEmpty(outCriteria, each.getAttributeName(), each.getOperator(), each.getAttributeValue()); } } return outCriteria; }
Example 6
Source File: AtlasAuditService.java From atlas with Apache License 2.0 | 6 votes |
private SearchParameters getSearchParameters(AuditSearchParameters auditSearchParameters) throws AtlasBaseException { SearchParameters searchParameters = new SearchParameters(); searchParameters.setTypeName(ENTITY_TYPE_AUDIT_ENTRY); SearchParameters.FilterCriteria validFilter = getNonEmptyFilter(auditSearchParameters.getAuditFilters()); searchParameters.setEntityFilters(validFilter); searchParameters.setLimit(auditSearchParameters.getLimit()); searchParameters.setOffset(auditSearchParameters.getOffset()); String sortBy = auditSearchParameters.getSortBy(); validateSortByParameter(sortBy); searchParameters.setSortBy(auditSearchParameters.getSortBy()); searchParameters.setSortOrder(auditSearchParameters.getSortOrder()); return searchParameters; }
Example 7
Source File: EntitySearchProcessorTest.java From atlas with Apache License 2.0 | 5 votes |
@Test public void searchWithEntityTypesAndEntityFiltersAndTag() throws AtlasBaseException { SearchParameters params = new SearchParameters(); params.setTypeName(DATABASE_TYPE+","+HIVE_TABLE_TYPE); SearchParameters.FilterCriteria filterCriteria = getSingleFilterCondition("owner", SearchParameters.Operator.CONTAINS, "ETL"); params.setEntityFilters(filterCriteria); params.setClassification(LOGDATA_CLASSIFICATION); params.setLimit(20); SearchContext context = new SearchContext(params, typeRegistry, graph, Collections.<String>emptySet()); EntitySearchProcessor processor = new EntitySearchProcessor(context); assertEquals(processor.execute().size(), 2); }
Example 8
Source File: ExportImportAuditService.java From atlas with Apache License 2.0 | 5 votes |
public List<ExportImportAuditEntry> get(String userName, String operation, String cluster, String startTime, String endTime, int limit, int offset) throws AtlasBaseException { SearchParameters.FilterCriteria criteria = new SearchParameters.FilterCriteria(); criteria.setCondition(SearchParameters.FilterCriteria.Condition.AND); criteria.setCriterion(new ArrayList<>()); addSearchParameters(criteria, userName, operation, cluster, startTime, endTime); SearchParameters searchParameters = getSearchParameters(limit, offset, criteria); searchParameters.setAttributes(getAuditEntityAttributes()); AtlasSearchResult result = discoveryService.searchWithParameters(searchParameters); return toExportImportAuditEntry(result); }
Example 9
Source File: ExportImportAuditService.java From atlas with Apache License 2.0 | 5 votes |
private SearchParameters getSearchParameters(int limit, int offset, SearchParameters.FilterCriteria criteria) { SearchParameters searchParameters = new SearchParameters(); searchParameters.setTypeName(ENTITY_TYPE_NAME); searchParameters.setEntityFilters(criteria); searchParameters.setLimit(limit); searchParameters.setOffset(offset); return searchParameters; }
Example 10
Source File: ExportImportAuditService.java From atlas with Apache License 2.0 | 5 votes |
private void addSearchParameters(SearchParameters.FilterCriteria criteria, String userName, String operation, String cluster, String startTime, String endTime) { addParameterIfValueNotEmpty(criteria, ExportImportAuditEntryDTO.PROPERTY_USER_NAME, userName); addParameterIfValueNotEmpty(criteria, ExportImportAuditEntryDTO.PROPERTY_OPERATION, operation); addParameterIfValueNotEmpty(criteria, ExportImportAuditEntryDTO.PROPERTY_START_TIME, startTime); addParameterIfValueNotEmpty(criteria, ExportImportAuditEntryDTO.PROPERTY_END_TIME, endTime); addServerFilterCriteria(criteria, cluster); }
Example 11
Source File: ExportImportAuditService.java From atlas with Apache License 2.0 | 5 votes |
private void addServerFilterCriteria(SearchParameters.FilterCriteria parentCriteria, String cluster) { if (StringUtils.isEmpty(cluster)) { return; } SearchParameters.FilterCriteria criteria = new SearchParameters.FilterCriteria(); criteria.setCondition(SearchParameters.FilterCriteria.Condition.OR); criteria.setCriterion(new ArrayList<>()); addParameterIfValueNotEmpty(criteria, ExportImportAuditEntryDTO.PROPERTY_SOURCE_SERVER_NAME, cluster); addParameterIfValueNotEmpty(criteria, ExportImportAuditEntryDTO.PROPERTY_TARGET_SERVER_NAME, cluster); parentCriteria.getCriterion().add(criteria); }
Example 12
Source File: TestEntitiesREST.java From atlas with Apache License 2.0 | 5 votes |
@Test(dependsOnMethods = "testSearchByOtherSystemAttributes") public void testBasicSearchWithFilter() throws Exception { // database - phi, felt_classification // table1 - phi, classification, table2 - classification, // col - phi searchParameters = new SearchParameters(); searchParameters.setIncludeSubClassifications(false); searchParameters.setClassification(TestUtilsV2.CLASSIFICATION); SearchParameters.FilterCriteria fc = new SearchParameters.FilterCriteria(); fc.setOperator(SearchParameters.Operator.CONTAINS); fc.setAttributeValue("new comments"); fc.setAttributeName("tag"); searchParameters.setTagFilters(fc); AtlasSearchResult res = discoveryREST.searchWithParameters(searchParameters); Assert.assertNull(res.getEntities()); fc.setOperator(SearchParameters.Operator.ENDS_WITH); res = discoveryREST.searchWithParameters(searchParameters); Assert.assertNull(res.getEntities()); fc.setOperator(SearchParameters.Operator.STARTS_WITH); res = discoveryREST.searchWithParameters(searchParameters); Assert.assertNull(res.getEntities()); }
Example 13
Source File: TestEntitiesREST.java From atlas with Apache License 2.0 | 5 votes |
@Test(dependsOnMethods = "testSearchByMultiTags") public void testSearchByOtherSystemAttributes() throws Exception { // database - phi, felt_classification // table1 - phi, classification, table2 - classification, // col1 - phi, col2 - phi searchParameters = new SearchParameters(); searchParameters.setTypeName("_ALL_ENTITY_TYPES"); SearchParameters.FilterCriteria fc = new SearchParameters.FilterCriteria(); fc.setAttributeName(CLASSIFICATION_NAMES_KEY); fc.setOperator(SearchParameters.Operator.EQ); fc.setAttributeValue(CLASSIFICATION); searchParameters.setEntityFilters(fc); AtlasSearchResult res = discoveryREST.searchWithParameters(searchParameters); Assert.assertNotNull(res.getEntities()); Assert.assertEquals(res.getEntities().size(), 2); fc.setOperator(SearchParameters.Operator.CONTAINS); fc.setAttributeValue("cla"); res = discoveryREST.searchWithParameters(searchParameters); Assert.assertNotNull(res.getEntities()); Assert.assertEquals(res.getEntities().size(), 3); fc.setOperator(SearchParameters.Operator.CONTAINS); fc.setAttributeValue(PHI); res = discoveryREST.searchWithParameters(searchParameters); Assert.assertNotNull(res.getEntities()); Assert.assertEquals(res.getEntities().size(), 4); }
Example 14
Source File: AtlasAuditService.java From atlas with Apache License 2.0 | 5 votes |
private void addParameterIfValueNotEmpty(SearchParameters.FilterCriteria criteria, String attributeName, SearchParameters.Operator operator, String value) { if(StringUtils.isNotEmpty(value)) { SearchParameters.FilterCriteria filterCriteria = new SearchParameters.FilterCriteria(); filterCriteria.setAttributeName(attributeName); filterCriteria.setAttributeValue(value); filterCriteria.setOperator(operator); criteria.getCriterion().add(filterCriteria); } }
Example 15
Source File: BasicTestSetup.java From atlas with Apache License 2.0 | 5 votes |
public SearchParameters.FilterCriteria getSingleFilterCondition(String attName, SearchParameters.Operator op, String attrValue) { SearchParameters.FilterCriteria filterCriteria = new SearchParameters.FilterCriteria(); filterCriteria.setCondition(SearchParameters.FilterCriteria.Condition.AND); List<SearchParameters.FilterCriteria> criteria = new ArrayList<>(); SearchParameters.FilterCriteria f1 = new SearchParameters.FilterCriteria(); f1.setAttributeName(attName); f1.setOperator(op); String time = String.valueOf(System.currentTimeMillis()); f1.setAttributeValue(attrValue); criteria.add(f1); filterCriteria.setCriterion(criteria); return filterCriteria; }
Example 16
Source File: SearchProcessor.java From incubator-atlas with Apache License 2.0 | 5 votes |
protected void processSearchAttributes(AtlasStructType structType, FilterCriteria filterCriteria, Set<String> solrFiltered, Set<String> gremlinFiltered, Set<String> allAttributes) { if (structType == null || filterCriteria == null) { return; } Condition filterCondition = filterCriteria.getCondition(); List<FilterCriteria> criterion = filterCriteria.getCriterion(); if (filterCondition != null && CollectionUtils.isNotEmpty(criterion)) { for (SearchParameters.FilterCriteria criteria : criterion) { processSearchAttributes(structType, criteria, solrFiltered, gremlinFiltered, allAttributes); } } else if (StringUtils.isNotEmpty(filterCriteria.getAttributeName())) { try { String attributeName = filterCriteria.getAttributeName(); String qualifiedName = structType.getQualifiedAttributeName(attributeName); Set<String> indexedKeys = context.getIndexedKeys(); if (indexedKeys != null && indexedKeys.contains(qualifiedName)) { solrFiltered.add(attributeName); } else { LOG.warn("search includes non-indexed attribute '{}'; might cause poor performance", qualifiedName); gremlinFiltered.add(attributeName); } if (structType instanceof AtlasEntityType) { // Capture the entity attributes context.getEntityAttributes().add(attributeName); } allAttributes.add(attributeName); } catch (AtlasBaseException e) { LOG.warn(e.getMessage()); } } }
Example 17
Source File: EntitySearchProcessorTest.java From atlas with Apache License 2.0 | 5 votes |
@Test public void searchWithEntityTypesAndEntityFilters() throws AtlasBaseException { SearchParameters params = new SearchParameters(); params.setTypeName(DATABASE_TYPE+","+HIVE_TABLE_TYPE); SearchParameters.FilterCriteria filterCriteria = getSingleFilterCondition("owner", SearchParameters.Operator.CONTAINS, "ETL"); params.setEntityFilters(filterCriteria); params.setLimit(20); SearchContext context = new SearchContext(params, typeRegistry, graph, Collections.<String>emptySet()); EntitySearchProcessor processor = new EntitySearchProcessor(context); assertEquals(processor.execute().size(), 4); }
Example 18
Source File: EntitySearchProcessorTest.java From atlas with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = AtlasBaseException.class, expectedExceptionsMessageRegExp = "Attribute tableType not found for type "+DATABASE_TYPE) public void entityFiltersNotAllowed() throws AtlasBaseException { SearchParameters params = new SearchParameters(); params.setTypeName(DATABASE_TYPE+","+HIVE_TABLE_TYPE); SearchParameters.FilterCriteria filterCriteria = getSingleFilterCondition("tableType", SearchParameters.Operator.CONTAINS, "ETL"); params.setEntityFilters(filterCriteria); params.setLimit(20); SearchContext context = new SearchContext(params, typeRegistry, graph, Collections.<String>emptySet()); }
Example 19
Source File: SearchProcessor.java From atlas with Apache License 2.0 | 4 votes |
protected void processSearchAttributes(Set<? extends AtlasStructType> structTypes, FilterCriteria filterCriteria, Set<String> indexFiltered, Set<String> graphFiltered, Set<String> allAttributes) { if (CollectionUtils.isEmpty(structTypes) || filterCriteria == null) { return; } Condition filterCondition = filterCriteria.getCondition(); List<FilterCriteria> criterion = filterCriteria.getCriterion(); if (filterCondition != null && CollectionUtils.isNotEmpty(criterion)) { for (SearchParameters.FilterCriteria criteria : criterion) { processSearchAttributes(structTypes, criteria, indexFiltered, graphFiltered, allAttributes); } } else if (StringUtils.isNotEmpty(filterCriteria.getAttributeName())) { String attributeName = filterCriteria.getAttributeName(); if (StringUtils.equals(attributeName, Constants.IS_INCOMPLETE_PROPERTY_KEY)) { // when entity is incomplete (i.e. shell entity): // vertex property IS_INCOMPLETE_PROPERTY_KEY will be set to INCOMPLETE_ENTITY_VALUE // when entity is not incomplete (i.e. not a shell entity): // vertex property IS_INCOMPLETE_PROPERTY_KEY will not be set String attributeValue = filterCriteria.getAttributeValue(); switch (filterCriteria.getOperator()) { case EQ: if (attributeValue == null || StringUtils.equals(attributeValue, "0") || StringUtils.equalsIgnoreCase(attributeValue, "false")) { filterCriteria.setOperator(SearchParameters.Operator.IS_NULL); } else { filterCriteria.setOperator(SearchParameters.Operator.EQ); filterCriteria.setAttributeValue(Constants.INCOMPLETE_ENTITY_VALUE.toString()); } break; case NEQ: if (attributeValue == null || StringUtils.equals(attributeValue, "0") || StringUtils.equalsIgnoreCase(attributeValue, "false")) { filterCriteria.setOperator(SearchParameters.Operator.EQ); filterCriteria.setAttributeValue(Constants.INCOMPLETE_ENTITY_VALUE.toString()); } else { filterCriteria.setOperator(SearchParameters.Operator.IS_NULL); } break; case NOT_NULL: filterCriteria.setOperator(SearchParameters.Operator.EQ); filterCriteria.setAttributeValue(Constants.INCOMPLETE_ENTITY_VALUE.toString()); break; } } try { for (AtlasStructType structType : structTypes) { String qualifiedName = structType.getVertexPropertyName(attributeName); if (isIndexSearchable(filterCriteria, structType)) { indexFiltered.add(qualifiedName); } else { LOG.warn("not using index-search for attribute '{}'; might cause poor performance", structType.getVertexPropertyName(attributeName)); graphFiltered.add(qualifiedName); } if (structType instanceof AtlasEntityType && !isSystemAttribute(attributeName)) { // Capture the entity attributes context.getEntityAttributes().add(attributeName); } allAttributes.add(qualifiedName); } } catch (AtlasBaseException e) { LOG.warn(e.getMessage()); } } }
Example 20
Source File: DiscoveryREST.java From incubator-atlas with Apache License 2.0 | 4 votes |
private boolean isEmpty(SearchParameters.FilterCriteria filterCriteria) { return filterCriteria == null || (StringUtils.isEmpty(filterCriteria.getAttributeName()) && CollectionUtils.isEmpty(filterCriteria.getCriterion())); }