atlas-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mad...@apache.org
Subject [32/50] [abbrv] incubator-atlas git commit: ATLAS-1098 Atlas allows creation of tag with name isa which causes exceptions during search (apoorvnaik via kevalbhatt)
Date Fri, 23 Dec 2016 01:47:01 GMT
ATLAS-1098 Atlas allows creation of tag with name isa which causes exceptions during search
(apoorvnaik via kevalbhatt)

(cherry picked from commit 96f2306f9dfc133f9e7d79421dc97eee0a4d671e)


Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/5eaf6b40
Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/5eaf6b40
Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/5eaf6b40

Branch: refs/heads/0.7-incubating
Commit: 5eaf6b40fd37cff612a61ed095f9d5b380295986
Parents: 1eb5abf
Author: kevalbhatt <kbhatt@apache.org>
Authored: Fri Sep 9 22:33:57 2016 +0530
Committer: Madhan Neethiraj <madhan@apache.org>
Committed: Thu Dec 22 15:28:33 2016 -0800

----------------------------------------------------------------------
 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/5eaf6b40/release-log.txt
----------------------------------------------------------------------
diff --git a/release-log.txt b/release-log.txt
index 61a15ad..d94eb2b 100644
--- a/release-log.txt
+++ b/release-log.txt
@@ -31,6 +31,7 @@ ATLAS-409 Atlas will not import avro tables with schema read from a file
(dosset
 ATLAS-379 Create sqoop and falcon metadata addons (venkatnrangan,bvellanki,sowmyaramesh via
shwethags)
 
 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/5eaf6b40/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.
      *


Mime
View raw message