use of org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef in project incubator-atlas by apache.
the class AtlasTypeUtil method createRequiredListAttrDefWithConstraint.
public static AtlasAttributeDef createRequiredListAttrDefWithConstraint(String name, String dataType, String type, Map param) {
AtlasAttributeDef ret = AtlasTypeUtil.createListRequiredAttrDef(name, dataType);
ret.addConstraint(new AtlasConstraintDef(type, param));
return ret;
}
use of org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef in project incubator-atlas by apache.
the class AtlasTypeUtil method createOptionalAttrDefWithConstraint.
public static AtlasAttributeDef createOptionalAttrDefWithConstraint(String name, String typeName, String type, Map param) {
AtlasAttributeDef ret = AtlasTypeUtil.createOptionalAttrDef(name, typeName);
ret.addConstraint(new AtlasConstraintDef(type, param));
return ret;
}
use of org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef in project incubator-atlas by apache.
the class TestAtlasEntityType method createColumnEntityDefWithInvaidAttributeTypeForInverseAttribute.
private AtlasEntityDef createColumnEntityDefWithInvaidAttributeTypeForInverseAttribute() {
AtlasEntityDef column = new AtlasEntityDef(TYPE_COLUMN);
AtlasAttributeDef attrTable = new AtlasAttributeDef(ATTR_NAME, AtlasBaseTypeDef.ATLAS_TYPE_STRING);
Map<String, Object> params = new HashMap<>();
params.put(AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE, ATTR_NAME);
attrTable.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF, params));
column.addAttribute(attrTable);
return column;
}
use of org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef in project incubator-atlas by apache.
the class AtlasStructDefStoreV1 method toAttributeDefFromJson.
@VisibleForTesting
public static AtlasAttributeDef toAttributeDefFromJson(AtlasStructDef structDef, Map attribInfo, AtlasTypeDefGraphStoreV1 typeDefStore) throws AtlasBaseException {
AtlasAttributeDef ret = new AtlasAttributeDef();
ret.setName((String) attribInfo.get("name"));
ret.setTypeName((String) attribInfo.get("dataType"));
ret.setIsUnique((Boolean) attribInfo.get("isUnique"));
ret.setIsIndexable((Boolean) attribInfo.get("isIndexable"));
if ((Boolean) attribInfo.get("isComposite")) {
ret.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_OWNED_REF));
}
final String reverseAttributeName = (String) attribInfo.get("reverseAttributeName");
if (StringUtils.isNotBlank(reverseAttributeName)) {
ret.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF, new HashMap<String, Object>() {
{
put(AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE, reverseAttributeName);
}
}));
}
Map multiplicity = AtlasType.fromJson((String) attribInfo.get("multiplicity"), Map.class);
Number minCount = (Number) multiplicity.get("lower");
Number maxCount = (Number) multiplicity.get("upper");
Boolean isUnique = (Boolean) multiplicity.get("isUnique");
if (minCount == null || minCount.intValue() == 0) {
ret.setIsOptional(true);
ret.setValuesMinCount(0);
} else {
ret.setIsOptional(false);
ret.setValuesMinCount(minCount.intValue());
}
if (maxCount == null || maxCount.intValue() < 2) {
ret.setCardinality(AtlasAttributeDef.Cardinality.SINGLE);
ret.setValuesMaxCount(1);
} else {
if (isUnique == null || isUnique == Boolean.FALSE) {
ret.setCardinality(AtlasAttributeDef.Cardinality.LIST);
} else {
ret.setCardinality(AtlasAttributeDef.Cardinality.SET);
}
ret.setValuesMaxCount(maxCount.intValue());
}
return ret;
}
use of org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef in project incubator-atlas by apache.
the class BaseResourceIT method createTypeDefinitionsV2.
protected void createTypeDefinitionsV2() throws Exception {
AtlasConstraintDef isCompositeSourceConstraint = new AtlasConstraintDef(CONSTRAINT_TYPE_OWNED_REF);
AtlasConstraintDef isCompositeTargetConstraint = new AtlasConstraintDef(CONSTRAINT_TYPE_INVERSE_REF, Collections.<String, Object>singletonMap(CONSTRAINT_PARAM_ATTRIBUTE, "randomTable"));
AtlasEntityDef dbClsTypeDef = AtlasTypeUtil.createClassTypeDef(DATABASE_TYPE_V2, null, AtlasTypeUtil.createUniqueRequiredAttrDef(NAME, "string"), AtlasTypeUtil.createRequiredAttrDef(DESCRIPTION, "string"), AtlasTypeUtil.createOptionalAttrDef("locationUri", "string"), AtlasTypeUtil.createOptionalAttrDef("owner", "string"), AtlasTypeUtil.createOptionalAttrDef("createTime", "int"), AtlasTypeUtil.createOptionalAttrDef("createTime", "int"), //there is a serializ
new AtlasAttributeDef("randomTable", DataTypes.arrayTypeName(HIVE_TABLE_TYPE_V2), true, Cardinality.SET, 0, -1, false, true, Collections.singletonList(isCompositeSourceConstraint)));
AtlasEntityDef columnClsDef = AtlasTypeUtil.createClassTypeDef(COLUMN_TYPE_V2, null, AtlasTypeUtil.createOptionalAttrDef(NAME, "string"), AtlasTypeUtil.createOptionalAttrDef("dataType", "string"), AtlasTypeUtil.createOptionalAttrDef("comment", "string"));
AtlasStructDef structTypeDef = AtlasTypeUtil.createStructTypeDef("serdeType", AtlasTypeUtil.createRequiredAttrDef(NAME, "string"), AtlasTypeUtil.createRequiredAttrDef("serde", "string"));
AtlasEnumDef enumDef = new AtlasEnumDef("tableType", DESCRIPTION, Arrays.asList(new AtlasEnumDef.AtlasEnumElementDef("MANAGED", null, 1), new AtlasEnumDef.AtlasEnumElementDef("EXTERNAL", null, 2)));
AtlasEntityDef tblClsDef = AtlasTypeUtil.createClassTypeDef(HIVE_TABLE_TYPE_V2, ImmutableSet.of("DataSet"), AtlasTypeUtil.createOptionalAttrDef("owner", "string"), AtlasTypeUtil.createOptionalAttrDef("createTime", "long"), AtlasTypeUtil.createOptionalAttrDef("lastAccessTime", "date"), AtlasTypeUtil.createOptionalAttrDef("temporary", "boolean"), new AtlasAttributeDef("db", DATABASE_TYPE_V2, true, Cardinality.SINGLE, 0, 1, false, true, Collections.singletonList(isCompositeTargetConstraint)), //some tests don't set the columns field or set it to null...
AtlasTypeUtil.createOptionalAttrDef("columns", DataTypes.arrayTypeName(COLUMN_TYPE_V2)), AtlasTypeUtil.createOptionalAttrDef("tableType", "tableType"), AtlasTypeUtil.createOptionalAttrDef("serde1", "serdeType"), AtlasTypeUtil.createOptionalAttrDef("serde2", "serdeType"));
AtlasEntityDef loadProcessClsDef = AtlasTypeUtil.createClassTypeDef(HIVE_PROCESS_TYPE_V2, ImmutableSet.of("Process"), AtlasTypeUtil.createOptionalAttrDef("userName", "string"), AtlasTypeUtil.createOptionalAttrDef("startTime", "int"), AtlasTypeUtil.createOptionalAttrDef("endTime", "long"), AtlasTypeUtil.createRequiredAttrDef("queryText", "string"), AtlasTypeUtil.createRequiredAttrDef("queryPlan", "string"), AtlasTypeUtil.createRequiredAttrDef("queryId", "string"), AtlasTypeUtil.createRequiredAttrDef("queryGraph", "string"));
AtlasClassificationDef classificationTrait = AtlasTypeUtil.createTraitTypeDef("classification", ImmutableSet.<String>of(), AtlasTypeUtil.createRequiredAttrDef("tag", "string"));
AtlasClassificationDef piiTrait = AtlasTypeUtil.createTraitTypeDef("pii", ImmutableSet.<String>of());
AtlasClassificationDef phiTrait = AtlasTypeUtil.createTraitTypeDef("phi", ImmutableSet.<String>of());
AtlasClassificationDef pciTrait = AtlasTypeUtil.createTraitTypeDef("pci", ImmutableSet.<String>of());
AtlasClassificationDef soxTrait = AtlasTypeUtil.createTraitTypeDef("sox", ImmutableSet.<String>of());
AtlasClassificationDef secTrait = AtlasTypeUtil.createTraitTypeDef("sec", ImmutableSet.<String>of());
AtlasClassificationDef financeTrait = AtlasTypeUtil.createTraitTypeDef("finance", ImmutableSet.<String>of());
AtlasTypesDef typesDef = new AtlasTypesDef(ImmutableList.of(enumDef), ImmutableList.of(structTypeDef), ImmutableList.of(classificationTrait, piiTrait, phiTrait, pciTrait, soxTrait, secTrait, financeTrait), ImmutableList.of(dbClsTypeDef, columnClsDef, tblClsDef, loadProcessClsDef));
batchCreateTypes(typesDef);
}
Aggregations