Enable dependencies in the metadata for BAD entities

Allow Channels and Procedures to store dependencies on
Datasets and Functions

Prevent dropping of these dependencies

Add Error tests

Change-Id: Ic6ac2daad03844a042aded8e17bb231a06f59cbe
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/drop_function/drop_function.1.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/channel/drop_function/drop_function.1.ddl.sqlpp
new file mode 100644
index 0000000..a5d3775
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/queries/channel/drop_function/drop_function.1.ddl.sqlpp
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+/*
+* Description  : Drop Channel Function
+* Expected Res : Error
+* Date         : Jan 2018
+* Author       : Steven Jacobs
+*/
+
+drop dataverse channels if exists;
+create dataverse channels;
+use channels;
+
+create type TweetMessageTypeuuid as closed {
+  tweetid: uuid,
+  sender_location: point,
+  send_time: datetime,
+  referred_topics: {{ string }},
+  message_text: string,
+  countA: int32,
+  countB: int32
+};
+
+
+create dataset TweetMessageuuids(TweetMessageTypeuuid)
+primary key tweetid autogenerated;
+
+create function NearbyTweetsContainingText(place, text) {
+  (select m.message_text
+  from TweetMessageuuids m
+  where contains(m.message_text,text)
+  and spatial_intersect(m.sender_location, place))
+};
+
+create dataverse two;
+use two;
+
+create repetitive channel nearbyTweetChannel using channels.NearbyTweetsContainingText@2 period duration("PT10M");
+
+use channels;
+drop function NearbyTweetsContainingText@2;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/drop_function_dataverse/drop_function_dataverse.1.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/channel/drop_function_dataverse/drop_function_dataverse.1.ddl.sqlpp
new file mode 100644
index 0000000..d1047b0
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/queries/channel/drop_function_dataverse/drop_function_dataverse.1.ddl.sqlpp
@@ -0,0 +1,56 @@
+/*
+ * 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.
+ */
+/*
+* Description  : Drop Channel Function Dataverse
+* Expected Res : Error
+* Date         : Jan 2018
+* Author       : Steven Jacobs
+*/
+
+drop dataverse channels if exists;
+create dataverse channels;
+use channels;
+
+create type TweetMessageTypeuuid as closed {
+  tweetid: uuid,
+  sender_location: point,
+  send_time: datetime,
+  referred_topics: {{ string }},
+  message_text: string,
+  countA: int32,
+  countB: int32
+};
+
+
+create dataset TweetMessageuuids(TweetMessageTypeuuid)
+primary key tweetid autogenerated;
+
+create function NearbyTweetsContainingText(place, text) {
+  (select m.message_text
+  from TweetMessageuuids m
+  where contains(m.message_text,text)
+  and spatial_intersect(m.sender_location, place))
+};
+
+create dataverse two;
+use two;
+
+create repetitive channel nearbyTweetChannel using channels.NearbyTweetsContainingText@2 period duration("PT10M");
+
+drop dataverse channels;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/drop_results/drop_results.1.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/channel/drop_results/drop_results.1.ddl.sqlpp
new file mode 100644
index 0000000..432f3c5
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/queries/channel/drop_results/drop_results.1.ddl.sqlpp
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+/*
+* Description  : Drop Channel Results
+* Expected Res : Error
+* Date         : Jan 2018
+* Author       : Steven Jacobs
+*/
+
+drop dataverse two if exists;
+drop dataverse channels if exists;
+create dataverse channels;
+use channels;
+
+create type TweetMessageTypeuuid as closed {
+  tweetid: uuid,
+  sender_location: point,
+  send_time: datetime,
+  referred_topics: {{ string }},
+  message_text: string,
+  countA: int32,
+  countB: int32
+};
+
+
+create dataset TweetMessageuuids(TweetMessageTypeuuid)
+primary key tweetid autogenerated;
+
+create function NearbyTweetsContainingText(place, text) {
+  (select m.message_text
+  from TweetMessageuuids m
+  where contains(m.message_text,text)
+  and spatial_intersect(m.sender_location, place))
+};
+
+create dataverse two;
+use two;
+
+create repetitive channel nearbyTweetChannel using channels.NearbyTweetsContainingText@2 period duration("PT10M");
+
+drop dataset two.nearbyTweetChannelResults;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/drop_subscriptions/drop_subscriptions.1.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/channel/drop_subscriptions/drop_subscriptions.1.ddl.sqlpp
new file mode 100644
index 0000000..f6dc2bf
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/queries/channel/drop_subscriptions/drop_subscriptions.1.ddl.sqlpp
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+/*
+* Description  : Drop Channel Subscriptions
+* Expected Res : Error
+* Date         : Jan 2018
+* Author       : Steven Jacobs
+*/
+
+drop dataverse two if exists;
+drop dataverse channels if exists;
+create dataverse channels;
+use channels;
+
+create type TweetMessageTypeuuid as closed {
+  tweetid: uuid,
+  sender_location: point,
+  send_time: datetime,
+  referred_topics: {{ string }},
+  message_text: string,
+  countA: int32,
+  countB: int32
+};
+
+
+create dataset TweetMessageuuids(TweetMessageTypeuuid)
+primary key tweetid autogenerated;
+
+create function NearbyTweetsContainingText(place, text) {
+  (select m.message_text
+  from TweetMessageuuids m
+  where contains(m.message_text,text)
+  and spatial_intersect(m.sender_location, place))
+};
+
+create dataverse two;
+use two;
+
+create repetitive channel nearbyTweetChannel using channels.NearbyTweetsContainingText@2 period duration("PT10M");
+
+drop dataset two.nearbyTweetChannelSubscriptions;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.1.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.1.ddl.sqlpp
index fe1db99..638f7b5 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.1.ddl.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.1.ddl.sqlpp
@@ -23,6 +23,7 @@
 * Author       : Steven Jacobs
 */
 
