Sunday, 31 July 2022

How to find the maven installed location in my system?

Approach 1: Execute the command ‘mvn -version’ to find out the location, where Maven is installed in your system.

$mvn -version
Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537)
Maven home: /Users/krishna/Documents/softwares/apache-maven-3.8.4
Java version: 1.8.0_311, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_311.jdk/Contents/Home/jre
Default locale: en_GB, platform encoding: UTF-8
OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"

 

Property ‘Maven home:’ points to the maven location in your system.

 

Approach 2: If you add the maven bin directory path to your system path, then execute the command ‘which mvn’, it gives you the location of maven bin directory path. This command works in Linux and Mac systems.

$which mvn
/Users/krishna/Documents/softwares/apache-maven-3.8.4/bin/mvn

 

 

Previous                                                 Next                                                 Home

Quick guide to maven local repository

 

Maven support three kinds of repositories.

a.   Local repository: It is a is a directory on the computer where Maven runs. It caches remote downloads and contains temporary build artifacts that you have not yet released.

b.   Remote repository: Custom repository provided by your organization. In general, every organization configures a remote repository, where maven download the dependencies that are not exist in the local repository.

c.    Central repository: Repository provided by Maven community (https://repo1.maven.org/maven2/).

 

 


Typical flow looks like below.

a.   When you build a project that require dependency ‘X’.

b.   Maven check for the dependency ‘X’ in the local repository. If it exist, it build the artefact with given dependency. If the dependency is not exist in the local repository, maven contact the remote repository, download the dependency to local repository, and build the artifact.

 

Location of maven local repository

Default local repository location varies based on the operating system, find the following details.

 

Windows: 

C:\Users\<user_name>\.m2


Linux: 

/home/<user_name>/.m2 or ~/.m2


Mac: 

/Users/<user_name>/.m2 or ~/.m2


Customize maven local repository

You can customize the local repository location by updating the ‘localRepository’ property in the file '{MAVEN_HOME}\conf\settings.xml'.

<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->

  <localRepository>/Users/krishna/Documents/my_m2</localRepository>

</settings>

Can I pass my custom local repository location to the maven command?

Yes, you can specify the custom local repository location to the maven command using the argument -Dmaven.repo.local.

mvn -Dmaven.repo.local=/Users/krishna/Documents/my_m2 clean install

References

https://maven.apache.org/guides/introduction/introduction-to-repositories.html


Previous                                                 Next                                                 Home

Hive: Insert map data using INSERT statement

 

In this post, I am going to explain how to insert a map type data into a table using ‘INSERT’ statement.

 

We can insert map data into a table using map function.

 


INSERT INTO employee SELECT "1","Krishna",map('Java', '4.3Yrs', 'C', '3Yrs');

 

Step 1: Create an employee table.

CREATE TABLE employee (
    id INT,
    name STRING,
    technology_experience MAP<STRING,STRING>
 )
 STORED AS TEXTFILE;

 

 hive> CREATE TABLE employee (
    >     id INT,
    >     name STRING,
    >     technology_experience MAP<STRING,STRING>
    >  )
    >  STORED AS TEXTFILE;
OK
Time taken: 0.097 seconds
hive> ;
hive> ;
hive> DESCRIBE employee;
OK
id                  	int                 	                    
name                	string              	                    
technology_experience	map<string,string>  	                    
Time taken: 0.042 seconds, Fetched: 3 row(s)

Step 2: Insert data into employee table.

hive> INSERT INTO employee SELECT "1","Krishna",map('Java', '4.3Yrs', 'C', '3Yrs');
Query ID = cloudera_20220419061818_dc711fca-539b-4795-bdfb-bc7bc92208fe
Total jobs = 3
Launching Job 1 out of 3
Number of reduce tasks is set to 0 since there's no reduce operator
Starting Job = job_1649172504056_0033, Tracking URL = http://quickstart.cloudera:8088/proxy/application_1649172504056_0033/
Kill Command = /usr/lib/hadoop/bin/hadoop job  -kill job_1649172504056_0033
Hadoop job information for Stage-1: number of mappers: 1; number of reducers: 0
2022-04-19 06:18:31,108 Stage-1 map = 0%,  reduce = 0%
2022-04-19 06:18:37,452 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 1.35 sec
MapReduce Total cumulative CPU time: 1 seconds 350 msec
Ended Job = job_1649172504056_0033
Stage-4 is selected by condition resolver.
Stage-3 is filtered out by condition resolver.
Stage-5 is filtered out by condition resolver.
Moving data to: hdfs://quickstart.cloudera:8020/user/hive/warehouse/employee/.hive-staging_hive_2022-04-19_06-18-23_243_5625011913468047916-1/-ext-10000
Loading data to table default.employee
Table default.employee stats: [numFiles=1, numRows=1, totalSize=29, rawDataSize=28]
MapReduce Jobs Launched: 
Stage-Stage-1: Map: 1   Cumulative CPU: 1.35 sec   HDFS Read: 4305 HDFS Write: 101 SUCCESS
Total MapReduce CPU Time Spent: 1 seconds 350 msec
OK
Time taken: 15.389 seconds

Query employee table to confirm the data.

hive> SELECT * FROM employee;
OK
1	Krishna	{"Java":"4.3Yrs","C":"3Yrs"}
Time taken: 0.039 seconds, Fetched: 1 row(s)



 

 

 

Previous                                                    Next                                                    Home

Atlas Client: Get the classification associated with an entity

If you have an entity id, you can get the classifications associated with the entity using AtlasClientV2#getClassifications() method.

 


 

For example, there are two classifications ‘sensitive’ and ‘classified’ are attached to the entity products.

 

Below snippet is used to query all the classification of the entity by id.

 

Example

AtlasClassifications classifications = atlasClient.getClassifications(entityGuid);

List<AtlasClassification> entityClassifications = classifications.getList();
for (AtlasClassification atlasClassification : entityClassifications) {
  System.out.println(atlasClassification.getTypeName());
}

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 GetAllTheEntityClassifications class.

 

GetAllTheEntityClassifications.java

package com.sample.app.classifications;

import java.util.List;

import org.apache.atlas.AtlasClientV2;
import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.model.instance.AtlasClassification;
import org.apache.atlas.model.instance.AtlasClassification.AtlasClassifications;

import com.fasterxml.jackson.core.JsonProcessingException;

public class GetAllTheEntityClassifications {

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

    String entityGuid = "2b4cb4f9-b03e-4425-92de-8f1fc6c7e3aa";

    AtlasClassifications classifications = atlasClient.getClassifications(entityGuid);

    List<AtlasClassification> entityClassifications = classifications.getList();
    for (AtlasClassification atlasClassification : entityClassifications) {
      System.out.println(atlasClassification.getTypeName());
    }
  }

}

Output

sensitive_data
classified


Previous                                                    Next                                                    Home

Saturday, 30 July 2022

Browse postgresql server with pgAdmin user interface

pgAdmin tool will come as part of postgresql installation.

 

On window

Click on windows button and search for pgAdmin.

 

On Mac

Command + space and search for pgAdmin




Click on pgAdmin 4 to launch the tool. 

When you launch pgAdmin for the first time, it asks you to set a master password. This will be used to secure and later unlock saved passwords and other credentials. 

 

 


Enter the password and click on OK button.

 

Expand the Servers option available at left side panel of the window, it prompts you for the password to connect to local postgres instance.

 


Enter the password and click on OK button.

 

Upon successful authentication with postgres server, you can see three collections under PostgreSQL instance.

 


a.   Databases:

b.   Login/Group Roles

c.    Tablespaces

 

Expand Databases to list all the databases managed by this server instance. Expand Login/Group Roles to see all the available users in this server instance.

 

How to view the tables in a database?

Expand the database -> Schemas -> Tables.

 


Previous                                                 Next                                                 Home

Friday, 29 July 2022

Atlas Client: Get the classification by id

AtlasClientV2#getClassificationDefByGuid() return the classification associated with the id.

 

Example

AtlasClassificationDef atlasClassificationDef = atlasClient.getClassificationDefByGuid("d71e4578-3e55-4a86-ae04-c9c971ee0420");

 

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 JsonUtil, GetTheClassificationById classes.

 

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);
  }
}

GetTheClassificationById.java

package com.sample.app.classifications;

import org.apache.atlas.AtlasClientV2;
import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.model.typedef.AtlasClassificationDef;

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

public class GetTheClassificationById {

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

    AtlasClassificationDef atlasClassificationDef = atlasClient
        .getClassificationDefByGuid("d71e4578-3e55-4a86-ae04-c9c971ee0420");

    if (atlasClassificationDef == null) {
      System.out.println("No classification found");
      System.exit(1);
    }
    System.out.println(JsonUtil.prettyPrintJson(atlasClassificationDef));
  }

}

Output

{
  "category" : "CLASSIFICATION",
  "guid" : "d71e4578-3e55-4a86-ae04-c9c971ee0420",
  "createdBy" : "admin",
  "updatedBy" : "admin",
  "createTime" : 1644834992198,
  "updateTime" : 1644834992198,
  "version" : 1,
  "name" : "sensitive_data",
  "description" : "Entities with sensitive data can classified as sensitive",
  "typeVersion" : "1.0",
  "attributeDefs" : [ {
    "name" : "durationInDays",
    "typeName" : "int",
    "isOptional" : false,
    "cardinality" : "SINGLE",
    "valuesMinCount" : 1,
    "valuesMaxCount" : 1,
    "isUnique" : false,
    "isIndexable" : false,
    "includeInNotification" : false,
    "defaultValue" : "12",
    "searchWeight" : -1
  } ],
  "superTypes" : [ ],
  "entityTypes" : [ ],
  "subTypes" : [ ]
}

 

Previous                                                    Next                                                    Home