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
7be3a6f7
Commit
7be3a6f7
authored
Nov 21, 2019
by
Ashutosh Mestry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-3520: DSL Query special processing for '_'.
parent
df85aa7a
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
3 deletions
+14
-3
GremlinQueryComposer.java
...ain/java/org/apache/atlas/query/GremlinQueryComposer.java
+7
-1
DSLQueriesTest.java
.../src/test/java/org/apache/atlas/query/DSLQueriesTest.java
+5
-0
GremlinQueryComposerTest.java
...java/org/apache/atlas/query/GremlinQueryComposerTest.java
+2
-2
No files found.
repository/src/main/java/org/apache/atlas/query/GremlinQueryComposer.java
View file @
7be3a6f7
...
...
@@ -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
();
}
...
...
repository/src/test/java/org/apache/atlas/query/DSLQueriesTest.java
View file @
7be3a6f7
...
...
@@ -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
},
...
...
repository/src/test/java/org/apache/atlas/query/GremlinQueryComposerTest.java
View file @
7be3a6f7
...
...
@@ -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()"
);
}
...
...
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