Commit 32a794db by Shwetha GS

ATLAS-17 Parameterize schema API query per typeName (shwethags)

parent 7f2b49ba
...@@ -4,15 +4,15 @@ Apache Atlas Release Notes ...@@ -4,15 +4,15 @@ Apache Atlas Release Notes
--trunk - unreleased --trunk - unreleased
INCOMPATIBLE CHANGES: INCOMPATIBLE CHANGES:
ATLAS-17 Parameterize schema API query per typeName (shwethags)
ALL CHANGES: ALL CHANGES:
ATLAS-10 Update trunk version to 0.6-incubating-SNAPSHOT (shwethags) ATLAS-10 Update trunk version to 0.6-incubating-SNAPSHOT (shwethags)
--Release 0.5-incubating --Release 0.5-incubating
ALL CHANGES: ALL CHANGES:
ATLAS-13 Add project website (Venkatesh Seetharam) ATLAS-13 Add project website (Venkatesh Seetharam)
ATLAS-12 Update the copyright in Notice and License files (Venkatesh Seetharam) ATLAS-12 Update the copyright in Notice and License files (Venkatesh Seetharam)
ATLAS-9 Create branch-0.5 and update version to 0.5-incubating (shwethags) ATLAS-9 Create branch-0.5 and update version to 0.5-incubating (shwethags)
......
...@@ -32,6 +32,7 @@ import org.apache.atlas.query.HiveWhereUsedQuery; ...@@ -32,6 +32,7 @@ import org.apache.atlas.query.HiveWhereUsedQuery;
import org.apache.atlas.repository.EntityNotFoundException; import org.apache.atlas.repository.EntityNotFoundException;
import org.apache.atlas.repository.MetadataRepository; import org.apache.atlas.repository.MetadataRepository;
import org.apache.atlas.repository.graph.GraphProvider; import org.apache.atlas.repository.graph.GraphProvider;
import org.apache.atlas.typesystem.persistence.ReferenceableInstance;
import org.apache.commons.configuration.PropertiesConfiguration; import org.apache.commons.configuration.PropertiesConfiguration;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -53,26 +54,27 @@ public class HiveLineageService implements LineageService { ...@@ -53,26 +54,27 @@ public class HiveLineageService implements LineageService {
private static final Option<List<String>> SELECT_ATTRIBUTES = private static final Option<List<String>> SELECT_ATTRIBUTES =
Some.<List<String>>apply(List.<String>fromArray(new String[]{"name"})); Some.<List<String>>apply(List.<String>fromArray(new String[]{"name"}));
public static final String HIVE_TABLE_SCHEMA_QUERY_PREFIX = "atlas.lineage.hive.table.schema.query.";
private static final String HIVE_TABLE_TYPE_NAME; private static final String HIVE_TABLE_TYPE_NAME;
private static final String HIVE_PROCESS_TYPE_NAME; private static final String HIVE_PROCESS_TYPE_NAME;
private static final String HIVE_PROCESS_INPUT_ATTRIBUTE_NAME; private static final String HIVE_PROCESS_INPUT_ATTRIBUTE_NAME;
private static final String HIVE_PROCESS_OUTPUT_ATTRIBUTE_NAME; private static final String HIVE_PROCESS_OUTPUT_ATTRIBUTE_NAME;
private static final String HIVE_TABLE_SCHEMA_QUERY;
private static final String HIVE_TABLE_EXISTS_QUERY; private static final String HIVE_TABLE_EXISTS_QUERY;
private static final PropertiesConfiguration propertiesConf;
static { static {
// todo - externalize this using type system - dog food // todo - externalize this using type system - dog food
try { try {
PropertiesConfiguration conf = PropertiesUtil.getApplicationProperties(); propertiesConf = PropertiesUtil.getApplicationProperties();
HIVE_TABLE_TYPE_NAME = conf.getString("atlas.lineage.hive.table.type.name", "DataSet"); HIVE_TABLE_TYPE_NAME = propertiesConf.getString("atlas.lineage.hive.table.type.name", "DataSet");
HIVE_PROCESS_TYPE_NAME = conf.getString("atlas.lineage.hive.process.type.name", "Process"); HIVE_PROCESS_TYPE_NAME = propertiesConf.getString("atlas.lineage.hive.process.type.name", "Process");
HIVE_PROCESS_INPUT_ATTRIBUTE_NAME = conf.getString("atlas.lineage.hive.process.inputs.name", "inputs"); HIVE_PROCESS_INPUT_ATTRIBUTE_NAME = propertiesConf.getString("atlas.lineage.hive.process.inputs.name", "inputs");
HIVE_PROCESS_OUTPUT_ATTRIBUTE_NAME = conf.getString("atlas.lineage.hive.process.outputs.name", "outputs"); HIVE_PROCESS_OUTPUT_ATTRIBUTE_NAME = propertiesConf.getString("atlas.lineage.hive.process.outputs.name", "outputs");
HIVE_TABLE_SCHEMA_QUERY = HIVE_TABLE_EXISTS_QUERY = propertiesConf.getString("atlas.lineage.hive.table.exists.query",
conf.getString("atlas.lineage.hive.table.schema.query", "hive_table where name=\"%s\", columns");
HIVE_TABLE_EXISTS_QUERY = conf.getString("atlas.lineage.hive.table.exists.query",
"from " + HIVE_TABLE_TYPE_NAME + " where name=\"%s\""); "from " + HIVE_TABLE_TYPE_NAME + " where name=\"%s\"");
} catch (AtlasException e) { } catch (AtlasException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
...@@ -195,9 +197,10 @@ public class HiveLineageService implements LineageService { ...@@ -195,9 +197,10 @@ public class HiveLineageService implements LineageService {
public String getSchema(String tableName) throws AtlasException { public String getSchema(String tableName) throws AtlasException {
LOG.info("Fetching schema for tableName={}", tableName); LOG.info("Fetching schema for tableName={}", tableName);
ParamChecker.notEmpty(tableName, "table name cannot be null"); ParamChecker.notEmpty(tableName, "table name cannot be null");
validateTableExists(tableName); String typeName = validateTableExists(tableName);
final String schemaQuery = String.format(HIVE_TABLE_SCHEMA_QUERY, tableName); final String schemaQuery =
String.format(propertiesConf.getString(HIVE_TABLE_SCHEMA_QUERY_PREFIX + typeName), tableName);
return discoveryService.searchByDSL(schemaQuery); return discoveryService.searchByDSL(schemaQuery);
} }
...@@ -206,11 +209,14 @@ public class HiveLineageService implements LineageService { ...@@ -206,11 +209,14 @@ public class HiveLineageService implements LineageService {
* *
* @param tableName table name * @param tableName table name
*/ */
private void validateTableExists(String tableName) throws AtlasException { private String validateTableExists(String tableName) throws AtlasException {
final String tableExistsQuery = String.format(HIVE_TABLE_EXISTS_QUERY, tableName); final String tableExistsQuery = String.format(HIVE_TABLE_EXISTS_QUERY, tableName);
GremlinQueryResult queryResult = discoveryService.evaluate(tableExistsQuery); GremlinQueryResult queryResult = discoveryService.evaluate(tableExistsQuery);
if (!(queryResult.rows().length() > 0)) { if (!(queryResult.rows().length() > 0)) {
throw new EntityNotFoundException(tableName + " does not exist"); throw new EntityNotFoundException(tableName + " does not exist");
} }
ReferenceableInstance referenceable = (ReferenceableInstance)queryResult.rows().apply(0);
return referenceable.getTypeName();
} }
} }
...@@ -36,7 +36,7 @@ atlas.graph.index.search.elasticsearch.local-mode=true ...@@ -36,7 +36,7 @@ atlas.graph.index.search.elasticsearch.local-mode=true
#atlas.lineage.hive.process.outputs.name=outputs #atlas.lineage.hive.process.outputs.name=outputs
## Schema ## Schema
#atlas.lineage.hive.table.schema.query=hive_table where name=?, columns atlas.lineage.hive.table.schema.query.hive_table=hive_table where name='%s'\, columns
######### Security Properties ######### ######### Security Properties #########
......
...@@ -36,7 +36,8 @@ atlas.graph.index.search.elasticsearch.create.sleep=2000 ...@@ -36,7 +36,8 @@ atlas.graph.index.search.elasticsearch.create.sleep=2000
#atlas.lineage.hive.process.outputs.name=outputs #atlas.lineage.hive.process.outputs.name=outputs
## Schema ## Schema
#atlas.lineage.hive.table.schema.query=hive_table where name=?, columns atlas.lineage.hive.table.schema.query.hive_table=hive_table where name='%s'\, columns
atlas.lineage.hive.table.schema.query.Table=Table where name='%s'\, columns
######### Security Properties ######### ######### Security Properties #########
......
...@@ -36,7 +36,7 @@ atlas.graph.index.search.elasticsearch.create.sleep=2000 ...@@ -36,7 +36,7 @@ atlas.graph.index.search.elasticsearch.create.sleep=2000
#atlas.lineage.hive.process.outputs.name=outputs #atlas.lineage.hive.process.outputs.name=outputs
## Schema ## Schema
#atlas.lineage.hive.table.schema.query=hive_table where name=?, columns atlas.lineage.hive.table.schema.query.hive_table=hive_table where name='%s'\, columns
######### Security Properties ######### ######### Security Properties #########
......
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