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
7 years ago
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
master
No related merge requests found
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
23 deletions
+37
-23
GremlinQueryComposer.java
...ain/java/org/apache/atlas/query/GremlinQueryComposer.java
+16
-7
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 {
...
@@ -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
{
...
...
This diff is collapsed.
Click to expand it.
repository/src/main/java/org/apache/atlas/query/RegistryBasedLookup.java
View file @
8d1e7223
...
@@ -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
;
}
}
}
}
This diff is collapsed.
Click to expand it.
repository/src/test/java/org/apache/atlas/query/DSLQueriesTest.java
View file @
8d1e7223
...
@@ -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
};
};
}
}
...
...
This diff is collapsed.
Click to expand it.
repository/src/test/java/org/apache/atlas/query/GremlinQueryComposerTest.java
View file @
8d1e7223
...
@@ -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(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
)),__.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(2048
f)),__.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"
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
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