Search in sources :

Example 6 with AttributeInfo

use of org.apache.atlas.typesystem.types.AttributeInfo in project incubator-atlas by apache.

the class AbstractGremlinQueryOptimizerTest method getTestFieldInfo.

private FieldInfo getTestFieldInfo() throws AtlasException {
    AttributeDefinition def = new AttributeDefinition("foo", DataTypes.STRING_TYPE.getName(), Multiplicity.REQUIRED, false, null);
    AttributeInfo attrInfo = new AttributeInfo(TypeSystem.getInstance(), def, null);
    return new FieldInfo(DataTypes.STRING_TYPE, attrInfo, null, null);
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition) FieldInfo(org.apache.atlas.query.TypeUtils.FieldInfo)

Example 7 with AttributeInfo

use of org.apache.atlas.typesystem.types.AttributeInfo in project incubator-atlas by apache.

the class DefaultPropertyMapperTest method testToQualifiedName_specifiedMappings.

@Test
public void testToQualifiedName_specifiedMappings() throws Exception {
    String typeName = "testType";
    HierarchicalType dataType = createNiceMock(HierarchicalType.class);
    // currently only use key in map
    Map<String, AttributeInfo> fields = new HashMap<>();
    fields.put("foo", null);
    fields.put("prop", null);
    // can't mock FieldMapping due to direct access to final instance var 'fields'
    FieldMapping fieldMapping = new FieldMapping(fields, null, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    // mock expectations
    expect(dataType.fieldMapping()).andReturn(fieldMapping).anyTimes();
    expect(dataType.getQualifiedName("foo")).andReturn("foo");
    expect(dataType.getQualifiedName("prop")).andReturn("Prefix.prop");
    replay(dataType);
    Map<String, String> cleanToQualifiedMap = new HashMap<>();
    cleanToQualifiedMap.put("prop1", "property_1");
    Map<String, String> qualifiedToCleanMap = new HashMap<>();
    qualifiedToCleanMap.put("property_1", "prop1");
    PropertyMapper propertyMapper = new TestDefaultPropertyMapper(typeName, qualifiedToCleanMap, cleanToQualifiedMap, dataType);
    assertEquals(propertyMapper.toFullyQualifiedName("prop1", typeName), "property_1");
    assertEquals(propertyMapper.toFullyQualifiedName("foo", typeName), "foo");
    assertEquals(propertyMapper.toFullyQualifiedName("prop", typeName), "Prefix.prop");
    assertEquals(propertyMapper.toFullyQualifiedName("other", typeName), "other");
    assertEquals(propertyMapper.toFullyQualifiedName("Prefix.other", typeName), "Prefix.other");
    verify(dataType);
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) HashMap(java.util.HashMap) FieldMapping(org.apache.atlas.typesystem.types.FieldMapping) HierarchicalType(org.apache.atlas.typesystem.types.HierarchicalType) Test(org.testng.annotations.Test)

Example 8 with AttributeInfo

use of org.apache.atlas.typesystem.types.AttributeInfo in project incubator-atlas by apache.

the class DefaultPropertyMapperTest method testToQualifiedName_defaultMappings.

@Test
public void testToQualifiedName_defaultMappings() throws Exception {
    String typeName = "testType";
    HierarchicalType dataType = createNiceMock(HierarchicalType.class);
    // currently only use key in map
    Map<String, AttributeInfo> fields = new HashMap<>();
    fields.put("foo", null);
    fields.put("prop", null);
    // can't mock FieldMapping due to direct access to final instance var 'fields'
    FieldMapping fieldMapping = new FieldMapping(fields, null, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    // mock expectations
    expect(dataType.fieldMapping()).andReturn(fieldMapping).anyTimes();
    expect(dataType.getQualifiedName("foo")).andReturn("foo");
    expect(dataType.getQualifiedName("prop")).andReturn("Prefix.prop");
    replay(dataType);
    PropertyMapper propertyMapper = new TestDefaultPropertyMapper(dataType);
    assertEquals(propertyMapper.toFullyQualifiedName("foo", typeName), "foo");
    assertEquals(propertyMapper.toFullyQualifiedName("prop", typeName), "Prefix.prop");
    assertEquals(propertyMapper.toFullyQualifiedName("other", typeName), "other");
    assertEquals(propertyMapper.toFullyQualifiedName("Prefix.other", typeName), "Prefix.other");
    verify(dataType);
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) HashMap(java.util.HashMap) FieldMapping(org.apache.atlas.typesystem.types.FieldMapping) HierarchicalType(org.apache.atlas.typesystem.types.HierarchicalType) Test(org.testng.annotations.Test)

Example 9 with AttributeInfo

use of org.apache.atlas.typesystem.types.AttributeInfo in project incubator-atlas by apache.

the class DefaultPropertyMapperTest method testToCleanName_defaultMappings.

@Test
public void testToCleanName_defaultMappings() {
    String typeName = "testType";
    HierarchicalType dataType = createNiceMock(HierarchicalType.class);
    // currently only use key in map
    Map<String, AttributeInfo> fields = new HashMap<>();
    fields.put("foo", null);
    fields.put("prop", null);
    // can't mock FieldMapping due to direct access to final instance var 'fields'
    FieldMapping fieldMapping = new FieldMapping(fields, null, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    // mock expectations
    expect(dataType.fieldMapping()).andReturn(fieldMapping).anyTimes();
    replay(dataType);
    PropertyMapper propertyMapper = new TestDefaultPropertyMapper(dataType);
    assertEquals(propertyMapper.toCleanName("Prefix.prop", typeName), "prop");
    assertEquals(propertyMapper.toCleanName("foo", typeName), "foo");
    assertEquals(propertyMapper.toCleanName("other", typeName), "other");
    assertEquals(propertyMapper.toCleanName("Prefix.other", typeName), "Prefix.other");
    verify(dataType);
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) HashMap(java.util.HashMap) FieldMapping(org.apache.atlas.typesystem.types.FieldMapping) HierarchicalType(org.apache.atlas.typesystem.types.HierarchicalType) Test(org.testng.annotations.Test)

Example 10 with AttributeInfo

use of org.apache.atlas.typesystem.types.AttributeInfo in project incubator-atlas by apache.

the class StructInstance method setFloat.

public void setFloat(String attrName, float val) throws AtlasException {
    AttributeInfo i = fieldMapping.fields.get(attrName);
    if (i == null) {
        throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
    }
    if (i.dataType() != DataTypes.FLOAT_TYPE) {
        throw new AtlasException(String.format("Field %s for Struct %s is not a %s, call generic set method", attrName, getTypeName(), DataTypes.FLOAT_TYPE.getName()));
    }
    int pos = fieldMapping.fieldPos.get(attrName);
    int nullPos = fieldMapping.fieldNullPos.get(attrName);
    nullFlags[nullPos] = false;
    floats[pos] = val;
    explicitSets[nullPos] = true;
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) AtlasException(org.apache.atlas.AtlasException)

Aggregations

AttributeInfo (org.apache.atlas.typesystem.types.AttributeInfo)47 AtlasException (org.apache.atlas.AtlasException)26 HashMap (java.util.HashMap)6 IDataType (org.apache.atlas.typesystem.types.IDataType)6 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)5 FieldMapping (org.apache.atlas.typesystem.types.FieldMapping)5 Map (java.util.Map)4 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)4 HierarchicalType (org.apache.atlas.typesystem.types.HierarchicalType)4 Test (org.testng.annotations.Test)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)3 Id (org.apache.atlas.typesystem.persistence.Id)3 ImmutableBiMap (com.google.common.collect.ImmutableBiMap)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 ClosureExpression (org.apache.atlas.groovy.ClosureExpression)2 FunctionCallExpression (org.apache.atlas.groovy.FunctionCallExpression)2 GroovyExpression (org.apache.atlas.groovy.GroovyExpression)2 LiteralExpression (org.apache.atlas.groovy.LiteralExpression)2