Repository: incubator-atlas Updated Branches: refs/heads/master 0596c9fc3 -> 96f2306f9
ATLAS-1098 Atlas allows creation of tag with name isa which causes exceptions during search (apoorvnaik via kevalbhatt) Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/96f2306f Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/96f2306f Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/96f2306f Branch: refs/heads/master Commit: 96f2306f9dfc133f9e7d79421dc97eee0a4d671e Parents: 0596c9f Author: kevalbhatt <[email protected]> Authored: Fri Sep 9 22:33:57 2016 +0530 Committer: kevalbhatt <[email protected]> Committed: Fri Sep 9 22:33:57 2016 +0530 ---------------------------------------------------------------------- release-log.txt | 1 + .../atlas/services/DefaultMetadataService.java | 56 ++++++++++++++++++++ 2 files changed, 57 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/96f2306f/release-log.txt ---------------------------------------------------------------------- diff --git a/release-log.txt b/release-log.txt index 8bbed03..19fd159 100644 --- a/release-log.txt +++ b/release-log.txt @@ -10,6 +10,7 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai) ALL CHANGES: +ATLAS-1098 Atlas allows creation of tag with name "isa" which causes exceptions during search (apoorvnaik via kevalbhatt) ATLAS-1160 Update Atlas hive hook to read configuration from atlas-application.properties instead of hive-site.xml (mneethiraj via kevalbhatt) ATLAS-1154 Errors in Eclipse with web.xml (davidrad via dkantor) ATLAS-1147 UI: column name doesn't show up in schema tab for hive table (Kalyanikashikar via kevalbhatt) http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/96f2306f/repository/src/main/java/org/apache/atlas/services/DefaultMetadataService.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/services/DefaultMetadataService.java b/repository/src/main/java/org/apache/atlas/services/DefaultMetadataService.java index 4d05d49..6a937f4 100755 --- a/repository/src/main/java/org/apache/atlas/services/DefaultMetadataService.java +++ b/repository/src/main/java/org/apache/atlas/services/DefaultMetadataService.java @@ -33,6 +33,8 @@ import org.apache.atlas.ha.HAConfiguration; import org.apache.atlas.listener.ActiveStateChangeHandler; import org.apache.atlas.listener.EntityChangeListener; import org.apache.atlas.listener.TypesChangeListener; +import org.apache.atlas.query.QueryKeywords; +import org.apache.atlas.query.QueryParser; import org.apache.atlas.repository.MetadataRepository; import org.apache.atlas.repository.RepositoryException; import org.apache.atlas.repository.audit.EntityAuditRepository; @@ -64,12 +66,14 @@ import org.apache.atlas.typesystem.types.ValueConversionException; import org.apache.atlas.typesystem.types.cache.TypeCache; import org.apache.atlas.typesystem.types.utils.TypesUtil; import org.apache.atlas.utils.ParamChecker; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.configuration.Configuration; import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import scala.collection.Set; import javax.inject.Inject; import javax.inject.Singleton; @@ -240,6 +244,9 @@ public class DefaultMetadataService implements MetadataService, ActiveStateChang typeDefinition = ParamChecker.notEmpty(typeDefinition, "type definition"); TypesDef typesDef = validateTypeDefinition(typeDefinition); + // Also validate if the types being created are not keywords + validateIfNotKeyword(typesDef); + try { final TypeSystem.TransientTypeSystem transientTypeSystem = typeSystem.createTransientTypeSystem(typesDef, isUpdate); final Map<String, IDataType> typesAdded = transientTypeSystem.getTypesAdded(); @@ -285,6 +292,55 @@ public class DefaultMetadataService implements MetadataService, ActiveStateChang } } + private void validateIfNotKeyword(TypesDef typesDef) throws AtlasException { + List<EnumTypeDefinition> enumDefs = typesDef.enumTypesAsJavaList(); + List<StructTypeDefinition> structDefs = typesDef.structTypesAsJavaList(); + List<HierarchicalTypeDefinition<ClassType>> classDefs = typesDef.classTypesAsJavaList(); + List<HierarchicalTypeDefinition<TraitType>> traitDefs = typesDef.traitTypesAsJavaList(); + + // QueryParser has it's own set of keywords that should be avoided + Set<String> keywords = QueryParser.keywordCache().keySet(); + boolean keywordCacheNotEmpty = null != keywords && !keywords.isEmpty(); + + if (keywordCacheNotEmpty) { + if (CollectionUtils.isNotEmpty(enumDefs)) { + // Check if any enum name is a keyword + for (EnumTypeDefinition enumDef : enumDefs) { + if (keywords.contains(enumDef.name)) { + throw new AtlasException("Enum definition name \"" + enumDef.name + "\" is a keyword"); + } + } + } + + if (CollectionUtils.isNotEmpty(classDefs)){ + // Check if any class name is a keyword + for (HierarchicalTypeDefinition<ClassType> classDef : classDefs) { + if (keywords.contains(classDef.typeName)) { + throw new AtlasException("Class definition name \"" + classDef.typeName + "\" is a keyword"); + } + } + } + + if (CollectionUtils.isNotEmpty(structDefs)){ + // Check if any struct name is a keyword + for (StructTypeDefinition structDef : structDefs) { + if (keywords.contains(structDef.typeName)) { + throw new AtlasException("StructType definition name \"" + structDef.typeName + "\" is a keyword"); + } + } + } + + if (CollectionUtils.isNotEmpty(traitDefs)){ + // Check if any trait name is a keyword + for (HierarchicalTypeDefinition<TraitType> traitDef : traitDefs) { + if (keywords.contains(traitDef.typeName)) { + throw new AtlasException("TraitType definition name \"" + traitDef.typeName + "\" is a keyword"); + } + } + } + } + } + /** * Return the definition for the given type. *
