Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
atlas
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dataplatform
atlas
Commits
1c399cc7
Commit
1c399cc7
authored
Jun 18, 2019
by
lina.li
Committed by
Sarath Subramanian
Jun 18, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-3290: Impala Hook should get database name and table name from vertex metadata
Signed-off-by:
Sarath Subramanian
<
sarath@apache.org
>
parent
63779893
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
166 additions
and
2 deletions
+166
-2
AtlasImpalaHookContext.java
.../org/apache/atlas/impala/hook/AtlasImpalaHookContext.java
+40
-0
ImpalaLineageHook.java
.../java/org/apache/atlas/impala/hook/ImpalaLineageHook.java
+1
-1
BaseImpalaEvent.java
.../org/apache/atlas/impala/hook/events/BaseImpalaEvent.java
+1
-1
ImpalaLineageToolIT.java
...est/java/org/apache/atlas/impala/ImpalaLineageToolIT.java
+57
-0
impalaCreateTableAsSelectVertexIdNoTableName.json
...sources/impalaCreateTableAsSelectVertexIdNoTableName.json
+67
-0
No files found.
addons/impala-bridge/src/main/java/org/apache/atlas/impala/hook/AtlasImpalaHookContext.java
View file @
1c399cc7
...
@@ -23,7 +23,10 @@ import java.util.HashMap;
...
@@ -23,7 +23,10 @@ import java.util.HashMap;
import
java.util.Map
;
import
java.util.Map
;
import
org.apache.atlas.impala.model.ImpalaOperationType
;
import
org.apache.atlas.impala.model.ImpalaOperationType
;
import
org.apache.atlas.impala.model.ImpalaQuery
;
import
org.apache.atlas.impala.model.ImpalaQuery
;
import
org.apache.atlas.impala.model.LineageVertex
;
import
org.apache.atlas.impala.model.LineageVertexMetadata
;
import
org.apache.atlas.model.instance.AtlasEntity
;
import
org.apache.atlas.model.instance.AtlasEntity
;
import
org.apache.commons.lang.StringUtils
;
/**
/**
...
@@ -101,6 +104,43 @@ public class AtlasImpalaHookContext {
...
@@ -101,6 +104,43 @@ public class AtlasImpalaHookContext {
getClusterName
();
getClusterName
();
}
}
public
String
getQualifiedNameForColumn
(
LineageVertex
vertex
)
{
// get database name and table name
LineageVertexMetadata
metadata
=
vertex
.
getMetadata
();
if
(
metadata
==
null
)
{
return
getQualifiedNameForColumn
(
vertex
.
getVertexId
());
}
String
fullTableName
=
metadata
.
getTableName
();
if
(
StringUtils
.
isEmpty
(
fullTableName
))
{
throw
new
IllegalArgumentException
(
"fullTableName in column metadata is null"
);
}
int
sepPos
=
fullTableName
.
lastIndexOf
(
QNAME_SEP_ENTITY_NAME
);
if
(!
isSeparatorIndexValid
(
sepPos
))
{
throw
new
IllegalArgumentException
(
fullTableName
+
"in column metadata does not contain database name"
);
}
// get pure column name
String
columnName
=
vertex
.
getVertexId
();
if
(
StringUtils
.
isEmpty
(
columnName
))
{
throw
new
IllegalArgumentException
(
"column name in vertexId is null"
);
}
int
sepPosLast
=
columnName
.
lastIndexOf
(
QNAME_SEP_ENTITY_NAME
);
if
(
isSeparatorIndexValid
(
sepPosLast
))
{
columnName
=
columnName
.
substring
(
sepPosLast
+
1
);
}
return
getQualifiedNameForColumn
(
fullTableName
.
substring
(
0
,
sepPos
),
fullTableName
.
substring
(
sepPos
+
1
),
columnName
);
}
public
String
getQualifiedNameForColumn
(
String
fullColumnName
)
throws
IllegalArgumentException
{
public
String
getQualifiedNameForColumn
(
String
fullColumnName
)
throws
IllegalArgumentException
{
if
(
fullColumnName
==
null
)
{
if
(
fullColumnName
==
null
)
{
throw
new
IllegalArgumentException
(
"fullColumnName is null"
);
throw
new
IllegalArgumentException
(
"fullColumnName is null"
);
...
...
addons/impala-bridge/src/main/java/org/apache/atlas/impala/hook/ImpalaLineageHook.java
View file @
1c399cc7
...
@@ -124,7 +124,7 @@ public class ImpalaLineageHook extends AtlasHook {
...
@@ -124,7 +124,7 @@ public class ImpalaLineageHook extends AtlasHook {
}
catch
(
Throwable
t
)
{
}
catch
(
Throwable
t
)
{
LOG
.
error
(
"ImpalaLineageHook.process(): failed to process query {}"
,
LOG
.
error
(
"ImpalaLineageHook.process(): failed to process query {}"
,
lineageQuery
.
getQueryText
(
),
t
);
AtlasType
.
toJson
(
lineageQuery
),
t
);
}
}
if
(
LOG
.
isDebugEnabled
())
{
if
(
LOG
.
isDebugEnabled
())
{
...
...
addons/impala-bridge/src/main/java/org/apache/atlas/impala/hook/events/BaseImpalaEvent.java
View file @
1c399cc7
...
@@ -161,7 +161,7 @@ public abstract class BaseImpalaEvent {
...
@@ -161,7 +161,7 @@ public abstract class BaseImpalaEvent {
return
context
.
getQualifiedNameForTable
(
node
.
getVertexId
());
return
context
.
getQualifiedNameForTable
(
node
.
getVertexId
());
case
COLUMN:
case
COLUMN:
return
context
.
getQualifiedNameForColumn
(
node
.
getVertexId
()
);
return
context
.
getQualifiedNameForColumn
(
node
);
default
:
default
:
LOG
.
warn
(
"null qualified name for type: {} and name: {}"
,
nodeType
,
node
.
getVertexId
());
LOG
.
warn
(
"null qualified name for type: {} and name: {}"
,
nodeType
,
node
.
getVertexId
());
...
...
addons/impala-bridge/src/test/java/org/apache/atlas/impala/ImpalaLineageToolIT.java
View file @
1c399cc7
...
@@ -418,4 +418,60 @@ public class ImpalaLineageToolIT extends ImpalaLineageITBase {
...
@@ -418,4 +418,60 @@ public class ImpalaLineageToolIT extends ImpalaLineageITBase {
assertNotNull
(
ddlQueries
);
assertNotNull
(
ddlQueries
);
assertEquals
(
ddlQueries
.
size
(),
0
);
assertEquals
(
ddlQueries
.
size
(),
0
);
}
}
/**
* This tests
* 1) ImpalaLineageTool can parse one lineage file that contains "create table as select" command lineage,
* there is table vertex with createTime. The target vertex's vertexId does not contain db name and table name
* 2) Lineage is sent to Atlas
* 3) Atlas can get this lineage from Atlas
*/
@Test
public
void
testCreateTableAsSelectVertexIdNoTableNameFromFile
()
throws
Exception
{
String
IMPALA
=
dir
+
"impalaCreateTableAsSelectVertexIdNoTableName.json"
;
String
IMPALA_WAL
=
dir
+
"WALimpala.wal"
;
ImpalaLineageHook
impalaLineageHook
=
new
ImpalaLineageHook
();
// create database and tables to simulate Impala behavior that Impala updates metadata
// to HMS and HMSHook sends the metadata to Atlas, which has to happen before
// Atlas can handle lineage notification
String
dbName
=
"sales_db"
;
createDatabase
(
dbName
);
String
sourceTableName
=
"sales_asia"
;
createTable
(
dbName
,
sourceTableName
,
"(id string, name string)"
,
false
);
String
targetTableName
=
"sales_china"
;
createTable
(
dbName
,
targetTableName
,
"(id string, name string)"
,
false
);
// process lineage record, and send corresponding notification to Atlas
String
[]
args
=
new
String
[]{
"-d"
,
"./"
,
"-p"
,
"impala"
};
ImpalaLineageTool
toolInstance
=
new
ImpalaLineageTool
(
args
);
toolInstance
.
importHImpalaEntities
(
impalaLineageHook
,
IMPALA
,
IMPALA_WAL
);
// verify the process is saved in Atlas
// the value is from info in IMPALA_4.
String
createTime
=
new
Long
((
long
)
1560885039
*
1000
).
toString
();
String
processQFName
=
dbName
+
"."
+
targetTableName
+
AtlasImpalaHookContext
.
QNAME_SEP_CLUSTER_NAME
+
CLUSTER_NAME
+
AtlasImpalaHookContext
.
QNAME_SEP_PROCESS
+
createTime
;
processQFName
=
processQFName
.
toLowerCase
();
String
queryString
=
"create table "
+
targetTableName
+
" as select * from "
+
sourceTableName
;
AtlasEntity
processEntity1
=
validateProcess
(
processQFName
,
queryString
);
AtlasEntity
processExecutionEntity1
=
validateProcessExecution
(
processEntity1
,
queryString
);
AtlasObjectId
process1
=
toAtlasObjectId
(
processExecutionEntity1
.
getRelationshipAttribute
(
BaseImpalaEvent
.
ATTRIBUTE_PROCESS
));
Assert
.
assertEquals
(
process1
.
getGuid
(),
processEntity1
.
getGuid
());
Assert
.
assertEquals
(
numberOfProcessExecutions
(
processEntity1
),
1
);
String
guid
=
assertTableIsRegistered
(
dbName
,
targetTableName
);
AtlasEntity
entity
=
atlasClientV2
.
getEntityByGuid
(
guid
).
getEntity
();
List
ddlQueries
=
(
List
)
entity
.
getRelationshipAttribute
(
ATTRIBUTE_DDL_QUERIES
);
assertNotNull
(
ddlQueries
);
assertEquals
(
ddlQueries
.
size
(),
1
);
}
}
}
\ No newline at end of file
addons/impala-bridge/src/test/resources/impalaCreateTableAsSelectVertexIdNoTableName.json
0 → 100644
View file @
1c399cc7
{
"queryText"
:
"create table sales_china as select * from sales_asia"
,
"queryId"
:
"2940d0b242de53ea:e82ba8d300000000"
,
"hash"
:
"a705a9ec851a5440afca0dfb8df86cd5"
,
"user"
:
"root"
,
"timestamp"
:
1560885032
,
"endTime"
:
1560885040
,
"edges"
:[
{
"sources"
:[
1
],
"targets"
:[
0
],
"edgeType"
:
"PROJECTION"
},
{
"sources"
:[
3
],
"targets"
:[
2
],
"edgeType"
:
"PROJECTION"
}
],
"vertices"
:[
{
"id"
:
0
,
"vertexType"
:
"COLUMN"
,
"vertexId"
:
"id"
,
"metadata"
:{
"tableName"
:
"sales_db.sales_china"
,
"tableCreateTime"
:
1560885039
}
},
{
"id"
:
1
,
"vertexType"
:
"COLUMN"
,
"vertexId"
:
"sales_db.sales_asia.id"
,
"metadata"
:{
"tableName"
:
"sales_db.sales_asia"
,
"tableCreateTime"
:
1560884919
}
},
{
"id"
:
2
,
"vertexType"
:
"COLUMN"
,
"vertexId"
:
"name"
,
"metadata"
:{
"tableName"
:
"sales_db.sales_china"
,
"tableCreateTime"
:
1560885039
}
},
{
"id"
:
3
,
"vertexType"
:
"COLUMN"
,
"vertexId"
:
"sales_db.sales_asia.name"
,
"metadata"
:{
"tableName"
:
"sales_db.sales_asia"
,
"tableCreateTime"
:
1560884919
}
}
]
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment