Monday 22 August 2022

Atlas Client: Perform basic search

AtlasClientV2 provide ‘basicSearch’ method to perform basic search on types, classification and support pagination.

 

public AtlasSearchResult basicSearch(String typeName, String classification, String query, boolean excludeDeletedEntities, int limit, int offset) throws AtlasServiceException

 

public AtlasSearchResult basicSearch(String typeName, SearchParameters.FilterCriteria entityFilters, String classification, String query, boolean excludeDeletedEntities, int limit, int offset) throws AtlasServiceException

 

Example 1 Get all the first 10 in a ‘DataSet’ type.

AtlasSearchResult atlasSearchResult = atlasClient.basicSearch("DataSet", null, null, false, 10, 0);

  Example 2: Get all the entities attached with sensitive_data classification.

atlasSearchResult = atlasClient.basicSearch(null, "sensitive_data", null, false, 10, 0);

 

Example 3: Full text search for the string ‘sales’.

printAtlasSearchResult(atlasSearchResult, "Full text search for the string ‘sales’");

  Example 4: Get all the entities that are of type DataSet and contain the string sales.

 

atlasSearchResult = atlasClient.basicSearch("DataSet", null, "sales", false, Integer.MAX_VALUE, 0);

 

Find the below working application.

 

Create atlas-application.properties file under src/main/resources folder.

 

atlas-application.properties

atlas.client.readTimeoutMSecs=30000
atlas.client.connectTimeoutMSecs=30000

Define BasicSearchHelloWorld class.

 

BasicSearchHelloWorld.java

package com.sample.app.search;

import java.util.List;

import org.apache.atlas.AtlasClientV2;
import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.model.discovery.AtlasSearchResult;
import org.apache.atlas.model.instance.AtlasEntityHeader;

public class BasicSearchHelloWorld {

	private static void printAtlasSearchResult(AtlasSearchResult atlasSearchResult, String message) {
		System.out.println("\n" + message);
		System.out.println("________________________________________");
		List<AtlasEntityHeader> entityHeaders = atlasSearchResult.getEntities();

		for (AtlasEntityHeader atlasEntityHeader : entityHeaders) {
			System.out.println("\t" + atlasEntityHeader.getAttribute("name"));
		}
	}

	public static void main(String[] args) throws AtlasServiceException {
		AtlasClientV2 atlasClient = new AtlasClientV2(new String[] { "http://localhost:21000" },
				new String[] { "admin", "admin" });

		AtlasSearchResult atlasSearchResult = atlasClient.basicSearch("DataSet", null, null, false, 10, 0);
		printAtlasSearchResult(atlasSearchResult, "Get all the first 10 in a ‘DataSet’ type");

		atlasSearchResult = atlasClient.basicSearch(null, "sensitive_data", null, false, 10, 0);
		printAtlasSearchResult(atlasSearchResult, "Get all the entities attached with sensitive_data classification");

		atlasSearchResult = atlasClient.basicSearch(null, null, "sales", false, 10, 0);
		printAtlasSearchResult(atlasSearchResult, "Full text search for the string ‘sales’");

		atlasSearchResult = atlasClient.basicSearch(null, null, "sales", false, 10, 0);
		printAtlasSearchResult(atlasSearchResult, "Full text search for the string ‘sales’");

		atlasSearchResult = atlasClient.basicSearch("DataSet", null, "sales", false, Integer.MAX_VALUE, 0);
		printAtlasSearchResult(atlasSearchResult,
				"all the entities that are of type DataSet and contain the string sales’");

	}

}



Output

Get all the first 10 in a ‘DataSet’ type
________________________________________
	sales_from_germany.txt
	global_sales.txt
	sales_from_Canada.txt
	profit_in_Germany.txt
	profit_in_Canada.txt
	products
	CreateEntity_DEMO1
	CreateEntity_DEMO1
	DeleteEntityById_DEMO1
	DeleteEntityById_DEMO1

Get all the entities attached with sensitive_data classification
________________________________________
	products
	AttributeWithListOfStrings_DEMO1
	AttributeWithSetOfStrings_DEMO1
	AttributeTypeMap_DEMO1

Full text search for the string ‘sales’
________________________________________
	sales
	global_sales.txt
	mergeSalesDailyFromGermanyCanada

Full text search for the string ‘sales’
________________________________________
	sales
	global_sales.txt
	mergeSalesDailyFromGermanyCanada

all the entities that are of type DataSet and contain the string sales’
________________________________________
	sales
	global_sales.txt



Previous                                                    Next                                                    Home

No comments:

Post a Comment