You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by am...@apache.org on 2021/02/03 05:09:42 UTC

[atlas] branch master updated: ATLAS-4122: Advanced Search: Literals with double-quotes.

This is an automated email from the ASF dual-hosted git repository.

amestry pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/atlas.git


The following commit(s) were added to refs/heads/master by this push:
     new efcc31e  ATLAS-4122: Advanced Search: Literals with double-quotes.
efcc31e is described below

commit efcc31e8dcd5038eaa964386c3e123fb90f1b28b
Author: Ashutosh Mestry <am...@cloudera.com>
AuthorDate: Tue Feb 2 20:59:07 2021 -0800

    ATLAS-4122: Advanced Search: Literals with double-quotes.
---
 .../query/executors/GremlinClauseToTraversalTranslator.java      | 5 +++--
 .../src/test/java/org/apache/atlas/query/DSLQueriesTest.java     | 9 ++++++---
 .../java/org/apache/atlas/query/GremlinQueryComposerTest.java    | 8 ++++++++
 3 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/repository/src/main/java/org/apache/atlas/query/executors/GremlinClauseToTraversalTranslator.java b/repository/src/main/java/org/apache/atlas/query/executors/GremlinClauseToTraversalTranslator.java
index a7b05fd..156a65c 100644
--- a/repository/src/main/java/org/apache/atlas/query/executors/GremlinClauseToTraversalTranslator.java
+++ b/repository/src/main/java/org/apache/atlas/query/executors/GremlinClauseToTraversalTranslator.java
@@ -48,6 +48,8 @@ public class GremlinClauseToTraversalTranslator {
         private static final String EDGE_NAME_CLASSIFIED_AS          = "classifiedAs";
         private static final String EDGE_NAME_TRAIT_NAMES            = "__traitNames";
         private static final String EDGE_NAME_PROPAGATED_TRAIT_NAMES = "__propagatedTraitNames";
+        private static final String[] STR_TOKEN_SEARCH               = new String[]{"[", "]", "'", "\""};
+        private static final String[] STR_TOKEN_REPLACE              = new String[]{"", "", "", ""};
 
         private final AtlasGraph graph;
 
@@ -293,8 +295,7 @@ public class GremlinClauseToTraversalTranslator {
         }
 
         private String[] csvToArray(String strRhs) {
-            String csvRow = StringUtils.replaceEach(strRhs, new String[]{"[", "]", "'"}, new String[]{"", "", ""});
-
+            String csvRow = StringUtils.replaceEach(strRhs, STR_TOKEN_SEARCH, STR_TOKEN_REPLACE);
             return csvRow.split(",");
         }
 
diff --git a/repository/src/test/java/org/apache/atlas/query/DSLQueriesTest.java b/repository/src/test/java/org/apache/atlas/query/DSLQueriesTest.java
index 359cb31..0c1dd59 100644
--- a/repository/src/test/java/org/apache/atlas/query/DSLQueriesTest.java
+++ b/repository/src/test/java/org/apache/atlas/query/DSLQueriesTest.java
@@ -226,7 +226,8 @@ public class DSLQueriesTest extends BasicTestSetup {
                 {"hive_table hasTerm \"modernTrade@salesGlossary\" and hive_table isA Dimension",1, new ListValidator( "time_dim")},
                 {"hive_table hasTerm \"modernTrade@salesGlossary\" and db.name = \"Sales\" or (hive_table.name = \"sales_fact_monthly_mv\")", 2, new ListValidator("sales_fact_monthly_mv", "time_dim")},
                 {"hive_table where hive_table hasTerm \"modernTrade@salesGlossary\"", 2, new ListValidator("logging_fact_monthly_mv", "time_dim")},
-                {"hive_table where (name = \"product_dim\" and hive_table hasTerm \"ecommerce@salesGlossary\")", 1, new ListValidator("product_dim")}
+                {"hive_table where (name = \"product_dim\" and hive_table hasTerm \"ecommerce@salesGlossary\")", 1, new ListValidator("product_dim")},
+                {"hive_table where (name = 'product_dim' and hive_table hasTerm 'ecommerce@salesGlossary')", 1, new ListValidator("product_dim")}
         };
     }
 
@@ -283,14 +284,16 @@ public class DSLQueriesTest extends BasicTestSetup {
                 {"DataSet where name='sales_fact'", 1},
                 {"Asset where name='sales_fact'", 1},
                 {"hive_db _NOT_CLASSIFIED", 3},
-                {"_CLASSIFIED", 23}
+                {"_CLASSIFIED", 23},
+                {"hive_db where name = [\"Reporting\",\"Sales\"]", 2},
+                {"hive_db where name = ['Reporting', 'Sales']", 2},
         };
     }
 
     @Test(dataProvider = "basicProvider")
     public void basic(String query, int expected) throws AtlasBaseException {
         queryAssert(query, expected, DEFAULT_LIMIT, 0);
-//        queryAssert(query.replace("where", " "), expected, DEFAULT_LIMIT, 0);
+        queryAssert(query.replace("where", " "), expected, DEFAULT_LIMIT, 0);
     }
 
     @DataProvider(name = "systemAttributesProvider")
diff --git a/repository/src/test/java/org/apache/atlas/query/GremlinQueryComposerTest.java b/repository/src/test/java/org/apache/atlas/query/GremlinQueryComposerTest.java
index 0e8af18..3594e2f 100644
--- a/repository/src/test/java/org/apache/atlas/query/GremlinQueryComposerTest.java
+++ b/repository/src/test/java/org/apache/atlas/query/GremlinQueryComposerTest.java
@@ -41,6 +41,14 @@ import static org.testng.Assert.fail;
 import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection.OUT;
 public class GremlinQueryComposerTest {
     @Test
+    public void withinClause() {
+        String expected1 = "g.V().has('__typeName', within('Asset','Table')).has('Asset.__s_name', within('t1','t2','t3')).dedup().limit(25).toList()";
+        String expected2 = "g.V().has('__typeName', within('Asset','Table')).has('Asset.__s_name', within(\"t1\",\"t2\",\"t3\")).dedup().limit(25).toList()";
+        verify("Asset where name=['t1', 't2', 't3']", expected1);
+        verify("Asset where name=[\"t1\", \"t2\", \"t3\"]", expected2);
+    }
+
+    @Test
     public void classification() {
         String expected = "g.V().outE('classifiedAs').has('__name', within('PII')).outV().dedup().limit(25).toList()";
         verify("PII", expected);