Commit f75d7f40 by Sarath Subramanian

ATLAS-3202: Hive hook: getStorageDescEntity() throws NPE if bucketCols is null

parent 49db4cac
...@@ -475,7 +475,7 @@ public abstract class BaseHiveEvent { ...@@ -475,7 +475,7 @@ public abstract class BaseHiveEvent {
ret.setAttribute(ATTRIBUTE_NUM_BUCKETS, sd.getNumBuckets()); ret.setAttribute(ATTRIBUTE_NUM_BUCKETS, sd.getNumBuckets());
ret.setAttribute(ATTRIBUTE_STORED_AS_SUB_DIRECTORIES, sd.isStoredAsSubDirectories()); ret.setAttribute(ATTRIBUTE_STORED_AS_SUB_DIRECTORIES, sd.isStoredAsSubDirectories());
if (sd.getBucketCols().size() > 0) { if (sd.getBucketCols() != null && sd.getBucketCols().size() > 0) {
ret.setAttribute(ATTRIBUTE_BUCKET_COLS, sd.getBucketCols()); ret.setAttribute(ATTRIBUTE_BUCKET_COLS, sd.getBucketCols());
} }
...@@ -512,36 +512,38 @@ public abstract class BaseHiveEvent { ...@@ -512,36 +512,38 @@ public abstract class BaseHiveEvent {
} }
protected List<AtlasEntity> getColumnEntities(AtlasObjectId tableId, Table table, List<FieldSchema> fieldSchemas) { protected List<AtlasEntity> getColumnEntities(AtlasObjectId tableId, Table table, List<FieldSchema> fieldSchemas) {
List<AtlasEntity> ret = new ArrayList<>(); List<AtlasEntity> ret = new ArrayList<>();
boolean isKnownTable = tableId.getGuid() == null; boolean isKnownTable = tableId.getGuid() == null;
int columnPosition = 0;
int columnPosition = 0;
for (FieldSchema fieldSchema : fieldSchemas) { if (CollectionUtils.isNotEmpty(fieldSchemas)) {
String colQualifiedName = getQualifiedName(table, fieldSchema); for (FieldSchema fieldSchema : fieldSchemas) {
AtlasEntity column = context.getEntity(colQualifiedName); String colQualifiedName = getQualifiedName(table, fieldSchema);
AtlasEntity column = context.getEntity(colQualifiedName);
if (column == null) {
column = new AtlasEntity(HIVE_TYPE_COLUMN);
// if column's table was sent in an earlier notification, set 'guid' to null - which will:
// - result in this entity to be not included in 'referredEntities'
// - cause Atlas server to resolve the entity by its qualifiedName
if (isKnownTable) {
column.setGuid(null);
}
if (column == null) { column.setAttribute(ATTRIBUTE_TABLE, tableId);
column = new AtlasEntity(HIVE_TYPE_COLUMN); column.setAttribute(ATTRIBUTE_QUALIFIED_NAME, colQualifiedName);
column.setAttribute(ATTRIBUTE_NAME, fieldSchema.getName());
column.setAttribute(ATTRIBUTE_OWNER, table.getOwner());
column.setAttribute(ATTRIBUTE_COL_TYPE, fieldSchema.getType());
column.setAttribute(ATTRIBUTE_COL_POSITION, columnPosition++);
column.setAttribute(ATTRIBUTE_COMMENT, fieldSchema.getComment());
// if column's table was sent in an earlier notification, set 'guid' to null - which will: context.putEntity(colQualifiedName, column);
// - result in this entity to be not included in 'referredEntities'
// - cause Atlas server to resolve the entity by its qualifiedName
if (isKnownTable) {
column.setGuid(null);
} }
column.setAttribute(ATTRIBUTE_TABLE, tableId); ret.add(column);
column.setAttribute(ATTRIBUTE_QUALIFIED_NAME, colQualifiedName);
column.setAttribute(ATTRIBUTE_NAME, fieldSchema.getName());
column.setAttribute(ATTRIBUTE_OWNER, table.getOwner());
column.setAttribute(ATTRIBUTE_COL_TYPE, fieldSchema.getType());
column.setAttribute(ATTRIBUTE_COL_POSITION, columnPosition++);
column.setAttribute(ATTRIBUTE_COMMENT, fieldSchema.getComment());
context.putEntity(colQualifiedName, column);
} }
ret.add(column);
} }
return ret; return ret;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment