Commit 529ebcf8 by Suma S

Merge pull request #97 from hortonworks/master

Merging from master to DAL
parents 6e9dbbe8 c00f8de6
...@@ -50,6 +50,9 @@ public class MetadataServiceClient { ...@@ -50,6 +50,9 @@ public class MetadataServiceClient {
private static final Logger LOG = LoggerFactory.getLogger(MetadataServiceClient.class); private static final Logger LOG = LoggerFactory.getLogger(MetadataServiceClient.class);
public static final String NAME = "name"; public static final String NAME = "name";
public static final String GUID = "GUID"; public static final String GUID = "GUID";
public static final String TYPENAME = "typeName";
public static final String DEFINITION = "definition"; public static final String DEFINITION = "definition";
public static final String ERROR = "error"; public static final String ERROR = "error";
public static final String REQUEST_ID = "requestId"; public static final String REQUEST_ID = "requestId";
...@@ -82,6 +85,7 @@ public class MetadataServiceClient { ...@@ -82,6 +85,7 @@ public class MetadataServiceClient {
} catch (Exception e) { } catch (Exception e) {
LOG.info("Error processing client configuration.", e); LOG.info("Error processing client configuration.", e);
} }
URLConnectionClientHandler handler = SecureClientUtils.getClientConnectionHandler(config, clientConfig); URLConnectionClientHandler handler = SecureClientUtils.getClientConnectionHandler(config, clientConfig);
Client client = new Client(handler, config); Client client = new Client(handler, config);
......
...@@ -78,7 +78,7 @@ ...@@ -78,7 +78,7 @@
<slf4j.version>1.7.7</slf4j.version> <slf4j.version>1.7.7</slf4j.version>
<jetty.version>6.1.26</jetty.version> <jetty.version>6.1.26</jetty.version>
<jersey.version>1.9</jersey.version> <jersey.version>1.9</jersey.version>
<tinkerpop.version>2.5.0</tinkerpop.version> <tinkerpop.version>2.6.0</tinkerpop.version>
<titan.version>0.5.4</titan.version> <titan.version>0.5.4</titan.version>
<hadoop.version>2.6.0</hadoop.version> <hadoop.version>2.6.0</hadoop.version>
......
...@@ -71,7 +71,11 @@ public class DefaultGraphPersistenceStrategy implements GraphPersistenceStrategi ...@@ -71,7 +71,11 @@ public class DefaultGraphPersistenceStrategy implements GraphPersistenceStrategi
@Override @Override
public String fieldNameInVertex(IDataType<?> dataType, AttributeInfo aInfo) { public String fieldNameInVertex(IDataType<?> dataType, AttributeInfo aInfo) {
try {
return metadataRepository.getFieldNameInVertex(dataType, aInfo); return metadataRepository.getFieldNameInVertex(dataType, aInfo);
} catch (MetadataException e) {
throw new RuntimeException(e);
}
} }
@Override @Override
......
...@@ -23,6 +23,7 @@ import com.thinkaurelius.titan.core.TitanIndexQuery; ...@@ -23,6 +23,7 @@ import com.thinkaurelius.titan.core.TitanIndexQuery;
import com.thinkaurelius.titan.core.TitanProperty; import com.thinkaurelius.titan.core.TitanProperty;
import com.thinkaurelius.titan.core.TitanVertex; import com.thinkaurelius.titan.core.TitanVertex;
import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.blueprints.Vertex;
import org.apache.hadoop.metadata.MetadataServiceClient;
import org.apache.hadoop.metadata.discovery.DiscoveryException; import org.apache.hadoop.metadata.discovery.DiscoveryException;
import org.apache.hadoop.metadata.discovery.DiscoveryService; import org.apache.hadoop.metadata.discovery.DiscoveryService;
import org.apache.hadoop.metadata.query.Expressions; import org.apache.hadoop.metadata.query.Expressions;
...@@ -66,6 +67,8 @@ public class GraphBackedDiscoveryService implements DiscoveryService { ...@@ -66,6 +67,8 @@ public class GraphBackedDiscoveryService implements DiscoveryService {
private final TitanGraph titanGraph; private final TitanGraph titanGraph;
private final DefaultGraphPersistenceStrategy graphPersistenceStrategy; private final DefaultGraphPersistenceStrategy graphPersistenceStrategy;
public final static String SCORE = "score";
@Inject @Inject
GraphBackedDiscoveryService(GraphProvider<TitanGraph> graphProvider, GraphBackedDiscoveryService(GraphProvider<TitanGraph> graphProvider,
MetadataRepository metadataRepository) throws DiscoveryException { MetadataRepository metadataRepository) throws DiscoveryException {
...@@ -93,8 +96,8 @@ public class GraphBackedDiscoveryService implements DiscoveryService { ...@@ -93,8 +96,8 @@ public class GraphBackedDiscoveryService implements DiscoveryService {
if (guid != null) { //Filter non-class entities if (guid != null) { //Filter non-class entities
try { try {
row.put("guid", guid); row.put("guid", guid);
row.put("typeName", vertex.<String>getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY)); row.put(MetadataServiceClient.TYPENAME, vertex.<String>getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY));
row.put("score", result.getScore()); row.put(SCORE, result.getScore());
} catch (JSONException e) { } catch (JSONException e) {
LOG.error("Unable to create response", e); LOG.error("Unable to create response", e);
throw new DiscoveryException("Unable to create response"); throw new DiscoveryException("Unable to create response");
......
...@@ -23,41 +23,44 @@ public final class Constants { ...@@ -23,41 +23,44 @@ public final class Constants {
/** /**
* Globally Unique identifier property key. * Globally Unique identifier property key.
*/ */
public static final String GUID_PROPERTY_KEY = "guid";
public static final String INTERNAL_PROPERTY_KEY_PREFIX = "__";
public static final String GUID_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "guid";
public static final String GUID_INDEX = "guid_index"; public static final String GUID_INDEX = "guid_index";
/** /**
* Entity type name property key. * Entity type name property key.
*/ */
public static final String ENTITY_TYPE_PROPERTY_KEY = "typeName"; public static final String ENTITY_TYPE_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "typeName";
public static final String ENTITY_TYPE_INDEX = "type_index"; public static final String ENTITY_TYPE_INDEX = "type_index";
/** /**
* Entity type's super types property key. * Entity type's super types property key.
*/ */
public static final String SUPER_TYPES_PROPERTY_KEY = "superTypeNames"; public static final String SUPER_TYPES_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "superTypeNames";
public static final String SUPER_TYPES_INDEX = "super_types_index"; public static final String SUPER_TYPES_INDEX = "super_types_index";
/** /**
* Full-text for the entity for enabling full-text search. * Full-text for the entity for enabling full-text search.
*/ */
//weird issue in TitanDB if __ added to this property key. Not adding it for now
public static final String ENTITY_TEXT_PROPERTY_KEY = "entityText"; public static final String ENTITY_TEXT_PROPERTY_KEY = "entityText";
/** /**
* Properties for type store graph * Properties for type store graph
*/ */
public static final String TYPE_CATEGORY_PROPERTY_KEY = "type.category"; public static final String TYPE_CATEGORY_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "type.category";
public static final String VERTEX_TYPE_PROPERTY_KEY = "type"; public static final String VERTEX_TYPE_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "type";
public static final String TYPENAME_PROPERTY_KEY = "type.name"; public static final String TYPENAME_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "type.name";
/** /**
* Trait names property key and index name. * Trait names property key and index name.
*/ */
public static final String TRAIT_NAMES_PROPERTY_KEY = "traitNames"; public static final String TRAIT_NAMES_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "traitNames";
public static final String TRAIT_NAMES_INDEX = "trait_names_index"; public static final String TRAIT_NAMES_INDEX = "trait_names_index";
public static final String VERSION_PROPERTY_KEY = "version"; public static final String VERSION_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "version";
public static final String TIMESTAMP_PROPERTY_KEY = "timestamp"; public static final String TIMESTAMP_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "timestamp";
/** /**
* search backing index name. * search backing index name.
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
package org.apache.hadoop.metadata.repository; package org.apache.hadoop.metadata.repository;
import org.apache.hadoop.metadata.MetadataException;
import org.apache.hadoop.metadata.typesystem.IReferenceableInstance; import org.apache.hadoop.metadata.typesystem.IReferenceableInstance;
import org.apache.hadoop.metadata.typesystem.ITypedReferenceableInstance; import org.apache.hadoop.metadata.typesystem.ITypedReferenceableInstance;
import org.apache.hadoop.metadata.typesystem.ITypedStruct; import org.apache.hadoop.metadata.typesystem.ITypedStruct;
...@@ -61,7 +62,7 @@ public interface MetadataRepository { ...@@ -61,7 +62,7 @@ public interface MetadataRepository {
* @param aInfo attribute info * @param aInfo attribute info
* @return property key used to store a given attribute * @return property key used to store a given attribute
*/ */
String getFieldNameInVertex(IDataType<?> dataType, AttributeInfo aInfo); String getFieldNameInVertex(IDataType<?> dataType, AttributeInfo aInfo) throws MetadataException;
/** /**
* Return the edge label for a given attribute in the repository. * Return the edge label for a given attribute in the repository.
......
...@@ -122,8 +122,8 @@ public class GraphBackedMetadataRepository implements MetadataRepository { ...@@ -122,8 +122,8 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
} }
@Override @Override
public String getFieldNameInVertex(IDataType<?> dataType, AttributeInfo aInfo) { public String getFieldNameInVertex(IDataType<?> dataType, AttributeInfo aInfo) throws MetadataException {
return dataType.getName() + "." + aInfo.name; return getQualifiedName(dataType, aInfo.name);
} }
@Override @Override
......
...@@ -184,8 +184,14 @@ class GremlinTranslator(expr: Expression, ...@@ -184,8 +184,14 @@ class GremlinTranslator(expr: Expression,
} }
private def genQuery(expr: Expression, inSelect: Boolean): String = expr match { private def genQuery(expr: Expression, inSelect: Boolean): String = expr match {
case ClassExpression(clsName) => s"""has("${gPersistenceBehavior.typeAttributeName}","$clsName")""" case ClassExpression(clsName) =>
case TraitExpression(clsName) => s"""has("${gPersistenceBehavior.typeAttributeName}","$clsName")""" val typeName = gPersistenceBehavior.typeAttributeName
val superTypeName = gPersistenceBehavior.superTypeAttributeName
s"""filter{(it.$typeName == "$clsName") | (it.$superTypeName ? it.$superTypeName.contains("$clsName") : false)}"""
case TraitExpression(clsName) =>
val typeName = gPersistenceBehavior.typeAttributeName
val superTypeName = gPersistenceBehavior.superTypeAttributeName
s"""filter{(it.$typeName == "$clsName") | (it.$superTypeName ? it.$superTypeName.contains("$clsName") : false)}"""
case fe@FieldExpression(fieldName, fInfo, child) if fe.dataType.getTypeCategory == TypeCategory.PRIMITIVE => { case fe@FieldExpression(fieldName, fInfo, child) if fe.dataType.getTypeCategory == TypeCategory.PRIMITIVE => {
val fN = "\"" + gPersistenceBehavior.fieldNameInVertex(fInfo.dataType, fInfo.attrInfo) + "\"" val fN = "\"" + gPersistenceBehavior.fieldNameInVertex(fInfo.dataType, fInfo.attrInfo) + "\""
child match { child match {
......
...@@ -349,6 +349,33 @@ public class GraphBackedMetadataRepositoryTest { ...@@ -349,6 +349,33 @@ public class GraphBackedMetadataRepositoryTest {
} }
} }
@Test(dependsOnMethods = "testSubmitEntity")
public void testSearchByDSLWithInheritance() throws Exception {
String dslQuery = "Person where name = 'Jane'";
System.out.println("Executing dslQuery = " + dslQuery);
String jsonResults = discoveryService.searchByDSL(dslQuery);
Assert.assertNotNull(jsonResults);
JSONObject results = new JSONObject(jsonResults);
Assert.assertEquals(results.length(), 3);
System.out.println("results = " + results);
Object query = results.get("query");
Assert.assertNotNull(query);
JSONObject dataType = results.getJSONObject("dataType");
Assert.assertNotNull(dataType);
String typeName = dataType.getString("typeName");
Assert.assertEquals(typeName, "Person");
JSONArray rows = results.getJSONArray("rows");
Assert.assertEquals(rows.length(), 1);
JSONObject row = rows.getJSONObject(0);
Assert.assertEquals(row.getString("$typeName$"), "Manager");
Assert.assertEquals(row.getString("name"), "Jane");
}
/** /**
* Full text search requires GraphBackedSearchIndexer, and GraphBackedSearchIndexer can't be enabled in * Full text search requires GraphBackedSearchIndexer, and GraphBackedSearchIndexer can't be enabled in
* GraphBackedDiscoveryServiceTest because of its test data. So, test for full text search is in * GraphBackedDiscoveryServiceTest because of its test data. So, test for full text search is in
......
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