Friday, 3 June 2022

Atlas: Type system

Atlas type system allows you to define a model for metadata objects that you want to manage. The model is composed of types, entities (instance of type is called entity, maintain actual metadata), relationships between types etc.,

 

What is a Type?

Type is a collection of one or more attributes that is used to define properties of metadata object. If you are from object oriented programming background, type is similar to a class definition.

 

Every type has a definition associated with it. For example, find the below type definition.

 

Example of a type definition

{
   "category":"ENTITY",
   "guid":"4f80e340-cd53-4084-af46-e2c0f07e256e",
   "createdBy":"admin",
   "updatedBy":"admin",
   "createTime":1643362200198,
   "updateTime":1643362200198,
   "version":1,
   "name":"jdbc_column",
   "description":"Represent a RDBMS Column",
   "typeVersion":"1.0",
   "attributeDefs":[
      {
         "name":"dataType",
         "typeName":"string",
         "isOptional":true,
         "cardinality":"SINGLE",
         "valuesMinCount":0,
         "valuesMaxCount":1,
         "isUnique":false,
         "isIndexable":false,
         "includeInNotification":false,
         "searchWeight":-1
      }
   ],
   "superTypes":[
      "DataSet"
   ],
   "subTypes":[
      
   ],
   "relationshipAttributeDefs":[
      {
         "name":"inputToProcesses",
         "typeName":"array<Process>",
         "isOptional":true,
         "cardinality":"SET",
         "valuesMinCount":-1,
         "valuesMaxCount":-1,
         "isUnique":false,
         "isIndexable":false,
         "includeInNotification":false,
         "searchWeight":-1,
         "relationshipTypeName":"dataset_process_inputs",
         "isLegacyAttribute":false
      },
      {
         "name":"pipeline",
         "typeName":"spark_ml_pipeline",
         "isOptional":true,
         "cardinality":"SINGLE",
         "valuesMinCount":-1,
         "valuesMaxCount":-1,
         "isUnique":false,
         "isIndexable":false,
         "includeInNotification":false,
         "searchWeight":-1,
         "relationshipTypeName":"spark_ml_pipeline_dataset",
         "isLegacyAttribute":false
      },
      {
         "name":"schema",
         "typeName":"array<avro_schema>",
         "isOptional":true,
         "cardinality":"SET",
         "valuesMinCount":-1,
         "valuesMaxCount":-1,
         "isUnique":false,
         "isIndexable":false,
         "includeInNotification":false,
         "searchWeight":-1,
         "relationshipTypeName":"avro_schema_associatedEntities",
         "isLegacyAttribute":false
      },
      {
         "name":"model",
         "typeName":"spark_ml_model",
         "isOptional":true,
         "cardinality":"SINGLE",
         "valuesMinCount":-1,
         "valuesMaxCount":-1,
         "isUnique":false,
         "isIndexable":false,
         "includeInNotification":false,
         "searchWeight":-1,
         "relationshipTypeName":"spark_ml_model_dataset",
         "isLegacyAttribute":false
      },
      {
         "name":"meanings",
         "typeName":"array<AtlasGlossaryTerm>",
         "isOptional":true,
         "cardinality":"SET",
         "valuesMinCount":-1,
         "valuesMaxCount":-1,
         "isUnique":false,
         "isIndexable":false,
         "includeInNotification":false,
         "searchWeight":-1,
         "relationshipTypeName":"AtlasGlossarySemanticAssignment",
         "isLegacyAttribute":false
      },
      {
         "name":"table",
         "typeName":"jdbc_table",
         "isOptional":false,
         "cardinality":"SINGLE",
         "valuesMinCount":-1,
         "valuesMaxCount":-1,
         "isUnique":false,
         "isIndexable":false,
         "includeInNotification":false,
         "searchWeight":-1,
         "relationshipTypeName":"jdbc_table_to_column",
         "isLegacyAttribute":false
      },
      {
         "name":"outputFromProcesses",
         "typeName":"array<Process>",
         "isOptional":true,
         "cardinality":"SET",
         "valuesMinCount":-1,
         "valuesMaxCount":-1,
         "isUnique":false,
         "isIndexable":false,
         "includeInNotification":false,
         "searchWeight":-1,
         "relationshipTypeName":"process_dataset_outputs",
         "isLegacyAttribute":false
      }
   ],
   "businessAttributeDefs":{
      
   }
}

 

