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
c9303742
Commit
c9303742
authored
Jan 09, 2018
by
Ashutosh Mestry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-2229: Improved date handling.
parent
212417c9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
34 deletions
+41
-34
GremlinQueryComposer.java
...ain/java/org/apache/atlas/query/GremlinQueryComposer.java
+36
-30
RegistryBasedLookup.java
...main/java/org/apache/atlas/query/RegistryBasedLookup.java
+3
-2
DSLQueriesTest.java
.../src/test/java/org/apache/atlas/query/DSLQueriesTest.java
+0
-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 @
c9303742
...
...
@@ -28,18 +28,17 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
javax.inject.Inject
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.text.DateFormat
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
java.util.stream.Collectors
;
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
final
int
DEFAULT_QUERY_RESULT_LIMIT
=
25
;
private
final
int
DEFAULT_QUERY_RESULT_OFFSET
=
0
;
...
...
@@ -51,19 +50,19 @@ 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
);
@Inject
public
GremlinQueryComposer
(
AtlasTypeRegistry
typeRegistry
,
final
AtlasDSL
.
QueryMetadata
qmd
)
{
isNestedQuery
=
false
;
lookup
=
new
RegistryBasedLookup
(
errorList
,
typeRegistry
);
this
.
context
=
new
Context
(
errorList
,
lookup
);
queryMetadata
=
qmd
;
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
();
}
public
GremlinQueryComposer
(
AtlasTypeRegistry
typeRegistry
,
final
AtlasDSL
.
QueryMetadata
queryMetadata
,
int
limit
,
int
offset
)
{
this
(
typeRegistry
,
queryMetadata
);
public
GremlinQueryComposer
(
AtlasTypeRegistry
typeRegistry
,
final
AtlasDSL
.
QueryMetadata
qmd
,
int
limit
,
int
offset
)
{
this
(
new
RegistryBasedLookup
(
typeRegistry
),
qmd
,
false
);
this
.
context
=
new
Context
(
errorList
,
lookup
);
providedLimit
=
limit
;
providedOffset
=
offset
<
0
?
DEFAULT_QUERY_RESULT_OFFSET
:
offset
;
...
...
@@ -75,14 +74,7 @@ public class GremlinQueryComposer {
this
.
lookup
=
lookup
;
this
.
context
=
context
;
this
.
queryMetadata
=
qmd
;
init
();
}
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
();
}
...
...
@@ -267,9 +259,15 @@ public class GremlinQueryComposer {
close
();
String
items
[]
=
getFormattedClauses
(
queryMetadata
.
needTransformation
());
return
queryMetadata
.
needTransformation
()
?
String
s
=
queryMetadata
.
needTransformation
()
?
getTransformedClauses
(
items
)
:
String
.
join
(
"."
,
items
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Gremlin: {}"
,
s
);
}
return
s
;
}
private
String
getTransformedClauses
(
String
[]
items
)
{
...
...
@@ -315,10 +313,6 @@ public class GremlinQueryComposer {
}
}
private
static
String
quoted
(
String
rhs
)
{
return
IdentifierHelper
.
getQuoted
(
rhs
);
}
private
void
addSelectTransformation
(
final
SelectClauseComposer
selectClauseComposer
)
{
GremlinClause
fn
;
if
(
selectClauseComposer
.
isSelectNoop
)
{
...
...
@@ -343,14 +337,26 @@ public class GremlinQueryComposer {
private
String
addQuotesIfNecessary
(
String
rhs
)
{
if
(
IdentifierHelper
.
isTrueOrFalse
(
rhs
))
return
rhs
;
if
(
IdentifierHelper
.
isQuoted
(
rhs
))
return
rhs
;
return
q
uoted
(
rhs
);
return
IdentifierHelper
.
getQ
uoted
(
rhs
);
}
private
String
parseDate
(
String
rhs
)
{
String
s
=
IdentifierHelper
.
isQuoted
(
rhs
)
?
IdentifierHelper
.
removeQuotes
(
rhs
)
:
rhs
;
return
String
.
format
(
"'%d'"
,
DateTime
.
parse
(
s
).
getMillis
());
return
String
.
format
(
"'%d'"
,
getDateFormat
(
s
));
}
public
long
getDateFormat
(
String
s
)
{
try
{
return
dateFormat
.
parse
(
s
).
getTime
();
}
catch
(
ParseException
ex
)
{
errorList
.
add
(
ex
.
getMessage
());
}
return
-
1
;
}
private
void
close
()
{
...
...
repository/src/main/java/org/apache/atlas/query/RegistryBasedLookup.java
View file @
c9303742
...
...
@@ -24,14 +24,15 @@ import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import
org.apache.atlas.type.*
;
import
org.apache.commons.lang.StringUtils
;
import
java.util.ArrayList
;
import
java.util.List
;
class
RegistryBasedLookup
implements
Lookup
{
private
final
List
<
String
>
errorList
;
private
final
AtlasTypeRegistry
typeRegistry
;
public
RegistryBasedLookup
(
List
<
String
>
errorList
,
AtlasTypeRegistry
typeRegistry
)
{
this
.
errorList
=
errorList
;
public
RegistryBasedLookup
(
AtlasTypeRegistry
typeRegistry
)
{
this
.
errorList
=
new
ArrayList
<>()
;
this
.
typeRegistry
=
typeRegistry
;
}
...
...
repository/src/test/java/org/apache/atlas/query/DSLQueriesTest.java
View file @
c9303742
This diff is collapsed.
Click to expand it.
repository/src/test/java/org/apache/atlas/query/GremlinQueryComposerTest.java
View file @
c9303742
...
...
@@ -137,9 +137,9 @@ public class GremlinQueryComposerTest {
String
exMain
=
"g.V().has('__typeName', 'DB').as('d').order().by('DB.owner').limit(25).toList()"
;
verify
(
"DB as d select d.name, d.owner orderby (d.owner) limit 25"
,
getExpected
(
exSel
,
exMain
));
String
exMain2
=
"g.V().has('__typeName', 'Table').and(__.has('Table.name', eq(\"sales_fact\")),__.has('Table.createTime', gt('1
3885632
00000'))).order().by('Table.createTime').limit(25).toList()"
;
String
exMain2
=
"g.V().has('__typeName', 'Table').and(__.has('Table.name', eq(\"sales_fact\")),__.has('Table.createTime', gt('1
4182653
00000'))).order().by('Table.createTime').limit(25).toList()"
;
String
exSel2
=
"def f(r){ t=[['_col_0','_col_1']]; r.each({t.add([it.value('Table.name'),it.value('Table.createTime')])}); t.unique(); }"
;
verify
(
"Table where (name = \"sales_fact\" and createTime > \"2014-
01-01
\" ) select name as _col_0, createTime as _col_1 orderby _col_1"
,
verify
(
"Table where (name = \"sales_fact\" and createTime > \"2014-
12-11T02:35:0.0Z
\" ) select name as _col_0, createTime as _col_1 orderby _col_1"
,
getExpected
(
exSel2
,
exMain2
));
}
...
...
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