+drop dataverse two if exists;
 drop dataverse channels if exists;
 create dataverse channels;
 use channels;
diff --git a/asterix-bad/src/test/resources/runtimets/queries/procedure/create_procedure_check_metadata/create_procedure_check_metadata.1.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/procedure/create_procedure_check_metadata/create_procedure_check_metadata.1.ddl.sqlpp
new file mode 100644
index 0000000..71b2ed4
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/queries/procedure/create_procedure_check_metadata/create_procedure_check_metadata.1.ddl.sqlpp
@@ -0,0 +1,93 @@
+/*
+ * 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.
+ */
+/*
+* Description  : Create Procedure Check Metadata
+* Expected Res : Success
+* Date         : Jan 2017
+* Author       : Steven Jacobs
+*/
+
+drop dataverse two if exists;
+drop dataverse channels if exists;
+create dataverse channels;
+use channels;
+create type myLocation as {
+  id: int
+};
+create dataset UserLocations(myLocation)
+primary key id;
+
+create function really_contains(word,letter){
+contains(word,letter)
+};
+
+create dataverse two;
+use two;
+
+create function really_contains(word,letter){
+contains(word,letter)
+};
+
+create type myLocation as {
+  id: int
+};
+create dataset UserLocations(myLocation)
+primary key id;
+
+create procedure selectSome(r, otherRoom) {
+select roomNumber from channels.UserLocations
+where roomNumber = r
+or roomNumber = otherRoom
+and channels.really_contains(roomNumber,"l")
+order by id
+};
+
+create procedure deleteSome(r, otherRoom) {
+delete from channels.UserLocations
+where roomNumber = r
+or roomNumber = otherRoom
+and channels.really_contains(roomNumber,"l")
+};
+
+create procedure addMe() {
+  insert into channels.UserLocations([
+    {"timeStamp":current_datetime(), "roomNumber":222}]
+  )
+};
+
+create procedure localSelectSome(r, otherRoom) {
+select roomNumber from UserLocations
+where roomNumber = r
+or roomNumber = otherRoom
+and really_contains(roomNumber,"l")
+order by id
+};
+
+create procedure localDeleteSome(r, otherRoom) {
+delete from UserLocations
+where roomNumber = r
+or roomNumber = otherRoom
+and really_contains(roomNumber,"l")
+};
+
+create procedure localAddMe() {
+  insert into UserLocations([
+    {"timeStamp":current_datetime(), "roomNumber":222}]
+  )
+};
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/procedure/create_procedure_check_metadata/create_procedure_check_metadata.2.query.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/procedure/create_procedure_check_metadata/create_procedure_check_metadata.2.query.sqlpp
new file mode 100644
index 0000000..023c343
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/queries/procedure/create_procedure_check_metadata/create_procedure_check_metadata.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.
+ */
+
+select value x
+from Metadata.`Procedure` x
+order by x.ProcedureName;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/procedure/delete_procedure/delete_procedure.1.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/procedure/delete_procedure/delete_procedure.1.ddl.sqlpp
index 7dbf136..905211f 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/procedure/delete_procedure/delete_procedure.1.ddl.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/procedure/delete_procedure/delete_procedure.1.ddl.sqlpp
@@ -23,6 +23,7 @@
 * Author       : Steven Jacobs
 */
 
+drop dataverse two if exists;
 drop dataverse channels if exists;
 create dataverse channels;
 use channels;
diff --git a/asterix-bad/src/test/resources/runtimets/queries/procedure/delete_procedure_drop_dataset/delete_procedure_drop_dataset.1.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/procedure/delete_procedure_drop_dataset/delete_procedure_drop_dataset.1.ddl.sqlpp
new file mode 100644
index 0000000..1b88b19
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/queries/procedure/delete_procedure_drop_dataset/delete_procedure_drop_dataset.1.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.
+ */
+/*
+* Description  : Drop Procedure Dataset
+* Expected Res : Error
+* Date         : Jan 2018
+* Author       : Steven Jacobs
+*/
+
+drop dataverse two if exists;
+drop dataverse channels if exists;
+create dataverse channels;
+use channels;
+
+create type myLocation as {
+  timeStamp: datetime,
+  roomNumber: int
+};
+
+
+create dataset UserLocations(myLocation)
+primary key timeStamp;
+
+create dataverse two;
+use two;
+
+create procedure deleteAll() {
+delete from channels.UserLocations
+};
+
+use channels;
+drop dataset UserLocations;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/procedure/delete_procedure_drop_function/delete_procedure_drop_function.1.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/procedure/delete_procedure_drop_function/delete_procedure_drop_function.1.ddl.sqlpp
new file mode 100644
index 0000000..2322154
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/queries/procedure/delete_procedure_drop_function/delete_procedure_drop_function.1.ddl.sqlpp
@@ -0,0 +1,56 @@
+/*
+ * 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.
+ */
+/*
+* Description  : Delete Procedure drop function
+* Expected Res : Error
+* Date         : Jan 2018
+* Author       : Steven Jacobs
+*/
+
+drop dataverse two if exists;
+drop dataverse channels if exists;
+create dataverse channels;
+use channels;
+create type myLocation as {
+  id: int
+};
+create dataset UserLocations(myLocation)
+primary key id;
+insert into UserLocations(
+  [{"id":0, "roomNumber":4815162342},
+  {"id":1, "roomNumber":"lost"},
+  {"id":2, "roomNumber":108},
+  {"id":3, "roomNumber":"jacob"}]
+);
+
+create dataverse two;
+use two;
+
+create function really_contains(word,letter){
+contains(word,letter)
+};
+
+create procedure deleteSome(r, otherRoom) {
+delete from channels.UserLocations
+where roomNumber = r
+or roomNumber = otherRoom
+and really_contains(roomNumber,"l")
+};
+
+drop function really_contains@2;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/procedure/delete_procedure_drop_index/delete_procedure_drop_index.1.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/procedure/delete_procedure_drop_index/delete_procedure_drop_index.1.ddl.sqlpp
new file mode 100644
index 0000000..ab66a22
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/queries/procedure/delete_procedure_drop_index/delete_procedure_drop_index.1.ddl.sqlpp
@@ -0,0 +1,50 @@
+/*
+ * 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.
+ */
+/*
+* Description  : Drop Procedure Dataset Index
+* Expected Res : Error
+* Date         : Jan 2018
+* Author       : Steven Jacobs
+*/
+
+drop dataverse two if exists;
+drop dataverse channels if exists;
+create dataverse channels;
+use channels;
+
+create type myLocation as {
+  timeStamp: datetime,
+  roomNumber: int
+};
+
+
+create dataset UserLocations(myLocation)
+primary key timeStamp;
+
+create index rooms on UserLocations(roomNumber);
+
+create dataverse two;
+use two;
+
+create procedure deleteAll() {
+delete from channels.UserLocations
+};
+
+use channels;
+drop index UserLocations.rooms;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/procedure/insert_procedure_drop_dataset/insert_procedure_drop_dataset.1.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/procedure/insert_procedure_drop_dataset/insert_procedure_drop_dataset.1.ddl.sqlpp
new file mode 100644
index 0000000..260afab
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/queries/procedure/insert_procedure_drop_dataset/insert_procedure_drop_dataset.1.ddl.sqlpp
@@ -0,0 +1,50 @@
+/*
+ * 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.
+ */
+/*
+* Description  : Drop Procedure Dataset
+* Expected Res : Error
+* Date         : Jan 2018
+* Author       : Steven Jacobs
+*/
+
+drop dataverse two if exists;
+drop dataverse channels if exists;
+create dataverse channels;
+use channels;
+
+create type myLocation as {
+  timeStamp: datetime,
+  roomNumber: int
+};
+
+
+create dataset UserLocations(myLocation)
+primary key timeStamp;
+
+create dataverse two;
+use two;
+
+create procedure addMe() {
+  insert into channels.UserLocations([
+    {"timeStamp":current_datetime(), "roomNumber":222}]
+  )
+};
+
+use channels;
+drop dataset UserLocations;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/procedure/insert_procedure_drop_dataverse/insert_procedure_drop_dataverse.1.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/procedure/insert_procedure_drop_dataverse/insert_procedure_drop_dataverse.1.ddl.sqlpp
new file mode 100644
index 0000000..ad47b4e
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/queries/procedure/insert_procedure_drop_dataverse/insert_procedure_drop_dataverse.1.ddl.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ */
+/*
+* Description  : Drop Procedure Dataset Dataverse
+* Expected Res : Error
+* Date         : Jan 2018
+* Author       : Steven Jacobs
+*/
+
+drop dataverse two if exists;
+drop dataverse channels if exists;
+create dataverse channels;
+use channels;
+
+create type myLocation as {
+  timeStamp: datetime,
+  roomNumber: int
+};
+
+
+create dataset UserLocations(myLocation)
+primary key timeStamp;
+
+create dataverse two;
+use two;
+
+create procedure addMe() {
+  insert into channels.UserLocations([
+    {"timeStamp":current_datetime(), "roomNumber":222}]
+  )
+};
+
+drop dataverse channels;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/procedure/query_procedure_drop_dataset/query_procedure_drop_dataset.1.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/procedure/query_procedure_drop_dataset/query_procedure_drop_dataset.1.ddl.sqlpp
new file mode 100644
index 0000000..acb9f04
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/queries/procedure/query_procedure_drop_dataset/query_procedure_drop_dataset.1.ddl.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ */
+/*
+* Description  : Drop Procedure Dataset
+* Expected Res : Error
+* Date         : Jan 2018
+* Author       : Steven Jacobs
+*/
+
+drop dataverse two if exists;
+drop dataverse channels if exists;
+create dataverse channels;
+use channels;
+
+create type myLocation as {
+  timeStamp: datetime,
+  roomNumber: int
+};
+
+
+create dataset UserLocations(myLocation)
+primary key timeStamp;
+
+create dataverse two;
+use two;
+
+create procedure findMe() {
+select roomNumber from channels.UserLocations
+order by timeStamp
+};
+
+use channels;
+drop dataset UserLocations;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/procedure/query_procedure_drop_function/query_procedure_drop_function.1.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/procedure/query_procedure_drop_function/query_procedure_drop_function.1.ddl.sqlpp
new file mode 100644
index 0000000..0e648cd
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/queries/procedure/query_procedure_drop_function/query_procedure_drop_function.1.ddl.sqlpp
@@ -0,0 +1,59 @@
+/*
+ * 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.
+ */
+/*
+* Description  : Query Procedure drop function
+* Expected Res : Error
+* Date         : Jan 2018
+* Author       : Steven Jacobs
+*/
+
+drop dataverse two if exists;
+drop dataverse channels if exists;
+create dataverse channels;
+use channels;
+create type myLocation as {
+  id: int
+};
+create dataset UserLocations(myLocation)
+primary key id;
+insert into UserLocations(
+  [{"id":0, "roomNumber":4815162342},
+  {"id":1, "roomNumber":"lost"},
+  {"id":2, "roomNumber":108},
+  {"id":3, "roomNumber":"jacob"}]
+);
+
+create function really_contains(word,letter){
+contains(word,letter)
+};
+
+create dataverse two;
+use two;
+
+create procedure selectSome(r, otherRoom) {
+select roomNumber from channels.UserLocations
+where roomNumber = r
+or roomNumber = otherRoom
+and channels.really_contains(roomNumber,"l")
+order by id
+};
+
+
+use channels;
+drop function really_contains@2;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/procedure/repetitive_insert_procedure/repetitive_insert_procedure.1.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/procedure/repetitive_insert_procedure/repetitive_insert_procedure.1.ddl.sqlpp
index 76f7f38..370d516 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/procedure/repetitive_insert_procedure/repetitive_insert_procedure.1.ddl.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/procedure/repetitive_insert_procedure/repetitive_insert_procedure.1.ddl.sqlpp
@@ -23,6 +23,7 @@
 * Author       : Steven Jacobs
 */
 
