Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
atlas
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dataplatform
atlas
Commits
8d1e7223
Commit
8d1e7223
authored
Apr 09, 2018
by
Ashutosh Mestry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-2532: Advanced Search: Literals with MAX_VALUEs in Queries
parent
bc57e15e
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
19 deletions
+33
-19
GremlinQueryComposer.java
...ain/java/org/apache/atlas/query/GremlinQueryComposer.java
+12
-3
RegistryBasedLookup.java
...main/java/org/apache/atlas/query/RegistryBasedLookup.java
+16
-12
DSLQueriesTest.java
.../src/test/java/org/apache/atlas/query/DSLQueriesTest.java
+2
-2
GremlinQueryComposerTest.java
...java/org/apache/atlas/query/GremlinQueryComposerTest.java
+3
-2
No files found.
repository/src/main/java/org/apache/atlas/query/GremlinQueryComposer.java
View file @
8d1e7223
...
...
@@ -168,7 +168,7 @@ public class GremlinQueryComposer {
if
(
lhsI
.
isDate
())
{
rhs
=
parseDate
(
rhs
);
}
else
if
(
lhsI
.
isNumeric
())
{
rhs
=
parseNumber
(
rhs
);
rhs
=
parseNumber
(
rhs
,
this
.
context
);
}
rhs
=
addQuotesIfNecessary
(
lhsI
,
rhs
);
...
...
@@ -190,8 +190,8 @@ public class GremlinQueryComposer {
}
}
private
String
parseNumber
(
String
rhs
)
{
return
rhs
.
replace
(
"'"
,
""
).
replace
(
"\""
,
""
);
private
String
parseNumber
(
String
rhs
,
Context
context
)
{
return
rhs
.
replace
(
"'"
,
""
).
replace
(
"\""
,
""
)
+
context
.
getNumericTypeFormatter
()
;
}
public
void
addAndClauses
(
List
<
String
>
clauses
)
{
...
...
@@ -626,6 +626,7 @@ public class GremlinQueryComposer {
private
AtlasType
activeType
;
private
SelectClauseComposer
selectClauseComposer
;
private
ClauseValidator
validator
;
private
String
numericTypeFormatter
=
""
;
public
Context
(
Lookup
lookup
)
{
this
.
lookup
=
lookup
;
...
...
@@ -717,6 +718,14 @@ public class GremlinQueryComposer {
public
boolean
check
(
boolean
condition
,
AtlasErrorCode
vm
,
String
...
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
{
...
...
repository/src/main/java/org/apache/atlas/query/RegistryBasedLookup.java
View file @
8d1e7223
...
...
@@ -25,9 +25,7 @@ import org.apache.atlas.repository.Constants;
import
org.apache.atlas.type.*
;
import
org.apache.commons.lang.StringUtils
;
import
java.util.Arrays
;
import
java.util.HashSet
;
import
java.util.Set
;
import
java.util.*
;
class
RegistryBasedLookup
implements
Lookup
{
private
static
final
Set
<
String
>
SYSTEM_ATTRIBUTES
=
new
HashSet
<>(
...
...
@@ -38,14 +36,15 @@ class RegistryBasedLookup implements Lookup {
Constants
.
TIMESTAMP_PROPERTY_KEY
,
Constants
.
MODIFICATION_TIMESTAMP_PROPERTY_KEY
));
private
static
final
Set
<
String
>
NUMERIC_ATTRIBUTES
=
new
HashSet
<>(
Arrays
.
asList
(
AtlasBaseTypeDef
.
ATLAS_TYPE_SHORT
,
AtlasBaseTypeDef
.
ATLAS_TYPE_INT
,
AtlasBaseTypeDef
.
ATLAS_TYPE_LONG
,
AtlasBaseTypeDef
.
ATLAS_TYPE_FLOAT
,
AtlasBaseTypeDef
.
ATLAS_TYPE_DOUBLE
,
AtlasBaseTypeDef
.
ATLAS_TYPE_BIGINTEGER
,
AtlasBaseTypeDef
.
ATLAS_TYPE_BIGDECIMAL
));
private
static
final
Map
<
String
,
String
>
NUMERIC_ATTRIBUTES
=
new
HashMap
<
String
,
String
>()
{{
put
(
AtlasBaseTypeDef
.
ATLAS_TYPE_SHORT
,
""
);
put
(
AtlasBaseTypeDef
.
ATLAS_TYPE_INT
,
""
);
put
(
AtlasBaseTypeDef
.
ATLAS_TYPE_LONG
,
"L"
);
put
(
AtlasBaseTypeDef
.
ATLAS_TYPE_FLOAT
,
"f"
);
put
(
AtlasBaseTypeDef
.
ATLAS_TYPE_DOUBLE
,
"d"
);
put
(
AtlasBaseTypeDef
.
ATLAS_TYPE_BIGINTEGER
,
""
);
put
(
AtlasBaseTypeDef
.
ATLAS_TYPE_BIGDECIMAL
,
""
);
}};
private
final
AtlasTypeRegistry
typeRegistry
;
...
...
@@ -220,6 +219,11 @@ class RegistryBasedLookup implements Lookup {
}
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
;
}
}
repository/src/test/java/org/apache/atlas/query/DSLQueriesTest.java
View file @
8d1e7223
...
...
@@ -178,6 +178,7 @@ public class DSLQueriesTest extends BasicTestSetup {
{
"Person where (age <= 35)"
,
2
},
{
"Person where (age = 35)"
,
0
},
{
"Person where (age != 35)"
,
4
},
{
String
.
format
(
"Person where (age <= %f)"
,
Float
.
MAX_VALUE
),
4
},
{
"Person where (approximationOfPi > -3.4028235e+38)"
,
4
},
};
}
...
...
@@ -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 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
{
"hive_order"
}
// From src should be an Entity or Classification
};
}
...
...
repository/src/test/java/org/apache/atlas/query/GremlinQueryComposerTest.java
View file @
8d1e7223
...
...
@@ -309,8 +309,8 @@ public class GremlinQueryComposerTest {
@Test
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 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"
,
"g.V().has('__typeName', 'Table').has('Table.partitionSize', eq(2048
f
)).dedup().limit(25).toList()"
);
verify
(
"Table where partitionSize = 2048 or partitionSize = 10"
,
"g.V().has('__typeName', 'Table').or(__.has('Table.partitionSize', eq(2048
f)),__.has('Table.partitionSize', eq(10f
))).dedup().limit(25).toList()"
);
}
@Test
...
...
@@ -527,6 +527,7 @@ public class GremlinQueryComposerTest {
@Override
public
boolean
isNumeric
(
GremlinQueryComposer
.
Context
context
,
String
attrName
)
{
context
.
setNumericTypeFormatter
(
"f"
);
return
attrName
.
equals
(
"partitionSize"
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment