[ASTERIXDB-2979][MTD][GRAPH] Implement CREATE / DROP GRAPH

Initial commit. This supports CREATE GRAPH, DROP GRAPH, and prevents
dropping views / functions / datasets / synonyms / dataverses that a
graph depends on.

Change-Id: Ibaf4dc7066b85d8ea3b58c6b90fd83af3a700506
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb-graph/+/14644
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Ian Maxon <imaxon@uci.edu>
diff --git a/asterix-graphix/src/test/java/org/apache/asterix/graphix/test/GraphixExecutionTest.java b/asterix-graphix/src/test/java/org/apache/asterix/graphix/test/GraphixExecutionTest.java
new file mode 100644
index 0000000..0820e29
--- /dev/null
+++ b/asterix-graphix/src/test/java/org/apache/asterix/graphix/test/GraphixExecutionTest.java
@@ -0,0 +1,91 @@
+/*
+ * 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.asterix.graphix.test;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.asterix.test.common.TestExecutor;
+import org.apache.asterix.test.runtime.ExecutionTestUtil;
+import org.apache.asterix.testframework.context.TestCaseContext;
+import org.apache.asterix.testframework.xml.TestGroup;
+import org.apache.commons.lang3.StringUtils;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class GraphixExecutionTest {
+    protected static final String PATH_ACTUAL = "target/rttest" + File.separator;
+    protected static final String PATH_BASE =
+            StringUtils.join(new String[] { "src", "test", "resources", "runtimets" }, File.separator);
+    protected static final String TEST_CONFIG_FILE_NAME = "src/main/resources/cc.conf";
+    private static final String TEST_SUITE_FILE = "testsuite.xml";
+    private static final String ONLY_SUITE_FILE = "only.xml";
+
+    private static final GraphixIntegrationUtil integrationUtil = new GraphixIntegrationUtil();
+    private static final TestExecutor testExecutor = new TestExecutor();
+
+    protected static TestGroup FailedGroup;
+    protected TestCaseContext tcCtx;
+
+    public GraphixExecutionTest(TestCaseContext tcCtx) {
+        this.tcCtx = tcCtx;
+    }
+
+    @BeforeClass
+    public static void setUp() throws Exception {
+        //noinspection ResultOfMethodCallIgnored
+        new File(PATH_ACTUAL).mkdirs();
+        ExecutionTestUtil.setUp(true, TEST_CONFIG_FILE_NAME, integrationUtil, false, null);
+    }
+
+    @AfterClass
+    public static void tearDown() throws Exception {
+        ExecutionTestUtil.tearDown(true, integrationUtil, true);
+        integrationUtil.removeTestStorageFiles();
+    }
+
+    @Parameters(name = "ExecutionTest {index}: {0}")
+    public static Collection<Object[]> tests() throws Exception {
+        Collection<Object[]> test_cases = buildTestsInXml(ONLY_SUITE_FILE);
+        if (test_cases.size() == 0) {
+            test_cases = buildTestsInXml(TEST_SUITE_FILE);
+        }
+        return test_cases;
+    }
+
+    protected static Collection<Object[]> buildTestsInXml(String xmlfile) throws Exception {
+        Collection<Object[]> testArgs = new ArrayList<>();
+        TestCaseContext.Builder b = new TestCaseContext.Builder();
+        for (TestCaseContext ctx : b.build(new File(PATH_BASE), xmlfile)) {
+            testArgs.add(new Object[] { ctx });
+        }
+        return testArgs;
+    }
+
+    @Test
+    public void test() throws Exception {
+        testExecutor.executeTest(PATH_ACTUAL, tcCtx, null, false, FailedGroup);
+    }
+}
diff --git a/asterix-graphix/src/test/java/org/apache/asterix/graphix/test/GraphixIntegrationUtil.java b/asterix-graphix/src/test/java/org/apache/asterix/graphix/test/GraphixIntegrationUtil.java
new file mode 100644
index 0000000..e3ea8e9
--- /dev/null
+++ b/asterix-graphix/src/test/java/org/apache/asterix/graphix/test/GraphixIntegrationUtil.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2009-2013 by The Regents of the University of California
+ * Licensed 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 from
+ *
+ *     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.asterix.graphix.test;
+
+import org.apache.asterix.api.common.AsterixHyracksIntegrationUtil;
+import org.apache.hyracks.test.support.TestUtils;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class GraphixIntegrationUtil extends AsterixHyracksIntegrationUtil {
+    private static final String DEFAULT_CONF_FILE = "asterixdb/asterix-opt/asterix-graphix/src/main/resources/cc.conf";
+
+    public static void main(String[] args) {
+        TestUtils.redirectLoggingToConsole();
+        GraphixIntegrationUtil graphixIntegrationUtil = new GraphixIntegrationUtil();
+        try {
+            boolean cleanupOnStart = Boolean.getBoolean("cleanup.start");
+            boolean cleanupOnShutdown = Boolean.getBoolean("cleanup.shutdown");
+            String confFile = System.getProperty("external.lib", DEFAULT_CONF_FILE);
+            graphixIntegrationUtil.run(cleanupOnStart, cleanupOnShutdown, confFile);
+        } catch (Exception e) {
+            e.printStackTrace();
+            System.exit(1);
+        }
+    }
+}
diff --git a/asterix-graphix/src/test/java/org/apache/asterix/graphix/test/GraphixMetadataTest.java b/asterix-graphix/src/test/java/org/apache/asterix/graphix/test/GraphixMetadataTest.java
new file mode 100644
index 0000000..bf2c756
--- /dev/null
+++ b/asterix-graphix/src/test/java/org/apache/asterix/graphix/test/GraphixMetadataTest.java
@@ -0,0 +1,81 @@
+/*
+ * 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.asterix.graphix.test;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.asterix.test.common.TestExecutor;
+import org.apache.asterix.testframework.context.TestCaseContext;
+import org.apache.commons.lang3.StringUtils;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class GraphixMetadataTest {
+    private static final String PATH_ACTUAL = "target" + File.separator + "mdtest" + File.separator;
+    private static final String PATH_BASE =
+            StringUtils.join(new String[] { "src", "test", "resources", "metadata" + File.separator }, File.separator);
+    private static final String TEST_CONFIG_FILE_NAME = "src/main/resources/cc.conf";
+
+    private static final TestExecutor testExecutor = new TestExecutor();
+    private static final GraphixIntegrationUtil integrationUtil = new GraphixIntegrationUtil();
+
+    private final TestCaseContext tcCtx;
+
+    public GraphixMetadataTest(TestCaseContext tcCtx) {
+        this.tcCtx = tcCtx;
+    }
+
+    @BeforeClass
+    public static void setUp() throws Exception {
+        //noinspection ResultOfMethodCallIgnored
+        new File(PATH_ACTUAL).mkdirs();
+        integrationUtil.init(true, TEST_CONFIG_FILE_NAME);
+    }
+
+    @AfterClass
+    public static void tearDown() throws Exception {
+        integrationUtil.deinit(true);
+        File outdir = new File(PATH_ACTUAL);
+        File[] files = outdir.listFiles();
+        if (files == null || files.length == 0) {
+            //noinspection ResultOfMethodCallIgnored
+            outdir.delete();
+        }
+    }
+
+    @Parameters(name = "MetadataTest {index}: {0}")
+    public static Collection<Object[]> tests() throws Exception {
+        Collection<Object[]> testArgs = new ArrayList<>();
+        TestCaseContext.Builder b = new TestCaseContext.Builder();
+        for (TestCaseContext ctx : b.build(new File(PATH_BASE))) {
+            testArgs.add(new Object[] { ctx });
+        }
+        return testArgs;
+    }
+
+    @Test
+    public void test() throws Exception {
+        testExecutor.executeTest(PATH_ACTUAL, tcCtx, null, false);
+    }
+}
diff --git a/asterix-graphix/src/test/resources/metadata/queries/graphix/yelp-example/yelp-example.1.ddl.sqlpp b/asterix-graphix/src/test/resources/metadata/queries/graphix/yelp-example/yelp-example.1.ddl.sqlpp
new file mode 100644
index 0000000..0f4761d
--- /dev/null
+++ b/asterix-graphix/src/test/resources/metadata/queries/graphix/yelp-example/yelp-example.1.ddl.sqlpp
@@ -0,0 +1,115 @@
+/*
+ * 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.
+ */
+
+DROP DATAVERSE    Yelp IF EXISTS;
+DROP DATAVERSE    Yelp_A IF EXISTS;
+DROP DATAVERSE    Yelp_B IF EXISTS;
+CREATE DATAVERSE  Yelp;
+CREATE DATAVERSE  Yelp_A;
+CREATE DATAVERSE  Yelp_B;
+
+USE               Yelp_A;
+CREATE TYPE       GenericType
+AS                { _id: uuid };
+CREATE DATASET    Businesses (GenericType)
+PRIMARY KEY       _id AUTOGENERATED;
+CREATE DATASET    Checkins (GenericType)
+PRIMARY KEY       _id AUTOGENERATED;
+CREATE DATASET    Friends (GenericType)
+PRIMARY KEY       _id AUTOGENERATED;
+CREATE DATASET    Reviews (GenericType)
+PRIMARY KEY       _id AUTOGENERATED;
+CREATE DATASET    Tips (GenericType)
+PRIMARY KEY       _id AUTOGENERATED;
+CREATE DATASET    Users (GenericType)
+PRIMARY KEY       _id AUTOGENERATED;
+CREATE FUNCTION   RelevantBusinesses()
+                  { FROM Businesses B
+                    WHERE B.stars > 3.5
+                    SELECT B.* };
+
+USE               Yelp_B;
+CREATE TYPE       GenericType
+AS                { _id: uuid };
+CREATE DATASET    Businesses (GenericType)
+PRIMARY KEY       _id AUTOGENERATED;
+CREATE DATASET    Checkins (GenericType)
+PRIMARY KEY       _id AUTOGENERATED;
+CREATE DATASET    Friends (GenericType)
+PRIMARY KEY       _id AUTOGENERATED;
+CREATE DATASET    Reviews (GenericType)
+PRIMARY KEY       _id AUTOGENERATED;
+CREATE DATASET    Tips (GenericType)
+PRIMARY KEY       _id AUTOGENERATED;
+CREATE DATASET    Users (GenericType)
+PRIMARY KEY       _id AUTOGENERATED;
+CREATE SYNONYM    Yelpers FOR Users;
+
+USE               Yelp;
+CREATE GRAPH      YelpGraph_1 AS
+VERTEX            (:User)
+                  PRIMARY KEY (user_id)
+                  AS Yelp_B.Yelpers,
+VERTEX            (:Review)
+                  PRIMARY KEY (review_id)
+                  AS ( FROM    Yelp_A.Reviews R
+                       SELECT  VALUE R ),
+VERTEX            (:Business)
+                  PRIMARY KEY (business_id)
+                  AS ( FROM    Yelp_A.RelevantBusinesses() B
+                       SELECT  VALUE B ),
+EDGE              (:User)-[:FRIENDS_WITH]->(:User)
+                  PRIMARY KEY (user_id, friend)
+                  SOURCE KEY (user_id)
+                  DESTINATION KEY (friend)
+                  AS ( FROM    Yelp_B.Users U
+                       UNNEST  U.friends F
+                       SELECT  U.user_id, F AS friend ),
+EDGE              (:User)-[:FRIENDS_WITH]->(:User)
+                          PRIMARY KEY (user_id, friend)
+                          SOURCE KEY (user_id)
+                          DESTINATION KEY (friend)
+                          AS Yelp_B.Friends,
+EDGE              (:Review)-[:MADE_BY]->(:User)
+                  DESTINATION KEY (user_id),
+EDGE              (:Review)-[:ABOUT]->(:Business)
+                  DESTINATION KEY (business_id);
+
+CREATE GRAPH      YelpGraph_2 IF NOT EXISTS AS
+VERTEX            (:Review)
+                  PRIMARY KEY (review_id)
+                  AS ( FROM    Yelp_A.Reviews R
+                       SELECT  VALUE R ),
+VERTEX            (:Business)
+                  PRIMARY KEY (business_id)
+                  AS ( FROM    Yelp_A.RelevantBusinesses() B
+                       SELECT  VALUE B ),
+EDGE              (:Review)-[:ABOUT]->(:Business)
+                  DESTINATION KEY (business_id);
+CREATE GRAPH      YelpGraph_2 IF NOT EXISTS AS
+VERTEX            (:Review)
+                  PRIMARY KEY (review_id)
+                  AS ( FROM    Yelp_A.Reviews R
+                       SELECT  VALUE R ),
+VERTEX            (:Business)
+                  PRIMARY KEY (business_id)
+                  AS ( FROM    Yelp_A.RelevantBusinesses() B
+                       SELECT  VALUE B ),
+EDGE              (:Review)-[:ABOUT]->(:Business)
+                  DESTINATION KEY (business_id);
diff --git a/asterix-graphix/src/test/resources/metadata/queries/graphix/yelp-example/yelp-example.2.query.sqlpp b/asterix-graphix/src/test/resources/metadata/queries/graphix/yelp-example/yelp-example.2.query.sqlpp
new file mode 100644
index 0000000..b8151af
--- /dev/null
+++ b/asterix-graphix/src/test/resources/metadata/queries/graphix/yelp-example/yelp-example.2.query.sqlpp
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+
+FROM      `Metadata`.`Graph` G
+SELECT    G.DataverseName, G.GraphName, G.Dependencies, G.Vertices, G.Edges
+ORDER BY  G.DataverseName, G.GraphName;
diff --git a/asterix-graphix/src/test/resources/metadata/queries/graphix/yelp-example/yelp-example.3.ddl.sqlpp b/asterix-graphix/src/test/resources/metadata/queries/graphix/yelp-example/yelp-example.3.ddl.sqlpp
new file mode 100644
index 0000000..ca52d3d
--- /dev/null
+++ b/asterix-graphix/src/test/resources/metadata/queries/graphix/yelp-example/yelp-example.3.ddl.sqlpp
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+DROP GRAPH  Yelp.YelpGraph_1 IF EXISTS;
+DROP GRAPH  Yelp.YelpGraph_1 IF EXISTS;
diff --git a/asterix-graphix/src/test/resources/metadata/queries/graphix/yelp-example/yelp-example.4.query.sqlpp b/asterix-graphix/src/test/resources/metadata/queries/graphix/yelp-example/yelp-example.4.query.sqlpp
new file mode 100644
index 0000000..b8151af
--- /dev/null
+++ b/asterix-graphix/src/test/resources/metadata/queries/graphix/yelp-example/yelp-example.4.query.sqlpp
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+
+FROM      `Metadata`.`Graph` G
+SELECT    G.DataverseName, G.GraphName, G.Dependencies, G.Vertices, G.Edges
+ORDER BY  G.DataverseName, G.GraphName;
diff --git a/asterix-graphix/src/test/resources/metadata/queries/graphix/yelp-example/yelp-example.5.ddl.sqlpp b/asterix-graphix/src/test/resources/metadata/queries/graphix/yelp-example/yelp-example.5.ddl.sqlpp
new file mode 100644
index 0000000..586a718
--- /dev/null
+++ b/asterix-graphix/src/test/resources/metadata/queries/graphix/yelp-example/yelp-example.5.ddl.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+
+CREATE OR REPLACE GRAPH   Yelp.YelpGraph_2 AS
+VERTEX                    (:User)
+                          PRIMARY KEY (user_id)
+                          AS Yelp_B.Yelpers,
+VERTEX                    (:Review)
+                          PRIMARY KEY (review_id)
+                          AS ( FROM    Yelp_A.Reviews R
+                               SELECT  VALUE R ),
+VERTEX                    (:Business)
+                          PRIMARY KEY (business_id)
+                          AS ( FROM    Yelp_A.RelevantBusinesses() B
+                               SELECT  VALUE B ),
+EDGE                      (:User)-[:FRIENDS_WITH]->(:User)
+                          PRIMARY KEY (user_id, friend)
+                          SOURCE KEY (user_id)
+                          DESTINATION KEY (friend)
+                          AS ( FROM    Yelp_B.Users U
+                               UNNEST  U.friends F
+                               SELECT  U.user_id, F AS friend ),
+EDGE                      (:User)-[:FRIENDS_WITH]->(:User)
+                                  PRIMARY KEY (user_id, friend)
+                                  SOURCE KEY (user_id)
+                                  DESTINATION KEY (friend)
+                                  AS Yelp_B.Friends,
+EDGE                      (:Review)-[:MADE_BY]->(:User)
+                          DESTINATION KEY (user_id),
+EDGE                      (:Review)-[:ABOUT]->(:Business)
+                          DESTINATION KEY (business_id);
diff --git a/asterix-graphix/src/test/resources/metadata/queries/graphix/yelp-example/yelp-example.6.query.sqlpp b/asterix-graphix/src/test/resources/metadata/queries/graphix/yelp-example/yelp-example.6.query.sqlpp
new file mode 100644
index 0000000..b8151af
--- /dev/null
+++ b/asterix-graphix/src/test/resources/metadata/queries/graphix/yelp-example/yelp-example.6.query.sqlpp
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+
+FROM      `Metadata`.`Graph` G
+SELECT    G.DataverseName, G.GraphName, G.Dependencies, G.Vertices, G.Edges
+ORDER BY  G.DataverseName, G.GraphName;
diff --git a/asterix-graphix/src/test/resources/metadata/queries/graphix/yelp-example/yelp-example.7.ddl.sqlpp b/asterix-graphix/src/test/resources/metadata/queries/graphix/yelp-example/yelp-example.7.ddl.sqlpp
new file mode 100644
index 0000000..d846648
--- /dev/null
+++ b/asterix-graphix/src/test/resources/metadata/queries/graphix/yelp-example/yelp-example.7.ddl.sqlpp
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+
+DROP  DATAVERSE Yelp;
+DROP  DATAVERSE Yelp_A;
+DROP  DATAVERSE Yelp_B;
\ No newline at end of file
diff --git a/asterix-graphix/src/test/resources/metadata/queries/graphix/yelp-example/yelp-example.8.query.sqlpp b/asterix-graphix/src/test/resources/metadata/queries/graphix/yelp-example/yelp-example.8.query.sqlpp
new file mode 100644
index 0000000..9667fd6
--- /dev/null
+++ b/asterix-graphix/src/test/resources/metadata/queries/graphix/yelp-example/yelp-example.8.query.sqlpp
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+
+FROM    `Metadata`.`Graph` G
+WHERE   G.DataverseName IN [ "Yelp", "Yelp_A", "Yelp_B" ]
+SELECT  VALUE { "count": COUNT(*) };
diff --git a/asterix-graphix/src/test/resources/metadata/results/graphix/yelp-example/yelp-example.1.adm b/asterix-graphix/src/test/resources/metadata/results/graphix/yelp-example/yelp-example.1.adm
new file mode 100644
index 0000000..31c330c
--- /dev/null
+++ b/asterix-graphix/src/test/resources/metadata/results/graphix/yelp-example/yelp-example.1.adm
@@ -0,0 +1,2 @@
+{ "DataverseName": "Yelp", "GraphName": "YelpGraph_1", "Dependencies": [ [ [ "Yelp_A", "Reviews" ], [ "Yelp_B", "Users" ], [ "Yelp_B", "Friends" ] ], [ [ "Yelp_B", "Yelpers" ] ], [ [ "Yelp_A", "RelevantBusinesses", "0" ] ] ], "Vertices": [ { "Label": "User", "PrimaryKey": [ [ "user_id" ] ], "Definitions": [ "Yelp_B.Yelpers" ] }, { "Label": "Review", "PrimaryKey": [ [ "review_id" ] ], "Definitions": [ "( FROM    Yelp_A.Reviews R\n                       SELECT  VALUE R )" ] }, { "Label": "Business", "PrimaryKey": [ [ "business_id" ] ], "Definitions": [ "( FROM    Yelp_A.RelevantBusinesses() B\n                       SELECT  VALUE B )" ] } ], "Edges": [ { "Label": "FRIENDS_WITH", "DestinationLabel": "User", "SourceLabel": "User", "PrimaryKey": [ [ "user_id" ], [ "friend" ] ], "DestinationKey": [ [ "friend" ] ], "SourceKey": [ [ "user_id" ] ], "Definitions": [ "( FROM    Yelp_B.Users U\n                       UNNEST  U.friends F\n                       SELECT  U.user_id, F AS friend )", "Yelp_B.Friends" ] }, { "Label": "MADE_BY", "DestinationLabel": "User", "SourceLabel": "Review", "PrimaryKey": [ [ "review_id" ] ], "DestinationKey": [ [ "user_id" ] ], "SourceKey": [ [ "review_id" ] ], "Definitions": [ "" ] }, { "Label": "ABOUT", "DestinationLabel": "Business", "SourceLabel": "Review", "PrimaryKey": [ [ "review_id" ] ], "DestinationKey": [ [ "business_id" ] ], "SourceKey": [ [ "review_id" ] ], "Definitions": [ "" ] } ] }
+{ "DataverseName": "Yelp", "GraphName": "YelpGraph_2", "Dependencies": [ [ [ "Yelp_A", "Reviews" ] ], [  ], [ [ "Yelp_A", "RelevantBusinesses", "0" ] ] ], "Vertices": [ { "Label": "Review", "PrimaryKey": [ [ "review_id" ] ], "Definitions": [ "( FROM    Yelp_A.Reviews R\n                       SELECT  VALUE R )" ] }, { "Label": "Business", "PrimaryKey": [ [ "business_id" ] ], "Definitions": [ "( FROM    Yelp_A.RelevantBusinesses() B\n                       SELECT  VALUE B )" ] } ], "Edges": [ { "Label": "ABOUT", "DestinationLabel": "Business", "SourceLabel": "Review", "PrimaryKey": [ [ "review_id" ] ], "DestinationKey": [ [ "business_id" ] ], "SourceKey": [ [ "review_id" ] ], "Definitions": [ "" ] } ] }
\ No newline at end of file
diff --git a/asterix-graphix/src/test/resources/metadata/results/graphix/yelp-example/yelp-example.2.adm b/asterix-graphix/src/test/resources/metadata/results/graphix/yelp-example/yelp-example.2.adm
new file mode 100644
index 0000000..a749b72
--- /dev/null
+++ b/asterix-graphix/src/test/resources/metadata/results/graphix/yelp-example/yelp-example.2.adm
@@ -0,0 +1 @@
+{ "DataverseName": "Yelp", "GraphName": "YelpGraph_2", "Dependencies": [ [ [ "Yelp_A", "Reviews" ] ], [  ], [ [ "Yelp_A", "RelevantBusinesses", "0" ] ] ], "Vertices": [ { "Label": "Review", "PrimaryKey": [ [ "review_id" ] ], "Definitions": [ "( FROM    Yelp_A.Reviews R\n                       SELECT  VALUE R )" ] }, { "Label": "Business", "PrimaryKey": [ [ "business_id" ] ], "Definitions": [ "( FROM    Yelp_A.RelevantBusinesses() B\n                       SELECT  VALUE B )" ] } ], "Edges": [ { "Label": "ABOUT", "DestinationLabel": "Business", "SourceLabel": "Review", "PrimaryKey": [ [ "review_id" ] ], "DestinationKey": [ [ "business_id" ] ], "SourceKey": [ [ "review_id" ] ], "Definitions": [ "" ] } ] }
diff --git a/asterix-graphix/src/test/resources/metadata/results/graphix/yelp-example/yelp-example.3.adm b/asterix-graphix/src/test/resources/metadata/results/graphix/yelp-example/yelp-example.3.adm
new file mode 100644
index 0000000..80af6cb
--- /dev/null
+++ b/asterix-graphix/src/test/resources/metadata/results/graphix/yelp-example/yelp-example.3.adm
@@ -0,0 +1 @@
+{ "DataverseName": "Yelp", "GraphName": "YelpGraph_2", "Dependencies": [ [ [ "Yelp_A", "Reviews" ], [ "Yelp_B", "Users" ], [ "Yelp_B", "Friends" ] ], [ [ "Yelp_B", "Yelpers" ] ], [ [ "Yelp_A", "RelevantBusinesses", "0" ] ] ], "Vertices": [ { "Label": "User", "PrimaryKey": [ [ "user_id" ] ], "Definitions": [ "Yelp_B.Yelpers" ] }, { "Label": "Review", "PrimaryKey": [ [ "review_id" ] ], "Definitions": [ "( FROM    Yelp_A.Reviews R\n                               SELECT  VALUE R )" ] }, { "Label": "Business", "PrimaryKey": [ [ "business_id" ] ], "Definitions": [ "( FROM    Yelp_A.RelevantBusinesses() B\n                               SELECT  VALUE B )" ] } ], "Edges": [ { "Label": "FRIENDS_WITH", "DestinationLabel": "User", "SourceLabel": "User", "PrimaryKey": [ [ "user_id" ], [ "friend" ] ], "DestinationKey": [ [ "friend" ] ], "SourceKey": [ [ "user_id" ] ], "Definitions": [ "( FROM    Yelp_B.Users U\n                               UNNEST  U.friends F\n                               SELECT  U.user_id, F AS friend )", "Yelp_B.Friends" ] }, { "Label": "MADE_BY", "DestinationLabel": "User", "SourceLabel": "Review", "PrimaryKey": [ [ "review_id" ] ], "DestinationKey": [ [ "user_id" ] ], "SourceKey": [ [ "review_id" ] ], "Definitions": [ "" ] }, { "Label": "ABOUT", "DestinationLabel": "Business", "SourceLabel": "Review", "PrimaryKey": [ [ "review_id" ] ], "DestinationKey": [ [ "business_id" ] ], "SourceKey": [ [ "review_id" ] ], "Definitions": [ "" ] } ] }
diff --git a/asterix-graphix/src/test/resources/metadata/results/graphix/yelp-example/yelp-example.4.adm b/asterix-graphix/src/test/resources/metadata/results/graphix/yelp-example/yelp-example.4.adm
new file mode 100644
index 0000000..c1a0ea2
--- /dev/null
+++ b/asterix-graphix/src/test/resources/metadata/results/graphix/yelp-example/yelp-example.4.adm
@@ -0,0 +1 @@
+{ "count": 0 }
\ No newline at end of file
diff --git a/asterix-graphix/src/test/resources/metadata/testsuite.xml b/asterix-graphix/src/test/resources/metadata/testsuite.xml
new file mode 100644
index 0000000..2f45b91
--- /dev/null
+++ b/asterix-graphix/src/test/resources/metadata/testsuite.xml
@@ -0,0 +1,28 @@
+<!--
+  ~ 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.
+  -->
+<test-suite xmlns="urn:xml.testframework.asterix.apache.org"
+            ResultOffsetPath="results"
+            QueryOffsetPath="queries"
+            QueryFileExtension=".sqlpp">
+  <test-group name="yelp-example">
+    <test-case FilePath="graphix">
+      <compilation-unit name="yelp-example">
+        <output-dir compare="Text">yelp-example</output-dir>
+      </compilation-unit>
+    </test-case>
+  </test-group>
+</test-suite>
diff --git a/asterix-graphix/src/test/resources/runtimets/only.xml b/asterix-graphix/src/test/resources/runtimets/only.xml
new file mode 100644
index 0000000..9cb8228
--- /dev/null
+++ b/asterix-graphix/src/test/resources/runtimets/only.xml
@@ -0,0 +1,25 @@
+<!--
+ ! 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.
+ !-->
+<test-suite xmlns="urn:xml.testframework.asterix.apache.org"
+            ResultOffsetPath="results"
+            QueryOffsetPath="queries"
+            QueryFileExtension=".sqlpp">
+  <test-group name="failed">
+  </test-group>
+</test-suite>
diff --git a/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.1.ddl.sqlpp b/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.1.ddl.sqlpp
new file mode 100644
index 0000000..ff47a77
--- /dev/null
+++ b/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.1.ddl.sqlpp
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+
+// Verify that a dataset that a graph is dependent on cannot be dropped.
+
+DROP DATAVERSE    TestDataverse IF EXISTS;
+CREATE DATAVERSE  TestDataverse;
+USE               TestDataverse;
+
+CREATE TYPE       GenericType
+AS                { _id: uuid };
+
+CREATE DATASET    GenericDataset (GenericType)
+PRIMARY KEY       _id AUTOGENERATED;
+
+CREATE GRAPH      TestGraph AS
+VERTEX            (:Vertex1)
+                  PRIMARY KEY (_id)
+                  AS GenericDataset,
+VERTEX            (:Vertex2)
+                  PRIMARY KEY (_id)
+                  AS GenericDataset,
+EDGE              (:Vertex1)-[:EDGE_1]->(:Vertex2)
+                  DESTINATION KEY (_foreign_id);
+
+DROP DATASET      GenericDataset;
diff --git a/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.10.ddl.sqlpp b/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.10.ddl.sqlpp
new file mode 100644
index 0000000..fe00035
--- /dev/null
+++ b/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.10.ddl.sqlpp
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ */
+
+// Verify that we cannot create a graph in the same dataverse with the same name.
+
+DROP DATAVERSE    TestDataverse1 IF EXISTS;
+DROP DATAVERSE    TestDataverse2 IF EXISTS;
+CREATE DATAVERSE  TestDataverse1;
+CREATE DATAVERSE  TestDataverse2;
+
+USE               TestDataverse1;
+CREATE TYPE       GenericType
+AS                { _id: uuid };
+
+CREATE DATASET    GenericDataset (GenericType)
+PRIMARY KEY       _id AUTOGENERATED;
+
+CREATE GRAPH      TestGraph AS
+VERTEX            (:Vertex1)
+                  PRIMARY KEY (_id)
+                  AS GenericDataset,
+VERTEX            (:Vertex2)
+                  PRIMARY KEY (_id)
+                  AS GenericDataset,
+EDGE              (:Vertex1)-[:EDGE_1]->(:Vertex2)
+                  DESTINATION KEY (_foreign_id);
+
+USE               TestDataverse2;
+CREATE TYPE       GenericType
+AS                { _id: uuid };
+
+CREATE DATASET    GenericDataset (GenericType)
+PRIMARY KEY       _id AUTOGENERATED;
+
+CREATE GRAPH      TestGraph AS
+VERTEX            (:Vertex1)
+                  PRIMARY KEY (_id)
+                  AS GenericDataset,
+VERTEX            (:Vertex2)
+                  PRIMARY KEY (_id)
+                  AS GenericDataset,
+EDGE              (:Vertex1)-[:EDGE_1]->(:Vertex2)
+                  DESTINATION KEY (_foreign_id);
+
+USE               TestDataverse1;
+CREATE GRAPH      TestGraph IF NOT EXISTS AS
+VERTEX            (:Vertex1)
+                  PRIMARY KEY (_id)
+                  AS GenericDataset;
+
+USE               TestDataverse2;
+CREATE GRAPH      TestGraph AS
+VERTEX            (:Vertex1)
+                  PRIMARY KEY (_id)
+                  AS GenericDataset;
diff --git a/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.11.ddl.sqlpp b/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.11.ddl.sqlpp
new file mode 100644
index 0000000..ff0f01e
--- /dev/null
+++ b/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.11.ddl.sqlpp
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ */
+
+// Verify that we cannot drop a graph that doesn't exist.
+
+DROP DATAVERSE    TestDataverse IF EXISTS;
+CREATE DATAVERSE  TestDataverse;
+USE               TestDataverse;
+
+CREATE TYPE       GenericType
+AS                { _id: uuid };
+
+CREATE DATASET    GenericDataset (GenericType)
+PRIMARY KEY       _id AUTOGENERATED;
+
+CREATE GRAPH      TestGraph AS
+VERTEX            (:Vertex1)
+                  PRIMARY KEY (_id)
+                  AS GenericDataset,
+VERTEX            (:Vertex2)
+                  PRIMARY KEY (_id)
+                  AS GenericDataset,
+EDGE              (:Vertex1)-[:EDGE_1]->(:Vertex2)
+                  DESTINATION KEY (_foreign_id);
+
+DROP GRAPH        GraphThatDoesntExist1 IF EXISTS;
+DROP GRAPH        GraphThatDoesntExist2;
diff --git a/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.2.ddl.sqlpp b/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.2.ddl.sqlpp
new file mode 100644
index 0000000..09693af
--- /dev/null
+++ b/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.2.ddl.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+
+// Verify that a function that a graph is dependent on cannot be dropped.
+
+DROP DATAVERSE    TestDataverse IF EXISTS;
+CREATE DATAVERSE  TestDataverse;
+USE               TestDataverse;
+
+CREATE TYPE       GenericType
+AS                { _id: uuid };
+
+CREATE DATASET    GenericDataset (GenericType)
+PRIMARY KEY       _id AUTOGENERATED;
+
+CREATE FUNCTION   TestFunction () { SELECT VALUE { "a": 1, "b": 1 } };
+
+CREATE GRAPH      TestGraph AS
+VERTEX            (:Vertex1)
+                  PRIMARY KEY (_id)
+                  AS GenericDataset,
+VERTEX            (:Vertex2)
+                  PRIMARY KEY (_id)
+                  AS GenericDataset,
+EDGE              (:Vertex1)-[:EDGE_1]->(:Vertex2)
+                  PRIMARY KEY (a, b)
+                  SOURCE KEY (a)
+                  DESTINATION KEY (b)
+                  AS ( FROM TestFunction() T
+                       SELECT T.* );
+
+DROP FUNCTION     TestFunction();
diff --git a/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.3.ddl.sqlpp b/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.3.ddl.sqlpp
new file mode 100644
index 0000000..a812ea1
--- /dev/null
+++ b/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.3.ddl.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+
+// Verify that a view that a graph is dependent on cannot be dropped.
+
+DROP DATAVERSE    TestDataverse IF EXISTS;
+CREATE DATAVERSE  TestDataverse;
+USE               TestDataverse;
+
+CREATE TYPE       GenericType
+AS                { _id: uuid };
+
+CREATE DATASET    GenericDataset (GenericType)
+PRIMARY KEY       _id AUTOGENERATED;
+
+CREATE VIEW       TestView AS SELECT VALUE { "a": 1, "b": 1 };
+
+CREATE GRAPH      TestGraph AS
+VERTEX            (:Vertex1)
+                  PRIMARY KEY (_id)
+                  AS GenericDataset,
+VERTEX            (:Vertex2)
+                  PRIMARY KEY (_id)
+                  AS GenericDataset,
+EDGE              (:Vertex1)-[:EDGE_1]->(:Vertex2)
+                  PRIMARY KEY (a, b)
+                  SOURCE KEY (a)
+                  DESTINATION KEY (b)
+                  AS ( FROM TestView T
+                       SELECT T.* );
+
+DROP VIEW        TestView;
diff --git a/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.4.ddl.sqlpp b/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.4.ddl.sqlpp
new file mode 100644
index 0000000..0cdec73
--- /dev/null
+++ b/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.4.ddl.sqlpp
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+
+// Verify that a synonym that a graph is dependent on cannot be dropped.
+
+DROP DATAVERSE    TestDataverse IF EXISTS;
+CREATE DATAVERSE  TestDataverse;
+USE               TestDataverse;
+
+CREATE TYPE       GenericType
+AS                { _id: uuid };
+
+CREATE DATASET    GenericDataset (GenericType)
+PRIMARY KEY       _id AUTOGENERATED;
+
+CREATE SYNONYM    DatasetSynonym FOR GenericDataset;
+
+CREATE GRAPH      TestGraph AS
+VERTEX            (:Vertex1)
+                  PRIMARY KEY (_id)
+                  AS GenericDataset,
+VERTEX            (:Vertex2)
+                  PRIMARY KEY (_id)
+                  AS DatasetSynonym,
+EDGE              (:Vertex1)-[:EDGE_1]->(:Vertex2)
+                  DESTINATION KEY (_foreign_id);
+
+DROP SYNONYM      DatasetSynonym;
diff --git a/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.5.ddl.sqlpp b/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.5.ddl.sqlpp
new file mode 100644
index 0000000..844389f
--- /dev/null
+++ b/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.5.ddl.sqlpp
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+
+// Verify that a dataverse that a graph is dependent on cannot be dropped.
+
+DROP DATAVERSE    TestDataverse IF EXISTS;
+DROP DATAVERSE    TestDataverse2 IF EXISTS;
+CREATE DATAVERSE  TestDataverse;
+CREATE DATAVERSE  TestDataverse2;
+
+USE               TestDataverse;
+CREATE TYPE       GenericType
+AS                { _id: uuid };
+
+USE               TestDataverse2;
+CREATE TYPE       GenericType
+AS                { _id: uuid };
+
+USE               TestDataverse;
+CREATE DATASET    GenericDataset (GenericType)
+PRIMARY KEY       _id AUTOGENERATED;
+
+USE               TestDataverse2;
+CREATE DATASET    GenericDataset (GenericType)
+PRIMARY KEY       _id AUTOGENERATED;
+
+USE               TestDataverse;
+CREATE GRAPH      TestGraph AS
+VERTEX            (:Vertex1)
+                  PRIMARY KEY (_id)
+                  AS GenericDataset,
+VERTEX            (:Vertex2)
+                  PRIMARY KEY (_id)
+                  AS TestDataverse2.GenericDataset,
+EDGE              (:Vertex1)-[:EDGE_1]->(:Vertex2)
+                  DESTINATION KEY (_foreign_id);
+
+DROP DATAVERSE    TestDataverse2;
diff --git a/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.6.ddl.sqlpp b/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.6.ddl.sqlpp
new file mode 100644
index 0000000..f6173aa
--- /dev/null
+++ b/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.6.ddl.sqlpp
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ */
+
+// Verify that a dataset variable as an element definition is a valid dataset.
+
+DROP DATAVERSE    TestDataverse IF EXISTS;
+CREATE DATAVERSE  TestDataverse;
+USE               TestDataverse;
+
+CREATE TYPE       GenericType
+AS                { _id: uuid };
+
+CREATE DATASET    GenericDataset (GenericType)
+PRIMARY KEY       _id AUTOGENERATED;
+
+CREATE GRAPH      TestGraph AS
+VERTEX            (:Vertex1)
+                  PRIMARY KEY (_id)
+                  AS DatasetThatDoesNotExist,
+VERTEX            (:Vertex2)
+                  PRIMARY KEY (_id)
+                  AS GenericDataset,
+EDGE              (:Vertex1)-[:EDGE_1]->(:Vertex2)
+                  DESTINATION KEY (_foreign_id);
diff --git a/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.7.ddl.sqlpp b/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.7.ddl.sqlpp
new file mode 100644
index 0000000..5191339
--- /dev/null
+++ b/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.7.ddl.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+
+// Verify that a subquery as an element definition is a valid query.
+
+DROP DATAVERSE    TestDataverse IF EXISTS;
+CREATE DATAVERSE  TestDataverse;
+USE               TestDataverse;
+
+CREATE TYPE       GenericType
+AS                { _id: uuid };
+
+CREATE DATASET    GenericDataset (GenericType)
+PRIMARY KEY       _id AUTOGENERATED;
+
+CREATE GRAPH      TestGraph AS
+VERTEX            (:Vertex1)
+                  PRIMARY KEY (_id)
+                  AS GenericDataset,
+VERTEX            (:Vertex2)
+                  PRIMARY KEY (_id)
+                  AS GenericDataset,
+EDGE              (:Vertex1)-[:EDGE_1]->(:Vertex2)
+                  PRIMARY KEY (_id, _foreign_id)
+                  SOURCE KEY (_id)
+                  DESTINATION KEY (_foreign_id)
+                  AS ( FROM GenericDataset G,
+                            GenericDataset G2
+                       SELECT V );
diff --git a/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.8.ddl.sqlpp b/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.8.ddl.sqlpp
new file mode 100644
index 0000000..eb0fa47
--- /dev/null
+++ b/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.8.ddl.sqlpp
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+
+// Verify that vertices w/ the same label cannot have conflicting primary keys.
+
+DROP DATAVERSE    TestDataverse IF EXISTS;
+CREATE DATAVERSE  TestDataverse;
+USE               TestDataverse;
+
+CREATE TYPE       GenericType
+AS                { _id: uuid };
+
+CREATE DATASET    GenericDataset (GenericType)
+PRIMARY KEY       _id AUTOGENERATED;
+
+CREATE GRAPH      TestGraph AS
+VERTEX            (:Vertex1)
+                  PRIMARY KEY (_id)
+                  AS GenericDataset,
+VERTEX            (:Vertex1)
+                  PRIMARY KEY (_other_id)
+                  AS ( FROM GenericDataset
+                       SELECT VALUE { "_other_id": _other_id } );
diff --git a/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.9.ddl.sqlpp b/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.9.ddl.sqlpp
new file mode 100644
index 0000000..7c5269e
--- /dev/null
+++ b/asterix-graphix/src/test/resources/runtimets/queries/graphix/error-handling/error-handling.9.ddl.sqlpp
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ */
+
+// Verify that edges do not reference a vertex label that does not exist.
+
+DROP DATAVERSE    TestDataverse IF EXISTS;
+CREATE DATAVERSE  TestDataverse;
+USE               TestDataverse;
+
+CREATE TYPE       GenericType
+AS                { _id: uuid };
+
+CREATE DATASET    GenericDataset (GenericType)
+PRIMARY KEY       _id AUTOGENERATED;
+
+CREATE GRAPH      TestGraph AS
+VERTEX            (:Vertex1)
+                  PRIMARY KEY (_id)
+                  AS GenericDataset,
+VERTEX            (:Vertex2)
+                  PRIMARY KEY (_id)
+                  AS GenericDataset,
+EDGE              (:Vertex1)-[:EDGE_1]->(:Vertex3)
+                  DESTINATION KEY (_foreign_id);
diff --git a/asterix-graphix/src/test/resources/runtimets/testsuite.xml b/asterix-graphix/src/test/resources/runtimets/testsuite.xml
new file mode 100644
index 0000000..ea6db85
--- /dev/null
+++ b/asterix-graphix/src/test/resources/runtimets/testsuite.xml
@@ -0,0 +1,41 @@
+<!--
+ ! 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.
+ !-->
+<test-suite xmlns="urn:xml.testframework.asterix.apache.org"
+            ResultOffsetPath="results"
+            QueryOffsetPath="queries"
+            QueryFileExtension=".sqlpp">
+  <test-group name="error-handling">
+    <test-case FilePath="graphix">
+      <compilation-unit name="error-handling">
+        <output-dir compare="Text">error-handling</output-dir>
+        <expected-error>Cannot drop dataset (or view) TestDataverse.GenericDataset being used by graph TestGraph</expected-error>
+        <expected-error>Cannot drop function TestDataverse.TestFunction() being used by graph TestGraph</expected-error>
+        <expected-error>Cannot drop dataset (or view) TestDataverse.TestView being used by graph TestGraph</expected-error>
+        <expected-error>Cannot drop synonym TestDataverse.DatasetSynonym being used by graph TestGraph</expected-error>
+        <expected-error>Cannot drop dataverse: dataset (or view) TestDataverse2.GenericDataset being used by graph TestGraph</expected-error>
+        <expected-error>Bad definition for a graph element(.)*Cannot find dataset DatasetThatDoesNotExist in dataverse TestDataverse nor an alias with name DatasetThatDoesNotExist</expected-error>
+        <expected-error>Bad definition for a graph element(.)*Cannot resolve ambiguous alias reference for identifier V</expected-error>
+        <expected-error>Conflicting primary keys for vertices with label Vertex1</expected-error>
+        <expected-error>Destination vertex Vertex3 not found in the edge EDGE_1.</expected-error>
+        <expected-error>Graph TestGraph already exists.</expected-error>
+        <expected-error>Graph GraphThatDoesntExist2 does not exist.</expected-error>
+      </compilation-unit>
+    </test-case>
+  </test-group>
+</test-suite>
\ No newline at end of file