+drop dataverse two if exists;
 drop dataverse channels if exists;
 create dataverse channels;
 use channels;
diff --git a/asterix-bad/src/test/resources/runtimets/results/channel/create_channel_check_metadata/create_channel_check_metadata.1.adm b/asterix-bad/src/test/resources/runtimets/results/channel/create_channel_check_metadata/create_channel_check_metadata.1.adm
index e009733..bee9157 100644
--- a/asterix-bad/src/test/resources/runtimets/results/channel/create_channel_check_metadata/create_channel_check_metadata.1.adm
+++ b/asterix-bad/src/test/resources/runtimets/results/channel/create_channel_check_metadata/create_channel_check_metadata.1.adm
@@ -1 +1 @@
-{ "DataverseName": "channels", "ChannelName": "nearbyTweetChannel", "SubscriptionsDatasetName": "nearbyTweetChannelSubscriptions", "ResultsDatasetName": "nearbyTweetChannelResults", "Function": "channels.NearbyTweetsContainingText@2", "Duration": "PT10M" }
\ No newline at end of file
+{ "DataverseName": "channels", "ChannelName": "nearbyTweetChannel", "SubscriptionsDatasetName": "nearbyTweetChannelSubscriptions", "ResultsDatasetName": "nearbyTweetChannelResults", "Function": [ "channels", "NearbyTweetsContainingText", "2" ], "Duration": "PT10M", "Dependencies": [ [ [ "channels", "nearbyTweetChannelResults" ], [ "channels", "nearbyTweetChannelSubscriptions" ] ], [ [ "channels", "NearbyTweetsContainingText", "2" ] ] ] }
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/results/channel/drop_channel_check_metadata/drop_channel_check_metadata.1.adm b/asterix-bad/src/test/resources/runtimets/results/channel/drop_channel_check_metadata/drop_channel_check_metadata.1.adm
index 1da5787..1c492ac 100644
--- a/asterix-bad/src/test/resources/runtimets/results/channel/drop_channel_check_metadata/drop_channel_check_metadata.1.adm
+++ b/asterix-bad/src/test/resources/runtimets/results/channel/drop_channel_check_metadata/drop_channel_check_metadata.1.adm
@@ -1,2 +1,2 @@
-{ "DataverseName": "channels", "ChannelName": "nearbyTweetChannel1", "SubscriptionsDatasetName": "nearbyTweetChannel1Subscriptions", "ResultsDatasetName": "nearbyTweetChannel1Results", "Function": "channels.NearbyTweetsContainingText@2", "Duration": "PT10M" }
-{ "DataverseName": "channels", "ChannelName": "nearbyTweetChannel3", "SubscriptionsDatasetName": "nearbyTweetChannel3Subscriptions", "ResultsDatasetName": "nearbyTweetChannel3Results", "Function": "channels.NearbyTweetsContainingText@2", "Duration": "PT10M" }
\ No newline at end of file
+{ "DataverseName": "channels", "ChannelName": "nearbyTweetChannel1", "SubscriptionsDatasetName": "nearbyTweetChannel1Subscriptions", "ResultsDatasetName": "nearbyTweetChannel1Results", "Function": [ "channels", "NearbyTweetsContainingText", "2" ], "Duration": "PT10M", "Dependencies": [ [ [ "channels", "nearbyTweetChannel1Results" ], [ "channels", "nearbyTweetChannel1Subscriptions" ] ], [ [ "channels", "NearbyTweetsContainingText", "2" ] ] ] }
+{ "DataverseName": "channels", "ChannelName": "nearbyTweetChannel3", "SubscriptionsDatasetName": "nearbyTweetChannel3Subscriptions", "ResultsDatasetName": "nearbyTweetChannel3Results", "Function": [ "channels", "NearbyTweetsContainingText", "2" ], "Duration": "PT10M", "Dependencies": [ [ [ "channels", "nearbyTweetChannel3Results" ], [ "channels", "nearbyTweetChannel3Subscriptions" ] ], [ [ "channels", "NearbyTweetsContainingText", "2" ] ] ] }
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/results/procedure/create_procedure_check_metadata/create_procedure_check_metadata.1.adm b/asterix-bad/src/test/resources/runtimets/results/procedure/create_procedure_check_metadata/create_procedure_check_metadata.1.adm
new file mode 100644
index 0000000..4308c83
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/results/procedure/create_procedure_check_metadata/create_procedure_check_metadata.1.adm
@@ -0,0 +1,6 @@
+{ "DataverseName": "two", "ProcedureName": "addMe", "Arity": "0", "Params": [  ], "ReturnType": "VOID", "Definition": "insert into channels.UserLocations([\n    {\"timeStamp\":current_datetime(), \"roomNumber\":222}]\n  )", "Language": "AQL", "Duration": "", "Dependencies": [ [ [ "channels", "UserLocations" ] ], [  ] ] }
+{ "DataverseName": "two", "ProcedureName": "deleteSome", "Arity": "2", "Params": [ "$r", "$otherRoom" ], "ReturnType": "VOID", "Definition": "delete from channels.UserLocations\nwhere roomNumber = r\nor roomNumber = otherRoom\nand channels.really_contains(roomNumber,\"l\")", "Language": "AQL", "Duration": "", "Dependencies": [ [ [ "channels", "UserLocations" ] ], [ [ "channels", "really_contains", "2" ] ] ] }
+{ "DataverseName": "two", "ProcedureName": "localAddMe", "Arity": "0", "Params": [  ], "ReturnType": "VOID", "Definition": "insert into UserLocations([\n    {\"timeStamp\":current_datetime(), \"roomNumber\":222}]\n  )", "Language": "AQL", "Duration": "", "Dependencies": [ [ [ "two", "UserLocations" ] ], [  ] ] }
+{ "DataverseName": "two", "ProcedureName": "localDeleteSome", "Arity": "2", "Params": [ "$r", "$otherRoom" ], "ReturnType": "VOID", "Definition": "delete from UserLocations\nwhere roomNumber = r\nor roomNumber = otherRoom\nand really_contains(roomNumber,\"l\")", "Language": "AQL", "Duration": "", "Dependencies": [ [ [ "two", "UserLocations" ] ], [ [ "two", "really_contains", "2" ] ] ] }
+{ "DataverseName": "two", "ProcedureName": "localSelectSome", "Arity": "2", "Params": [ "$r", "$otherRoom" ], "ReturnType": "VOID", "Definition": "select roomNumber from UserLocations\nwhere roomNumber = r\nor roomNumber = otherRoom\nand really_contains(roomNumber,\"l\")\norder by id", "Language": "AQL", "Duration": "", "Dependencies": [ [ [ "two", "UserLocations" ] ], [ [ "two", "really_contains", "2" ] ] ] }
+{ "DataverseName": "two", "ProcedureName": "selectSome", "Arity": "2", "Params": [ "$r", "$otherRoom" ], "ReturnType": "VOID", "Definition": "select roomNumber from channels.UserLocations\nwhere roomNumber = r\nor roomNumber = otherRoom\nand channels.really_contains(roomNumber,\"l\")\norder by id", "Language": "AQL", "Duration": "", "Dependencies": [ [ [ "channels", "UserLocations" ] ], [ [ "channels", "really_contains", "2" ] ] ] }
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/testsuite.xml b/asterix-bad/src/test/resources/runtimets/testsuite.xml
index 1b2844b..3c72a14 100644
--- a/asterix-bad/src/test/resources/runtimets/testsuite.xml
+++ b/asterix-bad/src/test/resources/runtimets/testsuite.xml
@@ -22,6 +22,11 @@
              QueryFileExtension=".sqlpp">
   <test-group name="channel">
     <test-case FilePath="procedure">
