Commit a22495b9 by Jayendra Parab Committed by nixonrodrigues

ATLAS-4005 : DSL search gives error if select clause contains attributes with null values.

parent 8f5ba447
...@@ -62,7 +62,7 @@ enum GremlinClause { ...@@ -62,7 +62,7 @@ enum GremlinClause {
INLINE_SUM("r.sum({it.value('%s')})"), INLINE_SUM("r.sum({it.value('%s')})"),
INLINE_MAX("r.max({it.value('%s')}).value('%s')"), INLINE_MAX("r.max({it.value('%s')}).value('%s')"),
INLINE_MIN("r.min({it.value('%s')}).value('%s')"), INLINE_MIN("r.min({it.value('%s')}).value('%s')"),
INLINE_GET_PROPERTY("it.value('%s')"), INLINE_GET_PROPERTY("it.property('%s').isPresent() ? it.value('%s') : \"\""),
INLINE_TRANSFORM_CALL("f(%s)"), INLINE_TRANSFORM_CALL("f(%s)"),
INLINE_DEFAULT_SORT(".sort()"), INLINE_DEFAULT_SORT(".sort()"),
INLINE_SORT_DESC(".sort{a,b -> b <=> a}"), INLINE_SORT_DESC(".sort{a,b -> b <=> a}"),
......
...@@ -253,10 +253,6 @@ public class GremlinQueryComposer { ...@@ -253,10 +253,6 @@ public class GremlinQueryComposer {
public void addSelect(SelectClauseComposer selectClauseComposer) { public void addSelect(SelectClauseComposer selectClauseComposer) {
process(selectClauseComposer); process(selectClauseComposer);
if (CollectionUtils.isEmpty(context.getErrorList())) {
addSelectAttrExistsCheck(selectClauseComposer);
}
// If the query contains orderBy and groupBy then the transformation determination is deferred to the method processing orderBy // If the query contains orderBy and groupBy then the transformation determination is deferred to the method processing orderBy
if (!(queryMetadata.hasOrderBy() && queryMetadata.hasGroupBy())) { if (!(queryMetadata.hasOrderBy() && queryMetadata.hasGroupBy())) {
addSelectTransformation(selectClauseComposer, null, false); addSelectTransformation(selectClauseComposer, null, false);
...@@ -382,24 +378,6 @@ public class GremlinQueryComposer { ...@@ -382,24 +378,6 @@ public class GremlinQueryComposer {
return ia.getRaw(); return ia.getRaw();
} }
private void addSelectAttrExistsCheck(final SelectClauseComposer selectClauseComposer) {
// For each of the select attributes we need to add a presence check as well, if there's no explicit where for the same
// NOTE: One side-effect is that the result table will be empty if any of the attributes is null or empty for the type
String[] qualifiedAttributes = selectClauseComposer.getAttributes();
if (qualifiedAttributes != null && qualifiedAttributes.length > 0) {
for (int i = 0; i < qualifiedAttributes.length; i++) {
String qualifiedAttribute = qualifiedAttributes[i];
IdentifierHelper.Info idMetadata = createInfo(qualifiedAttribute);
// Only primitive attributes need to be checked
if (idMetadata.isPrimitive() && !selectClauseComposer.isAggregatorIdx(i) && !attributesProcessed.contains(qualifiedAttribute)) {
add(GremlinClause.HAS_PROPERTY, getPropertyForClause(idMetadata));
}
}
// All these checks should be done before the grouping happens (if any)
moveToLast(GremlinClause.GROUP_BY);
}
}
private void process(SelectClauseComposer scc) { private void process(SelectClauseComposer scc) {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("addSelect(items.length={})", scc.getItems() != null ? scc.getItems().length : 0); LOG.debug("addSelect(items.length={})", scc.getItems() != null ? scc.getItems().length : 0);
...@@ -412,6 +390,11 @@ public class GremlinQueryComposer { ...@@ -412,6 +390,11 @@ public class GremlinQueryComposer {
for (int i = 0; i < scc.getItems().length; i++) { for (int i = 0; i < scc.getItems().length; i++) {
IdentifierHelper.Info ia = createInfo(scc.getItem(i)); IdentifierHelper.Info ia = createInfo(scc.getItem(i));
if(StringUtils.isEmpty(ia.getQualifiedName())) {
context.getErrorList().add("Unable to find qualified name for " + ia.getAttributeName());
continue;
}
if (scc.isAggregatorWithArgument(i) && !ia.isPrimitive()) { if (scc.isAggregatorWithArgument(i) && !ia.isPrimitive()) {
context.check(false, AtlasErrorCode.INVALID_DSL_SELECT_INVALID_AGG, ia.getQualifiedName()); context.check(false, AtlasErrorCode.INVALID_DSL_SELECT_INVALID_AGG, ia.getQualifiedName());
return; return;
......
...@@ -87,7 +87,7 @@ class SelectClauseComposer { ...@@ -87,7 +87,7 @@ class SelectClauseComposer {
} }
public boolean assign(int i, String qualifiedName, GremlinClause clause) { public boolean assign(int i, String qualifiedName, GremlinClause clause) {
items[i] = clause.get(qualifiedName); items[i] = clause.get(qualifiedName, qualifiedName);
return true; return true;
} }
......
...@@ -216,8 +216,11 @@ public class DSLQueriesTest extends BasicTestSetup { ...@@ -216,8 +216,11 @@ public class DSLQueriesTest extends BasicTestSetup {
{"hive_column where hive_column isa PII", 4}, {"hive_column where hive_column isa PII", 4},
{"hive_column where hive_column isa PII select hive_column.qualifiedName", 4}, {"hive_column where hive_column isa PII select hive_column.qualifiedName", 4},
{"hive_column select hive_column.qualifiedName", 17}, {"hive_column select hive_column.qualifiedName", 17},
{"hive_column select hive_column.qualifiedName, hive_column.description", 17},
{"hive_column select qualifiedName", 17}, {"hive_column select qualifiedName", 17},
{"hive_column select qualifiedName, description", 17},
{"hive_column where hive_column.name=\"customer_id\"", 2}, {"hive_column where hive_column.name=\"customer_id\"", 2},
{"hive_column where hive_column.name=\"customer_id\" select qualifiedName, description", 2},
{"from hive_table select hive_table.qualifiedName", 10}, {"from hive_table select hive_table.qualifiedName", 10},
{"hive_db where (name = \"Reporting\")", 1}, {"hive_db where (name = \"Reporting\")", 1},
{"hive_db where (name = \"Reporting\") select name as _col_0, owner as _col_1", 1}, {"hive_db where (name = \"Reporting\") select name as _col_0, owner as _col_1", 1},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment