Search in sources :

Example 6 with AttributeDefinition

use of org.apache.atlas.v1.model.typedef.AttributeDefinition in project atlas by apache.

the class BaseResourceIT method createTypeDefinitionsV1.

protected void createTypeDefinitionsV1() throws Exception {
    ClassTypeDefinition dbClsDef = TypesUtil.createClassTypeDef(DATABASE_TYPE, null, null, TypesUtil.createUniqueRequiredAttrDef(NAME, AtlasBaseTypeDef.ATLAS_TYPE_STRING), TypesUtil.createRequiredAttrDef(DESCRIPTION, AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("locationUri", AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("owner", AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("createTime", AtlasBaseTypeDef.ATLAS_TYPE_INT), new AttributeDefinition("tables", AtlasBaseTypeDef.getArrayTypeName(HIVE_TABLE_TYPE), Multiplicity.OPTIONAL, false, "db"));
    ClassTypeDefinition columnClsDef = TypesUtil.createClassTypeDef(COLUMN_TYPE, null, null, attrDef(NAME, AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("dataType", AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("comment", AtlasBaseTypeDef.ATLAS_TYPE_STRING));
    StructTypeDefinition structTypeDefinition = new StructTypeDefinition("serdeType", null, Arrays.asList(new AttributeDefinition[] { TypesUtil.createRequiredAttrDef(NAME, AtlasBaseTypeDef.ATLAS_TYPE_STRING), TypesUtil.createRequiredAttrDef("serde", AtlasBaseTypeDef.ATLAS_TYPE_STRING) }));
    EnumValue[] values = { new EnumValue("MANAGED", 1), new EnumValue("EXTERNAL", 2) };
    EnumTypeDefinition enumTypeDefinition = new EnumTypeDefinition("tableType", null, null, Arrays.asList(values));
    ClassTypeDefinition tblClsDef = TypesUtil.createClassTypeDef(HIVE_TABLE_TYPE, null, Collections.singleton("DataSet"), attrDef("owner", AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("createTime", AtlasBaseTypeDef.ATLAS_TYPE_LONG), attrDef("lastAccessTime", AtlasBaseTypeDef.ATLAS_TYPE_DATE), attrDef("temporary", AtlasBaseTypeDef.ATLAS_TYPE_BOOLEAN), new AttributeDefinition("db", DATABASE_TYPE, Multiplicity.OPTIONAL, true, "tables"), new AttributeDefinition("columns", AtlasBaseTypeDef.getArrayTypeName(COLUMN_TYPE), Multiplicity.OPTIONAL, true, null), new AttributeDefinition("tableType", "tableType", Multiplicity.OPTIONAL, false, null), new AttributeDefinition("serde1", "serdeType", Multiplicity.OPTIONAL, false, null), new AttributeDefinition("serde2", "serdeType", Multiplicity.OPTIONAL, false, null));
    ClassTypeDefinition loadProcessClsDef = TypesUtil.createClassTypeDef(HIVE_PROCESS_TYPE, null, Collections.singleton("Process"), attrDef("userName", AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("startTime", AtlasBaseTypeDef.ATLAS_TYPE_INT), attrDef("endTime", AtlasBaseTypeDef.ATLAS_TYPE_LONG), attrDef("queryText", AtlasBaseTypeDef.ATLAS_TYPE_STRING, Multiplicity.REQUIRED), attrDef("queryPlan", AtlasBaseTypeDef.ATLAS_TYPE_STRING, Multiplicity.REQUIRED), attrDef("queryId", AtlasBaseTypeDef.ATLAS_TYPE_STRING, Multiplicity.REQUIRED), attrDef("queryGraph", AtlasBaseTypeDef.ATLAS_TYPE_STRING, Multiplicity.REQUIRED));
    TraitTypeDefinition classificationTrait = TypesUtil.createTraitTypeDef("classification", null, Collections.<String>emptySet(), TypesUtil.createRequiredAttrDef("tag", AtlasBaseTypeDef.ATLAS_TYPE_STRING));
    TraitTypeDefinition piiTrait = TypesUtil.createTraitTypeDef(PII_TAG, null, Collections.<String>emptySet());
    TraitTypeDefinition phiTrait = TypesUtil.createTraitTypeDef(PHI_TAG, null, Collections.<String>emptySet());
    TraitTypeDefinition pciTrait = TypesUtil.createTraitTypeDef(PCI_TAG, null, Collections.<String>emptySet());
    TraitTypeDefinition soxTrait = TypesUtil.createTraitTypeDef(SOX_TAG, null, Collections.<String>emptySet());
    TraitTypeDefinition secTrait = TypesUtil.createTraitTypeDef(SEC_TAG, null, Collections.<String>emptySet());
    TraitTypeDefinition financeTrait = TypesUtil.createTraitTypeDef(FINANCE_TAG, null, Collections.<String>emptySet());
    TraitTypeDefinition factTrait = TypesUtil.createTraitTypeDef("Fact" + randomString(), null, Collections.<String>emptySet());
    TraitTypeDefinition etlTrait = TypesUtil.createTraitTypeDef("ETL" + randomString(), null, Collections.<String>emptySet());
    TraitTypeDefinition dimensionTrait = TypesUtil.createTraitTypeDef("Dimension" + randomString(), null, Collections.<String>emptySet());
    TraitTypeDefinition metricTrait = TypesUtil.createTraitTypeDef("Metric" + randomString(), null, Collections.<String>emptySet());
    createType(getTypesDef(Collections.singletonList(enumTypeDefinition), Collections.singletonList(structTypeDefinition), Arrays.asList(classificationTrait, piiTrait, phiTrait, pciTrait, soxTrait, secTrait, financeTrait, factTrait, etlTrait, dimensionTrait, metricTrait), Arrays.asList(dbClsDef, columnClsDef, tblClsDef, loadProcessClsDef)));
}
Also used : EnumValue(org.apache.atlas.v1.model.typedef.EnumTypeDefinition.EnumValue)

Example 7 with AttributeDefinition

use of org.apache.atlas.v1.model.typedef.AttributeDefinition in project atlas by apache.

the class TypeConverterUtil method structToTypesDef.

private static TypesDef structToTypesDef(AtlasStructType structType, AtlasTypeRegistry registry) {
    String typeName = structType.getStructDef().getName();
    String typeDesc = structType.getStructDef().getDescription();
    String typeVersion = structType.getStructDef().getTypeVersion();
    List<AttributeDefinition> attributes = getAttributes(structType, registry);
    StructTypeDefinition structTypeDef = new StructTypeDefinition(typeName, typeDesc, typeVersion, attributes);
    TypesDef ret = new TypesDef(null, Arrays.asList(structTypeDef), null, null);
    return ret;
}
Also used : TypesDef(org.apache.atlas.v1.model.typedef.TypesDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) AttributeDefinition(org.apache.atlas.v1.model.typedef.AttributeDefinition) StructTypeDefinition(org.apache.atlas.v1.model.typedef.StructTypeDefinition)

Example 8 with AttributeDefinition

use of org.apache.atlas.v1.model.typedef.AttributeDefinition in project atlas by apache.

the class TypeConverterUtil method toAtlasAttributeDef.

public static AtlasAttributeDef toAtlasAttributeDef(final AttributeDefinition attrDefinition) {
    AtlasAttributeDef ret = new AtlasAttributeDef(attrDefinition.getName(), attrDefinition.getDataTypeName());
    ret.setIsIndexable(attrDefinition.getIsIndexable());
    ret.setIsUnique(attrDefinition.getIsUnique());
    if (attrDefinition.getIsComposite()) {
        ret.addConstraint(new AtlasConstraintDef(CONSTRAINT_TYPE_OWNED_REF));
    }
    if (StringUtils.isNotBlank(attrDefinition.getReverseAttributeName())) {
        ret.addConstraint(new AtlasConstraintDef(CONSTRAINT_TYPE_INVERSE_REF, new HashMap<String, Object>() {

            {
                put(CONSTRAINT_PARAM_ATTRIBUTE, attrDefinition.getReverseAttributeName());
            }
        }));
    }
    // Multiplicity attribute mapping
    Multiplicity multiplicity = attrDefinition.getMultiplicity();
    int minCount = multiplicity.getLower();
    int maxCount = multiplicity.getUpper();
    boolean isUnique = multiplicity.getIsUnique();
    if (minCount == 0) {
        ret.setIsOptional(true);
        ret.setValuesMinCount(0);
    } else {
        ret.setIsOptional(false);
        ret.setValuesMinCount(minCount);
    }
    if (maxCount < 2) {
        ret.setCardinality(Cardinality.SINGLE);
        ret.setValuesMaxCount(1);
    } else {
        if (!isUnique) {
            ret.setCardinality(Cardinality.LIST);
        } else {
            ret.setCardinality(Cardinality.SET);
        }
        ret.setValuesMaxCount(maxCount);
    }
    return ret;
}
Also used : Multiplicity(org.apache.atlas.v1.model.typedef.Multiplicity) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) AtlasConstraintDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)

Example 9 with AttributeDefinition

use of org.apache.atlas.v1.model.typedef.AttributeDefinition in project atlas by apache.

the class TypeConverterUtil method getAttributes.

private static List<AttributeDefinition> getAttributes(AtlasStructType structType, AtlasTypeRegistry registry) {
    List<AttributeDefinition> ret = new ArrayList<>();
    List<AtlasAttributeDef> attrDefs = structType.getStructDef().getAttributeDefs();
    if (CollectionUtils.isNotEmpty(attrDefs)) {
        for (AtlasAttributeDef attrDef : attrDefs) {
            AtlasAttribute attribute = structType.getAttribute(attrDef.getName());
            AttributeDefinition oldAttrDef = AtlasStructDefStoreV1.toAttributeDefinition(attribute);
            ret.add(new AttributeDefinition(oldAttrDef.getName(), oldAttrDef.getDataTypeName(), new Multiplicity(oldAttrDef.getMultiplicity()), oldAttrDef.getIsComposite(), oldAttrDef.getIsUnique(), oldAttrDef.getIsIndexable(), oldAttrDef.getReverseAttributeName()));
        }
    }
    return ret;
}
Also used : AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) Multiplicity(org.apache.atlas.v1.model.typedef.Multiplicity) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) AttributeDefinition(org.apache.atlas.v1.model.typedef.AttributeDefinition)

Example 10 with AttributeDefinition

use of org.apache.atlas.v1.model.typedef.AttributeDefinition in project atlas by apache.

the class TypeConverterUtil method entityToTypesDef.

private static TypesDef entityToTypesDef(AtlasEntityType entityType, AtlasTypeRegistry registry) {
    String typeName = entityType.getEntityDef().getName();
    String typeDesc = entityType.getEntityDef().getDescription();
    String typeVersion = entityType.getEntityDef().getTypeVersion();
    Set<String> superTypes = entityType.getEntityDef().getSuperTypes();
    List<AttributeDefinition> attributes = getAttributes(entityType, registry);
    ClassTypeDefinition classTypeDef = new ClassTypeDefinition(typeName, typeDesc, typeVersion, attributes, superTypes);
    TypesDef ret = new TypesDef(null, null, null, Arrays.asList(classTypeDef));
    return ret;
}
Also used : TypesDef(org.apache.atlas.v1.model.typedef.TypesDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) AttributeDefinition(org.apache.atlas.v1.model.typedef.AttributeDefinition) ClassTypeDefinition(org.apache.atlas.v1.model.typedef.ClassTypeDefinition)

Aggregations

AttributeDefinition (org.apache.atlas.v1.model.typedef.AttributeDefinition)10 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)8 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)4 Multiplicity (org.apache.atlas.v1.model.typedef.Multiplicity)4 TypesDef (org.apache.atlas.v1.model.typedef.TypesDef)4 ClassTypeDefinition (org.apache.atlas.v1.model.typedef.ClassTypeDefinition)3 TraitTypeDefinition (org.apache.atlas.v1.model.typedef.TraitTypeDefinition)3 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)2 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)2 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)2 AtlasConstraintDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)2 StructTypeDefinition (org.apache.atlas.v1.model.typedef.StructTypeDefinition)2 java.util (java.util)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)1 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)1 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)1 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)1