You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by ma...@apache.org on 2017/11/05 20:31:34 UTC
[12/40] atlas git commit: ATLAS-2251: Remove TypeSystem and related
implementation, to avoid unncessary duplicate of type details in cache
http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/repository/src/test/java/org/apache/atlas/utils/HiveModel.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/utils/HiveModel.java b/repository/src/test/java/org/apache/atlas/utils/HiveModel.java
deleted file mode 100644
index 4fc0473..0000000
--- a/repository/src/test/java/org/apache/atlas/utils/HiveModel.java
+++ /dev/null
@@ -1,303 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.atlas.utils;
-
-import org.apache.atlas.TestUtils;
-import org.apache.atlas.typesystem.ITypedReferenceableInstance;
-import org.apache.atlas.typesystem.Referenceable;
-import org.apache.atlas.typesystem.Struct;
-import org.apache.atlas.typesystem.persistence.Id;
-import org.apache.atlas.typesystem.types.ClassType;
-import org.apache.atlas.typesystem.types.Multiplicity;
-import org.apache.atlas.typesystem.types.TypeSystem;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-
-/**
- * Allows easy creation of entities for classes in the hive test model.
- *
- */
-public class HiveModel {
-
- public static class StructInstance {
-
- public String getTypeName() {
- return getClass().getSimpleName();
- }
-
- public Struct toStruct() throws Exception {
-
- Struct entity = new Struct(getTypeName());
- addDeclaredFields(getClass(), entity);
- return entity;
- }
-
- protected void addDeclaredFields(Class clazz, Struct r) throws Exception {
-
- for (Field f : clazz.getDeclaredFields()) {
-
- if (Modifier.isTransient(f.getModifiers())) {
- continue;
- }
- String fieldName = f.getName();
-
- f.setAccessible(true);
- Object value = f.get(this);
-
- if (value instanceof List) {
-
- List listValue = (List) value;
- List toSet = new ArrayList(listValue.size());
- for (Object listItem : listValue) {
- Object toAdd = null;
- toAdd = convertValue(listItem);
- toSet.add(toAdd);
- }
- r.set(fieldName, toSet);
- } else {
-
- Object converted = convertValue(value);
- r.set(fieldName, converted);
- }
- }
-
- if (clazz != StructInstance.class) {
- addDeclaredFields(clazz.getSuperclass(), r);
- }
- }
-
- private Object convertValue(Object toConvert) throws Exception {
-
- if (toConvert instanceof ClassInstance) {
- return ((ClassInstance) toConvert).toReferenceable();
- }
- if (toConvert instanceof StructInstance) {
- return ((StructInstance) toConvert).toStruct();
- } else {
- return toConvert;
- }
- }
- }
-
- public static class ClassInstance<T> extends StructInstance {
-
- private transient final Id guid;
- private transient List<String> traits = new ArrayList();
-
- public T withTrait(String name) {
- traits.add(name);
- return getInstance();
- }
-
- public T withTraits(List<String> names) {
- traits.addAll(names);
- return getInstance();
- }
-
- public T getInstance() {
- return (T) this;
- }
-
- public ClassInstance() {
- guid = new Id(getTypeName());
- }
-
- public Referenceable toReferenceable() throws Exception {
-
- String[] traitArray = new String[traits.size()];
- traitArray = traits.toArray(traitArray);
- Referenceable entity = new Referenceable(getTypeName(), traitArray);
- entity.replaceWithNewId(guid);
- addDeclaredFields(getClass(), entity);
-
- return entity;
- }
-
- public List<ITypedReferenceableInstance> getTypedReferencebles() throws Exception {
-
- List<ITypedReferenceableInstance> result = new ArrayList();
- for (ClassInstance containedInstance : getAllInstances()) {
- Referenceable entity = containedInstance.toReferenceable();
- ClassType type = TypeSystem.getInstance().getDataType(ClassType.class, entity.getTypeName());
- ITypedReferenceableInstance converted = type.convert(entity, Multiplicity.REQUIRED);
- result.add(converted);
- }
- return result;
- }
-
- protected List<ClassInstance> getAllInstances() {
-
- return (List) Collections.singletonList(this);
- }
-
- public Id getId() {
- return guid;
- }
- }
-
- public static class NamedInstance<T> extends ClassInstance<T> {
-
- private final String name;
-
- public NamedInstance(String name) {
- super();
- this.name = name;
- }
- }
-
- public static class HiveOrder extends StructInstance {
-
- private String col;
- private int order;
-
- public HiveOrder(String col, int order) {
- super();
- this.col = col;
- this.order = order;
- }
-
- }
-
- public static class DB extends NamedInstance<DB> {
-
- private String owner;
- private int createTime;
- private String clusterName;
-
- public DB(String name, String owner, int createTime, String clusterName) {
- super(name);
- this.owner = owner;
- this.createTime = createTime;
- this.clusterName = clusterName;
- }
- }
-
- public static class StorageDescriptor extends ClassInstance<StorageDescriptor> {
-
- private String inputFormat;
- private String outputFormat;
- private List<HiveOrder> sortCols;
-
- public StorageDescriptor(String inputFormat, String outputFormat, List<HiveOrder> sortCols) {
- super();
- this.inputFormat = inputFormat;
- this.outputFormat = outputFormat;
- this.sortCols = sortCols;
- }
- }
-
- public static class Column extends NamedInstance<Column> {
-
- private String type;
- private StorageDescriptor sd;
-
- public Column(String name, String type) {
- super(name);
- this.type = type;
- }
-
- public void setStorageDescriptor(StorageDescriptor sd) {
- this.sd = sd;
- }
- }
-
- public static class Table extends NamedInstance<Table> {
-
- private DB db;
- private Date created;
- private StorageDescriptor sd;
- private transient List<Column> colDefs;
-
- public Table(String name, DB db, StorageDescriptor sd, List<Column> colDefs) {
- this(name, db, sd, new Date(TestUtils.TEST_DATE_IN_LONG), colDefs);
- }
-
- public Table(String name, DB db, StorageDescriptor sd, Date created, List<Column> colDefs) {
-
- super(name);
- this.colDefs = colDefs;
- this.db = db;
- this.sd = sd;
- this.created = created;
- for (Column col : colDefs) {
- col.setStorageDescriptor(sd);
- }
- }
-
- public List<Column> getColumns() {
- return colDefs;
- }
-
- @Override
- protected List<ClassInstance> getAllInstances() {
-
- List<ClassInstance> result = new ArrayList(colDefs.size() + 2);
- result.add(sd);
- result.addAll(colDefs);
- result.add(this);
- return result;
- }
- }
-
- public static class Partition extends ClassInstance<Partition> {
-
- private List<String> values;
- private Table table;
-
- public Partition(List<String> values, Table table) {
-
- super();
- this.values = values;
- this.table = table;
- }
-
- }
-
- public static class LoadProcess extends NamedInstance<LoadProcess> {
-
- private List<Table> inputTables;
- private Table outputTable;
-
- public LoadProcess(String name, List<Table> inputTables, Table outputTable) {
- super(name);
- this.inputTables = inputTables;
- this.outputTable = outputTable;
- }
-
- }
-
- public static class View extends NamedInstance<View> {
-
- private DB db;
- private List<Table> inputTables;
-
- public View(String name, DB db, List<Table> inputTables) {
- super(name);
- this.db = db;
- this.inputTables = inputTables;
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/repository/src/test/java/org/apache/atlas/utils/ObjectUpdateSynchronizerTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/utils/ObjectUpdateSynchronizerTest.java b/repository/src/test/java/org/apache/atlas/utils/ObjectUpdateSynchronizerTest.java
deleted file mode 100644
index 03ebae4..0000000
--- a/repository/src/test/java/org/apache/atlas/utils/ObjectUpdateSynchronizerTest.java
+++ /dev/null
@@ -1,218 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.atlas.utils;
-
-import org.apache.atlas.GraphTransactionInterceptor;
-import org.apache.commons.lang.ArrayUtils;
-import org.apache.commons.lang.RandomStringUtils;
-import org.springframework.util.CollectionUtils;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-
-public class ObjectUpdateSynchronizerTest {
- private static final GraphTransactionInterceptor.ObjectUpdateSynchronizer objectUpdateSynchronizer = new GraphTransactionInterceptor.ObjectUpdateSynchronizer();
-
- private final List<Integer> outputList = new ArrayList<>();
- private final int MAX_COUNT = 10;
-
- class CounterThread extends Thread {
- String ids[];
- public CounterThread(String id) {
- this.ids = new String[1];
- this.ids[0] = id;
- }
-
- public void setIds(String... ids) {
- this.ids = ids;
- }
-
- public void run() {
- objectUpdateSynchronizer.lockObject(CollectionUtils.arrayToList(ids));
- for (int i = 0; i < MAX_COUNT; i++) {
- outputList.add(i);
- RandomStringUtils.randomAlphabetic(20);
- }
-
- objectUpdateSynchronizer.releaseLockedObjects();
- }
- }
-
- @BeforeMethod
- public void clearOutputList() {
- outputList.clear();
- }
-
- @Test
- public void singleThreadRun() throws InterruptedException {
- verifyMultipleThreadRun(1);
- }
-
- @Test
- public void twoThreadsAccessingDifferntGuids_DoNotSerialize() throws InterruptedException {
- CounterThread th[] = getCounterThreads(false, 2);
-
- startCounterThreads(th);
- waitForThreadsToEnd(th);
- assertArrayNotEquals(populateExpectedArrayOutput(2));
- }
-
- @Test
- public void twoThreadsAccessingSameGuid_Serialize() throws InterruptedException {
- verifyMultipleThreadRun(2);
- }
-
- @Test
- public void severalThreadsAccessingSameGuid_Serialize() throws InterruptedException {
- verifyMultipleThreadRun(10);
- }
-
- @Test
- public void severalThreadsSequentialAccessingListOfGuids() throws InterruptedException {
- CounterThread th[] = getCounterThreads(false, 10);
- int i = 0;
- th[i++].setIds("1", "2", "3", "4", "5");
- th[i++].setIds("1", "2", "3", "4");
- th[i++].setIds("1", "2", "3");
- th[i++].setIds("1", "2");
- th[i++].setIds("1");
- th[i++].setIds("1", "2");
- th[i++].setIds("1", "2", "3");
- th[i++].setIds("1", "2", "3", "4");
- th[i++].setIds("1", "2", "3", "4", "5");
- th[i++].setIds("1");
-
- startCounterThreads(th);
- waitForThreadsToEnd(th);
- assertArrayEquals(populateExpectedArrayOutput(th.length));
- }
-
- @Test
- public void severalThreadsNonSequentialAccessingListOfGuids() throws InterruptedException {
- CounterThread th[] = getCounterThreads(false, 5);
- int i = 0;
- th[i++].setIds("2", "1", "3", "4", "5");
- th[i++].setIds("3", "2", "4", "1");
- th[i++].setIds("2", "3", "1");
- th[i++].setIds("1", "2");
- th[i++].setIds("1");
-
- startCounterThreads(th);
- waitForThreadsToEnd(th);
- assertArrayEquals(populateExpectedArrayOutput(th.length));
- }
-
- @Test
- public void severalThreadsAccessingOverlappingListOfGuids() throws InterruptedException {
- CounterThread th[] = getCounterThreads(false, 5);
- int i = 0;
- th[i++].setIds("1", "2", "3", "4", "5");
- th[i++].setIds("3", "4", "5", "6");
- th[i++].setIds("5", "6", "7");
- th[i++].setIds("7", "8");
- th[i++].setIds("8");
-
- startCounterThreads(th);
- waitForThreadsToEnd(th);
- assertArrayNotEquals(populateExpectedArrayOutput(th.length));
- }
-
-
- @Test
- public void severalThreadsAccessingOverlappingListOfGuids2() throws InterruptedException {
- CounterThread th[] = getCounterThreads(false, 3);
- int i = 0;
- th[i++].setIds("1", "2", "3", "4", "5");
- th[i++].setIds("6", "7", "8", "9");
- th[i++].setIds("4", "5", "6");
-
- startCounterThreads(th);
- waitForThreadsToEnd(th);
- assertArrayNotEquals(populateExpectedArrayOutput(th.length));
- }
-
- @Test
- public void severalThreadsAccessingOverlappingListOfGuidsEnsuringSerialOutput() throws InterruptedException {
- CounterThread th[] = getCounterThreads(false, 5);
- int i = 0;
- th[i++].setIds("1", "2", "3", "4", "7");
- th[i++].setIds("3", "4", "5", "7");
- th[i++].setIds("5", "6", "7");
- th[i++].setIds("7", "8");
- th[i++].setIds("7");
-
- startCounterThreads(th);
- waitForThreadsToEnd(th);
- assertArrayEquals(populateExpectedArrayOutput(th.length));
- }
-
- private void verifyMultipleThreadRun(int limit) throws InterruptedException {
- CounterThread[] th = getCounterThreads(limit);
- startCounterThreads(th);
- waitForThreadsToEnd(th);
- assertArrayEquals(populateExpectedArrayOutput(limit));
- }
-
- private void startCounterThreads(CounterThread[] th) {
- for (int i = 0; i < th.length; i++) {
- th[i].start();
- }
- }
- private CounterThread[] getCounterThreads(int limit) {
- return getCounterThreads(true, limit);
- }
-
- private CounterThread[] getCounterThreads(boolean sameId, int limit) {
- CounterThread th[] = new CounterThread[limit];
- for (Integer i = 0; i < limit; i++) {
- th[i] = new CounterThread(sameId ? "1" : i.toString());
- }
- return th;
- }
-
-
- private void assertArrayEquals(List<Integer> expected) {
- assertEquals(outputList.toArray(), expected.toArray());
- }
-
- private void assertArrayNotEquals(List<Integer> expected) {
- assertFalse(ArrayUtils.isEquals(outputList.toArray(), expected));
- }
-
- private void waitForThreadsToEnd(CounterThread... threads) throws InterruptedException {
- for (Thread t : threads) {
- t.join();
- }
- }
-
- private List<Integer> populateExpectedArrayOutput(int limit) {
- List<Integer> list = new ArrayList<>();
- for (int i = 0; i < limit*MAX_COUNT; i+=MAX_COUNT) {
- for (int j = 0; j < MAX_COUNT; j++) {
- list.add(j);
- }
- }
-
- return list;
- }
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/repository/src/test/scala/org/apache/atlas/query/ExpressionTest.scala
----------------------------------------------------------------------
diff --git a/repository/src/test/scala/org/apache/atlas/query/ExpressionTest.scala b/repository/src/test/scala/org/apache/atlas/query/ExpressionTest.scala
deleted file mode 100755
index 918f327..0000000
--- a/repository/src/test/scala/org/apache/atlas/query/ExpressionTest.scala
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.atlas.query
-
-import org.apache.atlas.DBSandboxer
-import org.apache.atlas.query.Expressions._
-import org.apache.atlas.repository.BaseTest
-import org.testng.annotations.{BeforeMethod, Listeners, Test}
-
-class ExpressionTest extends BaseTest {
-
- @BeforeMethod
- override def setup {
- super.setup
-
- QueryTestsUtils.setupTypes
-
- }
-
- @Test def testClass: Unit = {
- val e = QueryProcessor.validate(_class("DB"))
- println(e)
- }
-
- @Test def testFilter: Unit = {
- val e = QueryProcessor.validate(_class("DB").where(id("name").`=`(string("Reporting"))))
- println(e)
- }
-
- @Test def testSelect: Unit = {
- val e = QueryProcessor.validate(_class("DB").where(id("name").`=`(string("Reporting"))).
- select(id("name"), id("owner")))
- println(e)
- }
-
- @Test def testNegTypeTest: Unit = {
- try {
- val e = QueryProcessor.validate(_class("DB").where(id("name")))
- println(e)
- } catch {
- case e: ExpressionException if e.getMessage.endsWith("expression: DB where name") => ()
- }
- }
-
- @Test def testIsTrait: Unit = {
- val e = QueryProcessor.validate(_class("DB").where(isTrait("JdbcAccess")))
- println(e)
- }
-
- @Test def testIsTraitNegative: Unit = {
- try {
- val e = QueryProcessor.validate(_class("DB").where(isTrait("Jdb")))
- println(e)
- } catch {
- case e: ExpressionException if e.getMessage.endsWith("not a TraitType, expression: is Jdb") => ()
- }
- }
-
- @Test def testhasField: Unit = {
- val e = QueryProcessor.validate(_class("DB").where(hasField("name")))
- println(e)
- }
-
- @Test def testHasFieldNegative: Unit = {
- try {
- val e = QueryProcessor.validate(_class("DB").where(hasField("nam")))
- println(e)
- } catch {
- case e: ExpressionException if e.getMessage.endsWith("not a TraitType, expression: is Jdb") => ()
- }
- }
-
- @Test def testFieldReference: Unit = {
- val e = QueryProcessor.validate(_class("DB").field("Table"))
- println(e)
- }
-
- @Test def testNegFieldReference: Unit = {
- try {
- val e = QueryProcessor.validate(_class("DB").where(_class("LoadProcess").hasField("name")))
- println(e)
- } catch {
- case e: ExpressionException
- if e.getMessage.endsWith("srcType of field doesn't match input type, expression: LoadProcess has name") => ()
- }
- }
-
- @Test def testFieldReferenceRedundant: Unit = {
- val e = QueryProcessor.validate(_class("DB").where(_class("DB").hasField("name")))
- println(e)
- }
-
- @Test def testBackReference: Unit = {
- val e = QueryProcessor.validate(
- _class("DB").as("db1").field("Table").where(id("db1").field("name").`=`(string("Reporting"))))
- println(e)
- }
-
- @Test def testArith: Unit = {
- val e = QueryProcessor.validate(_class("DB").where(id("name").`=`(string("Reporting"))).
- select(id("name"), id("createTime") + int(1)))
- println(e)
- }
-
- @Test def testComparisonLogical: Unit = {
- val e = QueryProcessor.validate(_class("DB").where(id("name").`=`(string("Reporting")).
- and(id("createTime") + int(1) > int(0))))
- println(e)
- }
-
- @Test def testJoinAndSelect1: Unit = {
- val e = QueryProcessor.validate(
- _class("DB").as("db1").field("Table").as("tab").where((id("db1").field("createTime") + int(1) > int(0))
- .and(id("db1").field("name").`=`(string("Reporting")))).select(id("db1").field("name").as("dbName"),
- id("tab").field("name").as("tabName"))
- )
- println(e)
- }
-
- @Test def testJoinAndSelect2: Unit = {
- val e = QueryProcessor.validate(
- _class("DB").as("db1").field("Table").as("tab").where((id("db1").field("createTime") + int(1) > int(0))
- .or(id("db1").field("name").`=`(string("Reporting"))))
- .select(id("db1").field("name").as("dbName"), id("tab").field("name").as("tabName"))
- )
- println(e)
- }
-
- @Test def testJoinAndSelect3: Unit = {
- val e = QueryProcessor.validate(
- _class("DB").as("db1").field("Table").as("tab").where((id("db1").field("createTime") + int(1) > int(0))
- .and(id("db1").field("name").`=`(string("Reporting")))
- .or(id("db1").hasField("owner")))
- .select(id("db1").field("name").as("dbName"), id("tab").field("name").as("tabName"))
- )
- println(e)
- }
-
- @Test def testJoinAndSelect4: Unit = {
- val e = QueryProcessor.validate(
- _class("DB") as "db1" join "Table" as "tab" where (
- id("db1").field("createTime") + int(1) > int(0) and
- (id("db1") `.` "name" `=` string("Reporting")) or
- (id("db1") hasField "owner")
- ) select(
- id("db1") `.` "name" as "dbName", id("tab") `.` "name" as "tabName"
- )
- )
- println(e)
- }
-
- @Test def testLineageAll: Unit = {
- val e = QueryProcessor.validate(_class("Table").loop(id("LoadProcess").field("outputTable")))
- println(e)
- }
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/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
deleted file mode 100755
index a948d16..0000000
--- a/repository/src/test/scala/org/apache/atlas/query/GremlinTest.scala
+++ /dev/null
@@ -1,1068 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.atlas.query
-
-import org.apache.atlas.repository.graphdb.AtlasGraph
-import org.apache.atlas.discovery.graph.DefaultGraphPersistenceStrategy
-import org.apache.atlas.query.Expressions._
-import org.apache.atlas.repository.graph.{AtlasGraphProvider, GraphBackedMetadataRepository}
-import org.apache.atlas.typesystem.types.TypeSystem
-import org.testng.annotations._
-import org.apache.atlas.repository.graph.AtlasGraphProvider
-import org.apache.atlas.{DBSandboxer, TestUtils}
-import org.apache.atlas.graph.GraphSandboxUtil
-
-class GremlinTest extends BaseGremlinTest {
-
- var g: AtlasGraph[_,_] = null
- var gp: GraphPersistenceStrategies = null;
-
- @BeforeMethod
- def resetRequestContext() {
- TestUtils.resetRequestContext()
- }
-
- @BeforeClass
- def beforeAll() {
- TypeSystem.getInstance().reset()
- var repo = new GraphBackedMetadataRepository(null, new AtlasGraphProvider().get())
- TestUtils.setupGraphProvider(repo)
- //force graph to be initialized first
- AtlasGraphProvider.getGraphInstance()
-
- //create types and indices up front. Without this, some of the property keys (particularly __traitNames and __superTypes)
- //get ended up created implicitly with some graph backends with the wrong multiplicity. This also makes the queries
- //we execute perform better :-)
- QueryTestsUtils.setupTypesAndIndices()
-
- gp = new DefaultGraphPersistenceStrategy(repo)
- g = QueryTestsUtils.setupTestGraph(repo)
- }
-
- @AfterClass
- def afterAll() {
- AtlasGraphProvider.cleanup()
- }
-
-
- @Test def testClass {
- val r = QueryProcessor.evaluate(_class("DB"), g, gp)
- validateJson(r, """{
- | "query": "DB",
- | "dataType": {
- | "superTypes": [
- |
- | ],
- | "hierarchicalMetaTypeName": "org.apache.atlas.typesystem.types.ClassType",
- | "typeName": "DB",
- | "attributeDefinitions": [
- | {
- | "name": "name",
- | "dataTypeName": "string",
- | "multiplicity": {
- | "lower": 0,
- | "upper": 1,
- | "isUnique": false
- | },
- | "isComposite": false,
- | "isUnique": false,
- | "isIndexable": false,
- | "reverseAttributeName": null
- | },
- | {
- | "name": "owner",
- | "dataTypeName": "string",
- | "multiplicity": {
- | "lower": 0,
- | "upper": 1,
- | "isUnique": false
- | },
- | "isComposite": false,
- | "isUnique": false,
- | "isIndexable": false,
- | "reverseAttributeName": null
- | },
- | {
- | "name": "createTime",
- | "dataTypeName": "int",
- | "multiplicity": {
- | "lower": 0,
- | "upper": 1,
- | "isUnique": false
- | },
- | "isComposite": false,
- | "isUnique": false,
- | "isIndexable": false,
- | "reverseAttributeName": null
- |
- | },
- | {
- | "name": "clusterName",
- | "dataTypeName": "string",
- | "multiplicity": {
- | "lower": 0,
- | "upper": 1,
- | "isUnique": false
- | },
- | "isComposite": false,
- | "isUnique": false,
- | "isIndexable": false,
- | "reverseAttributeName": null
- | }
- | ]
- | },
- | "rows": [
- | {
- | "$typeName$": "DB",
- | "$id$": {
- | "$typeName$": "DB",
- | "version": 0
- | },
- | "owner": "John ETL",
- | "name": "Sales",
- | "createTime": 1000,
- | "clusterName": "test"
- | },
- | {
- | "$typeName$": "DB",
- | "$id$": {
- | "$typeName$": "DB",
- | "version": 0
- | },
- | "owner": "Jane BI",
- | "name": "Reporting",
- | "createTime": 1500,
- | "clusterName": "test"
- | }
- | ]
- | }""".stripMargin)
- }
-
- @Test def testName {
- val r = QueryProcessor.evaluate(_class("DB").field("name"), g, gp)
- validateJson(r, "{\n \"query\":\"DB.name\",\n \"dataType\":\"string\",\n \"rows\":[\n \"Sales\",\n \"Reporting\"\n ]\n}")
- }
-
- @Test def testFilter {
- var r = QueryProcessor.evaluate(_class("DB").where(id("name").`=`(string("Reporting"))), g, gp)
- validateJson(r, """{
- | "query": "DB where (name = \"Reporting\")",
- | "dataType": {
- | "superTypes": [],
- | "hierarchicalMetaTypeName": "org.apache.atlas.typesystem.types.ClassType",
- | "typeName": "DB",
- | "attributeDefinitions": [
- | {
- | "name": "name",
- | "dataTypeName": "string",
- | "multiplicity": {
- | "lower": 0,
- | "upper": 1,
- | "isUnique": false
- | },
- | "isComposite": false,
- | "isUnique": false,
- | "isIndexable": false,
- | "reverseAttributeName": null
- | },
- | {
- | "name": "owner",
- | "dataTypeName": "string",
- | "multiplicity": {
- | "lower": 0,
- | "upper": 1,
- | "isUnique": false
- | },
- | "isComposite": false,
- | "isUnique": false,
- | "isIndexable": false,
- | "reverseAttributeName": null
- | },
- | {
- | "name": "createTime",
- | "dataTypeName": "int",
- | "multiplicity": {
- | "lower": 0,
- | "upper": 1,
- | "isUnique": false
- | },
- | "isComposite": false,
- | "isUnique": false,
- | "isIndexable": false,
- | "reverseAttributeName": null
- | },
- | {
- | "name": "clusterName",
- | "dataTypeName": "string",
- | "multiplicity": {
- | "lower": 0,
- | "upper": 1,
- | "isUnique": false
- | },
- | "isComposite": false,
- | "isUnique": false,
- | "isIndexable": false,
- | "reverseAttributeName": null
- | }
- | ]
- | },
- | "rows": [
- | {
- | "$typeName$": "DB",
- | "$id$": {
- | "$typeName$": "DB",
- | "version": 0
- | },
- | "owner": "Jane BI",
- | "name": "Reporting",
- | "createTime": 1500,
- | "clusterName": "test"
- | }
- | ]
- |}""".stripMargin)
- }
-
- @Test def testFilter2 {
- var r = QueryProcessor.evaluate(_class("DB").where(id("DB").field("name").`=`(string("Reporting"))), g, gp)
- validateJson(r, """{
- | "query": "DB where (name = \"Reporting\")",
- | "dataType": {
- | "superTypes": [],
- | "hierarchicalMetaTypeName": "org.apache.atlas.typesystem.types.ClassType",
- | "typeName": "DB",
- | "attributeDefinitions": [
- | {
- | "name": "name",
- | "dataTypeName": "string",
- | "multiplicity": {
- | "lower": 0,
- | "upper": 1,
- | "isUnique": false
- | },
- | "isComposite": false,
- | "isUnique": false,
- | "isIndexable": false,
- | "reverseAttributeName": null
- | },
- | {
- | "name": "owner",
- | "dataTypeName": "string",
- | "multiplicity": {
- | "lower": 0,
- | "upper": 1,
- | "isUnique": false
- | },
- | "isComposite": false,
- | "isUnique": false,
- | "isIndexable": false,
- | "reverseAttributeName": null
- | },
- | {
- | "name": "createTime",
- | "dataTypeName": "int",
- | "multiplicity": {
- | "lower": 0,
- | "upper": 1,
- | "isUnique": false
- | },
- | "isComposite": false,
- | "isUnique": false,
- | "isIndexable": false,
- | "reverseAttributeName": null
- | },
- | {
- | "name": "clusterName",
- | "dataTypeName": "string",
- | "multiplicity": {
- | "lower": 0,
- | "upper": 1,
- | "isUnique": false
- | },
- | "isComposite": false,
- | "isUnique": false,
- | "isIndexable": false,
- | "reverseAttributeName": null
- | }
- | ]
- | },
- | "rows": [
- | {
- | "$typeName$": "DB",
- | "$id$": {
- | "$typeName$": "DB",
- | "version": 0
- | },
- | "owner": "Jane BI",
- | "name": "Reporting",
- | "createTime": 1500,
- | "clusterName": "test"
- | }
- | ]
- |}""".stripMargin)
- }
-
- @Test def testSelect {
- 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 _src1.name, _src1.owner as _src1.owner",
- | "dataType": {
- | "typeName": "__tempQueryResultStruct1",
- | "attributeDefinitions": [
- | {
- | "name": "_src1.name",
- | "dataTypeName": "string",
- | "multiplicity": {
- | "lower": 0,
- | "upper": 1,
- | "isUnique": false
- | },
- | "isComposite": false,
- | "isUnique": false,
- | "isIndexable": false,
- | "reverseAttributeName": null
- | },
- | {
- | "name": "_src1.owner",
- | "dataTypeName": "string",
- | "multiplicity": {
- | "lower": 0,
- | "upper": 1,
- | "isUnique": false
- | },
- | "isComposite": false,
- | "isUnique": false,
- | "isIndexable": false,
- | "reverseAttributeName": null
- | }
- | ]
- | },
- | "rows": [
- | {
- | "$typeName$": "__tempQueryResultStruct1",
- | "_src1.owner": "Jane BI",
- | "_src1.name": "Reporting"
- | }
- | ]
- |}""".stripMargin)
- }
-
- @Test def testIsTrait {
- val r = QueryProcessor.evaluate(_class("Table").where(isTrait("Dimension")), g, gp)
- validateJson(r, """{
- | "query":"Table where Table is Dimension",
- | "dataType":{
- | "superTypes":[
- |
- | ],
- | "hierarchicalMetaTypeName":"org.apache.atlas.typesystem.types.ClassType",
- | "typeName":"Table",
- | "attributeDefinitions":[
- | {
- | "name":"name",
- | "dataTypeName":"string",
- | "multiplicity":{
- | "lower":0,
- | "upper":1,
- | "isUnique":false
- | },
- | "isComposite":false,
- | "isUnique":false,
- | "isIndexable":false,
- | "reverseAttributeName":null
- | },
- | {
- | "name":"db",
- | "dataTypeName":"DB",
- | "multiplicity":{
- | "lower":1,
- | "upper":1,
- | "isUnique":false
- | },
- | "isComposite":false,
- | "isUnique":false,
- | "isIndexable":false,
- | "reverseAttributeName":null
- | },
- | {
- | "name":"sd",
- | "dataTypeName":"StorageDescriptor",
- | "multiplicity":{
- | "lower":1,
- | "upper":1,
- | "isUnique":false
- | },
- | "isComposite":false,
- | "isUnique":false,
- | "isIndexable":false,
- | "reverseAttributeName":null
- | },
- | {
- | "name":"created",
- | "dataTypeName":"date",
- | "multiplicity":{
- | "lower":0,
- | "upper":1,
- | "isUnique":false
- | },
- | "isComposite":false,
- | "isUnique":false,
- | "isIndexable":false,
- | "reverseAttributeName":null
- | }
- | ]
- | },
- | "rows":[
- | {
- | "$typeName$":"Table",
- | "$id$":{
- | "$typeName$":"Table",
- | "version":0
- | },
- | "created":"2014-12-11T02:35:58.440Z",
- | "sd":{
- | "$typeName$":"StorageDescriptor",
- | "version":0
- | },
- | "db":{
- | "$typeName$":"DB",
- | "version":0
- | },
- | "name":"product_dim",
- | "$traits$":{
- | "Dimension":{
- | "$typeName$":"Dimension"
- | }
- | }
- | },
- | {
- | "$typeName$":"Table",
- | "$id$":{
- | "$typeName$":"Table",
- | "version":0
- | },
- | "created":"2014-12-11T02:35:58.440Z",
- | "sd":{
- | "$typeName$":"StorageDescriptor",
- | "version":0
- | },
- | "db":{
- | "$typeName$":"DB",
- | "version":0
- | },
- | "name":"time_dim",
- | "$traits$":{
- | "Dimension":{
- | "$typeName$":"Dimension"
- | }
- | }
- | },
- | {
- | "$typeName$":"Table",
- | "$id$":{
- | "$typeName$":"Table",
- | "version":0
- | },
- | "created":"2014-12-11T02:35:58.440Z",
- | "sd":{
- | "$typeName$":"StorageDescriptor",
- | "version":0
- | },
- | "db":{
- | "$typeName$":"DB",
- | "version":0
- | },
- | "name":"customer_dim",
- | "$traits$":{
- | "Dimension":{
- | "$typeName$":"Dimension"
- | }
- | }
- | }
- | ]
- |}""".stripMargin)
- }
-
- @Test def testhasField {
- val r = QueryProcessor.evaluate(_class("DB").where(hasField("name")), g, gp)
- validateJson(r, """{
- | "query":"DB where DB has name",
- | "dataType":{
- | "superTypes":[
- |
- | ],
- | "hierarchicalMetaTypeName":"org.apache.atlas.typesystem.types.ClassType",
- | "typeName":"DB",
- | "attributeDefinitions":[
- | {
- | "name":"name",
- | "dataTypeName":"string",
- | "multiplicity":{
- | "lower":0,
- | "upper":1,
- | "isUnique":false
- | },
- | "isComposite":false,
- | "isUnique":false,
- | "isIndexable":false,
- | "reverseAttributeName":null
- | },
- | {
- | "name":"owner",
- | "dataTypeName":"string",
- | "multiplicity":{
- | "lower":0,
- | "upper":1,
- | "isUnique":false
- | },
- | "isComposite":false,
- | "isUnique":false,
- | "isIndexable":false,
- | "reverseAttributeName":null
- | },
- | {
- | "name":"createTime",
- | "dataTypeName":"int",
- | "multiplicity":{
- | "lower":0,
- | "upper":1,
- | "isUnique":false
- | },
- | "isComposite":false,
- | "isUnique":false,
- | "isIndexable":false,
- | "reverseAttributeName":null
- | },
- | {
- | "name":"clusterName",
- | "dataTypeName":"string",
- | "multiplicity":{
- | "lower":0,
- | "upper":1,
- | "isUnique":false
- | },
- | "isComposite":false,
- | "isUnique":false,
- | "isIndexable":false,
- | "reverseAttributeName":null
- | }
- | ]
- | },
- | "rows":[
- | {
- | "$typeName$":"DB",
- | "$id$":{
- | "$typeName$":"DB",
- | "version":0
- | },
- | "owner":"John ETL",
- | "name":"Sales",
- | "createTime":1000,
- | "clusterName":"test"
- | },
- | {
- | "$typeName$":"DB",
- | "$id$":{
- | "$typeName$":"DB",
- | "version":0
- | },
- | "owner":"Jane BI",
- | "name":"Reporting",
- | "createTime":1500,
- | "clusterName":"test"
- | }
- | ]
- |}""".stripMargin)
- }
-
- @Test def testFieldReference {
- val r = QueryProcessor.evaluate(_class("DB").field("Table"), g, gp)
- validateJson(r, """{
- | "query":"DB Table",
- | "dataType":{
- | "superTypes":[ ],
- | "hierarchicalMetaTypeName":"org.apache.atlas.typesystem.types.ClassType",
- | "typeName":"Table",
- | "attributeDefinitions":[
- | {
- | "name":"name",
- | "dataTypeName":"string",
- | "multiplicity":{
- | "lower":0,
- | "upper":1,
- | "isUnique":false
- | },
- | "isComposite":false,
- | "isUnique":false,
- | "isIndexable":false,
- | "reverseAttributeName":null
- | },
- | {
- | "name":"db",
- | "dataTypeName":"DB",
- | "multiplicity":{
- | "lower":1,
- | "upper":1,
- | "isUnique":false
- | },
- | "isComposite":false,
- | "isUnique":false,
- | "isIndexable":false,
- | "reverseAttributeName":null
- | },
- | {
- | "name":"sd",
- | "dataTypeName":"StorageDescriptor",
- | "multiplicity":{
- | "lower":1,
- | "upper":1,
- | "isUnique":false
- | },
- | "isComposite":false,
- | "isUnique":false,
- | "isIndexable":false,
- | "reverseAttributeName":null
- | },
- | {
- | "name":"created",
- | "dataTypeName":"date",
- | "multiplicity":{
- | "lower":0,
- | "upper":1,
- | "isUnique":false
- | },
- | "isComposite":false,
- | "isUnique":false,
- | "isIndexable":false,
- | "reverseAttributeName":null
- | }
- | ]
- | },
- | "rows":[
- | {
- | "$typeName$":"Table",
- | "$id$":{
- | "$typeName$":"Table",
- | "version":0
- | },
- | "created":"2014-12-11T02:35:58.440Z",
- | "sd":{
- | "$typeName$":"StorageDescriptor",
- | "version":0
- | },
- | "db":{
- | "$typeName$":"DB",
- | "version":0
- | },
- | "name":"sales_fact"
- | },
- | {
- | "$typeName$":"Table",
- | "$id$":{
- | "$typeName$":"Table",
- | "version":0
- | },
- | "created":"2014-12-11T02:35:58.440Z",
- | "sd":{
- | "$typeName$":"StorageDescriptor",
- | "version":0
- | },
- | "db":{
- | "$typeName$":"DB",
- | "version":0
- | },
- | "name":"product_dim",
- | "$traits$":{
- | "Dimension":{
- | "$typeName$":"Dimension"
- | }
- | }
- | },
- | {
- | "$typeName$":"Table",
- | "$id$":{
- | "$typeName$":"Table",
- | "version":0
- | },
- | "created":"2014-12-11T02:35:58.440Z",
- | "sd":{
- | "$typeName$":"StorageDescriptor",
- | "version":0
- | },
- | "db":{
- | "$typeName$":"DB",
- | "version":0
- | },
- | "name":"time_dim",
- | "$traits$":{
- | "Dimension":{
- | "$typeName$":"Dimension"
- | }
- | }
- | },
- | {
- | "$typeName$":"Table",
- | "$id$":{
- | "$typeName$":"Table",
- | "version":0
- | },
- | "created":"2014-12-11T02:35:58.440Z",
- | "sd":{
- | "$typeName$":"StorageDescriptor",
- | "version":0
- | },
- | "db":{
- | "$typeName$":"DB",
- | "version":0
- | },
- | "name":"customer_dim",
- | "$traits$":{
- | "Dimension":{
- | "$typeName$":"Dimension"
- | }
- | }
- | },
- | {
- | "$typeName$":"Table",
- | "$id$":{
- | "$typeName$":"Table",
- | "version":0
- | },
- | "created":"2014-12-11T02:35:58.440Z",
- | "sd":{
- | "$typeName$":"StorageDescriptor",
- | "version":0
- | },
- | "db":{
- | "$typeName$":"DB",
- | "version":0
- | },
- | "name":"sales_fact_daily_mv"
- | },
- | {
- | "$typeName$":"Table",
- | "$id$":{
- | "$typeName$":"Table",
- | "version":0
- | },
- | "created":"2014-12-11T02:35:58.440Z",
- | "sd":{
- | "$typeName$":"StorageDescriptor",
- | "version":0
- | },
- | "db":{
- | "$typeName$":"DB",
- | "version":0
- | },
- | "name":"sales_fact_monthly_mv"
- | }
- | ]
- |}""".stripMargin)
- }
-
- @Test def testBackReference {
- val r = QueryProcessor.evaluate(
- _class("DB").as("db").field("Table").where(id("db").field("name").`=`(string("Reporting"))), g, gp)
- validateJson(r, null)
- }
-
- @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 _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\":false,\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\":false,\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 {
- val r = QueryProcessor.evaluate(_class("DB").where(id("name").`=`(string("Reporting")).
- and(id("createTime") > int(0))), g, gp)
- validateJson(r, """{
- | "query": "DB where (name = \"Reporting\") and (createTime > 0)",
- | "dataType": {
- | "superTypes": [
- |
- | ],
- | "hierarchicalMetaTypeName": "org.apache.atlas.typesystem.types.ClassType",
- | "typeName": "DB",
- | "attributeDefinitions": [
- | {
- | "name": "name",
- | "dataTypeName": "string",
- | "multiplicity": {
- | "lower": 0,
- | "upper": 1,
- | "isUnique": false
- | },
- | "isComposite": false,
- | "isUnique": false,
- | "isIndexable": false,
- | "reverseAttributeName": null
- | },
- | {
- | "name": "owner",
- | "dataTypeName": "string",
- | "multiplicity": {
- | "lower": 0,
- | "upper": 1,
- | "isUnique": false
- | },
- | "isComposite": false,
- | "isUnique": false,
- | "isIndexable": false,
- | "reverseAttributeName": null
- | },
- | {
- | "name": "createTime",
- | "dataTypeName": "int",
- | "multiplicity": {
- | "lower": 0,
- | "upper": 1,
- | "isUnique": false
- | },
- | "isComposite": false,
- | "isUnique": false,
- | "isIndexable": false,
- | "reverseAttributeName": null
- | },
- | {
- | "name": "clusterName",
- | "dataTypeName": "string",
- | "multiplicity": {
- | "lower": 0,
- | "upper": 1,
- | "isUnique": false
- | },
- | "isComposite": false,
- | "isUnique": false,
- | "isIndexable": false,
- | "reverseAttributeName": null
- | }
- | ]
- | },
- | "rows": [
- | {
- | "$typeName$": "DB",
- | "$id$": {
- | "$typeName$": "DB",
- | "version": 0
- | },
- | "owner": "Jane BI",
- | "name": "Reporting",
- | "createTime": 1500,
- | "clusterName": "test"
- | }
- | ]
- |}""".stripMargin)
- }
-
- @Test def testJoinAndSelect1 {
- val r = QueryProcessor.evaluate(
- _class("DB").as("db1").where(id("name").`=`(string("Sales"))).field("Table").as("tab").
- where(isTrait("Dimension")).
- select(id("db1").field("name").as("dbName"), id("tab").field("name").as("tabName")), g, gp
- )
- validateJson(r, "{\n \"query\":\"DB as db1 where (name = \\\"Sales\\\") Table as tab where DB as db1 where (name = \\\"Sales\\\") Table as tab is Dimension as _src1 select db1.name as dbName, tab.name as tabName\",\n \"dataType\":{\n \"typeName\":\"__tempQueryResultStruct5\",\n \"attributeDefinitions\":[\n {\n \"name\":\"dbName\",\n \"dataTypeName\":\"string\",\n \"multiplicity\":{\n \"lower\":0,\n \"upper\":1,\n \"isUnique\":false\n },\n \"isComposite\":false,\n \"isUnique\":false,\n \"isIndexable\":false,\n \"reverseAttributeName\":null\n },\n {\n \"name\":\"tabName\",\n \"dataTypeName\":\"string\",\n \"multiplicity\":{\n \"lower\":0,\n \"upper\":1,\n \"isUnique\":false\n },\n \"isComposite\":false,\n \"isUnique\":false,\n \"isIndexable\":false,\n \"reverseAttributeName\":null\n }\n
]\n },\n \"rows\":[\n {\n \"$typeName$\":\"__tempQueryResultStruct5\",\n \"dbName\":\"Sales\",\n \"tabName\":\"product_dim\"\n },\n {\n \"$typeName$\":\"__tempQueryResultStruct5\",\n \"dbName\":\"Sales\",\n \"tabName\":\"time_dim\"\n },\n {\n \"$typeName$\":\"__tempQueryResultStruct5\",\n \"dbName\":\"Sales\",\n \"tabName\":\"customer_dim\"\n }\n ]\n}")
- }
-
- @Test def testJoinAndSelect2 {
- val r = QueryProcessor.evaluate(
- _class("DB").as("db1").where((id("db1").field("createTime") > int(0))
- .or(id("name").`=`(string("Reporting")))).field("Table").as("tab")
- .select(id("db1").field("name").as("dbName"), id("tab").field("name").as("tabName")), g, gp
- )
- validateJson(r, "{\n \"query\":\"DB as db1 where (createTime > 0) or (name = \\\"Reporting\\\") Table as tab select db1.name as dbName, tab.name as tabName\",\n \"dataType\":{\n \"typeName\":\"__tempQueryResultStruct6\",\n \"attributeDefinitions\":[\n {\n \"name\":\"dbName\",\n \"dataTypeName\":\"string\",\n \"multiplicity\":{\n \"lower\":0,\n \"upper\":1,\n \"isUnique\":false\n },\n \"isComposite\":false,\n \"isUnique\":false,\n \"isIndexable\":false,\n \"reverseAttributeName\":null\n },\n {\n \"name\":\"tabName\",\n \"dataTypeName\":\"string\",\n \"multiplicity\":{\n \"lower\":0,\n \"upper\":1,\n \"isUnique\":false\n },\n \"isComposite\":false,\n \"isUnique\":false,\n \"isIndexable\":false,\n \"reverseAttributeName\":null\n }\n ]\n },\n \"rows\":[\n {\n \"$typeName$\":\"__t
empQueryResultStruct6\",\n \"dbName\":\"Sales\",\n \"tabName\":\"sales_fact\"\n },\n {\n \"$typeName$\":\"__tempQueryResultStruct6\",\n \"dbName\":\"Sales\",\n \"tabName\":\"product_dim\"\n },\n {\n \"$typeName$\":\"__tempQueryResultStruct6\",\n \"dbName\":\"Sales\",\n \"tabName\":\"time_dim\"\n },\n {\n \"$typeName$\":\"__tempQueryResultStruct6\",\n \"dbName\":\"Sales\",\n \"tabName\":\"customer_dim\"\n },\n {\n \"$typeName$\":\"__tempQueryResultStruct6\",\n \"dbName\":\"Reporting\",\n \"tabName\":\"sales_fact_daily_mv\"\n },\n {\n \"$typeName$\":\"__tempQueryResultStruct6\",\n \"dbName\":\"Reporting\",\n \"tabName\":\"sales_fact_monthly_mv\"\n }\n ]\n}")
- }
-
- @Test def testJoinAndSelect3 {
- val r = QueryProcessor.evaluate(
- _class("DB").as("db1").where((id("db1").field("createTime") > int(0))
- .and(id("db1").field("name").`=`(string("Reporting")))
- .or(id("db1").hasField("owner"))).field("Table").as("tab")
- .select(id("db1").field("name").as("dbName"), id("tab").field("name").as("tabName")), g, gp
- )
- validateJson(r, "{\n \"query\":\"DB as db1 where (createTime > 0) and (name = \\\"Reporting\\\") or db1 has owner Table as tab select db1.name as dbName, tab.name as tabName\",\n \"dataType\":{\n \"typeName\":\"__tempQueryResultStruct7\",\n \"attributeDefinitions\":[\n {\n \"name\":\"dbName\",\n \"dataTypeName\":\"string\",\n \"multiplicity\":{\n \"lower\":0,\n \"upper\":1,\n \"isUnique\":false\n },\n \"isComposite\":false,\n \"isUnique\":false,\n \"isIndexable\":false,\n \"reverseAttributeName\":null\n },\n {\n \"name\":\"tabName\",\n \"dataTypeName\":\"string\",\n \"multiplicity\":{\n \"lower\":0,\n \"upper\":1,\n \"isUnique\":false\n },\n \"isComposite\":false,\n \"isUnique\":false,\n \"isIndexable\":false,\n \"reverseAttributeName\":null\n }\n ]\n },\n \"rows\":[\n {\n \"
$typeName$\":\"__tempQueryResultStruct7\",\n \"dbName\":\"Sales\",\n \"tabName\":\"sales_fact\"\n },\n {\n \"$typeName$\":\"__tempQueryResultStruct7\",\n \"dbName\":\"Sales\",\n \"tabName\":\"product_dim\"\n },\n {\n \"$typeName$\":\"__tempQueryResultStruct7\",\n \"dbName\":\"Sales\",\n \"tabName\":\"time_dim\"\n },\n {\n \"$typeName$\":\"__tempQueryResultStruct7\",\n \"dbName\":\"Sales\",\n \"tabName\":\"customer_dim\"\n },\n {\n \"$typeName$\":\"__tempQueryResultStruct7\",\n \"dbName\":\"Reporting\",\n \"tabName\":\"sales_fact_daily_mv\"\n },\n {\n \"$typeName$\":\"__tempQueryResultStruct7\",\n \"dbName\":\"Reporting\",\n \"tabName\":\"sales_fact_monthly_mv\"\n }\n ]\n}")
- }
-
- @Test def testJoinAndSelect4 {
- val r = QueryProcessor.evaluate(
- _class("DB").as("db1").where(id("name").`=`(string("Sales"))).field("Table").as("tab").
- where(isTrait("Dimension")).
- select(id("db1").as("dbO"), id("tab").field("name").as("tabName")), g, gp
- )
- validateJson(r, "{\n \"query\":\"DB as db1 where (name = \\\"Sales\\\") Table as tab where DB as db1 where (name = \\\"Sales\\\") Table as tab is Dimension as _src1 select db1 as dbO, tab.name as tabName\",\n \"dataType\":{\n \"typeName\":\"\",\n \"attributeDefinitions\":[\n {\n \"name\":\"dbO\",\n \"dataTypeName\":\"DB\",\n \"multiplicity\":{\n \"lower\":0,\n \"upper\":1,\n \"isUnique\":false\n },\n \"isComposite\":false,\n \"isUnique\":false,\n \"isIndexable\":false,\n \"reverseAttributeName\":null\n },\n {\n \"name\":\"tabName\",\n \"dataTypeName\":\"string\",\n \"multiplicity\":{\n \"lower\":0,\n \"upper\":1,\n \"isUnique\":false\n },\n \"isComposite\":false,\n \"isUnique\":false,\n \"isIndexable\":false,\n \"reverseAttributeName\":null\n }\n ]\n },\n \"rows\":[\n {\n \"$
typeName$\":\"\",\n \"dbO\":{\n \"$typeName$\":\"DB\",\n \"version\":0\n },\n \"tabName\":\"product_dim\"\n },\n {\n \"$typeName$\":\"\",\n \"dbO\":{\n \"$typeName$\":\"DB\",\n \"version\":0\n },\n \"tabName\":\"time_dim\"\n },\n {\n \"$typeName$\":\"\",\n \"dbO\":{\n \"$typeName$\":\"DB\",\n \"version\":0\n },\n \"tabName\":\"customer_dim\"\n }\n ]\n}")
- }
-
- @Test def testArrayComparision {
- val p = QueryParser
- val e = p("Partition as p where values = ['2015-01-01']," +
- " table where name = 'sales_fact_daily_mv'," +
- " 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 p",
- | "dataType":{
- | "typeName":"__tempQueryResultStruct2",
- | "attributeDefinitions":[
- | {
- | "name":"p",
- | "dataTypeName":"Partition",
- | "multiplicity":{
- | "lower":0,
- | "upper":1,
- | "isUnique":false
- | },
- | "isComposite":false,
- | "isUnique":false,
- | "isIndexable":false,
- | "reverseAttributeName":null
- | }
- | ]
- | },
- | "rows":[
- | {
- | "$typeName$":"__tempQueryResultStruct2",
- | "p":{
- | "$typeName$":"Partition",
- | "version":0
- | }
- | }
- | ]
- |}""".stripMargin)
- }
-
- @Test def testArrayComparisionWithSelectOnArray {
- val p = QueryParser
- val e = p("Partition as p where values = ['2015-01-01']," +
- " table where name = 'sales_fact_daily_mv'," +
- " db where name = 'Reporting' and clusterName = 'test' select p.values").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.values as p.values",
- | "dataType":{
- | "typeName":"__tempQueryResultStruct2",
- | "attributeDefinitions":[
- | {
- | "name":"p.values",
- | "dataTypeName":"array<string>",
- | "multiplicity":{
- | "lower":0,
- | "upper":1,
- | "isUnique":false
- | },
- | "isComposite":false,
- | "isUnique":false,
- | "isIndexable":false,
- | "reverseAttributeName":null
- | }
- | ]
- | },
- | "rows":[
- | {
- | "$typeName$":"__tempQueryResultStruct2",
- | "p.values":[
- | "2015-01-01"
- | ]
- | }
- | ]
- |}
- """.stripMargin)
- }
-
- @Test def testArrayInWhereClause {
- val p = QueryParser
- val e = p("Partition as p where values = ['2015-01-01']").right.get
- val r = QueryProcessor.evaluate(e, g, gp)
- validateJson(r, """{
- | "query":"Partition as p where (values = [\"2015-01-01\"])",
- | "dataType":{
- | "superTypes":[
- |
- | ],
- | "hierarchicalMetaTypeName":"org.apache.atlas.typesystem.types.ClassType",
- | "typeName":"Partition",
- | "attributeDefinitions":[
- | {
- | "name":"values",
- | "dataTypeName":"array<string>",
- | "multiplicity":{
- | "lower":1,
- | "upper":1,
- | "isUnique":false
- | },
- | "isComposite":false,
- | "isUnique":false,
- | "isIndexable":false,
- | "reverseAttributeName":null
- | },
- | {
- | "name":"table",
- | "dataTypeName":"Table",
- | "multiplicity":{
- | "lower":1,
- | "upper":1,
- | "isUnique":false
- | },
- | "isComposite":false,
- | "isUnique":false,
- | "isIndexable":false,
- | "reverseAttributeName":null
- | }
- | ]
- | },
- | "rows":[
- | {
- | "$typeName$":"Partition",
- | "$id$":{
- | "$typeName$":"Partition",
- | "version":0
- | },
- | "values":[
- | "2015-01-01"
- | ],
- | "table":{
- | "$typeName$":"Table",
- | "version":0
- | }
- | }
- | ]
- |}""".stripMargin)
- }
-
- @Test def testArrayWithStruct {
-// val p = new QueryParser
-// val e = p("from LoadProcess select inputTables").right.get
-// val r = QueryProcessor.evaluate(e, g)
- val r = QueryProcessor.evaluate(_class("LoadProcess").field("inputTables"), g, gp)
- validateJson(r)
- }
-
- @Test(expectedExceptions = Array(classOf[ExpressionException]))
- def testNegativeInvalidType {
- val p = QueryParser
- val e = p("from blah").right.get
- QueryProcessor.evaluate(e, g, gp)
- }
-
- @Test def testJoinAndSelect5 {
- val p = QueryParser
- val e = p("Table as t where name = 'sales_fact' db where name = 'Sales' and owner = 'John ETL' select t").right.get
- val r = QueryProcessor.evaluate(e, g, gp)
- validateJson(r)
- }
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/repository/src/test/scala/org/apache/atlas/query/GremlinTest2.scala
----------------------------------------------------------------------
diff --git a/repository/src/test/scala/org/apache/atlas/query/GremlinTest2.scala b/repository/src/test/scala/org/apache/atlas/query/GremlinTest2.scala
deleted file mode 100755
index 880a0c6..0000000
--- a/repository/src/test/scala/org/apache/atlas/query/GremlinTest2.scala
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.atlas.query
-
-import org.apache.atlas.{DBSandboxer, TestUtils}
-import org.apache.atlas.discovery.graph.DefaultGraphPersistenceStrategy
-import org.apache.atlas.query.Expressions._class
-import org.apache.atlas.query.Expressions._trait
-import org.apache.atlas.query.Expressions.id
-import org.apache.atlas.repository.graph.GraphBackedMetadataRepository
-import org.apache.atlas.repository.graphdb.AtlasGraph
-import org.apache.atlas.typesystem.types.TypeSystem
-import org.testng.annotations._
-import org.apache.atlas.repository.graph.AtlasGraphProvider
-
-class GremlinTest2 extends BaseGremlinTest {
-
- var g: AtlasGraph[_,_] = null
- var gp:GraphPersistenceStrategies = null;
-
- @BeforeMethod
- def resetRequestContext() {
- TestUtils.resetRequestContext();
- }
-
- @BeforeClass
- def beforeAll() {
- TypeSystem.getInstance().reset()
- QueryTestsUtils.setupTypes
- var repo = new GraphBackedMetadataRepository(null, null);
- gp = new DefaultGraphPersistenceStrategy(repo)
- g = QueryTestsUtils.setupTestGraph(repo)
- }
-
- @AfterClass
- def afterAll() {
- AtlasGraphProvider.cleanup();
- }
-
- @Test def testTraitSelect {
- val r = QueryProcessor.evaluate(_class("Table").as("t").join("Dimension").as("dim").select(id("t"), id("dim")), g)
- validateJson(r, "{\n \"query\":\"Table as t.Dimension as dim select t as _col_0, dim as _col_1\",\n \"dataType\":{\n \"typeName\":\"\",\n \"attributeDefinitions\":[\n {\n \"name\":\"_col_0\",\n \"dataTypeName\":\"Table\",\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\":\"Dimension\",\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$\":\"\",\n \"_col_1\":{\n \"$typeName$\":\"Dimension\"\n },\n \"_col_0\"
:{\n \"id\":\"3328\",\n \"$typeName$\":\"Table\",\n \"version\":0\n }\n },\n {\n \"$typeName$\":\"\",\n \"_col_1\":{\n \"$typeName$\":\"Dimension\"\n },\n \"_col_0\":{\n \"id\":\"4864\",\n \"$typeName$\":\"Table\",\n \"version\":0\n }\n },\n {\n \"$typeName$\":\"\",\n \"_col_1\":{\n \"$typeName$\":\"Dimension\"\n },\n \"_col_0\":{\n \"id\":\"6656\",\n \"$typeName$\":\"Table\",\n \"version\":0\n }\n }\n ]\n}")
- }
-
- @Test def testTrait {
- val r = QueryProcessor.evaluate(_trait("Dimension"), g)
- validateJson(r)
- }
-
- @Test def testTraitInstance {
- val r = QueryProcessor.evaluate(_trait("Dimension").traitInstance(), g)
- validateJson(r)
- }
-
- @Test def testInstanceAddedToFilter {
- val r = QueryProcessor.evaluate(_trait("Dimension").hasField("typeName"), g)
- validateJson(r)
- }
-
- @Test def testInstanceFilter {
- val r = QueryProcessor.evaluate(_trait("Dimension").traitInstance().hasField("name"), g)
- validateJson(r)
- }
-
- @Test def testLineageWithPath {
- val r = QueryProcessor.evaluate(_class("Table").loop(id("LoadProcess").field("outputTable")).path(), g)
- validateJson(r)
- }
-
- @Test def testLineageAllSelectWithPath {
- val r = QueryProcessor.evaluate(_class("Table").as("src").loop(id("LoadProcess").field("outputTable")).as("dest").
- select(id("src").field("name").as("srcTable"), id("dest").field("name").as("destTable")).path(), g)
- validateJson(r)
- }
-
- @Test def testLineageAllSelectWithPathFromParser {
- val p = QueryParser
- val e = p("Table as src loop (LoadProcess outputTable) as dest " +
- "select src.name as srcTable, dest.name as destTable withPath").right.get
- //Table as src loop (LoadProcess where LoadProcess.outputTable) as dest select src.name as srcTable, dest.name as destTable withPath
- val r = QueryProcessor.evaluate(e, g)
- validateJson(r)
- }
-
- @Test def testLineageAllSelectWithPathFromParser2 {
- val p = QueryParser
-
- val e = p("Table as src loop (`LoadProcess->outputTable` inputTables) as dest " +
- "select src.name as srcTable, dest.name as destTable withPath").right.get
- val r = QueryProcessor.evaluate(e, g)
- validateJson(r)
- }
-
- @Test def testHighLevelLineage {
- val r = InputLineageClosureQuery("Table", "name", "sales_fact_monthly_mv",
- "LoadProcess",
- "inputTables",
- "outputTable",
- None, Some(List("name")), true, getPersistenceStrategy(g), g).evaluate()
- validateJson(r)
- }
-
- @Test def testHighLevelLineageReturnGraph {
- val q = InputLineageClosureQuery("Table", "name", "sales_fact_monthly_mv",
- "LoadProcess",
- "inputTables",
- "outputTable",
- None, Some(List("name")), true, getPersistenceStrategy(g), g);
- val gr = q.evaluate();
- val r = q.graph(gr);
-
- println(r.toInstanceJson)
- //validateJson(r)
- }
-
- @Test def testHighLevelWhereUsed {
- val r = OutputLineageClosureQuery("Table", "name", "sales_fact",
- "LoadProcess",
- "inputTables",
- "outputTable",
- None, Some(List("name")), true, getPersistenceStrategy(g), g).evaluate()
- validateJson(r)
- }
-
- @Test def testHighLevelWhereUsedReturnGraph {
- val q = OutputLineageClosureQuery("Table", "name", "sales_fact",
- "LoadProcess",
- "inputTables",
- "outputTable",
- None, Some(List("name")), true, getPersistenceStrategy(g), g)
- val gr = q.evaluate();
- val r = q.graph(gr);
- println(r.toInstanceJson)
- }
-
- private def getPersistenceStrategy(g: AtlasGraph[_,_]) : GraphPersistenceStrategies = return GraphPersistenceStrategy1(g)
-
-}
\ No newline at end of file