Commit 7be3a6f7 by Ashutosh Mestry

ATLAS-3520: DSL Query special processing for '_'.

parent df85aa7a
......@@ -43,6 +43,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.TimeZone;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
......@@ -53,6 +54,7 @@ public class GremlinQueryComposer {
private static final Logger LOG = LoggerFactory.getLogger(GremlinQueryComposer.class);
private static final String ISO8601_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
private static final String ISO8601_DATE_FORMAT = "yyyy-MM-dd";
private static final String REGEX_ALPHA_NUMERIC_PATTERN = "[a-zA-Z0-9]+";
private static final ThreadLocal<DateFormat[]> DSL_DATE_FORMAT = ThreadLocal.withInitial(() -> {
final String formats[] = {ISO8601_FORMAT, ISO8601_DATE_FORMAT};
......@@ -197,7 +199,7 @@ public class GremlinQueryComposer {
final AtlasStructType.AtlasAttribute attribute = context.getActiveEntityType().getAttribute(lhsI.getAttributeName());
final AtlasStructDef.AtlasAttributeDef.IndexType indexType = attribute.getAttributeDef().getIndexType();
if (indexType == AtlasStructDef.AtlasAttributeDef.IndexType.STRING) {
if (indexType == AtlasStructDef.AtlasAttributeDef.IndexType.STRING || !containsNumberAndLettersOnly(rhs)) {
add(GremlinClause.STRING_CONTAINS, getPropertyForClause(lhsI), IdentifierHelper.getFixedRegEx(rhs));
} else {
add(GremlinClause.TEXT_CONTAINS, getPropertyForClause(lhsI), IdentifierHelper.getFixedRegEx(rhs));
......@@ -217,6 +219,10 @@ public class GremlinQueryComposer {
}
}
private boolean containsNumberAndLettersOnly(String rhs) {
return Pattern.matches(REGEX_ALPHA_NUMERIC_PATTERN, rhs);
}
private String parseNumber(String rhs, Context context) {
return rhs.replace("'", "").replace("\"", "") + context.getNumericTypeFormatter();
}
......
......@@ -462,6 +462,11 @@ public class DSLQueriesTest extends BasicTestSetup {
@DataProvider(name = "likeQueriesProvider")
private Object[][] likeQueries() {
return new Object[][]{
{"hive_table qualifiedName like \"*time_dim*\"", 1},
{"hive_db where qualifiedName like \"qualified:R*\"", 1},
{"hive_table db.name=\"Sales\"", 4},
{"hive_table qualifiedName =\"Sales.time_dim\" AND db.name=\"Sales\"", 1},
{"hive_table qualifiedName like \"*time_dim*\" AND db.name=\"Sales\"", 1},
{"hive_table where name like \"sa?es*\"", 3},
{"hive_db where name like \"R*\"", 1},
{"hive_db where hive_db.name like \"R???rt?*\" or hive_db.name like \"S?l?s\" or hive_db.name like\"Log*\"", 3},
......
......@@ -17,8 +17,6 @@
*/
package org.apache.atlas.query;
import afu.org.checkerframework.checker.igj.qual.I;
import jnr.ffi.annotations.In;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TypeCategory;
......@@ -171,6 +169,8 @@ public class GremlinQueryComposerTest {
"g.V().has('__typeName', 'Table').has('Asset.__s_name', org.janusgraph.core.attribute.Text.textRegex(\"Tab.*\")).dedup().limit(25).toList()");
verify("Table where owner like \"Tab*\"",
"g.V().has('__typeName', 'Table').has('Table.owner', org.janusgraph.core.attribute.Text.textContainsRegex(\"Tab.*\")).dedup().limit(25).toList()");
verify("Table where owner like \"*Tab_*\"",
"g.V().has('__typeName', 'Table').has('Table.owner', org.janusgraph.core.attribute.Text.textRegex(\".*Tab_.*\")).dedup().limit(25).toList()");
verify("from Table where (db.name = \"Reporting\")",
"g.V().has('__typeName', 'Table').out('__Table.db').has('DB.name', eq(\"Reporting\")).dedup().in('__Table.db').dedup().limit(25).toList()");
}
......
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