+      <compilation-unit name="create_procedure_check_metadata">
+        <output-dir compare="Text">create_procedure_check_metadata</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="procedure">
       <compilation-unit name="delete_procedure">
         <output-dir compare="Text">delete_procedure</output-dir>
       </compilation-unit>
@@ -52,13 +57,50 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="procedure">
-      <compilation-unit name="repetitive_insert_procedure">
-        <output-dir compare="Text">repetitive_insert_procedure</output-dir>
+      <compilation-unit name="insert_procedure_drop_dataset">
+        <output-dir compare="Text">insert_procedure_drop_dataset</output-dir>
+        <expected-error>Cannot alter dataset channels.UserLocations. two.addMe(Procedure) depends on it!</expected-error>
       </compilation-unit>
     </test-case>
-    <test-case FilePath="channel">
-      <compilation-unit name="room_occupants">
-        <output-dir compare="Text">room_occupants</output-dir>
+    <test-case FilePath="procedure">
+      <compilation-unit name="insert_procedure_drop_dataverse">
+        <output-dir compare="Text">insert_procedure_drop_dataverse</output-dir>
+        <expected-error>Cannot drop dataverse channels. two.addMe(Procedure) depends on it!</expected-error>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="procedure">
+      <compilation-unit name="delete_procedure_drop_dataset">
+        <output-dir compare="Text">delete_procedure_drop_dataset</output-dir>
+        <expected-error>Cannot alter dataset channels.UserLocations. two.deleteAll(Procedure) depends on it!</expected-error>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="procedure">
+      <compilation-unit name="delete_procedure_drop_function">
+        <output-dir compare="Text">delete_procedure_drop_function</output-dir>
+        <expected-error>Cannot drop function two.really_contains@2. two.deleteSome(Procedure) depends on it!</expected-error>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="procedure">
+      <compilation-unit name="delete_procedure_drop_index">
+        <output-dir compare="Text">delete_procedure_drop_index</output-dir>
+        <expected-error>Cannot alter dataset channels.UserLocations. two.deleteAll(Procedure) depends on it!</expected-error>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="procedure">
+      <compilation-unit name="query_procedure_drop_dataset">
+        <output-dir compare="Text">query_procedure_drop_dataset</output-dir>
+        <expected-error>Cannot alter dataset channels.UserLocations. two.findMe(Procedure) depends on it!</expected-error>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="procedure">
+      <compilation-unit name="query_procedure_drop_function">
+        <output-dir compare="Text">query_procedure_drop_function</output-dir>
+        <expected-error>Cannot drop function channels.really_contains@2. two.selectSome(Procedure) depends on it!</expected-error>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="procedure">
+      <compilation-unit name="repetitive_insert_procedure">
+        <output-dir compare="Text">repetitive_insert_procedure</output-dir>
       </compilation-unit>
     </test-case>
     <test-case FilePath="channel">
@@ -87,6 +129,35 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="channel">
+      <compilation-unit name="drop_function">
+        <output-dir compare="Text">drop_function</output-dir>
+        <expected-error>Cannot drop function channels.NearbyTweetsContainingText@2. two.nearbyTweetChannel(Channel) depends on it!</expected-error>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="channel">
+      <compilation-unit name="drop_results">
+        <output-dir compare="Text">drop_results</output-dir>
+        <expected-error>Cannot alter dataset two.nearbyTweetChannelResults. two.nearbyTweetChannel(Channel) depends on it!</expected-error>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="channel">
+      <compilation-unit name="drop_subscriptions">
+        <output-dir compare="Text">drop_subscriptions</output-dir>
+        <expected-error>Cannot alter dataset two.nearbyTweetChannelSubscriptions. two.nearbyTweetChannel(Channel) depends on it!</expected-error>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="channel">
+      <compilation-unit name="drop_function_dataverse">
+        <output-dir compare="Text">drop_function_dataverse</output-dir>
+        <expected-error>Cannot drop dataverse channels. two.nearbyTweetChannel(Channel) depends on it!</expected-error>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="channel">
+      <compilation-unit name="room_occupants">
+        <output-dir compare="Text">room_occupants</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="channel">
       <compilation-unit name="disasters_with_friends">
         <output-dir compare="Text">disasters_with_friends</output-dir>
       </compilation-unit>