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
ba4df832
Commit
ba4df832
authored
Jan 31, 2018
by
Ashutosh Mestry
Committed by
apoorvnaik
Jan 31, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-2430: Addressed close for nested queries.
Signed-off-by:
apoorvnaik
<
apoorvnaik@apache.org
>
parent
134d60fb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
56 deletions
+62
-56
GremlinQueryComposer.java
...ain/java/org/apache/atlas/query/GremlinQueryComposer.java
+45
-48
IdentifierHelper.java
...rc/main/java/org/apache/atlas/query/IdentifierHelper.java
+8
-8
DSLQueriesTest.java
.../src/test/java/org/apache/atlas/query/DSLQueriesTest.java
+1
-0
GremlinQueryComposerTest.java
...java/org/apache/atlas/query/GremlinQueryComposerTest.java
+8
-0
No files found.
repository/src/main/java/org/apache/atlas/query/GremlinQueryComposer.java
View file @
ba4df832
...
...
@@ -50,22 +50,22 @@ 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
ThreadLocal
<
DateFormat
[]>
DSL_DATE_FORMAT
=
ThreadLocal
.
withInitial
(()
->
{
final
String
formats
[]
=
{
ISO8601_FORMAT
,
ISO8601_DATE_FORMAT
};
DateFormat
[]
dfs
=
new
DateFormat
[
formats
.
length
];
DateFormat
[]
dfs
=
new
DateFormat
[
formats
.
length
];
for
(
int
i
=
0
;
i
<
formats
.
length
;
i
++)
{
dfs
[
i
]
=
new
SimpleDateFormat
(
formats
[
i
]);
dfs
[
i
].
setTimeZone
(
TimeZone
.
getTimeZone
(
"UTC"
));
}
}
return
dfs
;
});
private
final
String
EMPTY_STRING
=
""
;
private
final
int
DEFAULT_QUERY_RESULT_LIMIT
=
25
;
private
final
int
DEFAULT_QUERY_RESULT_OFFSET
=
0
;
private
final
GremlinClauseList
queryClauses
=
new
GremlinClauseList
();
private
final
Set
<
String
>
attributesProcessed
=
new
HashSet
<>();
private
final
String
EMPTY_STRING
=
""
;
private
final
int
DEFAULT_QUERY_RESULT_LIMIT
=
25
;
private
final
int
DEFAULT_QUERY_RESULT_OFFSET
=
0
;
private
final
GremlinClauseList
queryClauses
=
new
GremlinClauseList
();
private
final
Set
<
String
>
attributesProcessed
=
new
HashSet
<>();
private
final
Lookup
lookup
;
private
final
boolean
isNestedQuery
;
private
final
AtlasDSL
.
QueryMetadata
queryMetadata
;
...
...
@@ -104,12 +104,12 @@ public class GremlinQueryComposer {
LOG
.
debug
(
"addFrom(typeName={})"
,
typeName
);
}
IdentifierHelper
.
I
dentifierMetadata
ta
=
getIdMetadata
(
typeName
);
IdentifierHelper
.
I
nfo
typeInfo
=
createInfo
(
typeName
);
if
(
context
.
shouldRegister
(
t
a
.
get
()))
{
context
.
registerActive
(
t
a
.
get
());
if
(
context
.
shouldRegister
(
t
ypeInfo
.
get
()))
{
context
.
registerActive
(
t
ypeInfo
.
get
());
IdentifierHelper
.
I
dentifierMetadata
ia
=
getIdMetadata
(
ta
.
get
());
IdentifierHelper
.
I
nfo
ia
=
createInfo
(
typeInfo
.
get
());
if
(
ia
.
isTrait
())
{
add
(
GremlinClause
.
TRAIT
,
ia
);
...
...
@@ -121,7 +121,7 @@ public class GremlinQueryComposer {
}
}
}
else
{
IdentifierHelper
.
I
dentifierMetadata
ia
=
getIdMetadata
(
ta
.
get
());
IdentifierHelper
.
I
nfo
ia
=
createInfo
(
typeInfo
.
get
());
introduceType
(
ia
);
}
}
...
...
@@ -135,7 +135,7 @@ public class GremlinQueryComposer {
addFrom
(
typeName
);
}
add
(
GremlinClause
.
HAS_PROPERTY
,
getIdMetadata
(
attribute
));
add
(
GremlinClause
.
HAS_PROPERTY
,
createInfo
(
attribute
));
}
public
void
addIsA
(
String
typeName
,
String
traitName
)
{
...
...
@@ -143,8 +143,8 @@ public class GremlinQueryComposer {
addFrom
(
typeName
);
}
IdentifierHelper
.
I
dentifierMetadata
ia
=
getIdMetadata
(
traitName
);
add
(
GremlinClause
.
TRAIT
,
ia
);
IdentifierHelper
.
I
nfo
traitInfo
=
createInfo
(
traitName
);
add
(
GremlinClause
.
TRAIT
,
traitInfo
);
}
public
void
addWhere
(
String
lhs
,
String
operator
,
String
rhs
)
{
...
...
@@ -152,13 +152,13 @@ public class GremlinQueryComposer {
LOG
.
debug
(
"addWhere(lhs={}, operator={}, rhs={})"
,
lhs
,
operator
,
rhs
);
}
String
currentType
=
context
.
getActiveTypeName
();
IdentifierHelper
.
I
dentifierMetadata
org
=
null
;
IdentifierHelper
.
I
dentifierMetadata
lhsI
=
getIdMetadata
(
lhs
);
String
currentType
=
context
.
getActiveTypeName
();
IdentifierHelper
.
I
nfo
org
=
null
;
IdentifierHelper
.
I
nfo
lhsI
=
createInfo
(
lhs
);
if
(!
lhsI
.
isPrimitive
())
{
introduceType
(
lhsI
);
org
=
lhsI
;
lhsI
=
getIdMetadata
(
lhs
);
lhsI
=
createInfo
(
lhs
);
}
if
(!
context
.
validator
.
isValidQualifiedName
(
lhsI
.
getQualifiedName
(),
lhsI
.
getRaw
()))
{
...
...
@@ -204,10 +204,6 @@ public class GremlinQueryComposer {
this
.
attributesProcessed
.
addAll
(
attributesProcessed
);
}
public
void
addProcessedAttribute
(
String
attribute
)
{
attributesProcessed
.
add
(
attribute
);
}
public
void
addSelect
(
SelectClauseComposer
selectClauseComposer
)
{
process
(
selectClauseComposer
);
...
...
@@ -215,7 +211,6 @@ public class GremlinQueryComposer {
addSelectAttrExistsCheck
(
selectClauseComposer
);
}
// If the query contains orderBy and groupBy then the transformation determination is deferred to the method processing orderBy
if
(!(
queryMetadata
.
hasOrderBy
()
&&
queryMetadata
.
hasGroupBy
()))
{
addSelectTransformation
(
selectClauseComposer
,
null
,
false
);
...
...
@@ -277,8 +272,9 @@ public class GremlinQueryComposer {
public
String
get
()
{
close
();
String
items
[]
=
getFormattedClauses
(
queryMetadata
.
needTransformation
());
String
s
=
queryMetadata
.
needTransformation
()
?
boolean
mustTransform
=
!
isNestedQuery
&&
queryMetadata
.
needTransformation
();
String
items
[]
=
getFormattedClauses
(
mustTransform
);
String
s
=
mustTransform
?
getTransformedClauses
(
items
)
:
String
.
join
(
"."
,
items
);
...
...
@@ -298,7 +294,7 @@ public class GremlinQueryComposer {
LOG
.
debug
(
"addOrderBy(name={}, isDesc={})"
,
name
,
isDesc
);
}
IdentifierHelper
.
I
dentifierMetadata
ia
=
getIdMetadata
(
name
);
IdentifierHelper
.
I
nfo
ia
=
createInfo
(
name
);
if
(
queryMetadata
.
hasSelect
()
&&
queryMetadata
.
hasGroupBy
())
{
addSelectTransformation
(
this
.
context
.
selectClauseComposer
,
getQualifiedName
(
ia
),
isDesc
);
}
else
if
(
queryMetadata
.
hasGroupBy
())
{
...
...
@@ -314,7 +310,8 @@ public class GremlinQueryComposer {
for
(
DateFormat
dateFormat
:
DSL_DATE_FORMAT
.
get
())
{
try
{
return
dateFormat
.
parse
(
s
).
getTime
();
}
catch
(
ParseException
ignored
)
{}
}
catch
(
ParseException
ignored
)
{
}
}
context
.
validator
.
check
(
false
,
AtlasErrorCode
.
INVALID_DSL_INVALID_DATE
,
s
);
...
...
@@ -326,7 +323,7 @@ public class GremlinQueryComposer {
queryClauses
.
contains
(
GremlinClause
.
HAS_TYPE_WITHIN
)
!=
-
1
;
}
private
String
getQualifiedName
(
IdentifierHelper
.
I
dentifierMetadata
ia
)
{
private
String
getQualifiedName
(
IdentifierHelper
.
I
nfo
ia
)
{
return
context
.
validator
.
isValidQualifiedName
(
ia
.
getQualifiedName
(),
ia
.
getRaw
())
?
ia
.
getQualifiedName
()
:
ia
.
getRaw
();
}
...
...
@@ -337,8 +334,8 @@ public class GremlinQueryComposer {
String
[]
qualifiedAttributes
=
selectClauseComposer
.
getAttributes
();
if
(
qualifiedAttributes
!=
null
&&
qualifiedAttributes
.
length
>
0
)
{
for
(
int
i
=
0
;
i
<
qualifiedAttributes
.
length
;
i
++)
{
String
qualifiedAttribute
=
qualifiedAttributes
[
i
];
IdentifierHelper
.
I
dentifierMetadata
idMetadata
=
getIdMetadata
(
qualifiedAttribute
);
String
qualifiedAttribute
=
qualifiedAttributes
[
i
];
IdentifierHelper
.
I
nfo
idMetadata
=
createInfo
(
qualifiedAttribute
);
// Only primitive attributes need to be checked
if
(
idMetadata
.
isPrimitive
()
&&
!
selectClauseComposer
.
isAggregatorIdx
(
i
)
&&
!
attributesProcessed
.
contains
(
qualifiedAttribute
))
{
add
(
GremlinClause
.
HAS_PROPERTY
,
qualifiedAttribute
);
...
...
@@ -359,7 +356,7 @@ public class GremlinQueryComposer {
}
for
(
int
i
=
0
;
i
<
scc
.
getItems
().
length
;
i
++)
{
IdentifierHelper
.
I
dentifierMetadata
ia
=
getIdMetadata
(
scc
.
getItem
(
i
));
IdentifierHelper
.
I
nfo
ia
=
createInfo
(
scc
.
getItem
(
i
));
if
(
scc
.
isAggregatorWithArgument
(
i
)
&&
!
ia
.
isPrimitive
())
{
context
.
check
(
false
,
AtlasErrorCode
.
INVALID_DSL_SELECT_INVALID_AGG
,
ia
.
getQualifiedName
());
...
...
@@ -383,7 +380,7 @@ public class GremlinQueryComposer {
scc
.
incrementTypesIntroduced
();
scc
.
isSelectNoop
=
!
ia
.
hasParts
();
if
(
ia
.
hasParts
())
{
scc
.
assign
(
i
,
getQualifiedName
(
getIdMetadata
(
ia
.
get
())),
GremlinClause
.
INLINE_GET_PROPERTY
);
scc
.
assign
(
i
,
getQualifiedName
(
createInfo
(
ia
.
get
())),
GremlinClause
.
INLINE_GET_PROPERTY
);
}
}
else
{
scc
.
assign
(
i
,
getQualifiedName
(
ia
),
GremlinClause
.
INLINE_GET_PROPERTY
);
...
...
@@ -396,7 +393,7 @@ public class GremlinQueryComposer {
context
.
validator
.
check
(!
scc
.
hasMixedAttributes
(),
AtlasErrorCode
.
INVALID_DSL_SELECT_ATTR_MIXING
);
}
private
boolean
hasNoopCondition
(
IdentifierHelper
.
I
dentifierMetadata
ia
)
{
private
boolean
hasNoopCondition
(
IdentifierHelper
.
I
nfo
ia
)
{
return
!
ia
.
isPrimitive
()
&&
!
ia
.
isAttribute
()
&&
context
.
hasAlias
(
ia
.
getRaw
());
}
...
...
@@ -519,7 +516,7 @@ public class GremlinQueryComposer {
}
}
private
boolean
introduceType
(
IdentifierHelper
.
I
dentifierMetadata
ia
)
{
private
boolean
introduceType
(
IdentifierHelper
.
I
nfo
ia
)
{
if
(
ia
.
isReferredType
())
{
add
(
GremlinClause
.
OUT
,
ia
.
getEdgeLabel
());
context
.
registerActive
(
ia
);
...
...
@@ -528,7 +525,7 @@ public class GremlinQueryComposer {
return
ia
.
isReferredType
();
}
private
IdentifierHelper
.
I
dentifierMetadata
getIdMetadata
(
String
actualTypeName
)
{
private
IdentifierHelper
.
I
nfo
createInfo
(
String
actualTypeName
)
{
return
IdentifierHelper
.
create
(
context
,
lookup
,
actualTypeName
);
}
...
...
@@ -549,7 +546,7 @@ public class GremlinQueryComposer {
LOG
.
debug
(
"addOrderByClause(name={})"
,
name
,
descr
);
}
IdentifierHelper
.
I
dentifierMetadata
ia
=
getIdMetadata
(
name
);
IdentifierHelper
.
I
nfo
ia
=
createInfo
(
name
);
add
((!
descr
)
?
GremlinClause
.
ORDER_BY
:
GremlinClause
.
ORDER_BY_DESC
,
ia
);
}
...
...
@@ -558,16 +555,16 @@ public class GremlinQueryComposer {
LOG
.
debug
(
"addGroupByClause(name={})"
,
name
);
}
IdentifierHelper
.
I
dentifierMetadata
ia
=
getIdMetadata
(
name
);
IdentifierHelper
.
I
nfo
ia
=
createInfo
(
name
);
add
(
GremlinClause
.
GROUP_BY
,
ia
);
}
private
void
add
(
GremlinClause
clause
,
IdentifierHelper
.
I
dentifierMetadata
ia
)
{
if
(
context
!=
null
&&
!
context
.
validator
.
isValid
(
context
,
clause
,
i
a
))
{
private
void
add
(
GremlinClause
clause
,
IdentifierHelper
.
I
nfo
idInfo
)
{
if
(
context
!=
null
&&
!
context
.
validator
.
isValid
(
context
,
clause
,
i
dInfo
))
{
return
;
}
add
(
clause
,
(
i
a
.
getQualifiedName
()
==
null
?
ia
.
get
()
:
ia
.
getQualifiedName
()));
add
(
clause
,
(
i
dInfo
.
getQualifiedName
()
==
null
?
idInfo
.
get
()
:
idInfo
.
getQualifiedName
()));
}
private
void
add
(
GremlinClause
clause
,
String
...
args
)
{
...
...
@@ -623,10 +620,10 @@ public class GremlinQueryComposer {
}
}
public
void
registerActive
(
IdentifierHelper
.
I
dentifierMetadata
identifierMetadata
)
{
if
(
validator
.
check
(
StringUtils
.
isNotEmpty
(
i
dentifierMetadata
.
getTypeName
()),
AtlasErrorCode
.
INVALID_DSL_UNKNOWN_TYPE
,
i
dentifierMetadata
.
getRaw
()))
{
registerActive
(
i
dentifierMetadata
.
getTypeName
());
public
void
registerActive
(
IdentifierHelper
.
I
nfo
info
)
{
if
(
validator
.
check
(
StringUtils
.
isNotEmpty
(
i
nfo
.
getTypeName
()),
AtlasErrorCode
.
INVALID_DSL_UNKNOWN_TYPE
,
i
nfo
.
getRaw
()))
{
registerActive
(
i
nfo
.
getTypeName
());
}
else
{
activeType
=
UNKNOWN_TYPE
;
}
...
...
@@ -706,7 +703,7 @@ public class GremlinQueryComposer {
this
.
lookup
=
lookup
;
}
public
boolean
isValid
(
Context
ctx
,
GremlinClause
clause
,
IdentifierHelper
.
I
dentifierMetadata
ia
)
{
public
boolean
isValid
(
Context
ctx
,
GremlinClause
clause
,
IdentifierHelper
.
I
nfo
ia
)
{
switch
(
clause
)
{
case
TRAIT:
return
check
(
ia
.
isTrait
(),
AtlasErrorCode
.
INVALID_DSL_UNKNOWN_CLASSIFICATION
,
ia
.
getRaw
());
...
...
repository/src/main/java/org/apache/atlas/query/IdentifierHelper.java
View file @
ba4df832
...
...
@@ -47,12 +47,12 @@ public class IdentifierHelper {
return
ret
;
}
public
static
I
dentifierMetadata
create
(
GremlinQueryComposer
.
Context
context
,
org
.
apache
.
atlas
.
query
.
Lookup
lookup
,
String
identifier
)
{
I
dentifierMetadata
ia
=
new
IdentifierMetadata
(
identifier
);
i
a
.
update
(
lookup
,
context
);
return
i
a
;
public
static
I
nfo
create
(
GremlinQueryComposer
.
Context
context
,
org
.
apache
.
atlas
.
query
.
Lookup
lookup
,
String
identifier
)
{
I
nfo
idInfo
=
new
Info
(
identifier
);
i
dInfo
.
update
(
lookup
,
context
);
return
i
dInfo
;
}
private
static
String
extract
(
Pattern
p
,
String
s
)
{
...
...
@@ -106,7 +106,7 @@ public class IdentifierHelper {
}
public
static
class
I
dentifierMetadata
{
public
static
class
I
nfo
{
private
String
raw
;
private
String
actual
;
private
String
[]
parts
;
...
...
@@ -123,7 +123,7 @@ public class IdentifierHelper {
private
String
qualifiedName
;
private
boolean
isDate
;
public
I
dentifierMetadata
(
String
s
)
{
public
I
nfo
(
String
s
)
{
this
.
raw
=
removeQuotes
(
s
);
this
.
actual
=
IdentifierHelper
.
get
(
raw
);
}
...
...
repository/src/test/java/org/apache/atlas/query/DSLQueriesTest.java
View file @
ba4df832
...
...
@@ -214,6 +214,7 @@ public class DSLQueriesTest extends BasicTestSetup {
{
"hive_db as db1 hive_table where (db1.name = \"Reporting\")"
,
0
},
{
"hive_table where (name = \"sales_fact\" and createTime > \"2014-01-01\" ) select name as _col_0, createTime as _col_1"
,
1
},
{
"hive_table where (name = \"sales_fact\" and createTime >= \"2014-12-11T02:35:58.440Z\" ) select name as _col_0, createTime as _col_1"
,
1
},
{
"hive_table where (name = \"sales_fact\" and db.name = \"Sales\") select name, createTime"
,
1
},
{
"Dimension"
,
5
},
{
"JdbcAccess"
,
2
},
{
"ETL"
,
5
},
...
...
repository/src/test/java/org/apache/atlas/query/GremlinQueryComposerTest.java
View file @
ba4df832
...
...
@@ -314,6 +314,14 @@ public class GremlinQueryComposerTest {
}
@Test
public
void
whereComplexAndSelect
()
{
String
exSel
=
"def f(r){ t=[['name']]; r.each({t.add([it.value('Table.name')])}); t.unique(); }"
;
String
exMain
=
"g.V().has('__typeName', 'Table').and(__.out('__Table.db').has('DB.name', eq(\"Reporting\")).dedup().in('__Table.db'),__.has('Table.name', eq(\"sales_fact\"))).limit(local, 25).limit(25).toList()"
;
verify
(
"Table where db.name = \"Reporting\" and name =\"sales_fact\" select name"
,
getExpected
(
exSel
,
exMain
));
verify
(
"Table where db.name = \"Reporting\" and name =\"sales_fact\""
,
exMain
);
}
@Test
public
void
invalidQueries
()
{
verify
(
"hdfs_path like h1"
,
""
);
}
...
...
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