Commit f7da366d by Shwetha GS

support for utf8 characters

parent fa81143d
......@@ -614,6 +614,12 @@
<version>1.8.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
</dependencyManagement>
......
......@@ -23,6 +23,7 @@ import com.thinkaurelius.titan.core.TitanGraph;
import com.tinkerpop.blueprints.Compare;
import com.tinkerpop.blueprints.GraphQuery;
import com.tinkerpop.blueprints.Vertex;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.hadoop.metadata.RepositoryMetadataModule;
import org.apache.hadoop.metadata.TestUtils;
import org.apache.hadoop.metadata.discovery.graph.GraphBackedDiscoveryService;
......@@ -59,6 +60,9 @@ import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import static org.apache.hadoop.metadata.typesystem.types.utils.TypesUtil.createRequiredAttrDef;
import static org.apache.hadoop.metadata.typesystem.types.utils.TypesUtil.createStructTypeDef;
/**
* GraphBackedMetadataRepository test
*
......@@ -588,4 +592,25 @@ public class GraphBackedMetadataRepositoryTest {
ClassType tableType = typeSystem.getDataType(ClassType.class, TABLE_TYPE);
return tableType.convert(tableInstance, Multiplicity.REQUIRED);
}
private String random() {
return RandomStringUtils.random(10);
}
@Test
public void testUTFValues() throws Exception {
Referenceable hrDept = new Referenceable("Department");
Referenceable john = new Referenceable("Person");
john.set("name", random());
john.set("department", hrDept);
hrDept.set("name", random());
hrDept.set("employees", ImmutableList.of(john));
ClassType deptType = typeSystem.getDataType(ClassType.class, "Department");
ITypedReferenceableInstance hrDept2 = deptType.convert(hrDept, Multiplicity.REQUIRED);
guid = repositoryService.createEntity(hrDept2);
Assert.assertNotNull(guid);
}
}
......@@ -124,6 +124,12 @@
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
......
......@@ -38,7 +38,6 @@ public class AttributeInfo {
private IDataType dataType;
AttributeInfo(TypeSystem t, AttributeDefinition def, Map<String, IDataType> tempTypes) throws MetadataException {
TypeUtils.validateName(def.name);
this.name = def.name;
this.dataType = (tempTypes != null && tempTypes.containsKey(def.dataTypeName)) ?
tempTypes.get(def.dataTypeName) : t.getDataType(IDataType.class, def.dataTypeName);
......
......@@ -352,7 +352,6 @@ public class TypeSystem {
private void step1() throws MetadataException {
for (StructTypeDefinition sDef : structDefs) {
assert sDef.typeName != null;
TypeUtils.validateName(sDef.typeName);
if (dataType(sDef.typeName) != null) {
throw new MetadataException(
String.format("Cannot redefine type %s", sDef.typeName));
......@@ -365,7 +364,6 @@ public class TypeSystem {
for (HierarchicalTypeDefinition<TraitType> traitDef : traitDefs) {
assert traitDef.typeName != null;
TypeUtils.validateName(traitDef.typeName);
if (types.containsKey(traitDef.typeName)) {
throw new MetadataException(
String.format("Cannot redefine type %s", traitDef.typeName));
......@@ -380,7 +378,6 @@ public class TypeSystem {
for (HierarchicalTypeDefinition<ClassType> classDef : classDefs) {
assert classDef.typeName != null;
TypeUtils.validateName(classDef.typeName);
if (types.containsKey(classDef.typeName)) {
throw new MetadataException(
String.format("Cannot redefine type %s", classDef.typeName));
......
......@@ -50,13 +50,6 @@ public class TypeUtils {
}
}
public static void validateName(String name) throws MetadataException {
if (!NAME_PATTERN.matcher(name).matches()) {
throw new MetadataException(
String.format("Unsupported name for an attribute '%s'", name));
}
}
public static String parseAsArrayType(String typeName) {
Matcher m = ARRAY_TYPE_NAME_PATTERN.matcher(typeName);
return m.matches() ? m.group(1) : null;
......
......@@ -19,6 +19,7 @@
package org.apache.hadoop.metadata.typesystem.types;
import com.google.common.collect.ImmutableList;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.hadoop.metadata.typesystem.types.utils.TypesUtil;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
......@@ -29,6 +30,11 @@ import scala.actors.threadpool.Arrays;
import java.util.Collections;
import java.util.List;
import static org.apache.hadoop.metadata.typesystem.types.utils.TypesUtil.createClassTypeDef;
import static org.apache.hadoop.metadata.typesystem.types.utils.TypesUtil.createRequiredAttrDef;
import static org.apache.hadoop.metadata.typesystem.types.utils.TypesUtil.createStructTypeDef;
import static org.apache.hadoop.metadata.typesystem.types.utils.TypesUtil.createTraitTypeDef;
public class TypeSystemTest extends BaseTest {
@BeforeClass
......@@ -100,4 +106,34 @@ public class TypeSystemTest extends BaseTest {
Assert.assertFalse(Collections.disjoint(traitsNames, traits));
}
private String random() {
return RandomStringUtils.random(10);
}
@Test
public void testUTFNames() throws Exception {
TypeSystem ts = getTypeSystem();
String enumType = random();
EnumTypeDefinition orgLevelEnum =
new EnumTypeDefinition(enumType, new EnumValue(random(), 1), new EnumValue(random(), 2));
ts.defineEnumType(orgLevelEnum);
String structName = random();
String attrType = random();
StructTypeDefinition structType = createStructTypeDef(structName,
createRequiredAttrDef(attrType, DataTypes.STRING_TYPE));
String className = random();
HierarchicalTypeDefinition<ClassType> classType =
createClassTypeDef(className, ImmutableList.<String>of(),
createRequiredAttrDef(attrType, DataTypes.STRING_TYPE));
String traitName = random();
HierarchicalTypeDefinition<TraitType> traitType = createTraitTypeDef(traitName,
ImmutableList.<String>of(), createRequiredAttrDef(attrType, DataTypes.INT_TYPE));
ts.defineTypes(ImmutableList.of(structType), ImmutableList.of(traitType), ImmutableList.of(classType));
}
}
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