Commit a2ccdf12 by Ashutosh Mestry Committed by Madhan Neethiraj

ATLAS-2447: DSL improvement in handling of select clause

parent 3ec37cae
......@@ -36,11 +36,11 @@ enum GremlinClause {
AND("and(%s)"),
NESTED_START("__"),
NESTED_HAS_OPERATOR("has('%s', %s(%s))"),
LIMIT("limit(local, %s).limit(%s)"),
LIMIT("limit(%s)"),
ORDER_BY("order().by('%s')"),
ORDER_BY_DESC("order().by('%s', decr)"),
OUT("out('%s')"),
RANGE("range(local, %s, %s + %s).range(%s, %s + %s)"),
RANGE("range(%s, %s + %s)"),
SELECT("select('%s')"),
TO_LIST("toList()"),
TEXT_CONTAINS("has('%s', org.janusgraph.core.attribute.Text.textRegex(%s))"),
......
......@@ -167,9 +167,7 @@ public class GremlinQueryComposer {
if (lhsI.isDate()) {
rhs = parseDate(rhs);
}
if (lhsI.isNumeric()) {
} else if (lhsI.isNumeric()) {
rhs = parseNumber(rhs);
}
......@@ -492,6 +490,15 @@ public class GremlinQueryComposer {
if (isNestedQuery)
return;
// Need de-duping at the end so that correct results are fetched
if (queryClauses.size() > 2) {
// QueryClauses should've something more that just g.V() (hence 2)
add(GremlinClause.DEDUP);
// Range and limit must be present after the de-duping construct
moveToLast(GremlinClause.RANGE);
moveToLast(GremlinClause.LIMIT);
}
if (!queryMetadata.hasLimitOffset()) {
addDefaultLimit();
}
......
......@@ -44,6 +44,7 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
@Guice(modules = TestModules.TestOnlyModule.class)
public class DSLQueriesTest extends BasicTestSetup {
......@@ -176,7 +177,8 @@ public class DSLQueriesTest extends BasicTestSetup {
{"Person where (age < 50)", 3},
{"Person where (age <= 35)", 2},
{"Person where (age = 35)", 0},
{"Person where (age != 35)", 4}
{"Person where (age != 35)", 4},
{"Person where (approximationOfPi > -3.4028235e+38)", 4},
};
}
......@@ -606,9 +608,19 @@ public class DSLQueriesTest extends BasicTestSetup {
{"hive_table select owner, columns"}, // Can't select a mix of immediate attribute and referred entity
{"hive_table select owner, db.name"}, // Same as above
{"hive_order"}, // From src should be an Entity or Classification
{"Person where (age > -3.4028235e+38)"} // comparing float with BigDecimal
};
}
@Test
public void testQuery() {
try {
discoveryService.searchUsingDslQuery("hive_table select db", DEFAULT_LIMIT, 0);
} catch (AtlasBaseException e) {
fail("Should've been a success");
}
}
@Test(dataProvider = "errorQueriesProvider", expectedExceptions = { AtlasBaseException.class })
public void errorQueries(String query) throws AtlasBaseException {
LOG.debug(query);
......
......@@ -53,6 +53,11 @@ public class AtlasBaseExceptionMapper implements ExceptionMapper<AtlasBaseExcept
AtlasErrorCode errorCode = baseException.getAtlasErrorCode();
errorJsonMap.put("errorCode", errorCode.getErrorCode());
errorJsonMap.put("errorMessage", baseException.getMessage());
if (baseException.getCause() != null) {
errorJsonMap.put("errorCause", baseException.getCause().getMessage());
}
Response.ResponseBuilder responseBuilder = Response.status(errorCode.getHttpCode());
// No body for 204 (and maybe 304)
......
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