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
7 years ago
by
Ashutosh Mestry
Committed by
apoorvnaik
7 years ago
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
master
No related merge requests found
Show 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;
...
@@ -68,6 +68,7 @@ import javax.script.Bindings;
import
javax.script.ScriptEngine
;
import
javax.script.ScriptEngine
;
import
javax.script.ScriptException
;
import
javax.script.ScriptException
;
import
java.util.*
;
import
java.util.*
;
import
java.util.stream.Stream
;
import
static
org
.
apache
.
atlas
.
AtlasErrorCode
.
CLASSIFICATION_NOT_FOUND
;
import
static
org
.
apache
.
atlas
.
AtlasErrorCode
.
CLASSIFICATION_NOT_FOUND
;
import
static
org
.
apache
.
atlas
.
AtlasErrorCode
.
DISCOVERY_QUERY_FAILED
;
import
static
org
.
apache
.
atlas
.
AtlasErrorCode
.
DISCOVERY_QUERY_FAILED
;
...
@@ -897,9 +898,7 @@ public class EntityDiscoveryService implements AtlasDiscoveryService {
...
@@ -897,9 +898,7 @@ public class EntityDiscoveryService implements AtlasDiscoveryService {
@Override
@Override
public
String
getDslQueryUsingTypeNameClassification
(
String
query
,
String
typeName
,
String
classification
)
{
public
String
getDslQueryUsingTypeNameClassification
(
String
query
,
String
typeName
,
String
classification
)
{
final
String
whereDSLKeyword
=
"where"
;
final
String
whereDSLKeyword
=
"where"
;
final
String
isaDSLKeyword
=
"isa"
;
final
String
[]
keywords
=
new
String
[]{
whereDSLKeyword
,
"isa"
,
"is"
,
"limit"
,
"orderby"
,
"has"
};
final
String
isDSLKeyword
=
"is"
;
final
String
limitDSLKeyword
=
"limit"
;
final
String
whereFormat
=
whereDSLKeyword
+
" %s"
;
final
String
whereFormat
=
whereDSLKeyword
+
" %s"
;
String
queryStr
=
query
==
null
?
""
:
query
;
String
queryStr
=
query
==
null
?
""
:
query
;
...
@@ -907,10 +906,7 @@ public class EntityDiscoveryService implements AtlasDiscoveryService {
...
@@ -907,10 +906,7 @@ public class EntityDiscoveryService implements AtlasDiscoveryService {
if
(
StringUtils
.
isNotEmpty
(
typeName
))
{
if
(
StringUtils
.
isNotEmpty
(
typeName
))
{
if
(
StringUtils
.
isNotEmpty
(
query
))
{
if
(
StringUtils
.
isNotEmpty
(
query
))
{
String
s
=
query
.
toLowerCase
();
String
s
=
query
.
toLowerCase
();
if
(!
s
.
startsWith
(
whereDSLKeyword
)
&&
if
(!
Stream
.
of
(
keywords
).
anyMatch
(
x
->
s
.
startsWith
(
x
)))
{
!
s
.
startsWith
(
limitDSLKeyword
)
&&
!
s
.
startsWith
(
isaDSLKeyword
)
&&
!
s
.
startsWith
(
isDSLKeyword
))
{
queryStr
=
String
.
format
(
whereFormat
,
query
);
queryStr
=
String
.
format
(
whereFormat
,
query
);
}
}
}
}
...
@@ -921,7 +917,7 @@ public class EntityDiscoveryService implements AtlasDiscoveryService {
...
@@ -921,7 +917,7 @@ public class EntityDiscoveryService implements AtlasDiscoveryService {
if
(
StringUtils
.
isNotEmpty
(
classification
))
{
if
(
StringUtils
.
isNotEmpty
(
classification
))
{
// isa works with a type name only - like hive_column isa PII; it doesn't work with more complex query
// isa works with a type name only - like hive_column isa PII; it doesn't work with more complex query
if
(
StringUtils
.
isEmpty
(
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
;
return
queryStr
;
...
...
This diff is collapsed.
Click to expand it.
repository/src/main/java/org/apache/atlas/query/GremlinQueryComposer.java
View file @
c6cc3314
...
@@ -38,7 +38,7 @@ import java.util.stream.Stream;
...
@@ -38,7 +38,7 @@ import java.util.stream.Stream;
public
class
GremlinQueryComposer
{
public
class
GremlinQueryComposer
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
GremlinQueryComposer
.
class
);
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_LIMIT
=
25
;
private
final
int
DEFAULT_QUERY_RESULT_OFFSET
=
0
;
private
final
int
DEFAULT_QUERY_RESULT_OFFSET
=
0
;
...
@@ -50,13 +50,22 @@ public class GremlinQueryComposer {
...
@@ -50,13 +50,22 @@ public class GremlinQueryComposer {
private
int
providedLimit
=
DEFAULT_QUERY_RESULT_LIMIT
;
private
int
providedLimit
=
DEFAULT_QUERY_RESULT_LIMIT
;
private
int
providedOffset
=
DEFAULT_QUERY_RESULT_OFFSET
;
private
int
providedOffset
=
DEFAULT_QUERY_RESULT_OFFSET
;
private
Context
context
;
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
)
{
public
GremlinQueryComposer
(
Lookup
registryLookup
,
final
AtlasDSL
.
QueryMetadata
qmd
,
boolean
isNestedQuery
)
{
this
.
isNestedQuery
=
isNestedQuery
;
this
.
isNestedQuery
=
isNestedQuery
;
this
.
lookup
=
registryLookup
;
this
.
lookup
=
registryLookup
;
this
.
queryMetadata
=
qmd
;
this
.
queryMetadata
=
qmd
;
dateFormat
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"UTC"
));
init
();
init
();
}
}
...
@@ -74,7 +83,6 @@ public class GremlinQueryComposer {
...
@@ -74,7 +83,6 @@ public class GremlinQueryComposer {
this
.
lookup
=
lookup
;
this
.
lookup
=
lookup
;
this
.
context
=
context
;
this
.
context
=
context
;
this
.
queryMetadata
=
qmd
;
this
.
queryMetadata
=
qmd
;
dateFormat
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"UTC"
));
init
();
init
();
}
}
...
@@ -351,7 +359,7 @@ public class GremlinQueryComposer {
...
@@ -351,7 +359,7 @@ public class GremlinQueryComposer {
public
long
getDateFormat
(
String
s
)
{
public
long
getDateFormat
(
String
s
)
{
try
{
try
{
return
dateFormat
.
parse
(
s
).
getTime
();
return
DSL_DATE_FORMAT
.
get
()
.
parse
(
s
).
getTime
();
}
catch
(
ParseException
ex
)
{
}
catch
(
ParseException
ex
)
{
errorList
.
add
(
ex
.
getMessage
());
errorList
.
add
(
ex
.
getMessage
());
}
}
...
...
This diff is collapsed.
Click to expand it.
repository/src/main/java/org/apache/atlas/query/antlr4/AtlasDSLLexer.g4
View file @
c6cc3314
...
@@ -121,8 +121,6 @@ K_SUM: S U M ;
...
@@ -121,8 +121,6 @@ K_SUM: S U M ;
K_COUNT: C O U N T ;
K_COUNT: C O U N T ;
K_LOOP: L O O P ;
K_OFFSET: O F F S E T ;
K_OFFSET: O F F S E T ;
K_AS: A S ;
K_AS: A S ;
...
@@ -137,8 +135,6 @@ K_ASC: A S C ;
...
@@ -137,8 +135,6 @@ K_ASC: A S C ;
K_DESC: D E 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_TRUE: T R U E ;
K_FALSE: F A L S E ;
K_FALSE: F A L S E ;
...
@@ -158,12 +154,10 @@ KEYWORD: K_LIKE
...
@@ -158,12 +154,10 @@ KEYWORD: K_LIKE
| K_OR
| K_OR
| K_GROUPBY
| K_GROUPBY
| K_ORDERBY
| K_ORDERBY
| K_WITHPATH
| K_SUM
| K_SUM
| K_MIN
| K_MIN
| K_MAX
| K_MAX
| K_OFFSET
| K_OFFSET
| K_LOOP
| K_FROM
| K_FROM
| K_DESC
| K_DESC
| K_ASC
| K_ASC
...
...
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