Following are the key points to be noted while working with Atlas type system.

 

a. Every type is uniquely identified by a name in Atlas.

 

b. Every type must specify a type category at the time of creation. Type category can be

1.    primitive like boolean, byte, short, int, long, float, double,biginteger, bigdecimal, string, date.

2.    Enum

3.    Collection like array, map

4.     A composite like Entity, Struct, Classification, Relationship

 

Can these types inherit from other types?

Yes, only types of category Entity and classification can extend from other types. It is similar to inheritance in object oriented programming.

 

Only Entity and classification types can extend from other types.

 

Can a type inherit from more than one super types?

Yes, it is absolutely possible in Atlas.

 

Can I refer one type in the definition of other type?

Yes, you can do. For example, in the above definition we are referring AtlasGlossaryTerm, spark_ml_model in the above definition.

 

How to access a property of type?

Property can be accessed using the expression ‘type_name.attribute_name’. In the above example, ‘jdbc_column. dataType’ property is of type String.

 

 

Previous                                                    Next                                                    Home

Quick guide to sqoop jobs

Sqoop job is used to create a job that can

a.   save the command

b.   Execute the command

c.    Store the past state of the command, if the command relates to incremental imports

 

Let’s create a sqoop job, execute and check the job configuration etc.,

 

How to create a sqoop job?

We can create a sqoop job with below syntax.

 

Syntax

sqoop job --create {JOB_NAME} -- {COMMAND_TO_EXECUTE}

 

Example

sqoop job \
--create customer_import \
-- import \
--connect "jdbc:mysql://quickstart.cloudera:3306/retail_db" \
--username "root" \
--password "cloudera" \
--table "customers" \
--warehouse-dir /job-demo-1 \
--incremental append \
--check-column customer_id \
--last-value 0

[cloudera@quickstart ~]$ sqoop job \
> --create customer_import \
> -- import \
> --connect "jdbc:mysql://quickstart.cloudera:3306/retail_db" \
> --username "root" \
> --password "cloudera" \
> --table "customers" \
> --warehouse-dir /job-demo-1 \
> --incremental append \
> --check-column customer_id \
> --last-value 0 
Warning: /usr/lib/sqoop/../accumulo does not exist! Accumulo imports will fail.
Please set $ACCUMULO_HOME to the root of your Accumulo installation.
22/04/08 18:57:46 INFO sqoop.Sqoop: Running Sqoop version: 1.4.6-cdh5.13.0
22/04/08 18:57:47 WARN tool.BaseSqoopTool: Setting your password on the command-line is insecure. Consider using -P instead.

 

How to print all the sqoop jobs?

‘sqoop job --list' command print all the sqoop jobs.

[cloudera@quickstart ~]$ sqoop job --list
Warning: /usr/lib/sqoop/../accumulo does not exist! Accumulo imports will fail.
Please set $ACCUMULO_HOME to the root of your Accumulo installation.
22/04/08 18:54:58 INFO sqoop.Sqoop: Running Sqoop version: 1.4.6-cdh5.13.0
Available jobs:
  customer_import

 

How to execute the job?

Syntax

sqoop job --exec {job_name}

 

Example

sqoop job --exec customer_import

 

