Repository: incubator-atlas Updated Branches: refs/heads/master eec811ea3 -> ad36c887d
ATLAS-294 Select queries(ex: from DB select DB.name) response contains column names as _col_x instead of the actual names requested in the query.(thiyag via sumasai) Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/ad36c887 Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/ad36c887 Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/ad36c887 Branch: refs/heads/master Commit: ad36c887df65765ee41e99752ad95f5e8e59719f Parents: eec811e Author: Suma Shivaprasad <[email protected]> Authored: Fri Nov 20 10:35:54 2015 +0530 Committer: Suma Shivaprasad <[email protected]> Committed: Fri Nov 20 10:35:54 2015 +0530 ---------------------------------------------------------------------- .../org/apache/atlas/hive/hook/HiveHookIT.java | 10 ++++---- release-log.txt | 1 + .../org/apache/atlas/query/Expressions.scala | 4 +--- .../org/apache/atlas/query/QueryParser.scala | 2 +- .../org/apache/atlas/query/GremlinTest.scala | 24 ++++++++++---------- 5 files changed, 21 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/ad36c887/addons/hive-bridge/src/test/java/org/apache/atlas/hive/hook/HiveHookIT.java ---------------------------------------------------------------------- diff --git a/addons/hive-bridge/src/test/java/org/apache/atlas/hive/hook/HiveHookIT.java b/addons/hive-bridge/src/test/java/org/apache/atlas/hive/hook/HiveHookIT.java index 79ec319..16efe46 100755 --- a/addons/hive-bridge/src/test/java/org/apache/atlas/hive/hook/HiveHookIT.java +++ b/addons/hive-bridge/src/test/java/org/apache/atlas/hive/hook/HiveHookIT.java @@ -297,7 +297,7 @@ public class HiveHookIT { String query = String.format( "%s as t where tableName = '%s', db where name = '%s' and clusterName = '%s'" + " select t", HiveDataTypes.HIVE_TABLE.getName(), tableName.toLowerCase(), dbName.toLowerCase(), CLUSTER_NAME); - return assertEntityIsRegistered(query); + return assertEntityIsRegistered(query, "t"); } private String assertDatabaseIsRegistered(String dbName) throws Exception { @@ -322,10 +322,10 @@ public class HiveHookIT { + "db where name = '%s' and clusterName = '%s' select p", typeName, value, tableName.toLowerCase(), dbName.toLowerCase(), CLUSTER_NAME); - assertEntityIsRegistered(dslQuery); + assertEntityIsRegistered(dslQuery, "p"); } - private String assertEntityIsRegistered(final String query) throws Exception { + private String assertEntityIsRegistered(final String query, String... arg) throws Exception { waitFor(2000, new Predicate() { @Override public boolean evaluate() throws Exception { @@ -334,6 +334,8 @@ public class HiveHookIT { } }); + String column = (arg.length > 0) ? arg[0] : "_col_0"; + JSONArray results = dgiCLient.search(query); JSONObject row = results.getJSONObject(0); if (row.has("__guid")) { @@ -341,7 +343,7 @@ public class HiveHookIT { } else if (row.has("$id$")) { return row.getJSONObject("$id$").getString("id"); } else { - return row.getJSONObject("_col_0").getString("id"); + return row.getJSONObject(column).getString("id"); } } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/ad36c887/release-log.txt ---------------------------------------------------------------------- diff --git a/release-log.txt b/release-log.txt index 5e79f9e..6763fd2 100644 --- a/release-log.txt +++ b/release-log.txt @@ -9,6 +9,7 @@ ATLAS-54 Rename configs in hive hook (shwethags) ATLAS-3 Mixed Index creation fails with Date types (sumasai via shwethags) ALL CHANGES: +ATLAS-294 Select queries(ex: from DB select DB.name) response contains column names as "_col_x" instead of the actual names requested in the query.(thiyag via sumasai) ATLAS-297 KafkaNotificationTest.testSendReceiveMessage fails when atlas-server is running on the same machine (yhemanth via shwethags) ATLAS-306 change javadoc generation from 'package' to 'site' phase(jspeidel via sumasai) ATLAS-289 updateEntity does not remove existing edge for multiplicity-one reference (dkantor via shwethags) http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/ad36c887/repository/src/main/scala/org/apache/atlas/query/Expressions.scala ---------------------------------------------------------------------- diff --git a/repository/src/main/scala/org/apache/atlas/query/Expressions.scala b/repository/src/main/scala/org/apache/atlas/query/Expressions.scala index d591c20..a5dfa9f 100755 --- a/repository/src/main/scala/org/apache/atlas/query/Expressions.scala +++ b/repository/src/main/scala/org/apache/atlas/query/Expressions.scala @@ -676,13 +676,11 @@ object Expressions { override def toString = s"$child where $condExpr" } - val GEN_COL_ALIAS_PREFIX = "_col" - case class SelectExpression(child: Expression, selectList: List[Expression]) extends Expression { val children = List(child) ::: selectList lazy val selectListWithAlias = selectList.zipWithIndex map { case (s: AliasExpression, _) => s - case (x, i) => new AliasExpression(x, s"${GEN_COL_ALIAS_PREFIX}_$i") + case (x, i) => new AliasExpression(x, s"${x}") } lazy val dataType = { http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/ad36c887/repository/src/main/scala/org/apache/atlas/query/QueryParser.scala ---------------------------------------------------------------------- diff --git a/repository/src/main/scala/org/apache/atlas/query/QueryParser.scala b/repository/src/main/scala/org/apache/atlas/query/QueryParser.scala index d33a8e9..8583371 100755 --- a/repository/src/main/scala/org/apache/atlas/query/QueryParser.scala +++ b/repository/src/main/scala/org/apache/atlas/query/QueryParser.scala @@ -78,7 +78,7 @@ trait ExpressionUtils { def select(input: Expression, s: List[(Expression, Option[String])]) = { val selList = s.map { t => t._2 match { - case None => t._1 + case None => t._1.as(s"${t._1}") case _ => t._1.as(t._2.get) } } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/ad36c887/repository/src/test/scala/org/apache/atlas/query/GremlinTest.scala ---------------------------------------------------------------------- diff --git a/repository/src/test/scala/org/apache/atlas/query/GremlinTest.scala b/repository/src/test/scala/org/apache/atlas/query/GremlinTest.scala index c26a9c6..1097828 100755 --- a/repository/src/test/scala/org/apache/atlas/query/GremlinTest.scala +++ b/repository/src/test/scala/org/apache/atlas/query/GremlinTest.scala @@ -313,12 +313,12 @@ class GremlinTest extends BaseGremlinTest { val r = QueryProcessor.evaluate(_class("DB").where(id("name").`=`(string("Reporting"))). select(id("name"), id("owner")), g, gp) validateJson(r, """{ - | "query": "DB where (name = \"Reporting\") as _src1 select _src1.name as _col_0, _src1.owner as _col_1", + | "query": "DB where (name = \"Reporting\") as _src1 select _src1.name as _src1.name, _src1.owner as _src1.owner", | "dataType": { | "typeName": "__tempQueryResultStruct1", | "attributeDefinitions": [ | { - | "name": "_col_0", + | "name": "_src1.name", | "dataTypeName": "string", | "multiplicity": { | "lower": 0, @@ -331,7 +331,7 @@ class GremlinTest extends BaseGremlinTest { | "reverseAttributeName": null | }, | { - | "name": "_col_1", + | "name": "_src1.owner", | "dataTypeName": "string", | "multiplicity": { | "lower": 0, @@ -348,8 +348,8 @@ class GremlinTest extends BaseGremlinTest { | "rows": [ | { | "$typeName$": "__tempQueryResultStruct1", - | "_col_1": "Jane BI", - | "_col_0": "Reporting" + | "_src1.owner": "Jane BI", + | "_src1.name": "Reporting" | } | ] |}""".stripMargin); @@ -777,7 +777,7 @@ class GremlinTest extends BaseGremlinTest { @Test def testArith { val r = QueryProcessor.evaluate(_class("DB").where(id("name").`=`(string("Reporting"))). select(id("name"), id("createTime") + int(1)), g, gp) - validateJson(r, "{\n \"query\":\"DB where (name = \\\"Reporting\\\") as _src1 select _src1.name as _col_0, (_src1.createTime + 1) as _col_1\",\n \"dataType\":{\n \"typeName\":\"__tempQueryResultStruct3\",\n \"attributeDefinitions\":[\n {\n \"name\":\"_col_0\",\n \"dataTypeName\":\"string\",\n \"multiplicity\":{\n \"lower\":0,\n \"upper\":1,\n \"isUnique\":false\n },\n \"isComposite\":false,\n \"isUnique\":false,\n \"isIndexable\":true,\n \"reverseAttributeName\":null\n },\n {\n \"name\":\"_col_1\",\n \"dataTypeName\":\"int\",\n \"multiplicity\":{\n \"lower\":0,\n \"upper\":1,\n \"isUnique\":false\n },\n \"isComposite\":false,\n \"isUnique\":false,\n \"isIndexable\":true,\n \"reverseAttributeName\":null\n }\n ]\n },\n \"rows\":[\n {\n \"$typeName$\":\"__tempQueryResultStruct3\ ",\n \"_col_1\":1501,\n \"_col_0\":\"Reporting\"\n }\n ]\n}") + validateJson(r, "{\n \"query\":\"DB where (name = \\\"Reporting\\\") as _src1 select _src1.name as _src1.name, (_src1.createTime + 1) as (_src1.createTime + 1)\",\n \"dataType\":{\n \"typeName\":\"__tempQueryResultStruct3\",\n \"attributeDefinitions\":[\n {\n \"name\":\"_src1.name\",\n \"dataTypeName\":\"string\",\n \"multiplicity\":{\n \"lower\":0,\n \"upper\":1,\n \"isUnique\":false\n },\n \"isComposite\":false,\n \"isUnique\":false,\n \"isIndexable\":true,\n \"reverseAttributeName\":null\n },\n {\n \"name\":\"(_src1.createTime + 1)\",\n \"dataTypeName\":\"int\",\n \"multiplicity\":{\n \"lower\":0,\n \"upper\":1,\n \"isUnique\":false\n },\n \"isComposite\":false,\n \"isUnique\":false,\n \"isIndexable\":true,\n \"reverseAttributeName\":null\n }\n ]\n },\n \"rows\":[\n {\n \" $typeName$\":\"__tempQueryResultStruct3\",\n \"(_src1.createTime + 1)\":1501,\n \"_src1.name\":\"Reporting\"\n }\n ]\n}") } @Test def testComparisonLogical { @@ -906,12 +906,12 @@ class GremlinTest extends BaseGremlinTest { " db where name = 'Reporting' and clusterName = 'test' select p").right.get val r = QueryProcessor.evaluate(e, g, gp) validateJson(r, """{ - | "query":"Partition as p where (values = [\"2015-01-01\"]) table where (name = \"sales_fact_daily_mv\") db where (name = \"Reporting\") and (clusterName = \"test\") as _src1 select p as _col_0", + | "query":"Partition as p where (values = [\"2015-01-01\"]) table where (name = \"sales_fact_daily_mv\") db where (name = \"Reporting\") and (clusterName = \"test\") as _src1 select p as p", | "dataType":{ | "typeName":"__tempQueryResultStruct2", | "attributeDefinitions":[ | { - | "name":"_col_0", + | "name":"p", | "dataTypeName":"Partition", | "multiplicity":{ | "lower":0, @@ -928,7 +928,7 @@ class GremlinTest extends BaseGremlinTest { | "rows":[ | { | "$typeName$":"__tempQueryResultStruct2", - | "_col_0":{ + | "p":{ | "$typeName$":"Partition", | "version":0 | } @@ -945,12 +945,12 @@ class GremlinTest extends BaseGremlinTest { val r = QueryProcessor.evaluate(e, g, gp) validateJson(r, """{ - | "query":"Partition as p where (values = [\"2015-01-01\"]) table where (name = \"sales_fact_daily_mv\") db where (name = \"Reporting\") and (clusterName = \"test\") as _src1 select p.values as _col_0", + | "query":"Partition as p where (values = [\"2015-01-01\"]) table where (name = \"sales_fact_daily_mv\") db where (name = \"Reporting\") and (clusterName = \"test\") as _src1 select p.values as p.values", | "dataType":{ | "typeName":"__tempQueryResultStruct2", | "attributeDefinitions":[ | { - | "name":"_col_0", + | "name":"p.values", | "dataTypeName":"array<string>", | "multiplicity":{ | "lower":0, @@ -967,7 +967,7 @@ class GremlinTest extends BaseGremlinTest { | "rows":[ | { | "$typeName$":"__tempQueryResultStruct2", - | "_col_0":[ + | "p.values":[ | "2015-01-01" | ] | }
