Monday, 12 September 2022

Atlas Client: get term headers in a glossary

AtlasClientV2# getGlossaryTermHeaders method return all the term headers in a glossary.

 

Signature

public List<AtlasRelatedTermHeader> getGlossaryTermHeaders(String glossaryGuid, String sortByAttribute, int limit, int offset) throws AtlasServiceException

 

Example

List<AtlasRelatedTermHeader> glossaryTerms = atlasClient.getGlossaryTermHeaders(glossaryId, null, 10, 0);

Find the below working application.

 

atlas-application.properties

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

JsonUtil.java

package com.sample.app.util;

import java.io.IOException;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

public class JsonUtil {
	public static String marshal(Object obj) throws JsonProcessingException {
		ObjectMapper mapper = new ObjectMapper();
		return mapper.writeValueAsString(obj);
	}

	public static <T> T unmarshal(Class<T> clazz, String json)
			throws JsonParseException, JsonMappingException, IOException {
		ObjectMapper mapper = new ObjectMapper();
		return (T) mapper.readValue(json, clazz);
	}

	public static String prettyPrintJson(Object obj) throws JsonProcessingException {
		ObjectMapper mapper = new ObjectMapper();
		mapper.enable(SerializationFeature.INDENT_OUTPUT);
		return mapper.writeValueAsString(obj);
	}
}

GlossaryTermHeadersInAGlossary.java

package com.sample.app.glossary;

import java.util.List;

import org.apache.atlas.AtlasClientV2;
import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.sample.app.util.JsonUtil;

public class GlossaryTermHeadersInAGlossary {

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

    String glossaryId = "844a3e1a-110c-4bef-91bf-622dc1eab3e7";

    List<AtlasRelatedTermHeader> glossaryTerms = atlasClient.getGlossaryTermHeaders(glossaryId, null, 10, 0);

    if (glossaryTerms == null) {
      System.out.println("Glossary terms not exists");
    } else {
      System.out.println("atlasGlossary terms : \n" + JsonUtil.prettyPrintJson(glossaryTerms));
    }

  }

}

Output

atlasGlossary terms : 
[ {
  "termGuid" : "cd2dbbc5-0440-477e-a6e6-175eb13e3d46",
  "relationGuid" : "607768b1-d47a-4659-aa63-9acc8d175c80",
  "displayText" : "term1"
}, {
  "termGuid" : "8d0451be-bfe9-497c-aae9-f1892b156c94",
  "relationGuid" : "8fe3ae77-0a42-42a5-8230-5a1c954b819b",
  "displayText" : "term2"
}, {
  "termGuid" : "eb6afad3-2c82-4b16-8708-fc0694dbeb80",
  "relationGuid" : "80731d37-b42e-4e21-8d0e-ff9d20dc57e6",
  "displayText" : "term3"
}, {
  "termGuid" : "b480660d-d038-41bd-b2c1-076adedd2421",
  "relationGuid" : "10fc95da-1638-4c84-b8e3-41b79034ab58",
  "displayText" : "term4"
}, {
  "termGuid" : "8ba708a2-3e28-40a0-b0ee-3a642e2f5c5a",
  "relationGuid" : "cc153d34-6851-499d-988c-682eb0dd122d",
  "displayText" : "term5"
} ]


  

Previous                                                    Next                                                    Home

Hive: hex(string): Convert each character into hexa format

Signature

hex(string)

 

hive> SELECT hex('A');
OK
_c0
41
Time taken: 0.053 seconds, Fetched: 1 row(s)
hive> SELECT hex('AB');
OK
_c0
4142
Time taken: 0.058 seconds, Fetched: 1 row(s)
hive> SELECT hex('ABC');
OK
_c0
414243
Time taken: 0.042 seconds, Fetched: 1 row(s)

 

 

 

Previous                                                    Next                                                    Home

Sunday, 11 September 2022

Atlas Client: Get the terms in a glossary

AtlasClientV2#getGlossaryTerms method return the terms in a glossary.

 

Signature

public List<AtlasGlossaryTerm> getGlossaryTerms(String glossaryGuid, String sortByAttribute, int limit, int offset) throws AtlasServiceException

 

Example

List<AtlasGlossaryTerm> glossaryTerms = atlasClient.getGlossaryTerms(glossaryId, null, 10, 0);

 

Find the below working application.

 

atlas-application.properties
atlas.client.readTimeoutMSecs=30000
atlas.client.connectTimeoutMSecs=30000

 

JsonUtil.java

package com.sample.app.util;

import java.io.IOException;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

public class JsonUtil {
	public static String marshal(Object obj) throws JsonProcessingException {
		ObjectMapper mapper = new ObjectMapper();
		return mapper.writeValueAsString(obj);
	}