[cloudera@quickstart ~]$ sqoop job --exec customer_import
Warning: /usr/lib/sqoop/../accumulo does not exist! Accumulo imports will fail.
Please set $ACCUMULO_HOME to the root of your Accumulo installation.
22/04/08 18:58:29 INFO sqoop.Sqoop: Running Sqoop version: 1.4.6-cdh5.13.0
Enter password: 
22/04/08 18:58:40 INFO manager.MySQLManager: Preparing to use a MySQL streaming resultset.
22/04/08 18:58:40 INFO tool.CodeGenTool: Beginning code generation
22/04/08 18:58:40 INFO manager.SqlManager: Executing SQL statement: SELECT t.* FROM `customers` AS t LIMIT 1
22/04/08 18:58:40 INFO manager.SqlManager: Executing SQL statement: SELECT t.* FROM `customers` AS t LIMIT 1
22/04/08 18:58:40 INFO orm.CompilationManager: HADOOP_MAPRED_HOME is /usr/lib/hadoop-mapreduce
Note: /tmp/sqoop-cloudera/compile/d4e92057e12f71bb02c170e9c6aa826a/customers.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
22/04/08 18:58:42 INFO orm.CompilationManager: Writing jar file: /tmp/sqoop-cloudera/compile/d4e92057e12f71bb02c170e9c6aa826a/customers.jar
22/04/08 18:58:43 INFO tool.ImportTool: Maximal id query for free form incremental import: SELECT MAX(`customer_id`) FROM `customers`
22/04/08 18:58:43 INFO tool.ImportTool: Incremental import based on column `customer_id`
22/04/08 18:58:43 INFO tool.ImportTool: Lower bound value: 0
22/04/08 18:58:43 INFO tool.ImportTool: Upper bound value: 12440
22/04/08 18:58:43 WARN manager.MySQLManager: It looks like you are importing from mysql.
22/04/08 18:58:43 WARN manager.MySQLManager: This transfer can be faster! Use the --direct
22/04/08 18:58:43 WARN manager.MySQLManager: option to exercise a MySQL-specific fast path.
22/04/08 18:58:43 INFO manager.MySQLManager: Setting zero DATETIME behavior to convertToNull (mysql)
22/04/08 18:58:43 INFO mapreduce.ImportJobBase: Beginning import of customers
22/04/08 18:58:43 INFO Configuration.deprecation: mapred.job.tracker is deprecated. Instead, use mapreduce.jobtracker.address
22/04/08 18:58:43 INFO Configuration.deprecation: mapred.jar is deprecated. Instead, use mapreduce.job.jar
22/04/08 18:58:43 INFO Configuration.deprecation: mapred.map.tasks is deprecated. Instead, use mapreduce.job.maps
22/04/08 18:58:43 INFO client.RMProxy: Connecting to ResourceManager at /0.0.0.0:8032
22/04/08 18:58:44 WARN hdfs.DFSClient: Caught exception 
java.lang.InterruptedException
	at java.lang.Object.wait(Native Method)
	at java.lang.Thread.join(Thread.java:1281)
	at java.lang.Thread.join(Thread.java:1355)
	at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.closeResponder(DFSOutputStream.java:967)
	at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.endBlock(DFSOutputStream.java:705)
	at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.run(DFSOutputStream.java:894)
