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
c6cc3314
Commit
c6cc3314
authored
Jan 10, 2018
by
Ashutosh Mestry
Committed by
apoorvnaik
Jan 10, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-2229: Added thread-safety for SimpleDateFormat.
ATLAS-2229: Modified approach for detecting keywords. Removed unused keywords. Signed-off-by:
apoorvnaik
<
apoorvnaik@apache.org
>
parent
5c925920
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
19 deletions
+17
-19
EntityDiscoveryService.java
...va/org/apache/atlas/discovery/EntityDiscoveryService.java
+4
-8
GremlinQueryComposer.java
...ain/java/org/apache/atlas/query/GremlinQueryComposer.java
+13
-5
AtlasDSLLexer.g4
.../main/java/org/apache/atlas/query/antlr4/AtlasDSLLexer.g4
+0
-6
No files found.
repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java
View file @
c6cc3314
...
...
@@ -68,6 +68,7 @@ import javax.script.Bindings;
import
javax.script.ScriptEngine
;
import
javax.script.ScriptException
;
import
java.util.*
;
import
java.util.stream.Stream
;
import
static
org
.
apache
.
atlas
.
AtlasErrorCode
.
CLASSIFICATION_NOT_FOUND
;
import
static
org
.
apache
.
atlas
.
AtlasErrorCode
.
DISCOVERY_QUERY_FAILED
;
...
...
@@ -897,9 +898,7 @@ public class EntityDiscoveryService implements AtlasDiscoveryService {
@Override
public
String
getDslQueryUsingTypeNameClassification
(
String
query
,
String
typeName
,
String
classification
)
{
final
String
whereDSLKeyword
=
"where"
;
final
String
isaDSLKeyword
=
"isa"
;
final
String
isDSLKeyword
=
"is"
;
final
String
limitDSLKeyword
=
"limit"
;
final
String
[]
keywords
=
new
String
[]{
whereDSLKeyword
,
"isa"
,
"is"
,
"limit"
,
"orderby"
,
"has"
};
final
String
whereFormat
=
whereDSLKeyword
+
" %s"
;
String
queryStr
=
query
==
null
?
""
:
query
;
...
...
@@ -907,10 +906,7 @@ public class EntityDiscoveryService implements AtlasDiscoveryService {
if
(
StringUtils
.
isNotEmpty
(
typeName
))
{
if
(
StringUtils
.
isNotEmpty
(
query
))
{
String
s
=
query
.
toLowerCase
();
if
(!
s
.
startsWith
(
whereDSLKeyword
)
&&
!
s
.
startsWith
(
limitDSLKeyword
)
&&
!
s
.
startsWith
(
isaDSLKeyword
)
&&
!
s
.
startsWith
(
isDSLKeyword
))
{
if
(!
Stream
.
of
(
keywords
).
anyMatch
(
x
->
s
.
startsWith
(
x
)))
{
queryStr
=
String
.
format
(
whereFormat
,
query
);
}
}
...
...
@@ -921,7 +917,7 @@ public class EntityDiscoveryService implements AtlasDiscoveryService {
if
(
StringUtils
.
isNotEmpty
(
classification
))
{
// isa works with a type name only - like hive_column isa PII; it doesn't work with more complex query
if
(
StringUtils
.
isEmpty
(
query
))
{
queryStr
+=
String
.
format
(
"%s %s %s"
,
queryStr
,
isaDSLKeyword
,
classification
);
queryStr
+=
String
.
format
(
"%s %s %s"
,
queryStr
,
"isa"
,
classification
);
}
}
return
queryStr
;
...
...
repository/src/main/java/org/apache/atlas/query/GremlinQueryComposer.java
View file @
c6cc3314
...
...
@@ -38,7 +38,7 @@ import java.util.stream.Stream;
public
class
GremlinQueryComposer
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
GremlinQueryComposer
.
class
);
private
final
String
DATE_FORMAT_
ISO8601_FORMAT
=
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
;
private
static
final
String
ISO8601_FORMAT
=
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
;
private
final
int
DEFAULT_QUERY_RESULT_LIMIT
=
25
;
private
final
int
DEFAULT_QUERY_RESULT_OFFSET
=
0
;
...
...
@@ -50,13 +50,22 @@ public class GremlinQueryComposer {
private
int
providedLimit
=
DEFAULT_QUERY_RESULT_LIMIT
;
private
int
providedOffset
=
DEFAULT_QUERY_RESULT_OFFSET
;
private
Context
context
;
private
final
DateFormat
dateFormat
=
new
SimpleDateFormat
(
DATE_FORMAT_ISO8601_FORMAT
);
private
static
final
ThreadLocal
<
DateFormat
>
DSL_DATE_FORMAT
=
new
ThreadLocal
<
DateFormat
>()
{
@Override
public
DateFormat
initialValue
()
{
DateFormat
ret
=
new
SimpleDateFormat
(
ISO8601_FORMAT
);
ret
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"UTC"
));
return
ret
;
}
};
public
GremlinQueryComposer
(
Lookup
registryLookup
,
final
AtlasDSL
.
QueryMetadata
qmd
,
boolean
isNestedQuery
)
{
this
.
isNestedQuery
=
isNestedQuery
;
this
.
lookup
=
registryLookup
;
this
.
queryMetadata
=
qmd
;
dateFormat
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"UTC"
));
init
();
}
...
...
@@ -74,7 +83,6 @@ public class GremlinQueryComposer {
this
.
lookup
=
lookup
;
this
.
context
=
context
;
this
.
queryMetadata
=
qmd
;
dateFormat
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"UTC"
));
init
();
}
...
...
@@ -351,7 +359,7 @@ public class GremlinQueryComposer {
public
long
getDateFormat
(
String
s
)
{
try
{
return
dateFormat
.
parse
(
s
).
getTime
();
return
DSL_DATE_FORMAT
.
get
()
.
parse
(
s
).
getTime
();
}
catch
(
ParseException
ex
)
{
errorList
.
add
(
ex
.
getMessage
());
}
...
...
repository/src/main/java/org/apache/atlas/query/antlr4/AtlasDSLLexer.g4
View file @
c6cc3314
...
...
@@ -121,8 +121,6 @@ K_SUM: S U M ;
K_COUNT: C O U N T ;
K_LOOP: L O O P ;
K_OFFSET: O F F S E T ;
K_AS: A S ;
...
...
@@ -137,8 +135,6 @@ K_ASC: A S C ;
K_DESC: D E S C ;
K_WITHPATH: W I T H P A T H ;
K_TRUE: T R U E ;
K_FALSE: F A L S E ;
...
...
@@ -158,12 +154,10 @@ KEYWORD: K_LIKE
| K_OR
| K_GROUPBY
| K_ORDERBY
| K_WITHPATH
| K_SUM
| K_MIN
| K_MAX
| K_OFFSET
| K_LOOP
| K_FROM
| K_DESC
| K_ASC
...
...
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