	public static <T> T unmarshal(Class<T> clazz, String json)
			throws JsonParseException, JsonMappingException, IOException {
		ObjectMapper mapper = new ObjectMapper();
		return (T) mapper.readValue(json, clazz);
	}

	public static String prettyPrintJson(Object obj) throws JsonProcessingException {
		ObjectMapper mapper = new ObjectMapper();
		mapper.enable(SerializationFeature.INDENT_OUTPUT);
		return mapper.writeValueAsString(obj);
	}
}

 

GetTermsInAGlossary.java

package com.sample.app.glossary;

import java.util.List;

import org.apache.atlas.AtlasClientV2;
import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.model.glossary.AtlasGlossaryTerm;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.sample.app.util.JsonUtil;

public class GetTermsInAGlossary {

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

    String glossaryId = "844a3e1a-110c-4bef-91bf-622dc1eab3e7";

    List<AtlasGlossaryTerm> glossaryTerms = atlasClient.getGlossaryTerms(glossaryId, null, 10, 0);

    if (glossaryTerms == null) {
      System.out.println("Glossary terms not exists");
    } else {
      System.out.println("atlasGlossary terms : \n" + JsonUtil.prettyPrintJson(glossaryTerms));
    }

  }

}

 

Output

atlasGlossary terms : 
[ {
  "guid" : "cd2dbbc5-0440-477e-a6e6-175eb13e3d46",
  "qualifiedName" : "term1@myGlosary3",
  "name" : "term1",
  "shortDescription" : "term1...",
  "longDescription" : "term1...........",
  "classifications" : [ {
    "typeName" : "sensitive_data",
    "attributes" : {
      "durationInDays" : 8
    },
    "entityGuid" : "cd2dbbc5-0440-477e-a6e6-175eb13e3d46",
    "entityStatus" : "ACTIVE",
    "propagate" : true,
    "validityPeriods" : [ ],
    "removePropagationsOnEntityDelete" : false
  } ],
  "anchor" : {
    "glossaryGuid" : "844a3e1a-110c-4bef-91bf-622dc1eab3e7",
    "relationGuid" : "607768b1-d47a-4659-aa63-9acc8d175c80"
  },
  "assignedEntities" : [ {
    "guid" : "e63cb343-675e-4cde-9d49-ceb43fb1aacb",
    "typeName" : "DemoType6",
    "entityStatus" : "ACTIVE",
    "displayText" : "AttributeDefaultValue_DEMO1",
    "relationshipType" : "AtlasGlossarySemanticAssignment",
    "relationshipGuid" : "c02d605e-6165-448e-a77c-0df916781fb0",
    "relationshipStatus" : "ACTIVE",
    "relationshipAttributes" : {
      "typeName" : "AtlasGlossarySemanticAssignment",
      "attributes" : {
        "expression" : null,
        "createdBy" : null,
        "steward" : null,
        "confidence" : null,
        "description" : null,
        "source" : null,
        "status" : null
      }
    }
  }, {
    "guid" : "95731109-eb31-44e9-896e-60652e119312",
    "typeName" : "DemoType7",
    "entityStatus" : "ACTIVE",
    "displayText" : "CreateEntities_DEMO1",
    "relationshipType" : "AtlasGlossarySemanticAssignment",
    "relationshipGuid" : "981b2432-c033-42f5-bf37-07e4c3e41fad",
    "relationshipStatus" : "ACTIVE",
    "relationshipAttributes" : {
      "typeName" : "AtlasGlossarySemanticAssignment",
      "attributes" : {
        "expression" : null,
        "createdBy" : null,
        "steward" : null,
        "confidence" : null,
        "description" : null,
        "source" : null,
        "status" : null
      }
    }
  } ],
  "categories" : [ {
    "categoryGuid" : "80e199fb-f924-4470-adc1-8227b5650f6c",
    "relationGuid" : "c1a5772f-290e-4696-a80c-5cc5a69b9bdd"
  } ],
  "glossaryTermHeader" : {
    "termGuid" : "cd2dbbc5-0440-477e-a6e6-175eb13e3d46",
    "qualifiedName" : "term1@myGlosary3"
  }
}, {
  "guid" : "8d0451be-bfe9-497c-aae9-f1892b156c94",
  "qualifiedName" : "term2@myGlosary3",
  "name" : "term2",
  "shortDescription" : "term2...",
  "longDescription" : "term2......",
  "anchor" : {
    "glossaryGuid" : "844a3e1a-110c-4bef-91bf-622dc1eab3e7",
    "relationGuid" : "8fe3ae77-0a42-42a5-8230-5a1c954b819b"
  },
  "glossaryTermHeader" : {
    "termGuid" : "8d0451be-bfe9-497c-aae9-f1892b156c94",
    "qualifiedName" : "term2@myGlosary3"
  }
}, {
  "guid" : "eb6afad3-2c82-4b16-8708-fc0694dbeb80",
  "qualifiedName" : "term3@myGlosary3",
  "name" : "term3",
  "shortDescription" : "term3..",
  "longDescription" : "term3.......",
  "anchor" : {
    "glossaryGuid" : "844a3e1a-110c-4bef-91bf-622dc1eab3e7",
    "relationGuid" : "80731d37-b42e-4e21-8d0e-ff9d20dc57e6"
  },
  "glossaryTermHeader" : {
    "termGuid" : "eb6afad3-2c82-4b16-8708-fc0694dbeb80",
    "qualifiedName" : "term3@myGlosary3"
  }
}, {
  "guid" : "b480660d-d038-41bd-b2c1-076adedd2421",
  "qualifiedName" : "term4@myGlosary3",
  "name" : "term4",
  "shortDescription" : "term4...",
  "longDescription" : "term4.......",
  "anchor" : {
    "glossaryGuid" : "844a3e1a-110c-4bef-91bf-622dc1eab3e7",
    "relationGuid" : "10fc95da-1638-4c84-b8e3-41b79034ab58"
  },
  "glossaryTermHeader" : {
    "termGuid" : "b480660d-d038-41bd-b2c1-076adedd2421",
    "qualifiedName" : "term4@myGlosary3"
  }
}, {
  "guid" : "8ba708a2-3e28-40a0-b0ee-3a642e2f5c5a",
  "qualifiedName" : "term5@myGlosary3",
  "name" : "term5",
  "shortDescription" : "term5....",
  "longDescription" : "term5.......",
  "anchor" : {
    "glossaryGuid" : "844a3e1a-110c-4bef-91bf-622dc1eab3e7",
    "relationGuid" : "cc153d34-6851-499d-988c-682eb0dd122d"
  },
  "glossaryTermHeader" : {
    "termGuid" : "8ba708a2-3e28-40a0-b0ee-3a642e2f5c5a",
    "qualifiedName" : "term5@myGlosary3"
  }
} ]

 

You can confirm the same from AtlasUI.

 


 

  

Previous                                                    Next                                                    Home

Hive: hex(n): Return hexa value of this number

Signature

hex(n)

 

hive> SELECT * FROM emp;
OK
emp.id	emp.name	emp.hobbies	emp.technology_experience	emp.gender_age	emp.rating
1	Hari	["Football","Cricket"]	{"Java":"3.4Yrs","C":"4.5Yrs"}	{"gender":"Male","age":30}	-1.5
2	Chamu	["Trekking","Watching movies"]	{"Selenium":"5.6Yrs"}	{"gender":"Feale","age":38}	3.0
3	Sailu	["Chess","Listening to music"]	{"EmbeddedC":"9Yrs"}	{"gender":"Femle","age":32}	2.5
4	Gopi	["Cricket"]	{"Datastage":"11Yrs"}	{"gender":"Male","age":32}	-0.7
Time taken: 0.042 seconds, Fetched: 4 row(s)
hive> ;
hive> ;
hive> SELECT gender_age.age,hex(gender_age.age) FROM emp;
OK
age	_c1
30	1E
38	26
32	20
32	20
Time taken: 0.052 seconds, Fetched: 4 row(s)
hive>

 

 

Previous                                                    Next                                                    Home

Saturday, 10 September 2022

Atlas Client: Get glossary term by guid

AtlasClientV2#getGlossaryTerm method is used to get the glossary term by guid.

 

Signature

public AtlasGlossaryTerm getGlossaryTerm(String termGuid) throws AtlasServiceException

Example

AtlasGlossaryTerm atlasGlossaryTerm = atlasClient.getGlossaryTerm(termId);

Find the below working application.

 

atlas-application.properties

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

JsonUtil.java

package com.sample.app.util;

import java.io.IOException;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

public class JsonUtil {
	public static String marshal(Object obj) throws JsonProcessingException {
		ObjectMapper mapper = new ObjectMapper();
		return mapper.writeValueAsString(obj);
	}

	public static <T> T unmarshal(Class<T> clazz, String json)
			throws JsonParseException, JsonMappingException, IOException {
		ObjectMapper mapper = new ObjectMapper();
		return (T) mapper.readValue(json, clazz);
	}

	public static String prettyPrintJson(Object obj) throws JsonProcessingException {
		ObjectMapper mapper = new ObjectMapper();
		mapper.enable(SerializationFeature.INDENT_OUTPUT);
		return mapper.writeValueAsString(obj);
	}
}

GlossaryTermByGuid.java

package com.sample.app.glossary;

