Commit 8d1e7223 by Ashutosh Mestry

ATLAS-2532: Advanced Search: Literals with MAX_VALUEs in Queries

parent bc57e15e
...@@ -168,7 +168,7 @@ public class GremlinQueryComposer { ...@@ -168,7 +168,7 @@ public class GremlinQueryComposer {
if (lhsI.isDate()) { if (lhsI.isDate()) {
rhs = parseDate(rhs); rhs = parseDate(rhs);
} else if (lhsI.isNumeric()) { } else if (lhsI.isNumeric()) {
rhs = parseNumber(rhs); rhs = parseNumber(rhs, this.context);
} }
rhs = addQuotesIfNecessary(lhsI, rhs); rhs = addQuotesIfNecessary(lhsI, rhs);
...@@ -190,8 +190,8 @@ public class GremlinQueryComposer { ...@@ -190,8 +190,8 @@ public class GremlinQueryComposer {
} }
} }
private String parseNumber(String rhs) { private String parseNumber(String rhs, Context context) {
return rhs.replace("'", "").replace("\"", ""); return rhs.replace("'", "").replace("\"", "") + context.getNumericTypeFormatter();
} }
public void addAndClauses(List<String> clauses) { public void addAndClauses(List<String> clauses) {
...@@ -622,10 +622,11 @@ public class GremlinQueryComposer { ...@@ -622,10 +622,11 @@ public class GremlinQueryComposer {
private static final AtlasStructType UNKNOWN_TYPE = new AtlasStructType(new AtlasStructDef()); private static final AtlasStructType UNKNOWN_TYPE = new AtlasStructType(new AtlasStructDef());
private final Lookup lookup; private final Lookup lookup;
private final Map<String, String> aliasMap = new HashMap<>(); private final Map<String, String> aliasMap = new HashMap<>();
private AtlasType activeType; private AtlasType activeType;
private SelectClauseComposer selectClauseComposer; private SelectClauseComposer selectClauseComposer;
private ClauseValidator validator; private ClauseValidator validator;
private String numericTypeFormatter = "";
public Context(Lookup lookup) { public Context(Lookup lookup) {
this.lookup = lookup; this.lookup = lookup;
...@@ -717,6 +718,14 @@ public class GremlinQueryComposer { ...@@ -717,6 +718,14 @@ public class GremlinQueryComposer {
public boolean check(boolean condition, AtlasErrorCode vm, String... args) { public boolean check(boolean condition, AtlasErrorCode vm, String... args) {
return validator.check(condition, vm, args); return validator.check(condition, vm, args);
} }
public void setNumericTypeFormatter(String formatter) {
this.numericTypeFormatter = formatter;
}
public String getNumericTypeFormatter() {
return this.numericTypeFormatter;
}
} }
private static class ClauseValidator { private static class ClauseValidator {
......
...@@ -25,9 +25,7 @@ import org.apache.atlas.repository.Constants; ...@@ -25,9 +25,7 @@ import org.apache.atlas.repository.Constants;
import org.apache.atlas.type.*; import org.apache.atlas.type.*;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import java.util.Arrays; import java.util.*;
import java.util.HashSet;
import java.util.Set;
class RegistryBasedLookup implements Lookup { class RegistryBasedLookup implements Lookup {
private static final Set<String> SYSTEM_ATTRIBUTES = new HashSet<>( private static final Set<String> SYSTEM_ATTRIBUTES = new HashSet<>(
...@@ -38,14 +36,15 @@ class RegistryBasedLookup implements Lookup { ...@@ -38,14 +36,15 @@ class RegistryBasedLookup implements Lookup {
Constants.TIMESTAMP_PROPERTY_KEY, Constants.TIMESTAMP_PROPERTY_KEY,
Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY)); Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY));
private static final Set<String> NUMERIC_ATTRIBUTES = new HashSet<>( private static final Map<String, String> NUMERIC_ATTRIBUTES = new HashMap<String, String>() {{
Arrays.asList(AtlasBaseTypeDef.ATLAS_TYPE_SHORT, put(AtlasBaseTypeDef.ATLAS_TYPE_SHORT, "");
AtlasBaseTypeDef.ATLAS_TYPE_INT, put(AtlasBaseTypeDef.ATLAS_TYPE_INT, "");
AtlasBaseTypeDef.ATLAS_TYPE_LONG, put(AtlasBaseTypeDef.ATLAS_TYPE_LONG, "L");
AtlasBaseTypeDef.ATLAS_TYPE_FLOAT, put(AtlasBaseTypeDef.ATLAS_TYPE_FLOAT, "f");
AtlasBaseTypeDef.ATLAS_TYPE_DOUBLE, put(AtlasBaseTypeDef.ATLAS_TYPE_DOUBLE, "d");
AtlasBaseTypeDef.ATLAS_TYPE_BIGINTEGER, put(AtlasBaseTypeDef.ATLAS_TYPE_BIGINTEGER, "");
AtlasBaseTypeDef.ATLAS_TYPE_BIGDECIMAL)); put(AtlasBaseTypeDef.ATLAS_TYPE_BIGDECIMAL, "");
}};
private final AtlasTypeRegistry typeRegistry; private final AtlasTypeRegistry typeRegistry;
...@@ -220,6 +219,11 @@ class RegistryBasedLookup implements Lookup { ...@@ -220,6 +219,11 @@ class RegistryBasedLookup implements Lookup {
} }
AtlasType attr = et.getAttributeType(attrName); AtlasType attr = et.getAttributeType(attrName);
return attr != null && NUMERIC_ATTRIBUTES.contains(attr.getTypeName()); boolean ret = attr != null && NUMERIC_ATTRIBUTES.containsKey(attr.getTypeName());
if(ret) {
context.setNumericTypeFormatter(NUMERIC_ATTRIBUTES.get(attr.getTypeName()));
}
return ret;
} }
} }
...@@ -178,6 +178,7 @@ public class DSLQueriesTest extends BasicTestSetup { ...@@ -178,6 +178,7 @@ public class DSLQueriesTest extends BasicTestSetup {
{"Person where (age <= 35)", 2}, {"Person where (age <= 35)", 2},
{"Person where (age = 35)", 0}, {"Person where (age = 35)", 0},
{"Person where (age != 35)", 4}, {"Person where (age != 35)", 4},
{String.format("Person where (age <= %f)", Float.MAX_VALUE), 4},
{"Person where (approximationOfPi > -3.4028235e+38)", 4}, {"Person where (approximationOfPi > -3.4028235e+38)", 4},
}; };
} }
...@@ -607,8 +608,7 @@ public class DSLQueriesTest extends BasicTestSetup { ...@@ -607,8 +608,7 @@ public class DSLQueriesTest extends BasicTestSetup {
{"hive_table select db.name, columns"}, // Can't select more than one referred attribute {"hive_table select db.name, columns"}, // Can't select more than one referred attribute
{"hive_table select owner, columns"}, // Can't select a mix of immediate attribute and referred entity {"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_table select owner, db.name"}, // Same as above
{"hive_order"}, // From src should be an Entity or Classification {"hive_order"} // From src should be an Entity or Classification
{"Person where (age > -3.4028235e+38)"} // comparing float with BigDecimal
}; };
} }
......
...@@ -309,8 +309,8 @@ public class GremlinQueryComposerTest { ...@@ -309,8 +309,8 @@ public class GremlinQueryComposerTest {
@Test @Test
public void numericAttributes() { public void numericAttributes() {
verify("Table where partitionSize = 2048", "g.V().has('__typeName', 'Table').has('Table.partitionSize', eq(2048)).dedup().limit(25).toList()"); verify("Table where partitionSize = 2048", "g.V().has('__typeName', 'Table').has('Table.partitionSize', eq(2048f)).dedup().limit(25).toList()");
verify("Table where partitionSize = 2048 or partitionSize = 10", "g.V().has('__typeName', 'Table').or(__.has('Table.partitionSize', eq(2048)),__.has('Table.partitionSize', eq(10))).dedup().limit(25).toList()"); verify("Table where partitionSize = 2048 or partitionSize = 10", "g.V().has('__typeName', 'Table').or(__.has('Table.partitionSize', eq(2048f)),__.has('Table.partitionSize', eq(10f))).dedup().limit(25).toList()");
} }
@Test @Test
...@@ -527,6 +527,7 @@ public class GremlinQueryComposerTest { ...@@ -527,6 +527,7 @@ public class GremlinQueryComposerTest {
@Override @Override
public boolean isNumeric(GremlinQueryComposer.Context context, String attrName) { public boolean isNumeric(GremlinQueryComposer.Context context, String attrName) {
context.setNumericTypeFormatter("f");
return attrName.equals("partitionSize"); return attrName.equals("partitionSize");
} }
} }
......
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