You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by ma...@apache.org on 2017/11/12 18:14:42 UTC

[33/42] atlas git commit: ATLAS-2251: Remove TypeSystem and related implementation, to avoid unncessary duplicate of type details in cache

http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/gremlin/optimizer/GremlinQueryOptimizer.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/gremlin/optimizer/GremlinQueryOptimizer.java b/repository/src/main/java/org/apache/atlas/gremlin/optimizer/GremlinQueryOptimizer.java
deleted file mode 100644
index a0c08fd..0000000
--- a/repository/src/main/java/org/apache/atlas/gremlin/optimizer/GremlinQueryOptimizer.java
+++ /dev/null
@@ -1,262 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.atlas.gremlin.optimizer;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.atlas.gremlin.GremlinExpressionFactory;
-import org.apache.atlas.groovy.AbstractFunctionExpression;
-import org.apache.atlas.groovy.GroovyExpression;
-import org.apache.atlas.groovy.StatementListExpression;
-import org.apache.atlas.groovy.TraversalStepType;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.annotations.VisibleForTesting;
-
-
-
-/**
- * Optimizer for gremlin queries.  This class provides a framework for applying optimizations
- * to gremlin queries.  Each optimization is implemented as a class that implements {@link GremlinOptimization}.
- *
- * The GremlinQueryOptimizer is the entry point for applying these optimizations.
- *
- *
- */
-public final class GremlinQueryOptimizer {
-
-    private static final Logger LOGGER = LoggerFactory.getLogger(GremlinQueryOptimizer.class);
-
-
-    private final List<GremlinOptimization> optimizations = new ArrayList<>();
-
-    //Allows expression factory to be substituted in unit tests.
-    private static volatile GremlinExpressionFactory FACTORY = GremlinExpressionFactory.INSTANCE;
-
-    private static volatile GremlinQueryOptimizer INSTANCE = null;
-
-    private GremlinQueryOptimizer() {
-
-    }
-
-    private void addOptimization(GremlinOptimization opt) {
-        optimizations.add(opt);
-    }
-
-    public static GremlinQueryOptimizer getInstance() {
-        if(INSTANCE == null) {
-            synchronized(GremlinQueryOptimizer.class) {
-                if(INSTANCE == null) {
-                    GremlinQueryOptimizer createdInstance = new GremlinQueryOptimizer();
-                    //The order here is important.  If there is an "or" nested within an "and",
-                    //that will not be found if ExpandOrsOptimization runs before ExpandAndsOptimization.
-                    createdInstance.addOptimization(new ExpandAndsOptimization(FACTORY));
-                    createdInstance.addOptimization(new ExpandOrsOptimization(FACTORY));
-                    INSTANCE = createdInstance;
-                }
-            }
-        }
-        return INSTANCE;
-    }
-
-    /**
-     * For testing only
-     */
-    @VisibleForTesting
-    public static void setExpressionFactory(GremlinExpressionFactory factory) {
-        GremlinQueryOptimizer.FACTORY = factory;
-    }
-
-    /**
-     * For testing only
-     */
-    @VisibleForTesting
-    public static void reset() {
-        INSTANCE = null;
-    }
-
-    /**
-     * Optimizes the provided groovy expression.  Note that the optimization
-     * is a <i>destructive</i> process.  The source GroovyExpression will be
-     * modified as part of the optimization process.  This is done to avoid
-     * expensive copying operations where possible.
-     *
-     * @param source what to optimize
-     * @return the optimized query
-     */
-    public GroovyExpression optimize(GroovyExpression source) {
-        LOGGER.debug("Optimizing gremlin query: " + source);
-        OptimizationContext context = new OptimizationContext();
-        GroovyExpression updatedExpression = source;
-        for (GremlinOptimization opt : optimizations) {
-            updatedExpression = optimize(updatedExpression, opt, context);
-            LOGGER.debug("After "+ opt.getClass().getSimpleName() + ", query = " + updatedExpression);
-        }
-
-        StatementListExpression result = new StatementListExpression();
-        result.addStatements(context.getInitialStatements());
-        result.addStatement(updatedExpression);
-        LOGGER.debug("Final optimized query:  " + result.toString());
-        return result;
-    }
-
-    /**
-     * Optimizes the expression using the given optimization
-     * @param source
-     * @param optimization
-     * @param context
-     * @return
-     */
-    private GroovyExpression optimize(GroovyExpression source, GremlinOptimization optimization,
-                                          OptimizationContext context) {
-        GroovyExpression result = source;
-        if (optimization.appliesTo(source, context)) {
-            //Apply the optimization to the expression.
-            result = optimization.apply(source, context);
-        }
-        if (optimization.isApplyRecursively()) {
-            //Visit the children, update result with the optimized
-            //children.
-            List<GroovyExpression> updatedChildren = new ArrayList<>();
-            boolean changed = false;
-            for (GroovyExpression child : result.getChildren()) {
-                //Recursively optimize this child.
-                GroovyExpression updatedChild = optimize(child, optimization, context);
-                changed |= updatedChild != child;
-                updatedChildren.add(updatedChild);
-            }
-            if (changed) {
-                //TBD - Can we update in place rather than making a copy?
-                result = result.copy(updatedChildren);
-            }
-        }
-        return result;
-    }
-
-    /**
-     * Visits all expressions in the call hierarchy of an expression.  For example,
-     * in the expression g.V().has('x','y'), the order would be
-     * <ol>
-     *    <li>pre-visit has('x','y')</li>
-     *    <li>pre-visit V()</li>
-     *    <li>visit g (non-function caller)</li>
-     *    <li>post-visit V()</li>
-     *    <li>post-visit has('x','y')</li>
-     * </ol>
-     * @param expr
-     * @param visitor
-     */
-    public static void visitCallHierarchy(GroovyExpression expr, CallHierarchyVisitor visitor) {
-
-        if (expr == null) {
-            visitor.visitNullCaller();
-            return;
-        }
-        if (expr instanceof AbstractFunctionExpression) {
-            AbstractFunctionExpression functionCall = (AbstractFunctionExpression)expr;
-            if (!visitor.preVisitFunctionCaller(functionCall)) {
-                return;
-            }
-            GroovyExpression caller = functionCall.getCaller();
-            visitCallHierarchy(caller, visitor);
-            if (!visitor.postVisitFunctionCaller(functionCall)) {
-                return;
-            }
-        } else {
-            visitor.visitNonFunctionCaller(expr);
-        }
-    }
-
-    /**
-     * Determines if the given expression is an "or" expression.
-     * @param expr
-     * @return
-     */
-    public static boolean isOrExpression(GroovyExpression expr) {
-        return IsOr.INSTANCE.apply(expr);
-    }
-
-    /**
-     * Determines whether the given expression can safely
-     * be pulled out of an and/or expression.
-     *
-     * @param expr an argument to an and or or function
-     * @return
-     */
-    public static boolean isExtractable(GroovyExpression expr) {
-
-        HasForbiddenType hasForbiddenTypePredicate = new HasForbiddenType(FACTORY);
-
-        //alias could conflict with alias in parent traversal
-        hasForbiddenTypePredicate.addForbiddenType(TraversalStepType.SIDE_EFFECT);
-
-        //inlining out(), in() steps will change the result of calls after the and/or()
-        hasForbiddenTypePredicate.addForbiddenType(TraversalStepType.FLAT_MAP_TO_ELEMENTS);
-        hasForbiddenTypePredicate.addForbiddenType(TraversalStepType.FLAT_MAP_TO_VALUES);
-        hasForbiddenTypePredicate.addForbiddenType(TraversalStepType.BARRIER);
-        hasForbiddenTypePredicate.addForbiddenType(TraversalStepType.MAP_TO_ELEMENT);
-        hasForbiddenTypePredicate.addForbiddenType(TraversalStepType.MAP_TO_VALUE);
-
-        //caller expects to be able to continue the traversal.  We can't end it
-        hasForbiddenTypePredicate.addForbiddenType(TraversalStepType.END);
-
-
-        //we can't inline child traversals
-        hasForbiddenTypePredicate.addForbiddenType(TraversalStepType.SOURCE);
-        hasForbiddenTypePredicate.addForbiddenType(TraversalStepType.START);
-        hasForbiddenTypePredicate.addForbiddenType(TraversalStepType.SIDE_EFFECT);
-        hasForbiddenTypePredicate.addForbiddenType(TraversalStepType.NONE);
-        hasForbiddenTypePredicate.addForbiddenType(TraversalStepType.BRANCH);
-
-        ExpressionFinder forbiddenExpressionFinder = new ExpressionFinder(hasForbiddenTypePredicate);
-        GremlinQueryOptimizer.visitCallHierarchy(expr, forbiddenExpressionFinder);
-        return ! forbiddenExpressionFinder.isExpressionFound();
-    }
-
-    /**
-     * Recursively copies and follows the caller hierarchy of the expression until we come
-     * to a function call with a null caller.  The caller of that expression is set
-     * to newLeaf.
-     *
-     * @param expr
-     * @param newLeaf
-     * @return the updated (/copied) expression
-     */
-    public static GroovyExpression copyWithNewLeafNode(AbstractFunctionExpression expr, GroovyExpression newLeaf) {
-
-
-        AbstractFunctionExpression result = (AbstractFunctionExpression)expr.copy();
-
-        //remove leading anonymous traversal expression, if there is one
-        if(FACTORY.isLeafAnonymousTraversalExpression(expr)) {
-            result = (AbstractFunctionExpression)newLeaf;
-        } else {
-            GroovyExpression newCaller = null;
-            if (expr.getCaller() == null) {
-                newCaller = newLeaf;
-            } else {
-                newCaller = copyWithNewLeafNode((AbstractFunctionExpression)result.getCaller(), newLeaf);
-            }
-            result.setCaller(newCaller);
-        }
-        return result;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/gremlin/optimizer/HasForbiddenType.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/gremlin/optimizer/HasForbiddenType.java b/repository/src/main/java/org/apache/atlas/gremlin/optimizer/HasForbiddenType.java
deleted file mode 100644
index 3fb9faa..0000000
--- a/repository/src/main/java/org/apache/atlas/gremlin/optimizer/HasForbiddenType.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.atlas.gremlin.optimizer;
-
-import java.util.HashSet;
-import java.util.Set;
-import com.google.common.base.Function;
-
-import org.apache.atlas.gremlin.GremlinExpressionFactory;
-import org.apache.atlas.groovy.GroovyExpression;
-import org.apache.atlas.groovy.TraversalStepType;
-
-/**
- * Function that tests whether the expression is an 'or'
- * graph traversal function.
- */
-public final class HasForbiddenType implements Function<GroovyExpression, Boolean> {
-
-    private Set<TraversalStepType> forbiddenTypes =  new HashSet<>();
-    private final GremlinExpressionFactory factory;
-
-    public HasForbiddenType(GremlinExpressionFactory factory) {
-        this.factory = factory;
-    }
-
-    public void addForbiddenType(TraversalStepType type) {
-        forbiddenTypes.add(type);
-    }
-
-    @Override
-    public Boolean apply(GroovyExpression expr) {
-        if(factory.isLeafAnonymousTraversalExpression(expr)) {
-            return false;
-        }
-        return forbiddenTypes.contains(expr.getType());
-    }
-}

http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/gremlin/optimizer/IsOr.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/gremlin/optimizer/IsOr.java b/repository/src/main/java/org/apache/atlas/gremlin/optimizer/IsOr.java
deleted file mode 100644
index ab74087..0000000
--- a/repository/src/main/java/org/apache/atlas/gremlin/optimizer/IsOr.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.atlas.gremlin.optimizer;
-
-import com.google.common.base.Function;
-
-import org.apache.atlas.groovy.FunctionCallExpression;
-import org.apache.atlas.groovy.GroovyExpression;
-import org.apache.atlas.groovy.TraversalStepType;
-
-/**
- * Function that tests whether the expression is an 'or'
- * graph traversal function.
- */
-public final class IsOr implements Function<GroovyExpression, Boolean> {
-
-    public static final IsOr INSTANCE = new IsOr();
-
-    private IsOr() {
-    }
-
-    @Override
-    public Boolean apply(GroovyExpression expr) {
-        if (!(expr instanceof FunctionCallExpression)) {
-            return false;
-        }
-        if (expr.getType() != TraversalStepType.FILTER) {
-            return false;
-        }
-        FunctionCallExpression functionCall = (FunctionCallExpression)expr;
-        return functionCall.getFunctionName().equals("or");
-    }
-}

http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/gremlin/optimizer/IsOrParent.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/gremlin/optimizer/IsOrParent.java b/repository/src/main/java/org/apache/atlas/gremlin/optimizer/IsOrParent.java
deleted file mode 100644
index 72085d0..0000000
--- a/repository/src/main/java/org/apache/atlas/gremlin/optimizer/IsOrParent.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.atlas.gremlin.optimizer;
-
-import com.google.common.base.Function;
-
-import org.apache.atlas.groovy.AbstractFunctionExpression;
-import org.apache.atlas.groovy.FunctionCallExpression;
-import org.apache.atlas.groovy.GroovyExpression;
-import org.apache.atlas.groovy.TraversalStepType;
-
-/**
- * Matches an expression that gets called after calling or().  For example,
- * in g.V().or(x,y).toList(), "toList()" is the "or parent", so calling
- * "apply()" on this expression would return true and calling it on all
- * the other ones would return false.
- */
-public final class IsOrParent implements Function<GroovyExpression, Boolean> {
-
-    public static final IsOrParent INSTANCE = new IsOrParent();
-
-    private IsOrParent() {
-
-    }
-
-    @Override
-    public Boolean apply(GroovyExpression expr) {
-        if (!(expr instanceof AbstractFunctionExpression)) {
-            return false;
-        }
-        AbstractFunctionExpression functionCall = (AbstractFunctionExpression)expr;
-        GroovyExpression target = functionCall.getCaller();
-
-        if (!(target instanceof FunctionCallExpression)) {
-            return false;
-        }
-
-        if (target.getType() != TraversalStepType.FILTER) {
-            return false;
-        }
-
-        FunctionCallExpression targetFunction = (FunctionCallExpression)target;
-        return targetFunction.getFunctionName().equals("or");
-    }
-}

http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/gremlin/optimizer/OptimizationContext.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/gremlin/optimizer/OptimizationContext.java b/repository/src/main/java/org/apache/atlas/gremlin/optimizer/OptimizationContext.java
deleted file mode 100644
index 86c8b98..0000000
--- a/repository/src/main/java/org/apache/atlas/gremlin/optimizer/OptimizationContext.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.atlas.gremlin.optimizer;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.atlas.groovy.AbstractFunctionExpression;
-import org.apache.atlas.groovy.ClosureExpression;
-import org.apache.atlas.groovy.ClosureExpression.VariableDeclaration;
-import org.apache.atlas.groovy.GroovyExpression;
-import org.apache.atlas.groovy.IdentifierExpression;
-import org.apache.atlas.groovy.ListExpression;
-import org.apache.atlas.groovy.TypeCoersionExpression;
-import org.apache.atlas.groovy.VariableAssignmentExpression;
-
-/**
- * Maintains state information during gremlin optimization.
- */
-public class OptimizationContext {
-
-    private static final String TMP_ALIAS_NAME = "__tmp";
-    private static final String FINAL_ALIAS_NAME = "__res";
-    private static final String RESULT_VARIABLE = "r";
-    private final List<GroovyExpression> initialStatements = new ArrayList<>();
-    private GroovyExpression resultExpression = getResultVariable();
-    private int counter = 1;
-    private final Map<String, ClosureExpression> functionBodies = new HashMap<>();
-    private AbstractFunctionExpression rangeExpression;
-
-    public OptimizationContext() {
-
-    }
-
-    /**
-     * @return
-     */
-    public List<GroovyExpression> getInitialStatements() {
-        return initialStatements;
-    }
-
-    public void prependStatement(GroovyExpression expr) {
-        initialStatements.add(0, expr);
-    }
-
-    public String getUniqueFunctionName() {
-        return "f" + (counter++);
-    }
-
-
-    public GroovyExpression getDefineResultVariableStmt() {
-        GroovyExpression castExpression = new TypeCoersionExpression(new ListExpression(), "Set");
-        GroovyExpression resultVarDef =  new VariableAssignmentExpression(RESULT_VARIABLE, castExpression);
-        return resultVarDef;
-
-    }
-    public void setResultExpression(GroovyExpression expr) {
-        resultExpression = expr;
-    }
-
-    public GroovyExpression getResultExpression() {
-        return resultExpression;
-    }
-
-    public GroovyExpression getResultVariable() {
-        return new IdentifierExpression(RESULT_VARIABLE);
-    }
-
-    public ClosureExpression getUserDefinedFunctionBody(String functionName) {
-        return functionBodies.get(functionName);
-    }
-
-    public String addFunctionDefinition(VariableDeclaration decl, GroovyExpression body) {
-        String functionName = getUniqueFunctionName();
-        List<VariableDeclaration> decls = (decl == null) ? Collections.<VariableDeclaration>emptyList() : Collections.singletonList(decl);
-        ClosureExpression bodyClosure = new ClosureExpression(body, decls);
-        VariableAssignmentExpression expr = new VariableAssignmentExpression(functionName, bodyClosure);
-        initialStatements.add(expr);
-        functionBodies.put(functionName, bodyClosure);
-        return functionName;
-    }
-
-    public String getFinalAliasName() {
-        return FINAL_ALIAS_NAME;
-    }
-
-    public String getTempAliasName() {
-        return TMP_ALIAS_NAME;
-    }
-
-    public void setRangeExpression(AbstractFunctionExpression rangeExpression) {
-        this.rangeExpression = rangeExpression;
-    }
-
-    public AbstractFunctionExpression getRangeExpression() {
-        return rangeExpression;
-    }
-}

http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/gremlin/optimizer/OrderFinder.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/gremlin/optimizer/OrderFinder.java b/repository/src/main/java/org/apache/atlas/gremlin/optimizer/OrderFinder.java
deleted file mode 100644
index 792fc52..0000000
--- a/repository/src/main/java/org/apache/atlas/gremlin/optimizer/OrderFinder.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.atlas.gremlin.optimizer;
-
-import org.apache.atlas.gremlin.GremlinExpressionFactory;
-import org.apache.atlas.groovy.AbstractFunctionExpression;
-import org.apache.atlas.groovy.GroovyExpression;
-
-
-/**
- * Finds order expression in the call hierarchy.
- *
- */
-public class OrderFinder implements CallHierarchyVisitor {
-
-    private boolean hasOrderExpression;
-    private GremlinExpressionFactory gremlinFactory;
-
-    public OrderFinder(GremlinExpressionFactory gremlinFactory) {
-        this.gremlinFactory = gremlinFactory;
-    }
-
-    @Override
-    public boolean preVisitFunctionCaller(AbstractFunctionExpression expr) {
-
-        return true;
-    }
-
-    @Override
-    public void visitNonFunctionCaller(GroovyExpression expr) {
-    }
-
-    @Override
-    public void visitNullCaller() {
-    }
-
-    @Override
-    public boolean postVisitFunctionCaller(AbstractFunctionExpression functionCall) {
-
-        if (gremlinFactory.isOrderExpression(functionCall)) {
-            hasOrderExpression = true;
-            return false;
-        }
-        return true;
-    }
-
-
-    public boolean hasOrderExpression() {
-
-        return hasOrderExpression;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/gremlin/optimizer/PathExpressionFinder.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/gremlin/optimizer/PathExpressionFinder.java b/repository/src/main/java/org/apache/atlas/gremlin/optimizer/PathExpressionFinder.java
deleted file mode 100644
index 0e9070d..0000000
--- a/repository/src/main/java/org/apache/atlas/gremlin/optimizer/PathExpressionFinder.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.atlas.gremlin.optimizer;
-
-import org.apache.atlas.groovy.AbstractFunctionExpression;
-import org.apache.atlas.groovy.FunctionCallExpression;
-import org.apache.atlas.groovy.GroovyExpression;
-
-/**
- * Determines whether an expression contains a path() function.
- */
-public class PathExpressionFinder implements CallHierarchyVisitor {
-
-    private boolean found = false;
-
-    @Override
-    public boolean preVisitFunctionCaller(AbstractFunctionExpression expr) {
-        if(expr instanceof FunctionCallExpression) {
-            found = ((FunctionCallExpression)expr).getFunctionName().equals("path");
-            if(found) {
-                return false;
-            }
-        }
-        return true;
-    }
-
-    @Override
-    public void visitNonFunctionCaller(GroovyExpression expr) {
-
-    }
-
-    @Override
-    public void visitNullCaller() {
-
-    }
-
-    public boolean isPathExpressionFound() {
-        return found;
-    }
-
-    @Override
-    public boolean postVisitFunctionCaller(AbstractFunctionExpression functionCall) {
-
-        return false;
-    }
-}

http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/gremlin/optimizer/RangeFinder.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/gremlin/optimizer/RangeFinder.java b/repository/src/main/java/org/apache/atlas/gremlin/optimizer/RangeFinder.java
deleted file mode 100644
index fa8ca85..0000000
--- a/repository/src/main/java/org/apache/atlas/gremlin/optimizer/RangeFinder.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.atlas.gremlin.optimizer;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.atlas.gremlin.GremlinExpressionFactory;
-import org.apache.atlas.groovy.AbstractFunctionExpression;
-import org.apache.atlas.groovy.GroovyExpression;
-
-
-/**
- * Finds all range expressions in the call hierarchy.
- *
- */
-public class RangeFinder implements CallHierarchyVisitor {
-
-    private List<AbstractFunctionExpression> rangeExpressions = new ArrayList<>();
-    private GremlinExpressionFactory factory;
-
-    public RangeFinder(GremlinExpressionFactory factory) {
-        this.factory = factory;
-    }
-
-    @Override
-    public boolean preVisitFunctionCaller(AbstractFunctionExpression expr) {
-
-        return true;
-    }
-
-    @Override
-    public void visitNonFunctionCaller(GroovyExpression expr) {
-    }
-
-    @Override
-    public void visitNullCaller() {
-    }
-
-    @Override
-    public boolean postVisitFunctionCaller(AbstractFunctionExpression functionCall) {
-
-        if (factory.isRangeExpression(functionCall)) {
-            rangeExpressions.add(functionCall);
-        }
-        return true;
-    }
-
-    public List<AbstractFunctionExpression> getRangeExpressions() {
-        return rangeExpressions;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/gremlin/optimizer/RepeatExpressionFinder.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/gremlin/optimizer/RepeatExpressionFinder.java b/repository/src/main/java/org/apache/atlas/gremlin/optimizer/RepeatExpressionFinder.java
deleted file mode 100644
index 8344f36..0000000
--- a/repository/src/main/java/org/apache/atlas/gremlin/optimizer/RepeatExpressionFinder.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.atlas.gremlin.optimizer;
-
-import org.apache.atlas.gremlin.GremlinExpressionFactory;
-import org.apache.atlas.groovy.AbstractFunctionExpression;
-import org.apache.atlas.groovy.GroovyExpression;
-
-/**
- * Determines whether an expression contains a repeat/loop function.
- */
-public class RepeatExpressionFinder implements CallHierarchyVisitor {
-
-    private boolean found = false;
-    private GremlinExpressionFactory factory;
-
-    public RepeatExpressionFinder(GremlinExpressionFactory factory) {
-        this.factory = factory;
-    }
-
-    @Override
-    public boolean preVisitFunctionCaller(AbstractFunctionExpression expr) {
-
-        found = factory.isRepeatExpression(expr);
-        if(found) {
-            return false;
-        }
-        return true;
-    }
-
-    @Override
-    public void visitNonFunctionCaller(GroovyExpression expr) {
-
-    }
-
-    @Override
-    public void visitNullCaller() {
-
-    }
-
-    public boolean isRepeatExpressionFound() {
-        return found;
-    }
-
-    @Override
-    public boolean postVisitFunctionCaller(AbstractFunctionExpression functionCall) {
-
-        return false;
-    }
-}

http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/gremlin/optimizer/SplitPointFinder.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/gremlin/optimizer/SplitPointFinder.java b/repository/src/main/java/org/apache/atlas/gremlin/optimizer/SplitPointFinder.java
deleted file mode 100644
index f0295e7..0000000
--- a/repository/src/main/java/org/apache/atlas/gremlin/optimizer/SplitPointFinder.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.atlas.gremlin.optimizer;
-
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.atlas.gremlin.GremlinExpressionFactory;
-import org.apache.atlas.groovy.AbstractFunctionExpression;
-import org.apache.atlas.groovy.FunctionCallExpression;
-import org.apache.atlas.groovy.GroovyExpression;
-import org.apache.atlas.groovy.TraversalStepType;
-
-
-/**
- * This class finds the first place in the expression where the value of the
- * traverser is changed from being a vertex to being something else.  This is
- * important in the "or" optimization logic, since the union operation must be
- * done on *vertices* in order to preserve the semantics of the query.  In addition,
- * expressions that have side effects must be moved as well, so that those
- * side effects will be available to the steps that need them.
- */
-public class SplitPointFinder implements CallHierarchyVisitor {
-
-    //Any steps that change the traverser value to something that is not a vertex or edge
-    //must be included here, so that the union created by ExpandOrsOptimization
-    //is done over vertices/edges.
-    private static final Set<TraversalStepType> TYPES_REQUIRED_IN_RESULT_EXPRESSION = new HashSet<>(
-            Arrays.asList(
-                    TraversalStepType.BARRIER,
-                    TraversalStepType.BRANCH,
-                    TraversalStepType.SIDE_EFFECT,
-                    TraversalStepType.MAP_TO_VALUE,
-                    TraversalStepType.FLAT_MAP_TO_VALUES,
-                    TraversalStepType.END,
-                    TraversalStepType.NONE));
-
-    private final Set<String> requiredAliases = new HashSet<>();
-
-    //Exceptions to the requirement that all expressions with a type
-    //in the above list must be in the result expression.  If the
-    //function name is in this list, it is ok for that expression
-    //to not be in the result expression.  This mechanism allows
-    //aliases to remain outside the result expression.  Other
-    //exceptions may be found in the future.
-    private static final Map<TraversalStepType, WhiteList> WHITE_LISTS = new HashMap<>();
-    static {
-        WHITE_LISTS.put(TraversalStepType.SIDE_EFFECT, new WhiteList("as"));
-    }
-
-    private final GremlinExpressionFactory factory;
-
-    public SplitPointFinder(GremlinExpressionFactory factory) {
-        this.factory = factory;
-    }
-
-    /**
-     * Represents a set of function names.
-     */
-    private static final class WhiteList {
-        private Set<String> allowedFunctionNames = new HashSet<>();
-        public WhiteList(String... names) {
-            for(String name : names) {
-                allowedFunctionNames.add(name);
-            }
-        }
-        public boolean contains(String name) {
-            return allowedFunctionNames.contains(name);
-        }
-    }
-
-    private AbstractFunctionExpression splitPoint;
-
-    @Override
-    public boolean preVisitFunctionCaller(AbstractFunctionExpression expr) {
-        requiredAliases.addAll(factory.getAliasesRequiredByExpression(expr));
-        return true;
-    }
-
-    @Override
-    public void visitNonFunctionCaller(GroovyExpression expr) {
-
-    }
-
-    @Override
-    public void visitNullCaller() {
-
-    }
-
-    public AbstractFunctionExpression getSplitPoint() {
-        return splitPoint;
-    }
-
-    @Override
-    public boolean postVisitFunctionCaller(AbstractFunctionExpression functionCall) {
-        String aliasName = factory.getAliasNameIfRelevant(functionCall);
-        if (splitPoint == null) {
-
-            boolean required = isRequiredAlias(aliasName) ||
-                    isRequiredInResultExpression(functionCall);
-            if (required) {
-                splitPoint = functionCall;
-            }
-        }
-        removeSeenAlias(aliasName);
-
-        return true;
-    }
-
-    private void removeSeenAlias(String aliasName) {
-        if(aliasName != null) {
-            requiredAliases.remove(aliasName);
-        }
-    }
-
-    private boolean isRequiredAlias(String aliasName) {
-        if(aliasName != null) {
-            return requiredAliases.contains(aliasName);
-        }
-        return false;
-    }
-
-    private boolean isRequiredInResultExpression(AbstractFunctionExpression expr) {
-
-        TraversalStepType type = expr.getType();
-        if (!TYPES_REQUIRED_IN_RESULT_EXPRESSION.contains(type)) {
-            return false;
-        }
-
-        if(expr instanceof FunctionCallExpression) {
-            FunctionCallExpression functionCall = (FunctionCallExpression)expr;
-            //check if the white list permits this function call.  If there is
-            //no white list, all expressions with the current step type must go in the
-            //result expression.
-            WhiteList whiteList = WHITE_LISTS.get(type);
-            if(whiteList != null && whiteList.contains(functionCall.getFunctionName())) {
-                return false;
-            }
-        }
-        return true;
-
-    }
-}

http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/gremlin/optimizer/UpdatedExpressions.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/gremlin/optimizer/UpdatedExpressions.java b/repository/src/main/java/org/apache/atlas/gremlin/optimizer/UpdatedExpressions.java
deleted file mode 100644
index 06351ea..0000000
--- a/repository/src/main/java/org/apache/atlas/gremlin/optimizer/UpdatedExpressions.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.atlas.gremlin.optimizer;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.atlas.groovy.GroovyExpression;
-
-/**
- * Represents a list of updated expressions.
- */
-public class UpdatedExpressions {
-
-    private List<List<GroovyExpression>> updatedChildren = new ArrayList<>();
-    private boolean changed = false;
-
-    public UpdatedExpressions(boolean changed, List<List<GroovyExpression>> updatedChildren) {
-        this.changed = changed;
-        this.updatedChildren = updatedChildren;
-    }
-
-    public List<List<GroovyExpression>> getUpdatedChildren() {
-        return updatedChildren;
-    }
-
-    public boolean hasChanges() {
-        return changed;
-    }
-}

http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/query/Expressions.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/query/Expressions.java b/repository/src/main/java/org/apache/atlas/query/Expressions.java
new file mode 100644
index 0000000..9e93ce4
--- /dev/null
+++ b/repository/src/main/java/org/apache/atlas/query/Expressions.java
@@ -0,0 +1,45 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.atlas.query;
+
+
+import java.util.List;
+
+public class Expressions {
+    public static class Expression {
+
+    }
+
+    public static class AliasExpression {
+        public String alias() {
+            String ret = null;
+
+            return ret;
+        }
+
+    }
+
+    public static class SelectExpression {
+        public List<AliasExpression> toJavaList() {
+            List<AliasExpression> ret = null;
+
+            return ret;
+        }
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/query/GremlinQuery.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/query/GremlinQuery.java b/repository/src/main/java/org/apache/atlas/query/GremlinQuery.java
new file mode 100644
index 0000000..fcb1f48
--- /dev/null
+++ b/repository/src/main/java/org/apache/atlas/query/GremlinQuery.java
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.atlas.query;
+
+import org.apache.atlas.query.Expressions.Expression;
+
+
+public class GremlinQuery {
+
+    public boolean hasSelectList() {
+        boolean ret = false;
+
+        return ret;
+    }
+
+    public String queryStr() {
+        String ret = null;
+
+        return ret;
+    }
+
+    public Expression expr() {
+        Expression ret = null;
+
+        return ret;
+    }
+}

http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/query/GremlinTranslator.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/query/GremlinTranslator.java b/repository/src/main/java/org/apache/atlas/query/GremlinTranslator.java
new file mode 100644
index 0000000..5395ddd
--- /dev/null
+++ b/repository/src/main/java/org/apache/atlas/query/GremlinTranslator.java
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.atlas.query;
+
+import org.apache.atlas.query.Expressions.Expression;
+
+public class GremlinTranslator {
+    private Expression expression;
+
+    public GremlinTranslator(Expression expression) {
+        this.expression = expression;
+    }
+
+    public GremlinQuery translate() {
+        GremlinQuery ret = null;
+
+        return ret;
+    }
+}

http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/query/QueryParams.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/query/QueryParams.java b/repository/src/main/java/org/apache/atlas/query/QueryParams.java
new file mode 100644
index 0000000..5af8bc7
--- /dev/null
+++ b/repository/src/main/java/org/apache/atlas/query/QueryParams.java
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.atlas.query;
+
+
+public class QueryParams {
+    private int limit;
+    private int offset;
+
+    public QueryParams() {
+        this.limit  = -1;
+        this.offset = 0;
+    }
+
+    public QueryParams(int limit, int offset) {
+        this.limit  = limit;
+        this.offset = offset;
+    }
+
+    public int limit() {
+        return limit;
+    }
+
+    public void limit(int limit) {
+        this.limit = limit;
+    }
+
+    public int offset() {
+        return offset;
+    }
+
+    public void offset(int offset) {
+        this.offset = offset;
+    }
+}

http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/query/QueryParser.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/query/QueryParser.java b/repository/src/main/java/org/apache/atlas/query/QueryParser.java
new file mode 100644
index 0000000..1e5e5ff
--- /dev/null
+++ b/repository/src/main/java/org/apache/atlas/query/QueryParser.java
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.atlas.query;
+
+import org.apache.atlas.query.Expressions.Expression;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+
+public class QueryParser {
+    private static final Set<String> RESERVED_KEYWORDS =
+            new HashSet<>(Arrays.asList("[", "]", "(", ")", "=", "<", ">", "!=", "<=", ">=", ",", "and", "or", "+", "-",
+                                        "*", "/", ".", "select", "from", "where", "groupby", "loop", "isa", "is", "has",
+                                        "as", "times", "withPath", "limit", "offset", "orderby", "count", "max", "min",
+                                        "sum", "by", "order", "like"));
+
+    public static boolean isKeyword(String word) {
+        return RESERVED_KEYWORDS.contains(word);
+    }
+
+    public static Expression apply(String queryStr, QueryParams params) {
+        Expression ret = null;
+
+        return ret;
+    }
+}

http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/query/QueryProcessor.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/query/QueryProcessor.java b/repository/src/main/java/org/apache/atlas/query/QueryProcessor.java
new file mode 100644
index 0000000..04cf0b4
--- /dev/null
+++ b/repository/src/main/java/org/apache/atlas/query/QueryProcessor.java
@@ -0,0 +1,28 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.atlas.query;
+
+import org.apache.atlas.query.Expressions.Expression;
+
+public class QueryProcessor {
+    public static Expression validate(Expression expression) {
+        Expressions.Expression ret = null;
+
+        return ret;
+    }
+}

http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/query/SelectExpressionHelper.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/query/SelectExpressionHelper.java b/repository/src/main/java/org/apache/atlas/query/SelectExpressionHelper.java
new file mode 100644
index 0000000..a8748ef
--- /dev/null
+++ b/repository/src/main/java/org/apache/atlas/query/SelectExpressionHelper.java
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.atlas.query;
+
+import org.apache.atlas.query.Expressions.Expression;
+import org.apache.atlas.query.Expressions.SelectExpression;
+
+
+public class SelectExpressionHelper {
+    public static SelectExpression extractSelectExpression(Expression expr) {
+        SelectExpression ret = null;
+
+        return ret;
+    }
+}

http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/repository/DiscoverInstances.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/DiscoverInstances.java b/repository/src/main/java/org/apache/atlas/repository/DiscoverInstances.java
deleted file mode 100755
index 6261499..0000000
--- a/repository/src/main/java/org/apache/atlas/repository/DiscoverInstances.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.atlas.repository;
-
-import org.apache.atlas.AtlasException;
-import org.apache.atlas.typesystem.IReferenceableInstance;
-import org.apache.atlas.typesystem.persistence.Id;
-import org.apache.atlas.typesystem.types.DataTypes;
-import org.apache.atlas.typesystem.types.ObjectGraphWalker;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Graph walker implementation for discovering instances.
- */
-@Deprecated
-public class DiscoverInstances implements ObjectGraphWalker.NodeProcessor {
-
-    public final Map<Id, Id> idToNewIdMap;
-    public final Map<Id, IReferenceableInstance> idToInstanceMap;
-    final IRepository repository;
-
-    public DiscoverInstances(IRepository repository) {
-        this.repository = repository;
-        idToNewIdMap = new HashMap<>();
-        idToInstanceMap = new HashMap<>();
-    }
-
-    @Override
-    public void processNode(ObjectGraphWalker.Node nd) throws AtlasException {
-
-        IReferenceableInstance ref = null;
-        Id id = null;
-
-        if (nd.attributeName == null) {
-            ref = (IReferenceableInstance) nd.instance;
-            id = ref.getId();
-        } else if (nd.aInfo.dataType().getTypeCategory() == DataTypes.TypeCategory.CLASS) {
-            if (nd.value != null && (nd.value instanceof Id)) {
-                id = (Id) nd.value;
-            }
-        }
-
-        if (id != null) {
-            if (id.isUnassigned()) {
-                if (!idToNewIdMap.containsKey(id)) {
-                    idToNewIdMap.put(id, repository.newId(id.typeName));
-                }
-                if (ref != null && idToInstanceMap.containsKey(ref)) {
-                    // Oops
-                    throw new RepositoryException(
-                            String.format("Unexpected internal error: Id %s processed again", id));
-                }
-                if (ref != null) {
-                    idToInstanceMap.put(id, ref);
-                }
-            }
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/repository/IRepository.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/IRepository.java b/repository/src/main/java/org/apache/atlas/repository/IRepository.java
deleted file mode 100755
index 1637e11..0000000
--- a/repository/src/main/java/org/apache/atlas/repository/IRepository.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.atlas.repository;
-
-import org.apache.atlas.typesystem.IReferenceableInstance;
-import org.apache.atlas.typesystem.ITypedReferenceableInstance;
-import org.apache.atlas.typesystem.persistence.Id;
-import org.apache.atlas.typesystem.types.ClassType;
-import org.apache.atlas.typesystem.types.HierarchicalType;
-import org.apache.atlas.typesystem.types.TraitType;
-
-import java.util.List;
-
-/**
- * Metadata Repository interface.
- */
-@Deprecated
-public interface IRepository {
-
-    ITypedReferenceableInstance create(IReferenceableInstance i) throws RepositoryException;
-
-    ITypedReferenceableInstance update(ITypedReferenceableInstance i) throws RepositoryException;
-
-    void delete(ITypedReferenceableInstance i) throws RepositoryException;
-
-    Id newId(String typeName);
-
-    ITypedReferenceableInstance get(Id id) throws RepositoryException;
-
-    void defineClass(ClassType type) throws RepositoryException;
-
-    void defineTrait(TraitType type) throws RepositoryException;
-
-    void defineTypes(List<HierarchicalType> types) throws RepositoryException;
-}

http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/repository/MetadataRepository.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/MetadataRepository.java b/repository/src/main/java/org/apache/atlas/repository/MetadataRepository.java
deleted file mode 100644
index b72ee7d..0000000
--- a/repository/src/main/java/org/apache/atlas/repository/MetadataRepository.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.atlas.repository;
-
-import org.apache.atlas.AtlasException;
-import org.apache.atlas.CreateUpdateEntitiesResult;
-import org.apache.atlas.model.legacy.EntityResult;
-import org.apache.atlas.typesystem.ITypedReferenceableInstance;
-import org.apache.atlas.typesystem.ITypedStruct;
-import org.apache.atlas.typesystem.exception.EntityExistsException;
-import org.apache.atlas.typesystem.exception.EntityNotFoundException;
-import org.apache.atlas.typesystem.exception.TraitNotFoundException;
-import org.apache.atlas.typesystem.types.AttributeInfo;
-import org.apache.atlas.typesystem.types.IDataType;
-
-import java.util.List;
-
-/**
- * An interface for persisting metadata into a blueprints enabled graph db.
- */
-@Deprecated
-public interface MetadataRepository {
-
-    /**
-     * Returns the property key used to store entity type name.
-     *
-     * @return property key used to store entity type name.
-     */
-    String getTypeAttributeName();
-
-    /**
-     * Returns the property key used to store super type names.
-     *
-     * @return property key used to store super type names.
-     */
-    String getSuperTypeAttributeName();
-
-    /**
-     * Returns the attribute name used for entity state
-     * @return
-     */
-    String getStateAttributeName();
-    /**
-     * Returns the attribute name used for entity version
-     * @return
-     */
-    String getVersionAttributeName();
-
-    /**
-     * Return the property key used to store a given traitName in the repository.
-     *
-     * @param dataType  data type
-     * @param traitName trait name
-     * @return property key used to store a given traitName
-     */
-    String getTraitLabel(IDataType<?> dataType, String traitName);
-
-    /**
-     * Return the property key used to store a given attribute in the repository.
-     *
-     * @param dataType data type
-     * @param aInfo    attribute info
-     * @return property key used to store a given attribute
-     */
-    String getFieldNameInVertex(IDataType<?> dataType, AttributeInfo aInfo) throws AtlasException;
-
-    /**
-     * Return the edge label for a given attribute in the repository.
-     *
-     * @param dataType  data type
-     * @param aInfo    attribute info
-     * @return edge label for a given attribute
-     */
-    String getEdgeLabel(IDataType<?> dataType, AttributeInfo aInfo) throws AtlasException;
-
-    /**
-     * Creates an entity definition (instance) corresponding to a given type.
-     *
-     * @param entities     entity (typed instance)
-     * @return CreateOrUpdateEntitiesResult with the guids of the entities that were created
-     * @throws RepositoryException
-     * @throws EntityExistsException
-     */
-    CreateUpdateEntitiesResult createEntities(ITypedReferenceableInstance... entities) throws RepositoryException, EntityExistsException;
-
-    /**
-     * Fetch the complete definition of an entity given its GUID.
-     *
-     * @param guid globally unique identifier for the entity
-     * @return entity (typed instance) definition
-     * @throws RepositoryException
-     * @throws EntityNotFoundException
-     */
-    ITypedReferenceableInstance getEntityDefinition(String guid) throws RepositoryException, EntityNotFoundException;
-
-    /**
-     * Fetch the complete entity definitions for the entities with the given GUIDs
-     *
-     * @param guids globally unique identifiers for the entities
-     * @return entity (typed instance) definitions list
-     * @throws RepositoryException
-     * @throws EntityNotFoundException
-     */
-    List<ITypedReferenceableInstance> getEntityDefinitions(String... guids) throws RepositoryException, EntityNotFoundException;
-
-    /**
-     * Gets the list of entities for a given entity type.
-     *
-     * @param entityType name of a type which is unique
-     * @return a list of entity names for the given type
-     * @throws RepositoryException
-     */
-    List<String> getEntityList(String entityType) throws RepositoryException;
-
-    /**
-     * Deletes entities for the specified guids.
-     *
-     * @param guids globally unique identifiers for the deletion candidate entities
-     * @return guids of deleted entities
-     * @throws RepositoryException
-     */
-    EntityResult deleteEntities(List<String> guids) throws RepositoryException;
-    
-    
-    // Trait management functions
-
-    /**
-     * Gets the list of trait names for a given entity represented by a guid.
-     *
-     * @param guid globally unique identifier for the entity
-     * @return a list of trait names for the given entity guid
-     * @throws RepositoryException
-     */
-    List<String> getTraitNames(String guid) throws AtlasException;
-
-    /**
-     * Adds a new trait to an existing entity represented by a guid.
-     *
-     * @param guid          globally unique identifier for the entity
-     * @param traitInstance trait instance that needs to be added to entity
-     * @throws RepositoryException
-     */
-    void addTrait(String guid, ITypedStruct traitInstance) throws RepositoryException;
-
-    /**
-     * Adds a new trait to a list of entities represented by their respective guids
-     * @param entityGuids   list of globally unique identifier for the entities
-     * @param traitInstance trait instance that needs to be added to entities
-     * @throws RepositoryException
-     */
-    void addTrait(List<String> entityGuids, ITypedStruct traitInstance) throws RepositoryException;
-
-    /**
-     * Deletes a given trait from an existing entity represented by a guid.
-     *
-     * @param guid                 globally unique identifier for the entity
-     * @param traitNameToBeDeleted name of the trait
-     * @throws RepositoryException
-     */
-    void deleteTrait(String guid, String traitNameToBeDeleted) throws TraitNotFoundException, EntityNotFoundException, RepositoryException;
-
-    /**
-     * Adds/Updates the property to the entity that corresponds to the GUID
-     * Supports only primitive attribute/Class Id updations.
-     */
-    CreateUpdateEntitiesResult updatePartial(ITypedReferenceableInstance entity) throws RepositoryException;
-
-    /**
-     * Adds the property to the entity that corresponds to the GUID
-     * @param entitiesToBeUpdated The entities to be updated
-     */
-    CreateUpdateEntitiesResult updateEntities(ITypedReferenceableInstance... entitiesToBeUpdated) throws RepositoryException;
-
-    /**
-     * Returns the entity for the given type and qualified name
-     * @param entityType
-     * @param attribute
-     * @param value
-     * @return entity instance
-     */
-    ITypedReferenceableInstance getEntityDefinition(String entityType, String attribute, Object value) throws AtlasException;
-}

http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/repository/RepositoryConfiguration.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/RepositoryConfiguration.java b/repository/src/main/java/org/apache/atlas/repository/RepositoryConfiguration.java
deleted file mode 100644
index 261a6d0..0000000
--- a/repository/src/main/java/org/apache/atlas/repository/RepositoryConfiguration.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.atlas.repository;
-
-import org.apache.atlas.repository.graphdb.GraphDatabase;
-import org.apache.atlas.typesystem.types.TypeSystem;
-import org.apache.atlas.util.AtlasRepositoryConfiguration;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-@Configuration
-public class RepositoryConfiguration {
-    @Bean
-    public GraphDatabase getGraphDatabase() throws IllegalAccessException, InstantiationException {
-        return AtlasRepositoryConfiguration.getGraphDatabaseImpl().newInstance();
-    }
-
-    @Bean
-    public TypeSystem getTypeSystem() {
-        return TypeSystem.getInstance();
-    }
-}

http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/repository/audit/EntityAuditListener.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/audit/EntityAuditListener.java b/repository/src/main/java/org/apache/atlas/repository/audit/EntityAuditListener.java
index 2a1881b..47d4e1d 100644
--- a/repository/src/main/java/org/apache/atlas/repository/audit/EntityAuditListener.java
+++ b/repository/src/main/java/org/apache/atlas/repository/audit/EntityAuditListener.java
@@ -23,11 +23,12 @@ import org.apache.atlas.EntityAuditEvent;
 import org.apache.atlas.EntityAuditEvent.EntityAuditAction;
 import org.apache.atlas.RequestContextV1;
 import org.apache.atlas.listener.EntityChangeListener;
-import org.apache.atlas.typesystem.IReferenceableInstance;
-import org.apache.atlas.typesystem.IStruct;
-import org.apache.atlas.typesystem.ITypedReferenceableInstance;
-import org.apache.atlas.typesystem.json.InstanceSerialization;
-import org.apache.atlas.typesystem.types.AttributeInfo;
+import org.apache.atlas.v1.model.instance.Referenceable;
+import org.apache.atlas.v1.model.instance.Struct;
+import org.apache.atlas.type.AtlasEntityType;
+import org.apache.atlas.type.AtlasStructType;
+import org.apache.atlas.type.AtlasType;
+import org.apache.atlas.type.AtlasTypeRegistry;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.MapUtils;
 import org.slf4j.Logger;
@@ -49,17 +50,19 @@ import java.util.Map;
 public class EntityAuditListener implements EntityChangeListener {
     private static final Logger LOG = LoggerFactory.getLogger(EntityAuditListener.class);
 
-    private EntityAuditRepository auditRepository;
+    private final EntityAuditRepository auditRepository;
+    private final AtlasTypeRegistry     typeRegistry;
 
     @Inject
-    public EntityAuditListener(EntityAuditRepository auditRepository) {
+    public EntityAuditListener(EntityAuditRepository auditRepository, AtlasTypeRegistry typeRegistry) {
         this.auditRepository = auditRepository;
+        this.typeRegistry    = typeRegistry;
     }
 
     @Override
-    public void onEntitiesAdded(Collection<ITypedReferenceableInstance> entities, boolean isImport) throws AtlasException {
+    public void onEntitiesAdded(Collection<Referenceable> entities, boolean isImport) throws AtlasException {
         List<EntityAuditEvent> events = new ArrayList<>();
-        for (ITypedReferenceableInstance entity : entities) {
+        for (Referenceable entity : entities) {
             EntityAuditEvent event = createEvent(entity, isImport ? EntityAuditAction.ENTITY_IMPORT_CREATE : EntityAuditAction.ENTITY_CREATE);
             events.add(event);
         }
@@ -68,9 +71,9 @@ public class EntityAuditListener implements EntityChangeListener {
     }
 
     @Override
-    public void onEntitiesUpdated(Collection<ITypedReferenceableInstance> entities, boolean isImport) throws AtlasException {
+    public void onEntitiesUpdated(Collection<Referenceable> entities, boolean isImport) throws AtlasException {
         List<EntityAuditEvent> events = new ArrayList<>();
-        for (ITypedReferenceableInstance entity : entities) {
+        for (Referenceable entity : entities) {
             EntityAuditEvent event = createEvent(entity, isImport ? EntityAuditAction.ENTITY_IMPORT_UPDATE : EntityAuditAction.ENTITY_UPDATE);
             events.add(event);
         }
@@ -79,11 +82,11 @@ public class EntityAuditListener implements EntityChangeListener {
     }
 
     @Override
-    public void onTraitsAdded(ITypedReferenceableInstance entity, Collection<? extends IStruct> traits) throws AtlasException {
+    public void onTraitsAdded(Referenceable entity, Collection<? extends Struct> traits) throws AtlasException {
         if (traits != null) {
-            for (IStruct trait : traits) {
+            for (Struct trait : traits) {
                 EntityAuditEvent event = createEvent(entity, EntityAuditAction.TAG_ADD,
-                                                     "Added trait: " + InstanceSerialization.toJson(trait, true));
+                                                     "Added trait: " + AtlasType.toV1Json(trait));
 
                 auditRepository.putEvents(event);
             }
@@ -91,7 +94,7 @@ public class EntityAuditListener implements EntityChangeListener {
     }
 
     @Override
-    public void onTraitsDeleted(ITypedReferenceableInstance entity, Collection<String> traitNames) throws AtlasException {
+    public void onTraitsDeleted(Referenceable entity, Collection<String> traitNames) throws AtlasException {
         if (traitNames != null) {
             for (String traitName : traitNames) {
                 EntityAuditEvent event = createEvent(entity, EntityAuditAction.TAG_DELETE, "Deleted trait: " + traitName);
@@ -102,11 +105,11 @@ public class EntityAuditListener implements EntityChangeListener {
     }
 
     @Override
-    public void onTraitsUpdated(ITypedReferenceableInstance entity, Collection<? extends IStruct> traits) throws AtlasException {
+    public void onTraitsUpdated(Referenceable entity, Collection<? extends Struct> traits) throws AtlasException {
         if (traits != null) {
-            for (IStruct trait : traits) {
+            for (Struct trait : traits) {
                 EntityAuditEvent event = createEvent(entity, EntityAuditAction.TAG_UPDATE,
-                                                     "Updated trait: " + InstanceSerialization.toJson(trait, true));
+                                                     "Updated trait: " + AtlasType.toV1Json(trait));
 
                 auditRepository.putEvents(event);
             }
@@ -114,9 +117,9 @@ public class EntityAuditListener implements EntityChangeListener {
     }
 
     @Override
-    public void onEntitiesDeleted(Collection<ITypedReferenceableInstance> entities, boolean isImport) throws AtlasException {
+    public void onEntitiesDeleted(Collection<Referenceable> entities, boolean isImport) throws AtlasException {
         List<EntityAuditEvent> events = new ArrayList<>();
-        for (ITypedReferenceableInstance entity : entities) {
+        for (Referenceable entity : entities) {
             EntityAuditEvent event = createEvent(entity, isImport ? EntityAuditAction.ENTITY_IMPORT_DELETE : EntityAuditAction.ENTITY_DELETE, "Deleted entity");
             events.add(event);
         }
@@ -128,23 +131,23 @@ public class EntityAuditListener implements EntityChangeListener {
         return auditRepository.listEvents(guid, null, (short) 10);
     }
 
-    private EntityAuditEvent createEvent(ITypedReferenceableInstance entity, EntityAuditAction action)
+    private EntityAuditEvent createEvent(Referenceable entity, EntityAuditAction action)
             throws AtlasException {
         String detail = getAuditEventDetail(entity, action);
 
         return createEvent(entity, action, detail);
     }
 
-    private EntityAuditEvent createEvent(ITypedReferenceableInstance entity, EntityAuditAction action, String details)
+    private EntityAuditEvent createEvent(Referenceable entity, EntityAuditAction action, String details)
             throws AtlasException {
         return new EntityAuditEvent(entity.getId()._getId(), RequestContextV1.get().getRequestTime(), RequestContextV1.get().getUser(), action, details, entity);
     }
 
-    private String getAuditEventDetail(ITypedReferenceableInstance entity, EntityAuditAction action) throws AtlasException {
+    private String getAuditEventDetail(Referenceable entity, EntityAuditAction action) throws AtlasException {
         Map<String, Object> prunedAttributes = pruneEntityAttributesForAudit(entity);
 
         String auditPrefix  = getAuditPrefix(action);
-        String auditString  = auditPrefix + InstanceSerialization.toJson(entity, true);
+        String auditString  = auditPrefix + AtlasType.toV1Json(entity);
         byte[] auditBytes   = auditString.getBytes(StandardCharsets.UTF_8);
         long   auditSize    = auditBytes != null ? auditBytes.length : 0;
         long   auditMaxSize = auditRepository.repositoryMaxSize();
@@ -157,7 +160,7 @@ public class EntityAuditListener implements EntityChangeListener {
 
             clearAttributeValues(entity);
 
-            auditString = auditPrefix + InstanceSerialization.toJson(entity, true);
+            auditString = auditPrefix + AtlasType.toV1Json(entity);
 
             addAttributeValues(entity, attrValues);
         }
@@ -167,7 +170,7 @@ public class EntityAuditListener implements EntityChangeListener {
         return auditString;
     }
 
-    private void clearAttributeValues(IReferenceableInstance entity) throws AtlasException {
+    private void clearAttributeValues(Referenceable entity) throws AtlasException {
         Map<String, Object> attributesMap = entity.getValuesMap();
 
         if (MapUtils.isNotEmpty(attributesMap)) {
@@ -177,7 +180,7 @@ public class EntityAuditListener implements EntityChangeListener {
         }
     }
 
-    private void addAttributeValues(ITypedReferenceableInstance entity, Map<String, Object> attributesMap) throws AtlasException {
+    private void addAttributeValues(Referenceable entity, Map<String, Object> attributesMap) throws AtlasException {
         if (MapUtils.isNotEmpty(attributesMap)) {
             for (String attr : attributesMap.keySet()) {
                 entity.set(attr, attributesMap.get(attr));
@@ -185,17 +188,16 @@ public class EntityAuditListener implements EntityChangeListener {
         }
     }
 
-    private Map<String, Object> pruneEntityAttributesForAudit(ITypedReferenceableInstance entity) throws AtlasException {
+    private Map<String, Object> pruneEntityAttributesForAudit(Referenceable entity) throws AtlasException {
         Map<String, Object> ret               = null;
         Map<String, Object> entityAttributes  = entity.getValuesMap();
         List<String>        excludeAttributes = auditRepository.getAuditExcludeAttributes(entity.getTypeName());
+        AtlasEntityType     entityType        = typeRegistry.getEntityTypeByName(entity.getTypeName());
 
-        if (CollectionUtils.isNotEmpty(excludeAttributes) && MapUtils.isNotEmpty(entityAttributes)) {
-            Map<String, AttributeInfo> attributeInfoMap = entity.fieldMapping().fields;
-
-            for (String attrName : entityAttributes.keySet()) {
+        if (CollectionUtils.isNotEmpty(excludeAttributes) && MapUtils.isNotEmpty(entityAttributes) && entityType != null) {
+            for (AtlasStructType.AtlasAttribute attribute : entityType.getAllAttributes().values()) {
+                String        attrName  = attribute.getName();
                 Object        attrValue = entityAttributes.get(attrName);
-                AttributeInfo attrInfo  = attributeInfoMap.get(attrName);
 
                 if (excludeAttributes.contains(attrName)) {
                     if (ret == null) {
@@ -204,15 +206,15 @@ public class EntityAuditListener implements EntityChangeListener {
 
                     ret.put(attrName, attrValue);
                     entity.setNull(attrName);
-                } else if (attrInfo.isComposite) {
+                } else if (attribute.isOwnedRef()) {
                     if (attrValue instanceof Collection) {
-                        for (Object attribute : (Collection) attrValue) {
-                            if (attribute instanceof ITypedReferenceableInstance) {
-                                ret = pruneAttributes(ret, (ITypedReferenceableInstance) attribute);
+                        for (Object arrElem : (Collection) attrValue) {
+                            if (arrElem instanceof Referenceable) {
+                                ret = pruneAttributes(ret, (Referenceable) arrElem);
                             }
                         }
-                    } else if (attrValue instanceof ITypedReferenceableInstance) {
-                        ret = pruneAttributes(ret, (ITypedReferenceableInstance) attrValue);
+                    } else if (attrValue instanceof Referenceable) {
+                        ret = pruneAttributes(ret, (Referenceable) attrValue);
                     }
                 }
             }
@@ -221,9 +223,9 @@ public class EntityAuditListener implements EntityChangeListener {
         return ret;
     }
 
-    private Map<String, Object> pruneAttributes(Map<String, Object> ret, ITypedReferenceableInstance attribute) throws AtlasException {
-        ITypedReferenceableInstance attrInstance = attribute;
-        Map<String, Object>         prunedAttrs  = pruneEntityAttributesForAudit(attrInstance);
+    private Map<String, Object> pruneAttributes(Map<String, Object> ret, Referenceable attribute) throws AtlasException {
+        Referenceable       attrInstance = attribute;
+        Map<String, Object> prunedAttrs  = pruneEntityAttributesForAudit(attrInstance);
 
         if (MapUtils.isNotEmpty(prunedAttrs)) {
             if (ret == null) {
@@ -232,41 +234,42 @@ public class EntityAuditListener implements EntityChangeListener {
 
             ret.put(attrInstance.getId()._getId(), prunedAttrs);
         }
+
         return ret;
     }
 
-    private void restoreEntityAttributes(ITypedReferenceableInstance entity, Map<String, Object> prunedAttributes) throws AtlasException {
+    private void restoreEntityAttributes(Referenceable entity, Map<String, Object> prunedAttributes) throws AtlasException {
         if (MapUtils.isEmpty(prunedAttributes)) {
             return;
         }
 
-        Map<String, Object> entityAttributes = entity.getValuesMap();
+        AtlasEntityType     entityType       = typeRegistry.getEntityTypeByName(entity.getTypeName());
 
-        if (MapUtils.isNotEmpty(entityAttributes)) {
-            Map<String, AttributeInfo> attributeInfoMap = entity.fieldMapping().fields;
+        if (entityType != null && MapUtils.isNotEmpty(entityType.getAllAttributes())) {
+            Map<String, Object> entityAttributes = entity.getValuesMap();
 
-            for (String attrName : entityAttributes.keySet()) {
-                Object        attrValue = entityAttributes.get(attrName);
-                AttributeInfo attrInfo  = attributeInfoMap.get(attrName);
+            for (AtlasStructType.AtlasAttribute attribute : entityType.getAllAttributes().values()) {
+                String attrName  = attribute.getName();
+                Object attrValue = entityAttributes.get(attrName);
 
                 if (prunedAttributes.containsKey(attrName)) {
                     entity.set(attrName, prunedAttributes.get(attrName));
-                } else if (attrInfo.isComposite) {
+                } else if (attribute.isOwnedRef()) {
                     if (attrValue instanceof Collection) {
-                        for (Object attributeEntity : (Collection) attrValue) {
-                            if (attributeEntity instanceof ITypedReferenceableInstance) {
-                                restoreAttributes(prunedAttributes, (ITypedReferenceableInstance) attributeEntity);
+                        for (Object arrElem : (Collection) attrValue) {
+                            if (arrElem instanceof Referenceable) {
+                                restoreAttributes(prunedAttributes, (Referenceable) arrElem);
                             }
                         }
-                    } else if (attrValue instanceof ITypedReferenceableInstance) {
-                        restoreAttributes(prunedAttributes, (ITypedReferenceableInstance) attrValue);
+                    } else if (attrValue instanceof Referenceable) {
+                        restoreAttributes(prunedAttributes, (Referenceable) attrValue);
                     }
                 }
             }
         }
     }
 
-    private void restoreAttributes(Map<String, Object> prunedAttributes, ITypedReferenceableInstance attributeEntity) throws AtlasException {
+    private void restoreAttributes(Map<String, Object> prunedAttributes, Referenceable attributeEntity) throws AtlasException {
         Object                      obj          = prunedAttributes.get(attributeEntity.getId()._getId());
 
         if (obj instanceof Map) {

http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/repository/converters/AtlasClassificationFormatConverter.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/converters/AtlasClassificationFormatConverter.java b/repository/src/main/java/org/apache/atlas/repository/converters/AtlasClassificationFormatConverter.java
index cd4f165..d91772c 100644
--- a/repository/src/main/java/org/apache/atlas/repository/converters/AtlasClassificationFormatConverter.java
+++ b/repository/src/main/java/org/apache/atlas/repository/converters/AtlasClassificationFormatConverter.java
@@ -18,14 +18,13 @@
 package org.apache.atlas.repository.converters;
 
 import org.apache.atlas.AtlasErrorCode;
-import org.apache.atlas.AtlasException;
 import org.apache.atlas.exception.AtlasBaseException;
 import org.apache.atlas.model.TypeCategory;
 import org.apache.atlas.model.instance.AtlasClassification;
+import org.apache.atlas.v1.model.instance.Struct;
 import org.apache.atlas.type.AtlasClassificationType;
 import org.apache.atlas.type.AtlasType;
 import org.apache.atlas.type.AtlasTypeRegistry;
-import org.apache.atlas.typesystem.IStruct;
 import org.apache.commons.collections.MapUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -55,19 +54,12 @@ public class AtlasClassificationFormatConverter extends AtlasStructFormatConvert
                 } else {
                     ret = new AtlasClassification(type.getTypeName());
                 }
-            } else if (v1Obj instanceof IStruct) {
-                IStruct             struct    = (IStruct) v1Obj;
-                Map<String, Object> v1Attribs = null;
+            } else if (v1Obj instanceof Struct) {
+                Struct struct = (Struct) v1Obj;
 
-                try {
-                    v1Attribs = struct.getValuesMap();
-                } catch (AtlasException excp) {
-                    LOG.error("IStruct.getValuesMap() failed", excp);
-                }
-
-                ret = new AtlasClassification(type.getTypeName(), fromV1ToV2(classificationType, v1Attribs, ctx));
+                ret = new AtlasClassification(type.getTypeName(), fromV1ToV2(classificationType, struct.getValues(), ctx));
             } else {
-                throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, "Map or IStruct",
+                throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, "Map or Struct",
                                              v1Obj.getClass().getCanonicalName());
             }
         }