import org.apache.atlas.AtlasClientV2;
import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.model.glossary.AtlasGlossaryTerm;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.sample.app.util.JsonUtil;

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

    String termId = "cd2dbbc5-0440-477e-a6e6-175eb13e3d46";

    AtlasGlossaryTerm atlasGlossaryTerm = atlasClient.getGlossaryTerm(termId);

    if (atlasGlossaryTerm == null) {
      System.out.println("Glossary term not exists");
    } else {
      System.out.println("atlasGlossary term : \n" + JsonUtil.prettyPrintJson(atlasGlossaryTerm));
    }

  }
}

Output

atlasGlossary term : 
{
  "guid" : "cd2dbbc5-0440-477e-a6e6-175eb13e3d46",
  "qualifiedName" : "term1@myGlosary3",
  "name" : "term1",
  "shortDescription" : "term1...",
  "longDescription" : "term1...........",
  "classifications" : [ {
    "typeName" : "sensitive_data",
    "attributes" : {
      "durationInDays" : 8
    },
    "entityGuid" : "cd2dbbc5-0440-477e-a6e6-175eb13e3d46",
    "entityStatus" : "ACTIVE",
    "propagate" : true,
    "validityPeriods" : [ ],
    "removePropagationsOnEntityDelete" : false
  } ],
  "anchor" : {
    "glossaryGuid" : "844a3e1a-110c-4bef-91bf-622dc1eab3e7",
    "relationGuid" : "607768b1-d47a-4659-aa63-9acc8d175c80"
  },
  "assignedEntities" : [ {
    "guid" : "95731109-eb31-44e9-896e-60652e119312",
    "typeName" : "DemoType7",
    "entityStatus" : "ACTIVE",
    "displayText" : "CreateEntities_DEMO1",
    "relationshipType" : "AtlasGlossarySemanticAssignment",
    "relationshipGuid" : "981b2432-c033-42f5-bf37-07e4c3e41fad",
    "relationshipStatus" : "ACTIVE",
    "relationshipAttributes" : {
      "typeName" : "AtlasGlossarySemanticAssignment",
      "attributes" : {
        "expression" : null,
        "createdBy" : null,
        "steward" : null,
        "confidence" : null,
        "description" : null,
        "source" : null,
        "status" : null
      }
    }
  }, {
    "guid" : "e63cb343-675e-4cde-9d49-ceb43fb1aacb",
    "typeName" : "DemoType6",
    "entityStatus" : "ACTIVE",
    "displayText" : "AttributeDefaultValue_DEMO1",
    "relationshipType" : "AtlasGlossarySemanticAssignment",
    "relationshipGuid" : "c02d605e-6165-448e-a77c-0df916781fb0",
    "relationshipStatus" : "ACTIVE",
    "relationshipAttributes" : {
      "typeName" : "AtlasGlossarySemanticAssignment",
      "attributes" : {
        "expression" : null,
        "createdBy" : null,
        "steward" : null,
        "confidence" : null,
        "description" : null,
        "source" : null,
        "status" : null
      }
    }
  } ],
  "categories" : [ {
    "categoryGuid" : "80e199fb-f924-4470-adc1-8227b5650f6c",
    "relationGuid" : "c1a5772f-290e-4696-a80c-5cc5a69b9bdd",
    "displayText" : "category1"
  } ],
  "glossaryTermHeader" : {
    "termGuid" : "cd2dbbc5-0440-477e-a6e6-175eb13e3d46",
    "qualifiedName" : "term1@myGlosary3"
  }
}

You can confirm the same from Atlas UI.

 

Previous                                                    Next                                                    Home

Hive: floor(n): Return floor value of this number

Signature

floor(n)

 

‘floor’ function return the largest integer less than or equal to the given value n.

hive> SELECT * FROM emp;
OK
emp.id	emp.name	emp.hobbies	emp.technology_experience	emp.gender_age	emp.rating
1	Hari	["Football","Cricket"]	{"Java":"3.4Yrs","C":"4.5Yrs"}	{"gender":"Male","age":30}	-1.5
2	Chamu	["Trekking","Watching movies"]	{"Selenium":"5.6Yrs"}	{"gender":"Feale","age":38}	3.0
3	Sailu	["Chess","Listening to music"]	{"EmbeddedC":"9Yrs"}	{"gender":"Femle","age":32}	2.5
4	Gopi	["Cricket"]	{"Datastage":"11Yrs"}	{"gender":"Male","age":32}	-0.7
Time taken: 0.067 seconds, Fetched: 4 row(s)
hive> ;
hive> ;
hive> SELECT rating, floor(rating) FROM emp;
OK
rating	_c1
-1.5	-2
3.0	3
2.5	2
-0.7	-1
Time taken: 0.052 seconds, Fetched: 4 row(s)

 

 

Previous                                                    Next                                                    Home