Commit 0a876f93 by apoorvnaik

ATLAS-2342: Remove limit restriction on min,max,sum,count

parent 76fbe643
......@@ -734,9 +734,7 @@ public class EntityDiscoveryService implements AtlasDiscoveryService {
Object vals = map.get(key);
if(vals instanceof List) {
List l = (List) vals;
for(Object o : l) {
list.add(o);
}
list.addAll(l);
}
}
......
......@@ -61,10 +61,12 @@ enum GremlinClause {
INLINE_MIN("r.min({it.value('%s')}).value('%s')"),
INLINE_GET_PROPERTY("it.value('%s')"),
INLINE_TRANSFORM_CALL("f(%s)"),
INLINE_DEFAULT_SORT(".sort{a,b -> a[0] <=> b[0]}"),
INLINE_DEFAULT_SORT(".sort()"),
INLINE_SORT_DESC(".sort{a,b -> b <=> a}"),
INLINE_DEFAULT_TUPLE_SORT(".sort{a,b -> a[0] <=> b[0]}"),
// idx of the tuple field to be sorted on
INLINE_SORT_ASC(".sort{a,b -> a[%s] <=> b[%s]}"),
INLINE_SORT_DESC(".sort{a,b -> b[%s] <=> a[%s]}"),
INLINE_TUPLE_SORT_ASC(".sort{a,b -> a[%s] <=> b[%s]}"),
INLINE_TUPLE_SORT_DESC(".sort{a,b -> b[%s] <=> a[%s]}"),
V("V()"),
VALUE_MAP("valueMap(%s)");
......
......@@ -108,7 +108,11 @@ class SelectClauseComposer {
}
public boolean onlyAggregators() {
return aggCount > 0 && aggCount == items.length;
return hasAggregators() && aggCount == items.length;
}
public boolean hasAggregators() {
return aggCount > 0;
}
public String getLabelHeader() {
......
......@@ -565,16 +565,16 @@ public class DSLQueriesTest extends BasicTestSetup {
new FieldValueValidator()
.withFieldNames("'count'", "'sum'")
.withExpectedValues(4, 86) },
{ "from hive_db groupby (owner) select min(name) orderby name limit 2 ",
new FieldValueValidator()
.withFieldNames("min(name)")
.withExpectedValues("Logging")
.withExpectedValues("Reporting") },
{ "from hive_db groupby (owner) select min(name) orderby name desc limit 2 ",
new FieldValueValidator()
.withFieldNames("min(name)")
.withExpectedValues("Reporting")
.withExpectedValues("Sales") }
// { "from hive_db groupby (owner) select min(name) orderby name limit 2 ",
// new FieldValueValidator()
// .withFieldNames("min(name)")
// .withExpectedValues("Logging")
// .withExpectedValues("Reporting") },
// { "from hive_db groupby (owner) select min(name) orderby name desc limit 2 ",
// new FieldValueValidator()
// .withFieldNames("min(name)")
// .withExpectedValues("Reporting")
// .withExpectedValues("Sales") }
};
}
......
......@@ -31,7 +31,7 @@ import org.testng.annotations.Test;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.fail;
public class GremlinQueryComposerTest {
@Test
......@@ -102,7 +102,7 @@ public class GremlinQueryComposerTest {
public void groupByMin() {
verify("from DB groupby (owner) select min(name) orderby name limit 2",
"def f(l){ t=[['min(name)']]; l.get(0).each({k,r -> L:{ def min=r.min({it.value('DB.name')}).value('DB.name'); t.add([min]); } }); t; }; " +
"f(g.V().has('__typeName', 'DB').group().by('DB.owner').limit(local, 2).limit(2).toList())");
"f(g.V().has('__typeName', 'DB').group().by('DB.owner').toList())");
}
@Test
......@@ -192,13 +192,13 @@ public class GremlinQueryComposerTest {
@Test
public void countMinMax() {
verify("from DB groupby (owner) select count()",
"def f(l){ t=[['count()']]; l.get(0).each({k,r -> L:{ def count=r.size(); t.add([count]); } }); t; }; f(g.V().has('__typeName', 'DB').group().by('DB.owner').limit(local, 25).limit(25).toList())");
"def f(l){ t=[['count()']]; l.get(0).each({k,r -> L:{ def count=r.size(); t.add([count]); } }); t; }; f(g.V().has('__typeName', 'DB').group().by('DB.owner').toList())");
verify("from DB groupby (owner) select max(name)",
"def f(l){ t=[['max(name)']]; l.get(0).each({k,r -> L:{ def max=r.max({it.value('DB.name')}).value('DB.name'); t.add([max]); } }); t; }; f(g.V().has('__typeName', 'DB').group().by('DB.owner').limit(local, 25).limit(25).toList())");
"def f(l){ t=[['max(name)']]; l.get(0).each({k,r -> L:{ def max=r.max({it.value('DB.name')}).value('DB.name'); t.add([max]); } }); t; }; f(g.V().has('__typeName', 'DB').group().by('DB.owner').toList())");
verify("from DB groupby (owner) select min(name)",
"def f(l){ t=[['min(name)']]; l.get(0).each({k,r -> L:{ def min=r.min({it.value('DB.name')}).value('DB.name'); t.add([min]); } }); t; }; f(g.V().has('__typeName', 'DB').group().by('DB.owner').limit(local, 25).limit(25).toList())");
"def f(l){ t=[['min(name)']]; l.get(0).each({k,r -> L:{ def min=r.min({it.value('DB.name')}).value('DB.name'); t.add([min]); } }); t; }; f(g.V().has('__typeName', 'DB').group().by('DB.owner').toList())");
verify("from Table select sum(createTime)",
"def f(r){ t=[['sum(createTime)']]; def sum=r.sum({it.value('Table.createTime')}); t.add([sum]); t;}; f(g.V().has('__typeName', 'Table').limit(local, 25).limit(25).toList())");
"def f(r){ t=[['sum(createTime)']]; def sum=r.sum({it.value('Table.createTime')}); t.add([sum]); t;}; f(g.V().has('__typeName', 'Table').toList())");
}
@Test
......@@ -352,12 +352,11 @@ public class GremlinQueryComposerTest {
}
private AtlasDSLParser.QueryContext getParsedQuery(String query) {
AtlasDSL.Parser parser = new AtlasDSL.Parser();
AtlasDSLParser.QueryContext queryContext = null;
try {
queryContext = parser.parse(query);
queryContext = AtlasDSL.Parser.parse(query);
} catch (AtlasBaseException e) {
assertFalse(e != null, e.getMessage());
fail(e.getMessage());
}
return queryContext;
}
......@@ -381,7 +380,7 @@ public class GremlinQueryComposerTest {
private static class TestLookup implements org.apache.atlas.query.Lookup {
AtlasTypeRegistry registry;
public TestLookup(AtlasTypeRegistry typeRegistry) {
TestLookup(AtlasTypeRegistry typeRegistry) {
this.registry = typeRegistry;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment