Commit 381bc538 by Shwetha GS

hive hook using DSL to get table reference

parent 9e79cd94
...@@ -168,7 +168,13 @@ public class HiveMetaStoreBridge { ...@@ -168,7 +168,13 @@ public class HiveMetaStoreBridge {
if (results.length() == 0) { if (results.length() == 0) {
return null; return null;
} else { } else {
String guid = getGuidFromDSLResponse(results.getJSONObject(0)); String guid;
JSONObject row = results.getJSONObject(0);
if (row.has("$id$")) {
guid = row.getJSONObject("$id$").getString("id");
} else {
guid = row.getJSONObject("_col_0").getString("id");
}
return new Referenceable(guid, typeName, null); return new Referenceable(guid, typeName, null);
} }
} }
...@@ -186,15 +192,16 @@ public class HiveMetaStoreBridge { ...@@ -186,15 +192,16 @@ public class HiveMetaStoreBridge {
String typeName = HiveDataTypes.HIVE_TABLE.getName(); String typeName = HiveDataTypes.HIVE_TABLE.getName();
// String dslQuery = String.format("%s as t where name = '%s' dbName where name = '%s' and " String dslQuery = String.format(
// + "clusterName = '%s' select t", "%s as t where name = '%s', dbName where name = '%s' and " + "clusterName = '%s' select t",
// HiveDataTypes.HIVE_TABLE.getName(), tableName, dbName, clusterName); HiveDataTypes.HIVE_TABLE.getName(), tableName, dbName, clusterName);
String dbType = HiveDataTypes.HIVE_DB.getName(); return getEntityReferenceFromDSL(typeName, dslQuery);
String gremlinQuery = String.format("g.V.has('__typeName', '%s').has('%s.name', '%s').as('t').out" // String dbType = HiveDataTypes.HIVE_DB.getName();
+ "('__%s.dbName').has('%s.name', '%s').has('%s.clusterName', '%s').back('t').toList()", // String gremlinQuery = String.format("g.V.has('__typeName', '%s').has('%s.name', '%s').as('t').out"
typeName, typeName, tableName, typeName, dbType, dbName, dbType, clusterName); // + "('__%s.dbName').has('%s.name', '%s').has('%s.clusterName', '%s').back('t').toList()",
return getEntityReferenceFromGremlin(typeName, gremlinQuery); // typeName, typeName, tableName, typeName, dbType, dbName, dbType, clusterName);
// return getEntityReferenceFromGremlin(typeName, gremlinQuery);
} }
private Referenceable getEntityReferenceFromGremlin(String typeName, String gremlinQuery) throws MetadataServiceException, private Referenceable getEntityReferenceFromGremlin(String typeName, String gremlinQuery) throws MetadataServiceException,
...@@ -228,10 +235,6 @@ public class HiveMetaStoreBridge { ...@@ -228,10 +235,6 @@ public class HiveMetaStoreBridge {
return getEntityReferenceFromGremlin(typeName, gremlinQuery); return getEntityReferenceFromGremlin(typeName, gremlinQuery);
} }
private String getGuidFromDSLResponse(JSONObject jsonObject) throws JSONException {
return jsonObject.getJSONObject("$id$").getString("id");
}
private Referenceable getSDForTable(String dbName, String tableName) throws Exception { private Referenceable getSDForTable(String dbName, String tableName) throws Exception {
Referenceable tableRef = getTableReference(dbName, tableName); Referenceable tableRef = getTableReference(dbName, tableName);
if (tableRef == null) { if (tableRef == null) {
......
...@@ -215,8 +215,8 @@ public class HiveHookIT { ...@@ -215,8 +215,8 @@ public class HiveHookIT {
} }
private void assertTableIsRegistered(String dbName, String tableName) throws Exception { private void assertTableIsRegistered(String dbName, String tableName) throws Exception {
String query = String.format("%s where name = '%s', dbName where name = '%s' and clusterName = '%s'", String query = String.format("%s as t where name = '%s', dbName where name = '%s' and clusterName = '%s'"
HiveDataTypes.HIVE_TABLE.getName(), tableName, dbName, CLUSTER_NAME); + " select t", HiveDataTypes.HIVE_TABLE.getName(), tableName, dbName, CLUSTER_NAME);
assertEntityIsRegistered(query); assertEntityIsRegistered(query);
} }
...@@ -243,6 +243,11 @@ public class HiveHookIT { ...@@ -243,6 +243,11 @@ public class HiveHookIT {
private String assertEntityIsRegistered(String dslQuery) throws Exception{ private String assertEntityIsRegistered(String dslQuery) throws Exception{
JSONArray results = dgiCLient.searchByDSL(dslQuery); JSONArray results = dgiCLient.searchByDSL(dslQuery);
Assert.assertEquals(results.length(), 1); Assert.assertEquals(results.length(), 1);
return results.getJSONObject(0).getJSONObject("$id$").getString("id"); JSONObject row = results.getJSONObject(0);
if (row.has("$id$")) {
return row.getJSONObject("$id$").getString("id");
} else {
return row.getJSONObject("_col_0").getString("id");
}
} }
} }
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