22/04/08 18:58:45 INFO db.DBInputFormat: Using read commited transaction isolation
22/04/08 18:58:45 INFO db.DataDrivenDBInputFormat: BoundingValsQuery: SELECT MIN(`customer_id`), MAX(`customer_id`) FROM `customers` WHERE ( `customer_id` > 0 AND `customer_id` <= 12440 )
22/04/08 18:58:45 INFO db.IntegerSplitter: Split size: 3109; Num splits: 4 from: 1 to: 12440
22/04/08 18:58:45 INFO mapreduce.JobSubmitter: number of splits:4
22/04/08 18:58:45 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_1649172504056_0008
22/04/08 18:58:45 INFO impl.YarnClientImpl: Submitted application application_1649172504056_0008
22/04/08 18:58:45 INFO mapreduce.Job: The url to track the job: http://quickstart.cloudera:8088/proxy/application_1649172504056_0008/
22/04/08 18:58:45 INFO mapreduce.Job: Running job: job_1649172504056_0008
22/04/08 18:58:52 INFO mapreduce.Job: Job job_1649172504056_0008 running in uber mode : false
22/04/08 18:58:52 INFO mapreduce.Job:  map 0% reduce 0%
22/04/08 18:59:06 INFO mapreduce.Job:  map 25% reduce 0%
22/04/08 18:59:10 INFO mapreduce.Job:  map 50% reduce 0%
22/04/08 18:59:11 INFO mapreduce.Job:  map 100% reduce 0%
22/04/08 18:59:12 INFO mapreduce.Job: Job job_1649172504056_0008 completed successfully
22/04/08 18:59:12 INFO mapreduce.Job: Counters: 30
	File System Counters
		FILE: Number of bytes read=0
		FILE: Number of bytes written=690728
		FILE: Number of read operations=0
		FILE: Number of large read operations=0
		FILE: Number of write operations=0
		HDFS: Number of bytes read=487
		HDFS: Number of bytes written=953915
		HDFS: Number of read operations=16
		HDFS: Number of large read operations=0
		HDFS: Number of write operations=8
	Job Counters 
		Launched map tasks=4
		Other local map tasks=4
		Total time spent by all maps in occupied slots (ms)=52463
		Total time spent by all reduces in occupied slots (ms)=0
		Total time spent by all map tasks (ms)=52463
		Total vcore-milliseconds taken by all map tasks=52463
		Total megabyte-milliseconds taken by all map tasks=53722112
	Map-Reduce Framework
		Map input records=12440
		Map output records=12440
		Input split bytes=487
		Spilled Records=0
		Failed Shuffles=0
		Merged Map outputs=0
		GC time elapsed (ms)=682
		CPU time spent (ms)=4120
		Physical memory (bytes) snapshot=562405376
		Virtual memory (bytes) snapshot=6044942336
		Total committed heap usage (bytes)=243007488
	File Input Format Counters 
		Bytes Read=0
	File Output Format Counters 
		Bytes Written=953915
22/04/08 18:59:12 INFO mapreduce.ImportJobBase: Transferred 931.5576 KB in 29.0003 seconds (32.1223 KB/sec)
22/04/08 18:59:12 INFO mapreduce.ImportJobBase: Retrieved 12440 records.
22/04/08 18:59:12 INFO util.AppendUtils: Creating missing output directory - customers
22/04/08 18:59:12 INFO tool.ImportTool: Saving incremental import state to the metastore
22/04/08 18:59:12 INFO tool.ImportTool: Updated data for job: customer_import
[cloudera@quickstart ~]$

 

Points to note

a. Even though I supplied the password while creating the job, it still prompt me to enter the password. We can address by supplying a password file while creating the job. I will explain in later post.

b. From the log messages, you can see the statement ‘Saving incremental import state to the metastore’. Since we configured job to execute an incremental import command, sqoop job stores the state (like last-value) in the metastore.

 

Location of metastore

$HOME/.sqoop

[cloudera@quickstart ~]$ ls -lart $HOME/.sqoop
total 20
drwxrwxr-x 28 cloudera cloudera 4096 Apr  8 18:53 ..
-rw-rw-r--  1 cloudera cloudera 6757 Apr  8 18:59 metastore.db.script
-rw-rw-r--  1 cloudera cloudera  419 Apr  8 18:59 metastore.db.properties
drwxrwxr-x  2 cloudera cloudera 4096 Apr  8 18:59 .

 

‘sqoop’ use hsqldb to persist the job metadata.

 

Sample content of metastore.db.script file

[cloudera@quickstart ~]$ cat $HOME/.sqoop/metastore.db.script
CREATE SCHEMA PUBLIC AUTHORIZATION DBA
CREATE MEMORY TABLE SQOOP_ROOT(VERSION INTEGER,PROPNAME VARCHAR(128) NOT NULL,PROPVAL VARCHAR(256),CONSTRAINT SQOOP_ROOT_UNQ UNIQUE(VERSION,PROPNAME))
CREATE MEMORY TABLE SQOOP_SESSIONS(JOB_NAME VARCHAR(64) NOT NULL,PROPNAME VARCHAR(128) NOT NULL,PROPVAL VARCHAR(1024),PROPCLASS VARCHAR(32) NOT NULL,CONSTRAINT SQOOP_SESSIONS_UNQ UNIQUE(JOB_NAME,PROPNAME,PROPCLASS))
CREATE USER SA PASSWORD ""
GRANT DBA TO SA
SET WRITE_DELAY 10
SET SCHEMA PUBLIC
INSERT INTO SQOOP_ROOT VALUES(NULL,'sqoop.hsqldb.job.storage.version','0')
INSERT INTO SQOOP_ROOT VALUES(0,'sqoop.hsqldb.job.info.table','SQOOP_SESSIONS')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','sqoop.tool','import','schema')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','sqoop.property.set.id','0','schema')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','verbose','false','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','hcatalog.drop.and.create.table','false','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','incremental.last.value','12440','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','db.connect.string','jdbc:mysql://quickstart.cloudera:3306/retail_db','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','codegen.output.delimiters.escape','0','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','codegen.output.delimiters.enclose.required','false','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','codegen.input.delimiters.field','0','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','mainframe.input.dataset.type','p','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','split.limit','null','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','hbase.create.table','false','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','db.require.password','true','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','hdfs.append.dir','true','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','db.table','customers','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','codegen.input.delimiters.escape','0','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','accumulo.create.table','false','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','import.fetch.size','null','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','codegen.input.delimiters.enclose.required','false','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','db.username','root','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','reset.onemapper','false','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','codegen.output.delimiters.record','10','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','import.max.inline.lob.size','16777216','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','sqoop.throwOnError','false','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','hbase.bulk.load.enabled','false','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','hcatalog.create.table','false','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','db.clear.staging.table','false','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','incremental.col','customer_id','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','codegen.input.delimiters.record','0','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','hdfs.warehouse.dir','/job-demo-1','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','enable.compression','false','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','hive.overwrite.table','false','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','hive.import','false','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','codegen.input.delimiters.enclose','0','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','accumulo.batch.size','10240000','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','hive.drop.delims','false','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','customtool.options.jsonmap','{}','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','codegen.output.delimiters.enclose','0','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','hdfs.delete-target.dir','false','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','codegen.output.dir','.','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','codegen.auto.compile.dir','true','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','relaxed.isolation','false','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','mapreduce.num.mappers','4','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','accumulo.max.latency','5000','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','import.direct.split.size','0','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','sqlconnection.metadata.transaction.isolation.level','2','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','codegen.output.delimiters.field','44','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','export.new.update','UpdateOnly','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','incremental.mode','AppendRows','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','hdfs.file.format','TextFile','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','sqoop.oracle.escaping.disabled','true','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','codegen.compile.dir','/tmp/sqoop-cloudera/compile/d4e92057e12f71bb02c170e9c6aa826a','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','direct.import','false','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','temporary.dirRoot','_sqoop','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','hive.fail.table.exists','false','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','db.batch','false','SqoopOptions')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','sqoop.job.storage.implementations','com.cloudera.sqoop.metastore.hsqldb.HsqldbJobStorage,com.cloudera.sqoop.metastore.hsqldb.AutoHsqldbStorage','config')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','mapreduce.client.genericoptionsparser.used','true','config')
INSERT INTO SQOOP_SESSIONS VALUES('customer_import','sqoop.oracle.escaping.disabled','true','config')

 

Sample content of metastore.db.properties file

[cloudera@quickstart ~]$ cat $HOME/.sqoop/metastore.db.properties
#HSQL Database Engine 1.8.0.10
#Fri Apr 08 18:59:12 PDT 2022
hsqldb.script_format=0
runtime.gc_interval=0
sql.enforce_strict_size=false
hsqldb.cache_size_scale=8
readonly=false
hsqldb.nio_data_file=true
hsqldb.cache_scale=14
version=1.8.0
hsqldb.default_table_type=memory
hsqldb.cache_file_scale=1
hsqldb.log_size=200
modified=no
hsqldb.cache_version=1.7.0
hsqldb.original_version=1.8.0
hsqldb.compatible_version=1.8.0
[cloudera@quickstart ~]$

 

