You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by ap...@apache.org on 2018/01/10 22:22:56 UTC
[2/2] atlas git commit: ATLAS-2229: Added thread-safety for
SimpleDateFormat.
ATLAS-2229: Added thread-safety for SimpleDateFormat.
ATLAS-2229: Modified approach for detecting keywords. Removed unused keywords.
Signed-off-by: apoorvnaik <ap...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/c6cc3314
Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/c6cc3314
Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/c6cc3314
Branch: refs/heads/master
Commit: c6cc3314f234c87f856f928f2bdf1e2a935df5a2
Parents: 5c92592
Author: Ashutosh Mestry <am...@hortonworks.com>
Authored: Wed Jan 10 08:18:40 2018 -0800
Committer: apoorvnaik <ap...@apache.org>
Committed: Wed Jan 10 14:21:38 2018 -0800
----------------------------------------------------------------------
.../atlas/discovery/EntityDiscoveryService.java | 12 ++++--------
.../apache/atlas/query/GremlinQueryComposer.java | 18 +++++++++++++-----
.../apache/atlas/query/antlr4/AtlasDSLLexer.g4 | 6 ------
3 files changed, 17 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/atlas/blob/c6cc3314/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java b/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java
index ab69fe7..ba00782 100644
--- a/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java
+++ b/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java
@@ -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;
http://git-wip-us.apache.org/repos/asf/atlas/blob/c6cc3314/repository/src/main/java/org/apache/atlas/query/GremlinQueryComposer.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/query/GremlinQueryComposer.java b/repository/src/main/java/org/apache/atlas/query/GremlinQueryComposer.java
index 34a0842..6ccd44c 100644
--- a/repository/src/main/java/org/apache/atlas/query/GremlinQueryComposer.java
+++ b/repository/src/main/java/org/apache/atlas/query/GremlinQueryComposer.java
@@ -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());
}
http://git-wip-us.apache.org/repos/asf/atlas/blob/c6cc3314/repository/src/main/java/org/apache/atlas/query/antlr4/AtlasDSLLexer.g4
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/query/antlr4/AtlasDSLLexer.g4 b/repository/src/main/java/org/apache/atlas/query/antlr4/AtlasDSLLexer.g4
index 376dcea..15d1bb4 100644
--- a/repository/src/main/java/org/apache/atlas/query/antlr4/AtlasDSLLexer.g4
+++ b/repository/src/main/java/org/apache/atlas/query/antlr4/AtlasDSLLexer.g4
@@ -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