At last let’s confirm whether data is imported to HDFS or not by comparing the count of records.

 

Number of records in customers table.

mysql> select count(*) from customers;
+----------+
| count(*) |
+----------+
|    12440 |
+----------+
1 row in set (0.00 sec)

Let’s count the same in HDFS

[cloudera@quickstart ~]$ hadoop fs -ls /job-demo-1
Found 1 items
drwxr-xr-x   - cloudera supergroup          0 2022-04-08 18:59 /job-demo-1/customers
[cloudera@quickstart ~]$ 
[cloudera@quickstart ~]$ hadoop fs -ls /job-demo-1/customers
Found 4 items
-rw-r--r--   1 cloudera cloudera     237222 2022-04-08 18:59 /job-demo-1/customers/part-m-00000
-rw-r--r--   1 cloudera cloudera     238044 2022-04-08 18:59 /job-demo-1/customers/part-m-00001
-rw-r--r--   1 cloudera cloudera     238238 2022-04-08 18:59 /job-demo-1/customers/part-m-00002
-rw-r--r--   1 cloudera cloudera     240411 2022-04-08 18:59 /job-demo-1/customers/part-m-00003
[cloudera@quickstart ~]$ 
[cloudera@quickstart ~]$ hadoop fs -cat /job-demo-1/customers/* | wc -l
12440

 

 

Previous                                                    Next                                                    Home

Thursday, 2 June 2022

Java math abs: Get the absolute value of a number

‘java.lang.Math’ class provides ‘abs’ method to get the absolute value of a number. ‘abs’ method is available in below overloaded forms.

 

public static double abs(double a)

public static float abs(float a)

public static long abs(long a)

public static int abs(int a)

 

‘abs’ method return the absolute value of a number. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned.


 

AbsMethodDemo1.java

package com.sample.app;

import static java.lang.Math.abs;

public class AbsMethodDemo1 {

	public static void main(String[] args) {
		int a = 10;
		int b = -10;

		long c = 10l;
		long d = -10l;

		float e = 10.01f;
		float f = -10.01f;

		double g = 10.01;
		double h = -10.01;

		System.out.println("abs(" + a + ") : " + abs(a) + ", abs(" + b + ") : " + abs(b));
		System.out.println("abs(" + c + ") : " + abs(c) + ", abs(" + d + ") : " + abs(d));
		System.out.println("abs(" + e + ") : " + abs(e) + ", abs(" + f + ") : " + abs(f));
		System.out.println("abs(" + g + ") : " + abs(g) + ", abs(" + h + ") : " + abs(h));
	}

}

 

Output

abs(10) : 10, abs(-10) : 10
abs(10) : 10, abs(-10) : 10
abs(10.01) : 10.01, abs(-10.01) : 10.01
abs(10.01) : 10.01, abs(-10.01) : 10.01

 

Special cases for int and long

a. if the argument is equal to the value of Integer.MIN_VALUE, the most negative representable int value, the result is that same value, which is negative.

 

b. If the argument is equal to the value of Long.MIN_VALUE, the most negative representable long value, the result is that same value, which is negative.

 

AbsMethodDemo2.java

package com.sample.app;

import static java.lang.Math.abs;

public class AbsMethodDemo2 {
	public static void main(String[] args) {
		int a = Integer.MIN_VALUE;
		long b = Long.MIN_VALUE;

		System.out.println("abs(" + a + ") : " + abs(a));
		System.out.println("abs(" + b + ") : " + abs(b));
	}

}

Output

abs(-2147483648) : -2147483648
abs(-9223372036854775808) : -9223372036854775808

Special cases for float and double

a. If the argument is positive zero or negative zero, the result is positive zero.

b. If the argument is infinite, the result is positive infinity.

c. If the argument is NaN, the result is NaN.

 

AbsMethodDemo3.java

package com.sample.app;

import static java.lang.Math.abs;

public class AbsMethodDemo3 {
	public static void main(String[] args) {
		float f1 = 0f;
		float f2 = -0f;
		float f3 = Float.POSITIVE_INFINITY;
		float f4 = Float.NEGATIVE_INFINITY;
		float f5 = Float.NaN;

		double d1 = 0;
		double d2 = -0;
		double d3 = Double.POSITIVE_INFINITY;
		double d4 = Double.NEGATIVE_INFINITY;
		double d5 = Double.NaN;

		System.out.println("abs(" + f1 + ") : " + abs(f1));
		System.out.println("abs(" + f2 + ") : " + abs(f2));
		System.out.println("abs(" + f3 + ") : " + abs(f3));
		System.out.println("abs(" + f4 + ") : " + abs(f4));
		System.out.println("abs(" + f5 + ") : " + abs(f5) +"\n");

		System.out.println("abs(" + d1 + ") : " + abs(d1));
		System.out.println("abs(" + d2 + ") : " + abs(d2));
		System.out.println("abs(" + d3 + ") : " + abs(d3));
		System.out.println("abs(" + d4 + ") : " + abs(d4));
		System.out.println("abs(" + d5 + ") : " + abs(d5));

	}

}

Output

abs(0.0) : 0.0
abs(-0.0) : 0.0
abs(Infinity) : Infinity
abs(-Infinity) : Infinity
abs(NaN) : NaN

abs(0.0) : 0.0
abs(0.0) : 0.0
abs(Infinity) : Infinity
abs(-Infinity) : Infinity
abs(NaN) : NaN

 

 

Previous                                                 Next                                                 Home

Wednesday, 1 June 2022

Apache Atlas: Load sample data

In my previous post, I explained the installation process of Apache Atlas. In this post, I am going to explain how to load sample data to experiment with Apache atlas.

 

Go to atlas installation directory, navigate to bin folder and execute the script ‘quick_start.py’.

bash-3.2$ ./quick_start.py 
Enter username for atlas :- admin
Enter password for atlas :- 

  ‘quick_start.py’ script prompt for the username and password. Username is admin and password is admin, once the details entered, Script will start creating types, entities and lineage.

 

$ ./quick_start.py 
Enter username for atlas :- admin
Enter password for atlas :- 

Creating sample types: 
Created type [DB]
Created type [Table]
Created type [StorageDesc]
Created type [Column]
Created type [LoadProcess]
Created type [LoadProcessExecution]
Created type [View]
Created type [JdbcAccess]
Created type [ETL]
Created type [Metric]
Created type [PII]
Created type [Fact]
Created type [Dimension]
Created type [Log Data]
Created type [Table_DB]
Created type [View_DB]
Created type [View_Tables]
Created type [Table_Columns]
Created type [Table_StorageDesc]

Creating sample entities: 
Created entity of type [DB], guid: 0c9e2a2f-345b-4be5-a84d-fa247543a065
Created entity of type [DB], guid: 7a731c08-76d3-49f7-b53e-a19e22d41c51
Created entity of type [DB], guid: 773a3629-4d70-425f-99bb-9d5f3e4717f1
Created entity of type [Table], guid: db71918c-152b-4730-b028-17822f0c0c54
Created entity of type [Table], guid: 6edb96e7-cfdd-4294-9305-9a0d3e0f4ef8
Created entity of type [Table], guid: 47ea153d-5dea-4ecf-a503-084e55e152db
Created entity of type [Table], guid: 1cbf586a-d069-409e-b3b0-0d84df737035
Created entity of type [Table], guid: d30790a9-13e9-41d9-8962-be0f73d35cdf
Created entity of type [Table], guid: 1d7fe9c6-1732-496a-81f2-7b05bc2e775f
Created entity of type [Table], guid: 21e99241-fde0-472a-903c-74b79b2b3dc1
Created entity of type [Table], guid: 719336d9-1d36-44d3-8cd1-d9bca84fec0d
Created entity of type [View], guid: 3a368508-4b10-4947-8e24-0c781687c8b2
Created entity of type [View], guid: a980dd23-f536-40b3-a2ba-705993018059
Created entity of type [LoadProcess], guid: afb88ebb-0351-4a44-b670-41ca1021f3a1
Created entity of type [LoadProcessExecution], guid: 17a7d46d-ad0b-47a9-bc08-55f1d82eec2d
Created entity of type [LoadProcessExecution], guid: 55de77f8-07a2-452f-afa8-c62befb801e1
Created entity of type [LoadProcess], guid: a970999e-c0f2-46e1-8122-80ab4a697ef3
Created entity of type [LoadProcessExecution], guid: e167c2dd-19ea-411f-95d1-1e45a7fe3b0c
Created entity of type [LoadProcessExecution], guid: 4e779715-cede-4d41-9642-ce0f2974a275
Created entity of type [LoadProcess], guid: 175c3b87-4ed1-499b-bc18-97cc6b35fce0
Created entity of type [LoadProcessExecution], guid: 94215ab7-98f9-4abb-a9ba-4eaffda866fc
Created entity of type [LoadProcessExecution], guid: 27854b6a-87d9-41fe-96fa-1628a09fc02f

Sample DSL Queries: 
query [from DB] returned [3] rows.
query [DB] returned [3] rows.
query [DB where name=%22Reporting%22] returned [1] rows.
query [DB where name=%22encode_db_name%22] returned [ 0 ] rows.
query [Table where name=%2522sales_fact%2522] returned [1] rows.
query [DB where name="Reporting"] returned [1] rows.
query [DB where DB.name="Reporting"] returned [1] rows.
query [DB name = "Reporting"] returned [1] rows.
query [DB DB.name = "Reporting"] returned [1] rows.
query [DB where name="Reporting" select name, owner] returned [1] rows.
query [DB where DB.name="Reporting" select name, owner] returned [1] rows.
query [DB has name] returned [3] rows.
query [DB where DB has name] returned [3] rows.
query [DB is JdbcAccess] returned [ 0 ] rows.
query [from Table] returned [8] rows.
query [Table] returned [8] rows.
query [Table is Dimension] returned [4] rows.
query [Column where Column isa PII] returned [6] rows.
query [View is Dimension] returned [2] rows.
query [Column select Column.name] returned [8] rows.
query [Column select name] returned [8] rows.
query [Column where Column.name="customer_id"] returned [4] rows.
query [from Table select Table.name] returned [8] rows.
query [DB where (name = "Reporting")] returned [1] rows.
query [DB where DB is JdbcAccess] returned [ 0 ] rows.
query [DB where DB has name] returned [3] rows.
query [DB as db1 Table where (db1.name = "Reporting")] returned [ 0 ] rows.
query [Dimension] returned [7] rows.
query [JdbcAccess] returned [2] rows.
query [ETL] returned [10] rows.
query [Metric] returned [6] rows.
query [PII] returned [6] rows.
query [`Log Data`] returned [5] rows.
query [Table where name="sales_fact", columns] returned [4] rows.
query [Table where name="sales_fact", columns as column select column.name, column.dataType, column.comment] returned [4] rows.
query [from DataSet] returned [10] rows.
query [from Process] returned [3] rows.

Sample Lineage Info: 
loadSalesDaily(LoadProcess) -> sales_fact_daily_mv(Table)
loadSalesMonthly(LoadProcess) -> sales_fact_monthly_mv(Table)
sales_fact(Table) -> loadSalesDaily(LoadProcess)
time_dim(Table) -> loadSalesDaily(LoadProcess)
sales_fact_daily_mv(Table) -> loadSalesMonthly(LoadProcess)
Sample data added to Apache Atlas Server.

  Now, login to atlas ui ‘http://localhost:21000/’, and confirm that the types are created successfully.

 


 

Select ‘Table’ as option for ‘Search By Type’ and click on Search button to see all the onboarded tables.



 

 

Previous                                                    Next                                                    Home