Introducing BAD-CQ

a. Active datasets
  Active datasets are like regular datasets that can be
  inserted/upserted/deleted with statements and fed with data feeds
  directly.  Records stored in active datasets contain an additional
  active timestamp field (implemented using meta-records). The active
  timestamp is assigned inside the storage, right before persistence.
  This patch introduced new syntactic components to enable creating
  active datasets.  It also created a BAD query translator to make sure
  all DML statements can operate on active datasets.
b. Continuous channels
  Continuous channels are built on repetitive channels but provide
  continuous query semantics. To ensure that, this patch introduced an
  active timestamp manager on each node to manage channel execution
  times locally. Active timestamp managers are a local class that is
  tied to a JVM on a node. There is also an optimization rule for
  ensuring continuous query semantics in a distributed environment.
c. Active functions
  Active functions are used for helping users create continuous queries.
  They were added through the extension APIs.
d. BAD Islands
  As an application built on BAD-CQ, BAD islands show how we connect
  data channels to data feeds and share data between different BAD
  systems declaratively.
e. Cleanups and fixes
  This patch also cleaned up the BAD codebase and introduced tests for
  metadata, optimizer, and runtime. It fixed a type inferencing issue in
  InsertBrokerNotifierForChannelRule when there is a group-by in the
  query. Also, it optimized the broker notification delivery to use
  separate threads.

Change-Id: I77263c3fedd03205b83fe13978649b33fccda11c
diff --git a/asterix-bad/data/tweets.txt b/asterix-bad/data/tweets.txt
new file mode 100644
index 0000000..9f0798b
--- /dev/null
+++ b/asterix-bad/data/tweets.txt
@@ -0,0 +1,11 @@
+{"tid" : 0, "area_name": "UCI", "suspicious_level": 9, "text": "Tweet 1", "location": point("68.41629186478751, 44.631424133284966"), "timestamp": datetime("2018-11-09T00:00:00.000Z"), "threatening_flag": true}
+{"tid" : 1, "area_name": "SD", "suspicious_level": 2, "text": "Tweet 2", "location": point("2026.6769440649875, 2018.7964303566189"), "timestamp": datetime("2017-11-07T00:00:00.000Z"), "threatening_flag": false}
+{"tid" : 2, "area_name": "LA", "suspicious_level": 10, "text": "Tweet 3", "location": point("4037.165975321966, 4020.6200896429373"), "timestamp": datetime("2018-08-14T00:00:00.000Z"), "threatening_flag": true}
+{"tid" : 3, "area_name": "UCI", "suspicious_level": 5, "text": "Tweet 4", "location": point("6011.1101544678095, 6033.86438259922"), "timestamp": datetime("2018-05-18T00:00:00.000Z"), "threatening_flag": true}
+{"tid" : 4, "area_name": "UCI", "suspicious_level": 3, "text": "Tweet 5", "location": point("8059.243121712048, 8070.611768137903"), "timestamp": datetime("2018-10-27T00:00:00.000Z"), "threatening_flag": false}
+{"tid" : 5, "area_name": "LA", "suspicious_level": 8, "text": "Tweet 6", "location": point("10030.582330779562, 10035.23466920704"), "timestamp": datetime("2017-04-11T00:00:00.000Z"), "threatening_flag": false}
+{"tid" : 6, "area_name": "LA", "suspicious_level": 9, "text": "Tweet 7", "location": point("12074.059527318483, 12008.549148129303"), "timestamp": datetime("2017-04-23T00:00:00.000Z"), "threatening_flag": true}
+{"tid" : 7, "area_name": "UCI", "suspicious_level": 6, "text": "Tweet 8", "location": point("14047.406241253855, 14063.900105905997"), "timestamp": datetime("2018-06-06T00:00:00.000Z"), "threatening_flag": false}
+{"tid" : 8, "area_name": "LA", "suspicious_level": 8, "text": "Tweet 9", "location": point("16051.9846352692, 16078.599078960015"), "timestamp": datetime("2018-03-27T00:00:00.000Z"), "threatening_flag": true}
+{"tid" : 9, "area_name": "UCI", "suspicious_level": 1, "text": "Tweet 10", "location": point("18006.76288487177, 18014.17514030951"), "timestamp": datetime("2017-08-29T00:00:00.000Z"), "threatening_flag": false}
+{"tid" : 10, "area_name": "SD", "suspicious_level": 0, "text": "Tweet 11", "location": point("20088.467372365518, 20051.89371416724"), "timestamp": datetime("2017-10-01T00:00:00.000Z"), "threatening_flag": true}
diff --git a/asterix-bad/pom.xml b/asterix-bad/pom.xml
index c9ac366..9c96e68 100644
--- a/asterix-bad/pom.xml
+++ b/asterix-bad/pom.xml
@@ -27,7 +27,7 @@
     <properties>
     <asterix.version>0.9.5-SNAPSHOT</asterix.version>
     <hyracks.version>0.3.5-SNAPSHOT</hyracks.version>
-    <testLog4jConfigFile>${root.dir}/../../asterix-app/src/test/resources/log4j2-test.xml</testLog4jConfigFile>
+    <testLog4jConfigFile>src/main/resources/log4j2-bad.xml</testLog4jConfigFile>
     </properties>
     <build>
     <plugins>
@@ -100,6 +100,7 @@
         <configuration>
           <excludes combine.children="append">
             <exclude>src/test/resources/**/results/**</exclude>
+              <exclude>data/**</exclude>
           </excludes>
         </configuration>
       </plugin>
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/BADConstants.java b/asterix-bad/src/main/java/org/apache/asterix/bad/BADConstants.java
index a787778..391d84e 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/BADConstants.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/BADConstants.java
@@ -18,28 +18,15 @@
  */
 package org.apache.asterix.bad;
 
-import org.apache.asterix.common.metadata.DataverseName;
-
 public interface BADConstants {
     String SubscriptionId = "subscriptionId";
-    String BrokerName = "BrokerName";
     String ChannelName = "ChannelName";
     String ProcedureName = "ProcedureName";
-    String DataverseName = "DataverseName";
-    String BrokerEndPoint = "BrokerEndPoint";
     String DeliveryTime = "deliveryTime";
     String ResultId = "resultId";
-    String ChannelExecutionTime = "channelExecutionTime";
-    String ChannelSubscriptionsType = "ChannelSubscriptionsType";
     String ChannelResultsType = "ChannelResultsType";
     String ResultsDatasetName = "ResultsDatasetName";
     String SubscriptionsDatasetName = "SubscriptionsDatasetName";
-    String CHANNEL_EXTENSION_NAME = "Channel";
-    String PROCEDURE_KEYWORD = "Procedure";
-    String BROKER_KEYWORD = "Broker";
-    String RECORD_TYPENAME_BROKER = "BrokerRecordType";
-    String RECORD_TYPENAME_CHANNEL = "ChannelRecordType";
-    String RECORD_TYPENAME_PROCEDURE = "ProcedureRecordType";
     String subscriptionEnding = "Subscriptions";
     String resultsEnding = "Results";
     String BAD_METADATA_EXTENSION_NAME = "BADMetadataExtension";
@@ -52,10 +39,54 @@
     String FIELD_NAME_DEFINITION = "Definition";
     String FIELD_NAME_LANGUAGE = "Language";
     String FIELD_NAME_BODY = "Body";
+
+    /* --- Notification Fields --- */
+    String ChannelExecutionTime = "channelExecutionTime";
+    String CHANNEL_EXECUTION_EPOCH_TIME = "channelExecutionEpochTime";
+
+    // --- Active Dataset
+    String RECORD_TYPENAME_ACTIVE_RECORD = "ActiveRecordType";
+    String FIELD_NAME_ACTIVE_TS = "_active_timestamp";
+
     //To enable new Asterix TxnId for separate deployed job spec invocations
     byte[] TRANSACTION_ID_PARAMETER_NAME = "TxnIdParameter".getBytes();
     int EXECUTOR_TIMEOUT = 20;
 
+    /* --- Metadata Common --- */
+    String METADATA_TYPE_NAME_DATAVERSENAME = "DataverseName";
+
+    String METADATA_DATASET_CHANNEL = "Channel";
+    String METADATA_DATASET_PROCEDURE = "Procedure";
+    String METADATA_DATASET_BROKER = "Broker";
+
+    /* --- Metadata Datatypes --- */
+    String METADATA_TYPENAME_SUBSCRIPTIONS = "ChannelSubscriptionsType";
+    String METADATA_TYPENAME_BROKER = "BrokerRecordType";
+    String METADATA_TYPENAME_CHANNEL = "ChannelRecordType";
+    String METADATA_TYPENAME_PROCEDURE = "ProcedureRecordType";
+
+    /* --- Broker Field Names --- */
+    String METADATA_TYPE_FIELD_NAME_BROKERNAME = "BrokerName";
+    String METADATA_TYPE_FIELD_NAME_BROKER_END_POINT = "BrokerEndPoint";
+    String METADATA_TYPE_FIELD_NAME_BROKER_TYPE = "BrokerType";
+
+    /*  ---  Runtime Entities ---  */
+    String RUNTIME_ENTITY_PROCEDURE = "Procedure";
+    String RUNTIME_ENTITY_CHANNEL = "Channel";
+
+    /* --- Query Compilation --- */
+    String CONFIG_CHANNEL_NAME = "_internal_channelName";
+
+    /* --- BAD ISLANDS --- */
+    String GENERAL_BROKER_TYPE_NAME = "general";
+    String BAD_BROKER_TYPE_NAME = "bad";
+    String BAD_BROKER_FIELD_NAME_TYPE = "broker-type";
+    String BAD_FEED_FIELD_NAME_HOST = "bad-host";
+    String BAD_FEED_FIELD_NAME_CHANNEL = "bad-channel";
+    String BAD_FEED_FIELD_NAME_PARAMETERS = "bad-channel-parameters";
+    String BAD_FEED_FIELD_NAME_CHANNEL_DV = "bad-dataverse";
+    // String BAD_FEED_TYPE = "type"
+
     public enum ChannelJobType {
         REPETITIVE
     }
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/BADJobService.java b/asterix-bad/src/main/java/org/apache/asterix/bad/BADJobService.java
index af4ff03..4342dc6 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/BADJobService.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/BADJobService.java
@@ -18,7 +18,6 @@
  */
 package org.apache.asterix.bad;
 
-import java.io.StringReader;
 import java.time.Instant;
 import java.util.Date;
 import java.util.HashMap;
@@ -37,7 +36,7 @@
 import org.apache.asterix.app.result.fields.ResultsPrinter;
 import org.apache.asterix.app.translator.QueryTranslator;
 import org.apache.asterix.bad.lang.BADParserFactory;
-import org.apache.asterix.bad.lang.BADStatementExecutor;
+import org.apache.asterix.bad.lang.BADQueryTranslator;
 import org.apache.asterix.bad.metadata.DeployedJobSpecEventListener;
 import org.apache.asterix.common.api.IResponsePrinter;
 import org.apache.asterix.common.dataflow.ICcApplicationContext;
@@ -66,44 +65,44 @@
     private static final Logger LOGGER = Logger.getLogger(BADJobService.class.getName());
 
     //pool size one (only running one thread at a time)
-    private static final int POOL_SIZE = 1;
+    public static final int POOL_SIZE = 1;
 
     private static final long millisecondTimeout = BADConstants.EXECUTOR_TIMEOUT * 1000;
 
+    public static ScheduledExecutorService createExecutorServe() {
+        return Executors.newScheduledThreadPool(POOL_SIZE);
+    }
+
     public static void setupExecutorJob(EntityId entityId, JobSpecification channeljobSpec,
             IHyracksClientConnection hcc, DeployedJobSpecEventListener listener, ITxnIdFactory txnIdFactory,
             String duration) throws Exception {
+        ScheduledExecutorService ses = createExecutorServe();
+        listener.setExecutorService(ses);
         if (channeljobSpec != null) {
             channeljobSpec.setProperty(ActiveNotificationHandler.ACTIVE_ENTITY_PROPERTY_NAME, entityId);
             DeployedJobSpecId deployedId = hcc.deployJobSpec(channeljobSpec);
-            ScheduledExecutorService ses = startRepetitiveDeployedJobSpec(deployedId, hcc, findPeriod(duration),
-                    new HashMap<>(), entityId, txnIdFactory, listener);
+            startRepetitiveDeployedJobSpec(ses, deployedId, hcc, findPeriod(duration), new HashMap<>(), entityId,
+                    txnIdFactory, listener);
             listener.setDeployedJobSpecId(deployedId);
-            listener.setExecutorService(ses);
         }
-
     }
 
     //Starts running a deployed job specification periodically with an interval of "period" seconds
-    public static ScheduledExecutorService startRepetitiveDeployedJobSpec(DeployedJobSpecId distributedId,
-            IHyracksClientConnection hcc, long period, Map<byte[], byte[]> jobParameters, EntityId entityId,
-            ITxnIdFactory txnIdFactory, DeployedJobSpecEventListener listener) {
-        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(POOL_SIZE);
-        scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
-            @Override
-            public void run() {
-                try {
-                    if (!runDeployedJobSpecCheckPeriod(distributedId, hcc, jobParameters, period, entityId,
-                            txnIdFactory, listener)) {
-                        scheduledExecutorService.shutdown();
-                    }
-                } catch (Exception e) {
-                    LOGGER.log(Level.SEVERE, "Job Failed to run for " + entityId.getExtensionName() + " "
-                            + entityId.getDataverseName() + "." + entityId.getEntityName() + ".", e);
+    public static void startRepetitiveDeployedJobSpec(ScheduledExecutorService scheduledExecutorService,
+            DeployedJobSpecId distributedId, IHyracksClientConnection hcc, long period,
+            Map<byte[], byte[]> jobParameters, EntityId entityId, ITxnIdFactory txnIdFactory,
+            DeployedJobSpecEventListener listener) {
+        scheduledExecutorService.scheduleAtFixedRate(() -> {
+            try {
+                if (!runDeployedJobSpecCheckPeriod(distributedId, hcc, jobParameters, period, entityId, txnIdFactory,
+                        listener)) {
+                    scheduledExecutorService.shutdown();
                 }
+            } catch (Exception e) {
+                LOGGER.log(Level.SEVERE, "Job Failed to run for " + entityId.getExtensionName() + " "
+                        + entityId.getDataverseName() + "." + entityId.getEntityName() + ".", e);
             }
         }, period, period, TimeUnit.MILLISECONDS);
-        return scheduledExecutorService;
     }
 
     public static boolean runDeployedJobSpecCheckPeriod(DeployedJobSpecId distributedId, IHyracksClientConnection hcc,
@@ -207,8 +206,8 @@
     }
 
     public static void redeployJobSpec(EntityId entityId, String queryBodyString, MetadataProvider metadataProvider,
-            BADStatementExecutor badStatementExecutor, IHyracksClientConnection hcc,
-            IRequestParameters requestParameters, boolean useNewId) throws Exception {
+            BADQueryTranslator badStatementExecutor, IHyracksClientConnection hcc, IRequestParameters requestParameters,
+            boolean useNewId) throws Exception {
 
         ICcApplicationContext appCtx = metadataProvider.getApplicationContext();
         ActiveNotificationHandler activeEventHandler =
@@ -220,7 +219,7 @@
         }
 
         BADParserFactory factory = new BADParserFactory();
-        List<Statement> fStatements = factory.createParser(new StringReader(queryBodyString)).parse();
+        List<Statement> fStatements = factory.createParser(queryBodyString).parse();
         JobSpecification jobSpec = null;
         if (listener.getType().equals(DeployedJobSpecEventListener.PrecompiledType.PUSH_CHANNEL)
                 || listener.getType().equals(DeployedJobSpecEventListener.PrecompiledType.CHANNEL)) {
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/BADUtils.java b/asterix-bad/src/main/java/org/apache/asterix/bad/BADUtils.java
new file mode 100644
index 0000000..db1e06b
--- /dev/null
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/BADUtils.java
@@ -0,0 +1,38 @@
+/*
+ * 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.bad;
+
+import org.apache.asterix.metadata.declared.MetadataProvider;
+
+public class BADUtils {
+
+    public static MetadataProvider replicateMetadataProvider(MetadataProvider metadataProvider) {
+        MetadataProvider tempMdProvider = MetadataProvider.create(metadataProvider.getApplicationContext(),
+                metadataProvider.getDefaultDataverse());
+        tempMdProvider.setResultSetId(metadataProvider.getResultSetId());
+        tempMdProvider.getConfig().putAll(metadataProvider.getConfig());
+        tempMdProvider.setResultSetId(metadataProvider.getResultSetId());
+        tempMdProvider.setWriterFactory(metadataProvider.getWriterFactory());
+        tempMdProvider.setResultSerializerFactoryProvider(metadataProvider.getResultSerializerFactoryProvider());
+        tempMdProvider.setOutputFile(metadataProvider.getOutputFile());
+        return tempMdProvider;
+    }
+
+}
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADLangExtension.java b/asterix-bad/src/main/java/org/apache/asterix/bad/extension/BADLangExtension.java
similarity index 98%
rename from asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADLangExtension.java
rename to asterix-bad/src/main/java/org/apache/asterix/bad/extension/BADLangExtension.java
index 4e94508..024f3e4 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADLangExtension.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/extension/BADLangExtension.java
@@ -16,11 +16,12 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.asterix.bad.lang;
+package org.apache.asterix.bad.extension;
 
 import java.util.List;
 
 import org.apache.asterix.algebra.base.ILangExtension;
+import org.apache.asterix.bad.lang.BADCompilationProvider;
 import org.apache.asterix.bad.metadata.AllChannelsSearchKey;
 import org.apache.asterix.bad.metadata.AllProceduresSearchKey;
 import org.apache.asterix.bad.metadata.Broker;
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/metadata/BADMetadataExtension.java b/asterix-bad/src/main/java/org/apache/asterix/bad/extension/BADMetadataExtension.java
similarity index 75%
rename from asterix-bad/src/main/java/org/apache/asterix/bad/metadata/BADMetadataExtension.java
rename to asterix-bad/src/main/java/org/apache/asterix/bad/extension/BADMetadataExtension.java
index 49371f9..d0639e2 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/metadata/BADMetadataExtension.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/extension/BADMetadataExtension.java
@@ -16,13 +16,17 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.asterix.bad.metadata;
+package org.apache.asterix.bad.extension;
 
 import java.rmi.RemoteException;
 import java.util.Arrays;
 import java.util.List;
 
 import org.apache.asterix.bad.BADConstants;
+import org.apache.asterix.bad.function.BADFunctions;
+import org.apache.asterix.bad.function.rewriter.BADFeedRewriter;
+import org.apache.asterix.bad.metadata.BADMetadataIndexes;
+import org.apache.asterix.bad.metadata.BADMetadataRecordTypes;
 import org.apache.asterix.common.api.ExtensionId;
 import org.apache.asterix.common.exceptions.ACIDException;
 import org.apache.asterix.metadata.MetadataManager;
@@ -36,6 +40,9 @@
 import org.apache.asterix.metadata.entitytupletranslators.MetadataTupleTranslatorProvider;
 import org.apache.asterix.metadata.utils.MetadataConstants;
 import org.apache.asterix.metadata.utils.MetadataUtil;
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.asterix.om.typecomputer.impl.ABooleanTypeComputer;
+import org.apache.asterix.om.typecomputer.impl.ADateTimeTypeComputer;
 import org.apache.asterix.runtime.formats.NonTaggedDataFormat;
 import org.apache.hyracks.algebricks.common.utils.Pair;
 import org.apache.hyracks.api.application.INCServiceContext;
@@ -49,18 +56,21 @@
             NonTaggedDataFormat.class.getName(), MetadataUtil.PENDING_NO_OP);
 
     public static final Datatype BAD_SUBSCRIPTION_DATATYPE = new Datatype(MetadataConstants.METADATA_DATAVERSE_NAME,
-            BADConstants.ChannelSubscriptionsType, BADMetadataRecordTypes.channelSubscriptionsType, false);
+            BADConstants.METADATA_TYPENAME_SUBSCRIPTIONS, BADMetadataRecordTypes.channelSubscriptionsType, false);
     public static final Datatype BAD_RESULT_DATATYPE = new Datatype(MetadataConstants.METADATA_DATAVERSE_NAME,
             BADConstants.ChannelResultsType, BADMetadataRecordTypes.channelResultsType, false);
 
     public static final Datatype BAD_BROKER_DATATYPE = new Datatype(MetadataConstants.METADATA_DATAVERSE_NAME,
-            BADConstants.RECORD_TYPENAME_BROKER, BADMetadataRecordTypes.BROKER_RECORDTYPE, false);
+            BADConstants.METADATA_TYPENAME_BROKER, BADMetadataRecordTypes.BROKER_RECORDTYPE, false);
 
     public static final Datatype BAD_CHANNEL_DATATYPE = new Datatype(MetadataConstants.METADATA_DATAVERSE_NAME,
-            BADConstants.RECORD_TYPENAME_CHANNEL, BADMetadataRecordTypes.CHANNEL_RECORDTYPE, false);
+            BADConstants.METADATA_TYPENAME_CHANNEL, BADMetadataRecordTypes.CHANNEL_RECORDTYPE, false);
 
     public static final Datatype BAD_PROCEDURE_DATATYPE = new Datatype(MetadataConstants.METADATA_DATAVERSE_NAME,
-            BADConstants.RECORD_TYPENAME_PROCEDURE, BADMetadataRecordTypes.PROCEDURE_RECORDTYPE, false);
+            BADConstants.METADATA_TYPENAME_PROCEDURE, BADMetadataRecordTypes.PROCEDURE_RECORDTYPE, false);
+
+    public static final Datatype BAD_ACTIVE_RECORD_TYPE = new Datatype(MetadataConstants.METADATA_DATAVERSE_NAME,
+            BADConstants.RECORD_TYPENAME_ACTIVE_RECORD, BADMetadataRecordTypes.ACTIVE_RECORD_RECORD_TYPE, false);
 
     @Override
     public ExtensionId getId() {
@@ -112,6 +122,7 @@
                 MetadataManager.INSTANCE.addDatatype(mdTxnCtx, BAD_BROKER_DATATYPE);
                 MetadataManager.INSTANCE.addDatatype(mdTxnCtx, BAD_CHANNEL_DATATYPE);
                 MetadataManager.INSTANCE.addDatatype(mdTxnCtx, BAD_PROCEDURE_DATATYPE);
+                MetadataManager.INSTANCE.addDatatype(mdTxnCtx, BAD_ACTIVE_RECORD_TYPE);
                 // TODO prevent user from dropping these types
                 MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
             } catch (Exception e) {
@@ -121,5 +132,13 @@
         }
         // local recovery?
         // nothing for now
+        BuiltinFunctions.addFunction(BADFunctions.CURRENT_CHANNEL_TIME, ADateTimeTypeComputer.INSTANCE, false);
+        BuiltinFunctions.addFunction(BADFunctions.PREVIOUS_CHANNEL_TIME, ADateTimeTypeComputer.INSTANCE, false);
+        BuiltinFunctions.addFunction(BADFunctions.IS_NEW, ABooleanTypeComputer.INSTANCE, true);
+
+        // to shadow the master feed rewriter
+        BuiltinFunctions.addPrivateFunction(BuiltinFunctions.FEED_COLLECT, BADFeedRewriter.INSTANCE, true);
+        BuiltinFunctions.addUnnestFun(BuiltinFunctions.FEED_COLLECT, false);
+        BuiltinFunctions.addDatasourceFunction(BuiltinFunctions.FEED_COLLECT, BADFeedRewriter.INSTANCE);
     }
 }
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADQueryTranslatorExtension.java b/asterix-bad/src/main/java/org/apache/asterix/bad/extension/BADQueryTranslatorExtension.java
similarity index 94%
rename from asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADQueryTranslatorExtension.java
rename to asterix-bad/src/main/java/org/apache/asterix/bad/extension/BADQueryTranslatorExtension.java
index 23b44a7..fcb071c 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADQueryTranslatorExtension.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/extension/BADQueryTranslatorExtension.java
@@ -16,11 +16,12 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.asterix.bad.lang;
+package org.apache.asterix.bad.extension;
 
 import java.util.List;
 
 import org.apache.asterix.app.cc.IStatementExecutorExtension;
+import org.apache.asterix.bad.lang.BADQueryTranslatorFactory;
 import org.apache.asterix.common.api.ExtensionId;
 import org.apache.asterix.translator.IStatementExecutorFactory;
 import org.apache.hyracks.algebricks.common.utils.Pair;
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/recovery/BADRecoveryExtension.java b/asterix-bad/src/main/java/org/apache/asterix/bad/extension/BADRecoveryExtension.java
similarity index 94%
rename from asterix-bad/src/main/java/org/apache/asterix/bad/recovery/BADRecoveryExtension.java
rename to asterix-bad/src/main/java/org/apache/asterix/bad/extension/BADRecoveryExtension.java
index 609b6de..995be2c 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/recovery/BADRecoveryExtension.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/extension/BADRecoveryExtension.java
@@ -16,11 +16,12 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.asterix.bad.recovery;
+package org.apache.asterix.bad.extension;
 
 import java.util.List;
 
 import org.apache.asterix.app.cc.IGlobalRecoveryExtension;
+import org.apache.asterix.bad.recovery.BADGlobalRecoveryManager;
 import org.apache.asterix.common.api.ExtensionId;
 import org.apache.asterix.common.cluster.IGlobalRecoveryManager;
 import org.apache.asterix.common.context.IStorageComponentProvider;
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/feed/operators/BADLSMPrimaryInsertOperatorDescriptor.java b/asterix-bad/src/main/java/org/apache/asterix/bad/feed/operators/BADLSMPrimaryInsertOperatorDescriptor.java
new file mode 100644
index 0000000..8a92c56
--- /dev/null
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/feed/operators/BADLSMPrimaryInsertOperatorDescriptor.java
@@ -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.
+ */
+
+package org.apache.asterix.bad.feed.operators;
+
+import org.apache.asterix.runtime.operators.LSMPrimaryInsertOperatorDescriptor;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.dataflow.IOperatorNodePushable;
+import org.apache.hyracks.api.dataflow.value.IRecordDescriptorProvider;
+import org.apache.hyracks.api.dataflow.value.RecordDescriptor;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.api.job.IOperatorDescriptorRegistry;
+import org.apache.hyracks.storage.am.common.api.IModificationOperationCallbackFactory;
+import org.apache.hyracks.storage.am.common.api.ISearchOperationCallbackFactory;
+import org.apache.hyracks.storage.am.common.dataflow.IIndexDataflowHelperFactory;
+
+public class BADLSMPrimaryInsertOperatorDescriptor extends LSMPrimaryInsertOperatorDescriptor {
+    public BADLSMPrimaryInsertOperatorDescriptor(IOperatorDescriptorRegistry spec, RecordDescriptor outRecDesc,
+            int[] fieldPermutation, IIndexDataflowHelperFactory indexHelperFactory,
+            IIndexDataflowHelperFactory keyIndexHelperFactory,
+            IModificationOperationCallbackFactory modificationOpCallbackFactory,
+            ISearchOperationCallbackFactory searchOpCallbackFactory, int numOfPrimaryKeys, int[] filterFields) {
+        super(spec, outRecDesc, fieldPermutation, indexHelperFactory, keyIndexHelperFactory,
+                modificationOpCallbackFactory, searchOpCallbackFactory, numOfPrimaryKeys, filterFields);
+    }
+
+    @Override
+    public IOperatorNodePushable createPushRuntime(IHyracksTaskContext ctx,
+            IRecordDescriptorProvider recordDescProvider, int partition, int nPartitions) throws HyracksDataException {
+        RecordDescriptor intputRecDesc = recordDescProvider.getInputRecordDescriptor(getActivityId(), 0);
+        return new BADLSMPrimaryInsertOperatorNodePushable(ctx, partition, indexHelperFactory, keyIndexHelperFactory,
+                fieldPermutation, intputRecDesc, modCallbackFactory, searchOpCallbackFactory, numOfPrimaryKeys,
+                filterFields, sourceLoc);
+    }
+}
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/feed/operators/BADLSMPrimaryInsertOperatorNodePushable.java b/asterix-bad/src/main/java/org/apache/asterix/bad/feed/operators/BADLSMPrimaryInsertOperatorNodePushable.java
new file mode 100644
index 0000000..813fd0b
--- /dev/null
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/feed/operators/BADLSMPrimaryInsertOperatorNodePushable.java
@@ -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.
+ */
+
+package org.apache.asterix.bad.feed.operators;
+
+import java.nio.ByteBuffer;
+
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.runtime.operators.LSMPrimaryInsertOperatorNodePushable;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.dataflow.value.RecordDescriptor;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.api.exceptions.SourceLocation;
+import org.apache.hyracks.dataflow.common.data.accessors.ITupleReference;
+import org.apache.hyracks.storage.am.common.api.IModificationOperationCallbackFactory;
+import org.apache.hyracks.storage.am.common.api.ISearchOperationCallbackFactory;
+import org.apache.hyracks.storage.am.common.dataflow.IIndexDataflowHelperFactory;
+
+public class BADLSMPrimaryInsertOperatorNodePushable extends LSMPrimaryInsertOperatorNodePushable {
+
+    public BADLSMPrimaryInsertOperatorNodePushable(IHyracksTaskContext ctx, int partition,
+            IIndexDataflowHelperFactory indexHelperFactory, IIndexDataflowHelperFactory keyIndexHelperFactory,
+            int[] fieldPermutation, RecordDescriptor inputRecDesc,
+            IModificationOperationCallbackFactory modCallbackFactory,
+            ISearchOperationCallbackFactory searchCallbackFactory, int numOfPrimaryKeys, int[] filterFields,
+            SourceLocation sourceLoc) throws HyracksDataException {
+        super(ctx, partition, indexHelperFactory, keyIndexHelperFactory, fieldPermutation, inputRecDesc,
+                modCallbackFactory, searchCallbackFactory, numOfPrimaryKeys, filterFields, sourceLoc);
+    }
+
+    @Override
+    protected void beforeModification(ITupleReference tuple) {
+        if ((tuple.getFieldCount() == 3
+                && tuple.getFieldData(0)[tuple.getFieldStart(2)] == ATypeTag.SERIALIZED_RECORD_TYPE_TAG)
+                || (tuple.getFieldCount() == 4
+                        && tuple.getFieldData(0)[tuple.getFieldStart(2)] == ATypeTag.SERIALIZED_RECORD_TYPE_TAG)) {
+            int targetIdx = tuple.getFieldStart(2) + 14;
+            ByteBuffer tupleBuff = ByteBuffer.wrap(tuple.getFieldData(0));
+            tupleBuff.putLong(targetIdx, System.currentTimeMillis());
+        }
+    }
+}
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/feed/operators/BADLSMPrimaryUpsertOperatorDescriptor.java b/asterix-bad/src/main/java/org/apache/asterix/bad/feed/operators/BADLSMPrimaryUpsertOperatorDescriptor.java
new file mode 100644
index 0000000..46f9bc8
--- /dev/null
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/feed/operators/BADLSMPrimaryUpsertOperatorDescriptor.java
@@ -0,0 +1,55 @@
+/*
+ * 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.bad.feed.operators;
+
+import org.apache.asterix.om.types.ARecordType;
+import org.apache.asterix.runtime.operators.LSMPrimaryUpsertOperatorDescriptor;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.dataflow.IOperatorNodePushable;
+import org.apache.hyracks.api.dataflow.value.IMissingWriterFactory;
+import org.apache.hyracks.api.dataflow.value.IRecordDescriptorProvider;
+import org.apache.hyracks.api.dataflow.value.RecordDescriptor;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.api.job.IOperatorDescriptorRegistry;
+import org.apache.hyracks.storage.am.common.api.IModificationOperationCallbackFactory;
+import org.apache.hyracks.storage.am.common.api.ISearchOperationCallbackFactory;
+import org.apache.hyracks.storage.am.common.dataflow.IIndexDataflowHelperFactory;
+import org.apache.hyracks.storage.am.lsm.common.api.IFrameOperationCallbackFactory;
+
+public class BADLSMPrimaryUpsertOperatorDescriptor extends LSMPrimaryUpsertOperatorDescriptor {
+    public BADLSMPrimaryUpsertOperatorDescriptor(IOperatorDescriptorRegistry spec, RecordDescriptor outRecDesc,
+            int[] fieldPermutation, IIndexDataflowHelperFactory indexHelperFactory,
+            IMissingWriterFactory missingWriterFactory,
+            IModificationOperationCallbackFactory modificationOpCallbackFactory,
+            ISearchOperationCallbackFactory searchOpCallbackFactory,
+            IFrameOperationCallbackFactory frameOpCallbackFactory, int numPrimaryKeys, ARecordType recordType,
+            int filterIndex, boolean hasSecondaries) {
+        super(spec, outRecDesc, fieldPermutation, indexHelperFactory, missingWriterFactory,
+                modificationOpCallbackFactory, searchOpCallbackFactory, frameOpCallbackFactory, numPrimaryKeys,
+                recordType, filterIndex, hasSecondaries);
+    }
+
+    @Override
+    public IOperatorNodePushable createPushRuntime(IHyracksTaskContext ctx,
+            IRecordDescriptorProvider recordDescProvider, int partition, int nPartitions) throws HyracksDataException {
+        RecordDescriptor intputRecDesc = recordDescProvider.getInputRecordDescriptor(getActivityId(), 0);
+        return new BADLSMPrimaryUpsertOperatorNodePushable(ctx, partition, indexHelperFactory, fieldPermutation,
+                intputRecDesc, modCallbackFactory, searchOpCallbackFactory, numPrimaryKeys, recordType, filterIndex,
+                frameOpCallbackFactory, missingWriterFactory, hasSecondaries);
+    }
+}
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/feed/operators/BADLSMPrimaryUpsertOperatorNodePushable.java b/asterix-bad/src/main/java/org/apache/asterix/bad/feed/operators/BADLSMPrimaryUpsertOperatorNodePushable.java
new file mode 100644
index 0000000..b0c79d5
--- /dev/null
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/feed/operators/BADLSMPrimaryUpsertOperatorNodePushable.java
@@ -0,0 +1,58 @@
+/*
+ * 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.bad.feed.operators;
+
+import java.nio.ByteBuffer;
+
+import org.apache.asterix.om.types.ARecordType;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.runtime.operators.LSMPrimaryUpsertOperatorNodePushable;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.dataflow.value.IMissingWriterFactory;
+import org.apache.hyracks.api.dataflow.value.RecordDescriptor;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.dataflow.common.data.accessors.ITupleReference;
+import org.apache.hyracks.storage.am.common.api.IModificationOperationCallbackFactory;
+import org.apache.hyracks.storage.am.common.api.ISearchOperationCallbackFactory;
+import org.apache.hyracks.storage.am.common.dataflow.IIndexDataflowHelperFactory;
+import org.apache.hyracks.storage.am.lsm.common.api.IFrameOperationCallbackFactory;
+
+public class BADLSMPrimaryUpsertOperatorNodePushable extends LSMPrimaryUpsertOperatorNodePushable {
+    public BADLSMPrimaryUpsertOperatorNodePushable(IHyracksTaskContext ctx, int partition,
+            IIndexDataflowHelperFactory indexHelperFactory, int[] fieldPermutation, RecordDescriptor inputRecDesc,
+            IModificationOperationCallbackFactory modCallbackFactory,
+            ISearchOperationCallbackFactory searchCallbackFactory, int numOfPrimaryKeys, ARecordType recordType,
+            int filterFieldIndex, IFrameOperationCallbackFactory frameOpCallbackFactory,
+            IMissingWriterFactory missingWriterFactory, boolean hasSecondaries) throws HyracksDataException {
+        super(ctx, partition, indexHelperFactory, fieldPermutation, inputRecDesc, modCallbackFactory,
+                searchCallbackFactory, numOfPrimaryKeys, recordType, filterFieldIndex, frameOpCallbackFactory,
+                missingWriterFactory, hasSecondaries);
+    }
+
+    @Override
+    protected void beforeModification(ITupleReference tuple) {
+        if ((tuple.getFieldCount() == 3
+                && tuple.getFieldData(0)[tuple.getFieldStart(2)] == ATypeTag.SERIALIZED_RECORD_TYPE_TAG)
+                || (tuple.getFieldCount() == 4
+                        && tuple.getFieldData(0)[tuple.getFieldStart(2)] == ATypeTag.SERIALIZED_RECORD_TYPE_TAG)) {
+            int targetIdx = tuple.getFieldStart(2) + 14;
+            ByteBuffer tupleBuff = ByteBuffer.wrap(tuple.getFieldData(0));
+            tupleBuff.putLong(targetIdx, System.currentTimeMillis());
+        }
+    }
+}
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/function/BADFunctionCollection.java b/asterix-bad/src/main/java/org/apache/asterix/bad/function/BADFunctionCollection.java
new file mode 100644
index 0000000..15bb617
--- /dev/null
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/function/BADFunctionCollection.java
@@ -0,0 +1,37 @@
+/*
+ *
+ *  * 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.bad.function;
+
+import java.util.ArrayList;
+
+import org.apache.asterix.om.functions.IFunctionCollection;
+import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
+
+public class BADFunctionCollection implements IFunctionCollection {
+
+    private final ArrayList<IFunctionDescriptorFactory> descriptorFactories = new ArrayList<>();
+
+    @Override
+    public void add(IFunctionDescriptorFactory descriptorFactory) {
+
+    }
+}
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/function/BADFunctionRegistrant.java b/asterix-bad/src/main/java/org/apache/asterix/bad/function/BADFunctionRegistrant.java
new file mode 100644
index 0000000..15a5fc5
--- /dev/null
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/function/BADFunctionRegistrant.java
@@ -0,0 +1,34 @@
+/*
+ *
+ *  * 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.bad.function;
+
+import org.apache.asterix.bad.function.runtime.CurrentChannelTimeDescriptor;
+import org.apache.asterix.bad.function.runtime.PreviousChannelTimeDescriptor;
+import org.apache.asterix.om.functions.IFunctionCollection;
+import org.apache.asterix.om.functions.IFunctionRegistrant;
+
+public class BADFunctionRegistrant implements IFunctionRegistrant {
+    @Override
+    public void register(IFunctionCollection fc) {
+        fc.add(PreviousChannelTimeDescriptor.FACTORY);
+        fc.add(CurrentChannelTimeDescriptor.FACTORY);
+    }
+}
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/function/BADFunctions.java b/asterix-bad/src/main/java/org/apache/asterix/bad/function/BADFunctions.java
new file mode 100644
index 0000000..a342210
--- /dev/null
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/function/BADFunctions.java
@@ -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.
+ *
+ */
+
+package org.apache.asterix.bad.function;
+
+import org.apache.asterix.common.functions.FunctionConstants;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+
+public class BADFunctions {
+
+    public static final FunctionIdentifier IS_NEW = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "is-new", 1);
+
+    public static final FunctionIdentifier PREVIOUS_CHANNEL_TIME =
+            new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "previous-channel-time", 1);
+
+    public static final FunctionIdentifier CURRENT_CHANNEL_TIME =
+            new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "current-channel-time", 1);
+
+    public static final FunctionIdentifier ACTIVE_TIMESTAMP =
+            new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "active-timestamp", 1);
+
+}
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/function/rewriter/BADFeedRewriter.java b/asterix-bad/src/main/java/org/apache/asterix/bad/function/rewriter/BADFeedRewriter.java
new file mode 100644
index 0000000..7e25a23
--- /dev/null
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/function/rewriter/BADFeedRewriter.java
@@ -0,0 +1,184 @@
+/*
+ * 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.bad.function.rewriter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.asterix.common.exceptions.CompilationException;
+import org.apache.asterix.common.exceptions.ErrorCode;
+import org.apache.asterix.common.metadata.DataverseName;
+import org.apache.asterix.external.feed.watch.FeedActivityDetails;
+import org.apache.asterix.external.util.ExternalDataUtils;
+import org.apache.asterix.external.util.FeedUtils.FeedRuntimeType;
+import org.apache.asterix.metadata.declared.DataSourceId;
+import org.apache.asterix.metadata.declared.FeedDataSource;
+import org.apache.asterix.metadata.declared.MetadataProvider;
+import org.apache.asterix.metadata.entities.Dataset;
+import org.apache.asterix.metadata.entities.Feed;
+import org.apache.asterix.metadata.entities.FeedConnection;
+import org.apache.asterix.metadata.entities.FeedPolicyEntity;
+import org.apache.asterix.metadata.entities.InternalDatasetDetails;
+import org.apache.asterix.metadata.feeds.BuiltinFeedPolicies;
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.asterix.om.functions.IFunctionToDataSourceRewriter;
+import org.apache.asterix.om.typecomputer.base.IResultTypeComputer;
+import org.apache.asterix.om.types.ARecordType;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.om.types.IAType;
+import org.apache.asterix.om.utils.ConstantExpressionUtil;
+import org.apache.asterix.optimizer.rules.UnnestToDataScanRule;
+import org.apache.asterix.translator.util.PlanTranslationUtil;
+import org.apache.commons.lang3.mutable.Mutable;
+import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
+import org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator;
+import org.apache.hyracks.algebricks.core.algebra.base.IOptimizationContext;
+import org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable;
+import org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression;
+import org.apache.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment;
+import org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression;
+import org.apache.hyracks.algebricks.core.algebra.metadata.IMetadataProvider;
+import org.apache.hyracks.algebricks.core.algebra.operators.logical.DataSourceScanOperator;
+import org.apache.hyracks.algebricks.core.algebra.operators.logical.UnnestOperator;
+
+public class BADFeedRewriter implements IFunctionToDataSourceRewriter, IResultTypeComputer {
+    public static final BADFeedRewriter INSTANCE = new BADFeedRewriter();
+
+    private BADFeedRewriter() {
+    }
+
+    @Override
+    public boolean rewrite(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
+        AbstractFunctionCallExpression f = UnnestToDataScanRule.getFunctionCall(opRef);
+        UnnestOperator unnest = (UnnestOperator) opRef.getValue();
+        if (unnest.getPositionalVariable() != null) {
+            throw new CompilationException(ErrorCode.COMPILATION_ERROR, unnest.getSourceLocation(),
+                    "No positional variables are allowed over feeds.");
+        }
+        DataverseName dataverseName =
+                DataverseName.createFromCanonicalForm(ConstantExpressionUtil.getStringArgument(f, 0));
+        String sourceFeedName = ConstantExpressionUtil.getStringArgument(f, 1);
+        String getTargetFeed = ConstantExpressionUtil.getStringArgument(f, 2);
+        String subscriptionLocation = ConstantExpressionUtil.getStringArgument(f, 3);
+        String targetDataset = ConstantExpressionUtil.getStringArgument(f, 4);
+        String outputType = ConstantExpressionUtil.getStringArgument(f, 5);
+        MetadataProvider metadataProvider = (MetadataProvider) context.getMetadataProvider();
+        DataSourceId asid = new DataSourceId(dataverseName, getTargetFeed);
+        String policyName = (String) metadataProvider.getConfig().get(FeedActivityDetails.FEED_POLICY_NAME);
+        FeedPolicyEntity policy = metadataProvider.findFeedPolicy(dataverseName, policyName);
+        if (policy == null) {
+            policy = BuiltinFeedPolicies.getFeedPolicy(policyName);
+            if (policy == null) {
+                throw new CompilationException(ErrorCode.COMPILATION_ERROR, unnest.getSourceLocation(),
+                        "Unknown feed policy:" + policyName);
+            }
+        }
+        ArrayList<LogicalVariable> feedDataScanOutputVariables = new ArrayList<>();
+        String csLocations = (String) metadataProvider.getConfig().get(FeedActivityDetails.COLLECT_LOCATIONS);
+        List<LogicalVariable> pkVars = new ArrayList<>();
+        FeedDataSource ds = createFeedDataSource(asid, targetDataset, sourceFeedName, subscriptionLocation,
+                metadataProvider, policy, outputType, csLocations, unnest.getVariable(), context, pkVars);
+        // The order for feeds is <Record-Meta-PK>
+        feedDataScanOutputVariables.add(unnest.getVariable());
+        // Does it produce meta?
+        if (ds.hasMeta()) {
+            feedDataScanOutputVariables.add(context.newVar());
+        }
+        // Does it produce pk?
+        if (ds.isChange()) {
+            feedDataScanOutputVariables.addAll(pkVars);
+        }
+        DataSourceScanOperator scan = new DataSourceScanOperator(feedDataScanOutputVariables, ds);
+        scan.setSourceLocation(unnest.getSourceLocation());
+        List<Mutable<ILogicalOperator>> scanInpList = scan.getInputs();
+        scanInpList.addAll(unnest.getInputs());
+        opRef.setValue(scan);
+        context.computeAndSetTypeEnvironmentForOperator(scan);
+        return true;
+    }
+
+    private FeedDataSource createFeedDataSource(DataSourceId id, String targetDataset, String sourceFeedName,
+            String subscriptionLocation, MetadataProvider metadataProvider, FeedPolicyEntity feedPolicy,
+            String outputType, String locations, LogicalVariable recordVar, IOptimizationContext context,
+            List<LogicalVariable> pkVars) throws AlgebricksException {
+        Dataset dataset = metadataProvider.findDataset(id.getDataverseName(), targetDataset);
+        ARecordType feedOutputType = (ARecordType) metadataProvider.findType(id.getDataverseName(), outputType);
+        Feed sourceFeed = metadataProvider.findFeed(id.getDataverseName(), sourceFeedName);
+        FeedConnection feedConnection =
+                metadataProvider.findFeedConnection(id.getDataverseName(), sourceFeedName, targetDataset);
+        // Is a change feed?
+        List<IAType> pkTypes = null;
+        List<List<String>> partitioningKeys = null;
+        List<Integer> keySourceIndicator = null;
+
+        List<ScalarFunctionCallExpression> keyAccessScalarFunctionCallExpression;
+        if (ExternalDataUtils.isChangeFeed(sourceFeed.getConfiguration())) {
+            List<Mutable<ILogicalExpression>> keyAccessExpression = new ArrayList<>();
+            keyAccessScalarFunctionCallExpression = new ArrayList<>();
+            pkTypes = ((InternalDatasetDetails) dataset.getDatasetDetails()).getPrimaryKeyType();
+            partitioningKeys = ((InternalDatasetDetails) dataset.getDatasetDetails()).getPartitioningKey();
+            if (dataset.hasMetaPart()) {
+                keySourceIndicator = ((InternalDatasetDetails) dataset.getDatasetDetails()).getKeySourceIndicator();
+            }
+            for (int i = 0; i < partitioningKeys.size(); i++) {
+                List<String> key = partitioningKeys.get(i);
+                if (keySourceIndicator == null || keySourceIndicator.get(i).intValue() == 0) {
+                    PlanTranslationUtil.prepareVarAndExpression(key, recordVar, pkVars, keyAccessExpression, null,
+                            context, null);
+                } else {
+                    PlanTranslationUtil.prepareMetaKeyAccessExpression(key, recordVar, keyAccessExpression, pkVars,
+                            null, context, null);
+                }
+            }
+            keyAccessExpression.forEach(
+                    expr -> keyAccessScalarFunctionCallExpression.add((ScalarFunctionCallExpression) expr.getValue()));
+        } else {
+            keyAccessScalarFunctionCallExpression = null;
+        }
+        FeedDataSource feedDataSource = new FeedDataSource(sourceFeed, id, targetDataset, feedOutputType, null, pkTypes,
+                keyAccessScalarFunctionCallExpression, sourceFeed.getFeedId(),
+                FeedRuntimeType.valueOf(subscriptionLocation), locations.split(","), context.getComputationNodeDomain(),
+                feedConnection);
+        feedDataSource.getProperties().put(BuiltinFeedPolicies.CONFIG_FEED_POLICY_KEY, feedPolicy);
+        return feedDataSource;
+    }
+
+    @Override
+    public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env, IMetadataProvider<?, ?> mp)
+            throws AlgebricksException {
+        AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) expression;
+        if (f.getArguments().size() != BuiltinFunctions.FEED_COLLECT.getArity()) {
+            throw new AlgebricksException("Incorrect number of arguments -> arity is "
+                    + BuiltinFunctions.FEED_COLLECT.getArity() + ", not " + f.getArguments().size());
+        }
+        DataverseName dataverseName =
+                DataverseName.createFromCanonicalForm(ConstantExpressionUtil.getStringArgument(f, 0));
+        String outputTypeName = ConstantExpressionUtil.getStringArgument(f, 5);
+        if (outputTypeName == null) {
+            return BuiltinType.ANY;
+        }
+        MetadataProvider metadata = (MetadataProvider) mp;
+        IAType outputType = metadata.findType(dataverseName, outputTypeName);
+        if (outputType == null) {
+            throw new AlgebricksException("Unknown type " + outputTypeName);
+        }
+        return outputType;
+    }
+}
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/function/runtime/CurrentChannelTimeDescriptor.java b/asterix-bad/src/main/java/org/apache/asterix/bad/function/runtime/CurrentChannelTimeDescriptor.java
new file mode 100644
index 0000000..f3392ad
--- /dev/null
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/function/runtime/CurrentChannelTimeDescriptor.java
@@ -0,0 +1,116 @@
+/*
+ *
+ *  * 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.bad.function.runtime;
+
+import java.io.DataOutput;
+
+import org.apache.asterix.bad.function.BADFunctions;
+import org.apache.asterix.bad.runtime.ActiveTimestampManager;
+import org.apache.asterix.bad.runtime.ActiveTimestampState;
+import org.apache.asterix.formats.nontagged.SerializerDeserializerProvider;
+import org.apache.asterix.om.base.ADateTime;
+import org.apache.asterix.om.base.AMutableDateTime;
+import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IEvaluatorContext;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksJobletContext;
+import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.data.std.api.IPointable;
+import org.apache.hyracks.data.std.primitive.VoidPointable;
+import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
+import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+public class CurrentChannelTimeDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+
+    private static final long serialVersionUID = 1L;
+    private final static FunctionIdentifier FID = BADFunctions.CURRENT_CHANNEL_TIME;
+    private final static long ActiveStateKey = 1024;
+
+    public final static IFunctionDescriptorFactory FACTORY = CurrentChannelTimeDescriptor::new;
+
+    private CurrentChannelTimeDescriptor() {
+    }
+
+    @Override
+    public IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) {
+        return new IScalarEvaluatorFactory() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public IScalarEvaluator createScalarEvaluator(final IEvaluatorContext ctx) throws HyracksDataException {
+                return new IScalarEvaluator() {
+
+                    private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+                    private DataOutput out = resultStorage.getDataOutput();
+
+                    private final IPointable argPtr0 = new VoidPointable();
+                    private final IScalarEvaluator eval0 = args[0].createScalarEvaluator(ctx);
+
+                    @SuppressWarnings("unchecked")
+                    private ISerializerDeserializer<ADateTime> datetimeSerde =
+                            SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADATETIME);
+                    private AMutableDateTime aDateTime = new AMutableDateTime(0);
+                    private IHyracksJobletContext jobletCtx = ctx.getTaskContext().getJobletContext();
+
+                    @Override
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
+                        ActiveTimestampState existingState =
+                                (ActiveTimestampState) ctx.getTaskContext().getStateObject(ActiveStateKey);
+                        resultStorage.reset();
+
+                        if (existingState == null) {
+                            eval0.evaluate(tuple, argPtr0);
+                            String channelName = new String(argPtr0.getByteArray(), argPtr0.getStartOffset() + 2,
+                                    argPtr0.getLength() - 2);
+                            ActiveTimestampManager.progressChannelExecutionTimestamps(jobletCtx.getJobId(), channelName,
+                                    jobletCtx.getServiceContext().getNodeId());
+                            String nodeId = jobletCtx.getServiceContext().getNodeId();
+                            long previousChannelTime =
+                                    ActiveTimestampManager.getPreviousChannelExecutionTimestamp(channelName, nodeId);
+                            long currentChannelTime =
+                                    ActiveTimestampManager.getCurrentChannelExecutionTimestamp(channelName, nodeId);
+                            existingState = new ActiveTimestampState(jobletCtx.getJobId(), ActiveStateKey);
+                            existingState.setExecutionTime(previousChannelTime, currentChannelTime);
+                            ctx.getTaskContext().setStateObject(existingState);
+                        }
+                        aDateTime.setValue(existingState.getCurrentChannelExecutionTime());
+                        datetimeSerde.serialize(aDateTime, out);
+                        result.set(resultStorage);
+                    }
+                };
+            }
+        };
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.asterix.om.functions.IFunctionDescriptor#getIdentifier()
+     */
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return FID;
+    }
+
+}
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/function/runtime/PreviousChannelTimeDescriptor.java b/asterix-bad/src/main/java/org/apache/asterix/bad/function/runtime/PreviousChannelTimeDescriptor.java
new file mode 100644
index 0000000..f4dd1f5
--- /dev/null
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/function/runtime/PreviousChannelTimeDescriptor.java
@@ -0,0 +1,118 @@
+/*
+ *
+ *  * 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.bad.function.runtime;
+
+import java.io.DataOutput;
+
+import org.apache.asterix.bad.function.BADFunctions;
+import org.apache.asterix.bad.runtime.ActiveTimestampManager;
+import org.apache.asterix.bad.runtime.ActiveTimestampState;
+import org.apache.asterix.formats.nontagged.SerializerDeserializerProvider;
+import org.apache.asterix.om.base.ADateTime;
+import org.apache.asterix.om.base.AMutableDateTime;
+import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.IEvaluatorContext;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksJobletContext;
+import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.data.std.api.IPointable;
+import org.apache.hyracks.data.std.primitive.VoidPointable;
+import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
+import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+public class PreviousChannelTimeDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+
+    private static final long serialVersionUID = 1L;
+    private final static FunctionIdentifier FID = BADFunctions.PREVIOUS_CHANNEL_TIME;
+    private final static long ActiveStateKey = 1024;
+
+    public final static IFunctionDescriptorFactory FACTORY = PreviousChannelTimeDescriptor::new;
+
+    private PreviousChannelTimeDescriptor() {
+    }
+
+    @Override
+    public IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) {
+        return new IScalarEvaluatorFactory() {
+
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public IScalarEvaluator createScalarEvaluator(IEvaluatorContext ctx) throws HyracksDataException {
+                return new IScalarEvaluator() {
+
+                    private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+                    private DataOutput out = resultStorage.getDataOutput();
+                    private final IPointable argPtr0 = new VoidPointable();
+                    private final IScalarEvaluator eval0 = args[0].createScalarEvaluator(ctx);
+
+                    @SuppressWarnings("unchecked")
+                    private ISerializerDeserializer<ADateTime> datetimeSerde =
+                            SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADATETIME);
+                    private AMutableDateTime aDateTime = new AMutableDateTime(0);
+                    private IHyracksJobletContext jobletCtx = ctx.getTaskContext().getJobletContext();
+
+                    @Override
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
+
+                        ActiveTimestampState existingState =
+                                (ActiveTimestampState) ctx.getTaskContext().getStateObject(ActiveStateKey);
+                        resultStorage.reset();
+
+                        if (existingState == null) {
+                            eval0.evaluate(tuple, argPtr0);
+                            // offset the type
+                            String channelName = new String(argPtr0.getByteArray(), argPtr0.getStartOffset() + 2,
+                                    argPtr0.getLength() - 2);
+                            String nodeId = jobletCtx.getServiceContext().getNodeId();
+                            ActiveTimestampManager.progressChannelExecutionTimestamps(jobletCtx.getJobId(), channelName,
+                                    nodeId);
+                            long previousChannelTime =
+                                    ActiveTimestampManager.getPreviousChannelExecutionTimestamp(channelName, nodeId);
+                            long currentChannelTime =
+                                    ActiveTimestampManager.getCurrentChannelExecutionTimestamp(channelName, nodeId);
+                            existingState = new ActiveTimestampState(jobletCtx.getJobId(), ActiveStateKey);
+                            existingState.setExecutionTime(previousChannelTime, currentChannelTime);
+                            ctx.getTaskContext().setStateObject(existingState);
+                        }
+                        aDateTime.setValue(existingState.getPreviousChannelExecutionTime());
+                        datetimeSerde.serialize(aDateTime, out);
+                        result.set(resultStorage);
+                    }
+                };
+            }
+        };
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.asterix.om.functions.IFunctionDescriptor#getIdentifier()
+     */
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return FID;
+    }
+
+}
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADCompilationProvider.java b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADCompilationProvider.java
index 99f0d66..31a185a 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADCompilationProvider.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADCompilationProvider.java
@@ -18,6 +18,7 @@
  */
 package org.apache.asterix.bad.lang;
 
+import org.apache.asterix.algebra.base.ILangExpressionToPlanTranslatorFactory;
 import org.apache.asterix.compiler.provider.IRuleSetFactory;
 import org.apache.asterix.compiler.provider.SqlppCompilationProvider;
 import org.apache.asterix.lang.common.base.IParserFactory;
@@ -34,4 +35,8 @@
         return new BADRuleSetFactory();
     }
 
+    @Override
+    public ILangExpressionToPlanTranslatorFactory getExpressionToPlanTranslatorFactory() {
+        return new BADExpressionToPlanTranslatorFactory();
+    }
 }
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADExpressionToPlanTranslator.java b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADExpressionToPlanTranslator.java
new file mode 100644
index 0000000..23d10c5
--- /dev/null
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADExpressionToPlanTranslator.java
@@ -0,0 +1,220 @@
+/*
+ * 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.bad.lang;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.asterix.algebra.operators.CommitOperator;
+import org.apache.asterix.lang.common.base.Expression;
+import org.apache.asterix.lang.common.struct.VarIdentifier;
+import org.apache.asterix.metadata.declared.DatasetDataSource;
+import org.apache.asterix.metadata.declared.MetadataProvider;
+import org.apache.asterix.om.base.ADateTime;
+import org.apache.asterix.om.base.ARecord;
+import org.apache.asterix.om.base.IAObject;
+import org.apache.asterix.om.constants.AsterixConstantValue;
+import org.apache.asterix.om.types.ARecordType;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.om.types.IAType;
+import org.apache.asterix.translator.CompiledStatements;
+import org.apache.asterix.translator.SqlppExpressionToPlanTranslator;
+import org.apache.commons.lang3.mutable.Mutable;
+import org.apache.commons.lang3.mutable.MutableObject;
+import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
+import org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator;
+import org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable;
+import org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression;
+import org.apache.hyracks.algebricks.core.algebra.expressions.IAlgebricksConstantValue;
+import org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression;
+import org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator;
+import org.apache.hyracks.algebricks.core.algebra.operators.logical.DelegateOperator;
+import org.apache.hyracks.algebricks.core.algebra.operators.logical.InsertDeleteUpsertOperator;
+import org.apache.hyracks.api.exceptions.SourceLocation;
+import org.apache.hyracks.api.result.IResultMetadata;
+
+/**
+ * This class overrides the SqlppExpressionToPlanTranslator in AsterixDB to allow insert/upsert to
+ * datasets with meta records (active datasets). If inserting/upserting into an active dataset, the plan
+ * translator would attach a dummy active records containing the current timestamp as the active timestamp.
+ * In the case of data feeds, this active timestamp would then be updated by
+ * BADLSMPrimaryInsertOperatorNodePushable/BADLSMPrimaryUpsertOperatorNodePushable.
+ * Updates to SqlppExpressionToPlanTranslator in the AsterixDB master needs to be propagated into this class when
+ * bringing the BAD codebase to latest master.
+ *
+ * IMPORTANT NOTE: Currently, we assume active datasets are the only user of the datasets with meta records.
+ * If one want to use meta datasets in the BAD branch in the future, this needs to be refactored.
+ */
+public class BADExpressionToPlanTranslator extends SqlppExpressionToPlanTranslator {
+
+    public BADExpressionToPlanTranslator(MetadataProvider metadataProvider, int currentVarCounter,
+            Map<VarIdentifier, IAObject> externalVars) throws AlgebricksException {
+        super(metadataProvider, currentVarCounter, externalVars);
+    }
+
+    @Override
+    protected ILogicalOperator translateDelete(DatasetDataSource targetDatasource, Mutable<ILogicalExpression> varRef,
+            List<Mutable<ILogicalExpression>> varRefsForLoading,
+            List<Mutable<ILogicalExpression>> additionalFilteringExpressions, ILogicalOperator inputOp,
+            CompiledStatements.ICompiledDmlStatement stmt) throws AlgebricksException {
+        SourceLocation sourceLoc = stmt.getSourceLocation();
+        InsertDeleteUpsertOperator deleteOp;
+        if (!targetDatasource.getDataset().hasMetaPart()) {
+            deleteOp = new InsertDeleteUpsertOperator(targetDatasource, varRef, varRefsForLoading,
+                    InsertDeleteUpsertOperator.Kind.DELETE, false);
+        } else {
+            // prepare meta record
+            IAType metaType = metadataProvider.findMetaType(targetDatasource.getDataset());
+            LogicalVariable metaVar = context.newVar();
+            AssignOperator metaVariableAssignOp =
+                    new AssignOperator(metaVar, new MutableObject<>(makeMetaRecordExpr(metaType)));
+            metaVariableAssignOp.getInputs().add(new MutableObject<>(inputOp));
+            metaVariableAssignOp.setSourceLocation(sourceLoc);
+            // create insert op uses meta record
+            deleteOp = new InsertDeleteUpsertOperator(targetDatasource, varRef, varRefsForLoading,
+                    Collections.singletonList(new MutableObject<>(new VariableReferenceExpression(metaVar))),
+                    InsertDeleteUpsertOperator.Kind.DELETE, false);
+            // change current inputOp to be meta op
+            inputOp = metaVariableAssignOp;
+        }
+        deleteOp.setAdditionalFilteringExpressions(additionalFilteringExpressions);
+        deleteOp.getInputs().add(new MutableObject<>(inputOp));
+        deleteOp.setSourceLocation(sourceLoc);
+        DelegateOperator leafOperator = new DelegateOperator(new CommitOperator(true));
+        leafOperator.getInputs().add(new MutableObject<>(deleteOp));
+        leafOperator.setSourceLocation(sourceLoc);
+        return leafOperator;
+    }
+
+    @Override
+    protected ILogicalOperator translateUpsert(DatasetDataSource targetDatasource, Mutable<ILogicalExpression> varRef,
+            List<Mutable<ILogicalExpression>> varRefsForLoading, List<Mutable<ILogicalExpression>> filterExprs,
+            ILogicalOperator pkeyAssignOp, List<String> additionalFilteringField, LogicalVariable unnestVar,
+            ILogicalOperator topOp, List<Mutable<ILogicalExpression>> exprs, LogicalVariable resVar,
+            AssignOperator additionalFilteringAssign, CompiledStatements.ICompiledDmlStatement stmt,
+            IResultMetadata resultMetadata) throws AlgebricksException {
+        SourceLocation sourceLoc = stmt.getSourceLocation();
+        CompiledStatements.CompiledUpsertStatement compiledUpsert = (CompiledStatements.CompiledUpsertStatement) stmt;
+        Expression returnExpression = compiledUpsert.getReturnExpression();
+        InsertDeleteUpsertOperator upsertOp;
+        ILogicalOperator rootOperator;
+
+        ARecordType recordType = (ARecordType) targetDatasource.getItemType();
+
+        if (targetDatasource.getDataset().hasMetaPart()) {
+            IAType metaType = metadataProvider.findMetaType(targetDatasource.getDataset());
+            LogicalVariable metaVar = context.newVar();
+            AssignOperator metaVariableAssignOp =
+                    new AssignOperator(metaVar, new MutableObject<>(makeMetaRecordExpr(metaType)));
+            metaVariableAssignOp.getInputs().add(new MutableObject<>(pkeyAssignOp));
+            pkeyAssignOp = metaVariableAssignOp;
+
+            metaVariableAssignOp.setSourceLocation(sourceLoc);
+            List<Mutable<ILogicalExpression>> metaExprs = new ArrayList<>(1);
+            VariableReferenceExpression metaVarRef = new VariableReferenceExpression(metaVar);
+            metaExprs.add(new MutableObject<>(metaVarRef));
+            upsertOp = new InsertDeleteUpsertOperator(targetDatasource, varRef, varRefsForLoading, metaExprs,
+                    InsertDeleteUpsertOperator.Kind.UPSERT, false);
+
+            // set previous meta vars
+            List<LogicalVariable> metaVars = new ArrayList<>();
+            metaVars.add(context.newVar());
+            upsertOp.setPrevAdditionalNonFilteringVars(metaVars);
+            List<Object> metaTypes = new ArrayList<>();
+            metaTypes.add(targetDatasource.getMetaItemType());
+            upsertOp.setPrevAdditionalNonFilteringTypes(metaTypes);
+        } else {
+            upsertOp = new InsertDeleteUpsertOperator(targetDatasource, varRef, varRefsForLoading,
+                    InsertDeleteUpsertOperator.Kind.UPSERT, false);
+            // Create and add a new variable used for representing the original record
+            if (additionalFilteringField != null) {
+                upsertOp.setPrevFilterVar(context.newVar());
+                upsertOp.setPrevFilterType(recordType.getFieldType(additionalFilteringField.get(0)));
+            }
+        }
+        // Create and add a new variable used for representing the original record
+        upsertOp.setUpsertIndicatorVar(context.newVar());
+        upsertOp.setUpsertIndicatorVarType(BuiltinType.ABOOLEAN);
+        upsertOp.setPrevRecordVar(context.newVar());
+        upsertOp.setPrevRecordType(recordType);
+        upsertOp.setSourceLocation(sourceLoc);
+        upsertOp.setAdditionalFilteringExpressions(filterExprs);
+        upsertOp.getInputs().add(new MutableObject<>(pkeyAssignOp));
+
+        // Set up delegate operator
+        DelegateOperator delegateOperator = new DelegateOperator(new CommitOperator(returnExpression == null));
+        delegateOperator.getInputs().add(new MutableObject<>(upsertOp));
+        delegateOperator.setSourceLocation(sourceLoc);
+        rootOperator = delegateOperator;
+
+        // Compiles the return expression.
+        return processReturningExpression(rootOperator, upsertOp, compiledUpsert, resultMetadata);
+    }
+
+    @Override
+    protected ILogicalOperator translateInsert(DatasetDataSource targetDatasource, Mutable<ILogicalExpression> varRef,
+            List<Mutable<ILogicalExpression>> varRefsForLoading, List<Mutable<ILogicalExpression>> filterExprs,
+            ILogicalOperator inputOp, CompiledStatements.ICompiledDmlStatement stmt, IResultMetadata resultMetadata)
+            throws AlgebricksException {
+        SourceLocation sourceLoc = stmt.getSourceLocation();
+
+        InsertDeleteUpsertOperator insertOp;
+        if (!targetDatasource.getDataset().hasMetaPart()) {
+            insertOp = new InsertDeleteUpsertOperator(targetDatasource, varRef, varRefsForLoading,
+                    InsertDeleteUpsertOperator.Kind.INSERT, false);
+        } else {
+            // prepare meta record
+            IAType metaType = metadataProvider.findMetaType(targetDatasource.getDataset());
+            LogicalVariable metaVar = context.newVar();
+            AssignOperator metaVariableAssignOp =
+                    new AssignOperator(metaVar, new MutableObject<>(makeMetaRecordExpr(metaType)));
+            metaVariableAssignOp.getInputs().add(new MutableObject<>(inputOp));
+            metaVariableAssignOp.setSourceLocation(sourceLoc);
+            // create insert op uses meta record
+            insertOp = new InsertDeleteUpsertOperator(targetDatasource, varRef, varRefsForLoading,
+                    Collections.singletonList(new MutableObject<>(new VariableReferenceExpression(metaVar))),
+                    InsertDeleteUpsertOperator.Kind.INSERT, false);
+            // change current inputOp to be meta op
+            inputOp = metaVariableAssignOp;
+        }
+        insertOp.setAdditionalFilteringExpressions(filterExprs);
+        insertOp.getInputs().add(new MutableObject<>(inputOp));
+        insertOp.setSourceLocation(sourceLoc);
+
+        // Adds the commit operator.
+        CompiledStatements.CompiledInsertStatement compiledInsert = (CompiledStatements.CompiledInsertStatement) stmt;
+        Expression returnExpression = compiledInsert.getReturnExpression();
+        DelegateOperator rootOperator = new DelegateOperator(new CommitOperator(returnExpression == null));
+        rootOperator.getInputs().add(new MutableObject<>(insertOp));
+        rootOperator.setSourceLocation(sourceLoc);
+
+        // Compiles the return expression.
+        return processReturningExpression(rootOperator, insertOp, compiledInsert, resultMetadata);
+    }
+
+    private ILogicalExpression makeMetaRecordExpr(IAType metaRecordType) {
+        ARecord metaRecord =
+                new ARecord((ARecordType) metaRecordType, new IAObject[] { new ADateTime(System.currentTimeMillis()) });
+        IAlgebricksConstantValue metaConstantVal = new AsterixConstantValue(metaRecord);
+        ILogicalExpression expr = new ConstantExpression(metaConstantVal);
+        return expr;
+    }
+}
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADExpressionToPlanTranslatorFactory.java b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADExpressionToPlanTranslatorFactory.java
new file mode 100644
index 0000000..68a50ee
--- /dev/null
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADExpressionToPlanTranslatorFactory.java
@@ -0,0 +1,35 @@
+/*
+ * 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.bad.lang;
+
+import java.util.Map;
+
+import org.apache.asterix.algebra.base.ILangExpressionToPlanTranslator;
+import org.apache.asterix.algebra.base.ILangExpressionToPlanTranslatorFactory;
+import org.apache.asterix.lang.common.struct.VarIdentifier;
+import org.apache.asterix.metadata.declared.MetadataProvider;
+import org.apache.asterix.om.base.IAObject;
+import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+
+public class BADExpressionToPlanTranslatorFactory implements ILangExpressionToPlanTranslatorFactory {
+    @Override
+    public ILangExpressionToPlanTranslator createExpressionToPlanTranslator(MetadataProvider metadataProvider,
+            int currentVarCounter, Map<VarIdentifier, IAObject> externalVars) throws AlgebricksException {
+        return new BADExpressionToPlanTranslator(metadataProvider, currentVarCounter, externalVars);
+    }
+}
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADLangUtils.java b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADLangUtils.java
new file mode 100644
index 0000000..a8301a1
--- /dev/null
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADLangUtils.java
@@ -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.
+ */
+
+package org.apache.asterix.bad.lang;
+
+import java.net.URI;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.client.methods.RequestBuilder;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+
+public class BADLangUtils {
+
+    private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger.getLogger(BADLangUtils.class);
+
+    public static int executeStatement(String host, String stmt) throws Exception {
+        URI badURI = URI.create("http://" + host + ":19002/query/service");
+        RequestBuilder requestBuilder = RequestBuilder.post(badURI);
+        requestBuilder.addParameter("statement", stmt);
+        try {
+            HttpResponse response = submitRequest(requestBuilder.build());
+            if (response.getStatusLine().getStatusCode() != 200) {
+                throw new AlgebricksException("Connecting to " + host + " failed");
+            }
+            return response.getStatusLine().getStatusCode();
+        } catch (Exception e) {
+            LOGGER.error("Statement Failed at " + host);
+            throw e;
+        }
+    }
+
+    private static HttpResponse submitRequest(HttpUriRequest request) throws Exception {
+        ExecutorService executor = Executors.newSingleThreadExecutor();
+        CloseableHttpClient client = HttpClients.createDefault();
+        Future<HttpResponse> response = executor.submit(() -> {
+            try {
+                return client.execute(request);
+            } catch (Exception e) {
+                throw e;
+            }
+        });
+        try {
+            return response.get();
+        } catch (Exception e) {
+            client.close();
+            throw e;
+        } finally {
+            executor.shutdownNow();
+        }
+    }
+}
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADStatementExecutor.java b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADQueryTranslator.java
similarity index 70%
rename from asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADStatementExecutor.java
rename to asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADQueryTranslator.java
index 3cf2ce6..a0d33a1 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADStatementExecutor.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADQueryTranslator.java
@@ -20,14 +20,18 @@
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.ExecutorService;
 
 import org.apache.asterix.app.active.ActiveNotificationHandler;
 import org.apache.asterix.app.translator.QueryTranslator;
+import org.apache.asterix.bad.BADConstants;
 import org.apache.asterix.bad.BADJobService;
+import org.apache.asterix.bad.extension.BADLangExtension;
 import org.apache.asterix.bad.lang.statement.BrokerDropStatement;
 import org.apache.asterix.bad.lang.statement.ChannelDropStatement;
 import org.apache.asterix.bad.lang.statement.ProcedureDropStatement;
+import org.apache.asterix.bad.metadata.BADMetadataProvider;
 import org.apache.asterix.bad.metadata.Broker;
 import org.apache.asterix.bad.metadata.Channel;
 import org.apache.asterix.bad.metadata.DeployedJobSpecEventListener;
@@ -38,18 +42,24 @@
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.common.metadata.DataverseName;
 import org.apache.asterix.compiler.provider.ILangCompilationProvider;
+import org.apache.asterix.external.util.ExternalDataConstants;
 import org.apache.asterix.lang.common.base.Statement;
+import org.apache.asterix.lang.common.statement.CreateFeedStatement;
 import org.apache.asterix.lang.common.statement.CreateIndexStatement;
 import org.apache.asterix.lang.common.statement.DataverseDropStatement;
 import org.apache.asterix.lang.common.statement.DropDatasetStatement;
 import org.apache.asterix.lang.common.statement.FunctionDropStatement;
 import org.apache.asterix.lang.common.statement.IndexDropStatement;
+import org.apache.asterix.lang.common.statement.StartFeedStatement;
+import org.apache.asterix.lang.common.statement.StopFeedStatement;
 import org.apache.asterix.lang.common.struct.Identifier;
 import org.apache.asterix.metadata.MetadataManager;
 import org.apache.asterix.metadata.MetadataTransactionContext;
 import org.apache.asterix.metadata.declared.MetadataProvider;
 import org.apache.asterix.metadata.entities.Dataverse;
+import org.apache.asterix.metadata.entities.Feed;
 import org.apache.asterix.metadata.entities.Function;
+import org.apache.asterix.metadata.feeds.FeedMetadataUtil;
 import org.apache.asterix.translator.IRequestParameters;
 import org.apache.asterix.translator.SessionOutput;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
@@ -57,9 +67,9 @@
 import org.apache.hyracks.algebricks.common.utils.Triple;
 import org.apache.hyracks.api.client.IHyracksClientConnection;
 
-public class BADStatementExecutor extends QueryTranslator {
+public class BADQueryTranslator extends QueryTranslator {
 
-    public BADStatementExecutor(ICcApplicationContext appCtx, List<Statement> statements, SessionOutput output,
+    public BADQueryTranslator(ICcApplicationContext appCtx, List<Statement> statements, SessionOutput output,
             ILangCompilationProvider compliationProvider, ExecutorService executorService, IResponsePrinter printer) {
         super(appCtx, statements, output, compliationProvider, executorService, printer);
     }
@@ -80,7 +90,6 @@
                     if (!checkAll) {
                         return new Pair<>(channelsUsingDataset, proceduresUsingDataset);
                     }
-
                 }
             }
 
@@ -103,8 +112,7 @@
     }
 
     private Pair<List<Channel>, List<Procedure>> checkIfFunctionIsInUse(MetadataTransactionContext mdTxnCtx,
-            DataverseName dvId, String function, String arity, boolean checkAll)
-            throws CompilationException, AlgebricksException {
+            DataverseName dvId, String function, String arity, boolean checkAll) throws AlgebricksException {
         List<Channel> channelsUsingFunction = new ArrayList<>();
         List<Procedure> proceduresUsingFunction = new ArrayList<>();
 
@@ -142,7 +150,7 @@
     }
 
     private void throwErrorIfDatasetUsed(MetadataTransactionContext mdTxnCtx, DataverseName dataverse, String dataset)
-            throws CompilationException, AlgebricksException {
+            throws AlgebricksException {
         Pair<List<Channel>, List<Procedure>> dependents = checkIfDatasetIsInUse(mdTxnCtx, dataverse, dataset, false);
         if (dependents.first.size() > 0) {
             throw new CompilationException("Cannot alter dataset " + dataverse + "." + dataset + ". "
@@ -155,7 +163,7 @@
     }
 
     private void throwErrorIfFunctionUsed(MetadataTransactionContext mdTxnCtx, DataverseName dataverse, String function,
-            String arity, FunctionSignature sig) throws CompilationException, AlgebricksException {
+            String arity, FunctionSignature sig) throws AlgebricksException {
         Pair<List<Channel>, List<Procedure>> dependents =
                 checkIfFunctionIsInUse(mdTxnCtx, dataverse, function, arity, false);
         String errorStart = sig != null ? "Cannot drop function " + sig + "." : "Cannot drop index.";
@@ -170,6 +178,127 @@
     }
 
     @Override
+    protected void handleCreateFeedStatement(MetadataProvider metadataProvider, Statement stmt) throws Exception {
+        CreateFeedStatement cfs = (CreateFeedStatement) stmt;
+        Map<String, String> feedConfig = cfs.getConfiguration();
+        if (feedConfig.containsKey(BADConstants.BAD_FEED_FIELD_NAME_HOST)) {
+
+            // check parameters
+            if (!feedConfig.containsKey(BADConstants.BAD_FEED_FIELD_NAME_HOST)
+                    || !feedConfig.containsKey(BADConstants.BAD_FEED_FIELD_NAME_CHANNEL)
+                    || !feedConfig.containsKey(BADConstants.BAD_FEED_FIELD_NAME_PARAMETERS)
+                    || !feedConfig.containsKey(BADConstants.BAD_FEED_FIELD_NAME_CHANNEL_DV)) {
+                throw new AlgebricksException(
+                        "A BAD feed requires the host, dataverse name, channel name, and channel parameters of the other BAD system.");
+            }
+
+            // check format and http feed
+            if (!feedConfig.containsKey(ExternalDataConstants.KEY_ADAPTER_NAME)
+                    || !feedConfig.get(ExternalDataConstants.KEY_ADAPTER_NAME).toLowerCase().equals("http_adapter")) {
+                throw new AlgebricksException("A BAD feed needs a http adapter.");
+            }
+            if (!feedConfig.containsKey(ExternalDataConstants.KEY_FORMAT)
+                    || !feedConfig.get(ExternalDataConstants.KEY_FORMAT).toLowerCase().equals("adm")) {
+                throw new AlgebricksException("A BAD feed requires incoming data to be in ADM format.");
+            }
+            if (!feedConfig.containsKey(ExternalDataConstants.KEY_MODE)
+                    || !feedConfig.get(ExternalDataConstants.KEY_MODE).toLowerCase().equals("ip")) {
+                throw new AlgebricksException("A BAD feed requires an IP address.");
+            }
+        }
+        super.handleCreateFeedStatement(metadataProvider, stmt);
+    }
+
+    @Override
+    protected void handleStartFeedStatement(MetadataProvider metadataProvider, Statement stmt,
+            IHyracksClientConnection hcc) throws Exception {
+        StartFeedStatement sfs = (StartFeedStatement) stmt;
+        DataverseName dataverseName = getActiveDataverseName(sfs.getDataverseName());
+        String feedName = sfs.getFeedName().getValue();
+
+        // Retrieve Feed entity from Metadata
+        MetadataTransactionContext mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
+        metadataProvider.setMetadataTxnContext(mdTxnCtx);
+        Feed feed = FeedMetadataUtil.validateIfFeedExists(dataverseName, feedName,
+                metadataProvider.getMetadataTxnContext());
+        MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
+
+        // If it's a BAD feed
+        Map<String, String> feedConfig = feed.getConfiguration();
+        if (feedConfig.containsKey(BADConstants.BAD_FEED_FIELD_NAME_HOST)) {
+            String badHost = feedConfig.getOrDefault(BADConstants.BAD_FEED_FIELD_NAME_HOST, null);
+            String badChannelName = feedConfig.getOrDefault(BADConstants.BAD_FEED_FIELD_NAME_CHANNEL, null);
+            String badParameters = feedConfig.getOrDefault(BADConstants.BAD_FEED_FIELD_NAME_PARAMETERS, null);
+            String badDataverseName = feedConfig.getOrDefault(BADConstants.BAD_FEED_FIELD_NAME_CHANNEL_DV, null);
+
+            // construct statements
+            // add Broker to feed name as the broker name
+            try {
+                // create broker
+                String connStmtStr = String.format(
+                        "USE %s;\n"
+                                + "DROP BROKER %BROKER IF EXISTS; CREATE BROKER %sBroker AT \"http://%s\" with {\"broker-type\" : \"BAD\"};\n",
+                        badDataverseName, feed.getFeedName(), feed.getFeedName(),
+                        feed.getConfiguration().get("addresses"));
+                BADLangUtils.executeStatement(badHost, connStmtStr);
+
+                // create subs
+                String[] params = badParameters.split(";");
+                StringBuilder subStmtStr = new StringBuilder(String.format("USE %s;\n ", badDataverseName));
+                for (String param : params) {
+                    subStmtStr.append(String.format("SUBSCRIBE TO %s(%s) on %sBroker;", badChannelName, param,
+                            feed.getFeedName()));
+                }
+                BADLangUtils.executeStatement(badHost, subStmtStr.toString());
+            } catch (Exception e) {
+                // drop broker and all subs if anything goes wrong
+                String dropStmtStr = String.format(
+                        "USE %s;\n"
+                                + "DELETE FROM %sSubscriptions s WHERE s.BrokerName = \"%sBroker\"; DROP BROKER %sBroker",
+                        badDataverseName, badChannelName, feed.getFeedName(), feed.getFeedName());
+                BADLangUtils.executeStatement(badHost, dropStmtStr);
+                throw e;
+            }
+        }
+        MetadataProvider badMetadataProvider = BADMetadataProvider.create(metadataProvider.getApplicationContext(),
+                metadataProvider.getDefaultDataverse());
+        super.handleStartFeedStatement(badMetadataProvider, stmt, hcc);
+    }
+
+    @Override
+    protected void handleStopFeedStatement(MetadataProvider metadataProvider, Statement stmt) throws Exception {
+        StopFeedStatement sfst = (StopFeedStatement) stmt;
+        DataverseName dataverseName = getActiveDataverseName(sfst.getDataverseName());
+        String feedName = sfst.getFeedName().getValue();
+
+        // Retrieve Feed entity from Metadata
+        MetadataTransactionContext mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
+        metadataProvider.setMetadataTxnContext(mdTxnCtx);
+        Feed feed = FeedMetadataUtil.validateIfFeedExists(dataverseName, feedName,
+                metadataProvider.getMetadataTxnContext());
+        MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
+
+        Map<String, String> feedConfig = feed.getConfiguration();
+        if (feedConfig.containsKey(BADConstants.BAD_FEED_FIELD_NAME_HOST)) {
+            String badHost = feedConfig.getOrDefault(BADConstants.BAD_FEED_FIELD_NAME_HOST, null);
+            String badChannelName = feedConfig.getOrDefault(BADConstants.BAD_FEED_FIELD_NAME_CHANNEL, null);
+            String badDataverseName = feedConfig.getOrDefault(BADConstants.BAD_FEED_FIELD_NAME_CHANNEL_DV, null);
+
+            // construct statements
+            String dropStmtStr = String.format(
+                    "USE %s;\n"
+                            + "DELETE FROM %sSubscriptions s WHERE s.BrokerName = \"%sBroker\"; DROP BROKER %sBroker",
+                    badDataverseName, badChannelName, feed.getFeedName(), feed.getFeedName());
+
+            // make request
+            int responseCode = BADLangUtils.executeStatement(badHost, dropStmtStr);
+            if (responseCode != 200) {
+                throw new AlgebricksException("Connecting to " + badHost + " failed");
+            }
+        }
+    }
+
+    @Override
     public void handleDatasetDropStatement(MetadataProvider metadataProvider, Statement stmt,
             IHyracksClientConnection hcc, IRequestParameters requestParameters) throws Exception {
         MetadataTransactionContext mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADQueryTranslatorFactory.java b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADQueryTranslatorFactory.java
index ab5a96e..f7ca86b 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADQueryTranslatorFactory.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADQueryTranslatorFactory.java
@@ -35,6 +35,6 @@
     public QueryTranslator create(ICcApplicationContext appCtx, List<Statement> statements, SessionOutput output,
             ILangCompilationProvider compilationProvider, IStorageComponentProvider storageComponentProvider,
             IResponsePrinter printer) {
-        return new BADStatementExecutor(appCtx, statements, output, compilationProvider, executorService, printer);
+        return new BADQueryTranslator(appCtx, statements, output, compilationProvider, executorService, printer);
     }
 }
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADRuleSetFactory.java b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADRuleSetFactory.java
index 8d4b1e5..3c3ec59 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADRuleSetFactory.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/BADRuleSetFactory.java
@@ -22,57 +22,98 @@
 import java.util.List;
 
 import org.apache.asterix.bad.rules.InsertBrokerNotifierForChannelRule;
+import org.apache.asterix.bad.rules.RewriteChannelTimeFunctionToLocalVarRule;
 import org.apache.asterix.common.dataflow.ICcApplicationContext;
 import org.apache.asterix.compiler.provider.DefaultRuleSetFactory;
 import org.apache.asterix.compiler.provider.IRuleSetFactory;
 import org.apache.asterix.optimizer.base.RuleCollections;
+import org.apache.asterix.optimizer.rules.FeedScanCollectionToUnnest;
+import org.apache.asterix.optimizer.rules.MetaFunctionToMetaVariableRule;
 import org.apache.asterix.optimizer.rules.UnnestToDataScanRule;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.common.utils.Pair;
-import org.apache.hyracks.algebricks.compiler.rewriter.rulecontrollers.SequentialOnceRuleController;
+import org.apache.hyracks.algebricks.compiler.rewriter.rulecontrollers.SequentialFixpointRuleController;
 import org.apache.hyracks.algebricks.core.rewriter.base.AbstractRuleController;
 import org.apache.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
 
 public class BADRuleSetFactory implements IRuleSetFactory {
 
+    private boolean isSameRuleCollection(List<IAlgebraicRewriteRule> listA, List<IAlgebraicRewriteRule> listB) {
+        if (listA.size() != listB.size()) {
+            return false;
+        }
+        for (int i = 0; i < listA.size(); i++) {
+            if (!listA.get(i).getClass().equals(listB.get(i).getClass())) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    private void updateNormalizationRules(
+            List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>> logicalRuleSet,
+            ICcApplicationContext appCtx) {
+        // gen original normalization rules
+        List<IAlgebraicRewriteRule> originalNormalizationRules =
+                RuleCollections.buildNormalizationRuleCollection(appCtx);
+        // make a copy
+        List<IAlgebraicRewriteRule> alteredNormalizationRules = new ArrayList<>();
+        alteredNormalizationRules.addAll(originalNormalizationRules);
+
+        // insert the broker rule
+        for (int i = 0; i < alteredNormalizationRules.size(); i++) {
+            IAlgebraicRewriteRule rule = alteredNormalizationRules.get(i);
+            if (rule instanceof UnnestToDataScanRule) {
+                alteredNormalizationRules.add(i + 1, new InsertBrokerNotifierForChannelRule());
+            }
+        }
+
+        // replace all normalization rule collections with the new one
+        SequentialFixpointRuleController seqOnceCtrl = new SequentialFixpointRuleController(true);
+        for (int i = 0; i < logicalRuleSet.size(); i++) {
+            List<IAlgebraicRewriteRule> existingRuleCollection = logicalRuleSet.get(i).second;
+            if (isSameRuleCollection(existingRuleCollection, originalNormalizationRules)) {
+                logicalRuleSet.set(i, new Pair<>(seqOnceCtrl, alteredNormalizationRules));
+            }
+        }
+    }
+
+    private void addRewriteChannelTimeFunctionRule(
+            List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>> logicalRuleSet,
+            ICcApplicationContext appCtx) {
+        // gen original normalization rules
+        List<IAlgebraicRewriteRule> originalRuleCollection = RuleCollections.buildLoadFieldsRuleCollection(appCtx);
+        // make a copy
+        List<IAlgebraicRewriteRule> alteredRuleCollection = new ArrayList<>();
+        alteredRuleCollection.addAll(originalRuleCollection);
+        // insert the broker rule
+        for (int i = 0; i < alteredRuleCollection.size(); i++) {
+            IAlgebraicRewriteRule rule = alteredRuleCollection.get(i);
+            if (rule instanceof FeedScanCollectionToUnnest) {
+                alteredRuleCollection.add(i + 1, new MetaFunctionToMetaVariableRule());
+                alteredRuleCollection.add(i + 1, new RewriteChannelTimeFunctionToLocalVarRule());
+            }
+        }
+
+        // replace all normalization rule collections with the new one
+        SequentialFixpointRuleController seqCtrlNoDfs = new SequentialFixpointRuleController(true);
+        for (int i = 0; i < logicalRuleSet.size(); i++) {
+            List<IAlgebraicRewriteRule> existingRuleCollection = logicalRuleSet.get(i).second;
+            if (isSameRuleCollection(existingRuleCollection, originalRuleCollection)) {
+                logicalRuleSet.set(i, new Pair<>(seqCtrlNoDfs, alteredRuleCollection));
+            }
+        }
+    }
+
     @Override
     public List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>> getLogicalRewrites(
             ICcApplicationContext appCtx) throws AlgebricksException {
         List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>> logicalRuleSet =
                 DefaultRuleSetFactory.buildLogical(appCtx);
 
-        List<IAlgebraicRewriteRule> normalizationCollection = RuleCollections.buildNormalizationRuleCollection(appCtx);
-        List<IAlgebraicRewriteRule> alteredNormalizationCollection = new ArrayList<>();
-        alteredNormalizationCollection.addAll(normalizationCollection);
+        updateNormalizationRules(logicalRuleSet, appCtx);
+        addRewriteChannelTimeFunctionRule(logicalRuleSet, appCtx);
 
-        //Create a normalization collection that includes the broker rule
-        for (int i = 0; i < alteredNormalizationCollection.size(); i++) {
-            IAlgebraicRewriteRule rule = alteredNormalizationCollection.get(i);
-            if (rule instanceof UnnestToDataScanRule) {
-                alteredNormalizationCollection.add(i + 1, new InsertBrokerNotifierForChannelRule());
-                break;
-            }
-        }
-
-        //Find instances of the normalization collection and replace them with the new one
-        SequentialOnceRuleController seqOnceCtrl = new SequentialOnceRuleController(true);
-        for (int i = 0; i < logicalRuleSet.size(); i++) {
-            List<IAlgebraicRewriteRule> collection = logicalRuleSet.get(i).second;
-            if (collection.size() == normalizationCollection.size()) {
-                boolean isNormalizationCollection = true;
-                for (int j = 0; j < collection.size(); j++) {
-                    //Make sure the set of rules is the same
-                    if (!collection.get(j).getClass().equals(normalizationCollection.get(j).getClass())) {
-                        isNormalizationCollection = false;
-                        break;
-                    }
-                }
-                if (isNormalizationCollection) {
-                    //replace with the new collection
-                    logicalRuleSet.set(i, new Pair<>(seqOnceCtrl, alteredNormalizationCollection));
-                }
-            }
-        }
         return logicalRuleSet;
     }
 
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/CreateChannelStatement.java b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/AbstractCreateChannelStatement.java
similarity index 79%
rename from asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/CreateChannelStatement.java
rename to asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/AbstractCreateChannelStatement.java
index e29ff67..3020cb0 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/CreateChannelStatement.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/AbstractCreateChannelStatement.java
@@ -18,9 +18,6 @@
  */
 package org.apache.asterix.bad.lang.statement;
 
-import java.io.ByteArrayOutputStream;
-import java.io.DataOutputStream;
-import java.io.StringReader;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -33,7 +30,8 @@
 import org.apache.asterix.app.translator.QueryTranslator;
 import org.apache.asterix.bad.BADConstants;
 import org.apache.asterix.bad.BADJobService;
-import org.apache.asterix.bad.lang.BADLangExtension;
+import org.apache.asterix.bad.BADUtils;
+import org.apache.asterix.bad.extension.BADLangExtension;
 import org.apache.asterix.bad.lang.BADParserFactory;
 import org.apache.asterix.bad.metadata.Channel;
 import org.apache.asterix.bad.metadata.DeployedJobSpecEventListener;
@@ -43,17 +41,14 @@
 import org.apache.asterix.common.dataflow.ICcApplicationContext;
 import org.apache.asterix.common.exceptions.AsterixException;
 import org.apache.asterix.common.exceptions.CompilationException;
-import org.apache.asterix.common.exceptions.MetadataException;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.common.metadata.DataverseName;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.expression.CallExpr;
 import org.apache.asterix.lang.common.expression.IndexedTypeExpression;
-import org.apache.asterix.lang.common.expression.LiteralExpr;
 import org.apache.asterix.lang.common.expression.TypeExpression;
 import org.apache.asterix.lang.common.expression.TypeReferenceExpression;
-import org.apache.asterix.lang.common.literal.StringLiteral;
 import org.apache.asterix.lang.common.statement.CreateIndexStatement;
 import org.apache.asterix.lang.common.statement.DatasetDecl;
 import org.apache.asterix.lang.common.statement.IDatasetDetailsDecl;
@@ -66,9 +61,7 @@
 import org.apache.asterix.metadata.MetadataManager;
 import org.apache.asterix.metadata.MetadataTransactionContext;
 import org.apache.asterix.metadata.declared.MetadataProvider;
-import org.apache.asterix.metadata.entities.Function;
 import org.apache.asterix.metadata.utils.MetadataConstants;
-import org.apache.asterix.om.base.temporal.ADurationParserFactory;
 import org.apache.asterix.translator.IRequestParameters;
 import org.apache.asterix.translator.IStatementExecutor;
 import org.apache.asterix.translator.IStatementExecutor.ResultDelivery;
@@ -79,26 +72,24 @@
 import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.api.job.JobSpecification;
 import org.apache.hyracks.api.result.IResultSet;
-import org.apache.hyracks.dataflow.common.data.parsers.IValueParser;
 
-public class CreateChannelStatement extends ExtensionStatement {
+public abstract class AbstractCreateChannelStatement extends ExtensionStatement {
 
-    private static final Logger LOGGER = Logger.getLogger(CreateChannelStatement.class.getName());
-    private final Identifier channelName;
-    private final FunctionSignature function;
-    private final CallExpr period;
+    private static final Logger LOGGER = Logger.getLogger(AbstractCreateChannelStatement.class.getName());
+    protected String duration;
+    protected FunctionSignature function;
+    protected final CallExpr period;
     private DataverseName dataverseName;
-    private String duration;
     private String body;
     private String subscriptionsTableName;
     private String resultsTableName;
     private final boolean push;
+    private final Identifier channelName;
 
-    public CreateChannelStatement(DataverseName dataverseName, Identifier channelName, FunctionSignature function,
-            Expression period, boolean push) {
+    public AbstractCreateChannelStatement(DataverseName dataverseName, Identifier channelName, Expression period,
+            boolean push) {
         this.channelName = channelName;
         this.dataverseName = dataverseName;
-        this.function = function;
         this.period = (CallExpr) period;
         this.duration = "";
         this.push = push;
@@ -108,18 +99,6 @@
         return dataverseName;
     }
 
-    public Identifier getChannelName() {
-        return channelName;
-    }
-
-    public String getResultsName() {
-        return resultsTableName;
-    }
-
-    public String getSubscriptionsName() {
-        return subscriptionsTableName;
-    }
-
     public String getDuration() {
         return duration;
     }
@@ -142,27 +121,13 @@
         return null;
     }
 
-    public void initialize(MetadataTransactionContext mdTxnCtx) throws AlgebricksException, HyracksDataException {
-        Function lookup = MetadataManager.INSTANCE.getFunction(mdTxnCtx, function);
-        if (lookup == null) {
-            throw new MetadataException(" Unknown function " + function.getName());
-        }
-
-        if (!period.getFunctionSignature().getName().equals("duration")) {
-            throw new MetadataException(
-                    "Expected argument period as a duration, but got " + period.getFunctionSignature().getName() + ".");
-        }
-        duration = ((StringLiteral) ((LiteralExpr) period.getExprList().get(0)).getValue()).getValue();
-        IValueParser durationParser = ADurationParserFactory.INSTANCE.createValueParser();
-        ByteArrayOutputStream bos = new ByteArrayOutputStream();
-        DataOutputStream outputStream = new DataOutputStream(bos);
-        durationParser.parse(duration.toCharArray(), 0, duration.toCharArray().length, outputStream);
-    }
+    protected abstract void initialize(IStatementExecutor statementExecutor, MetadataProvider metadataProvider,
+            MetadataTransactionContext mdTxnCtx) throws Exception;
 
     private void createDatasets(IStatementExecutor statementExecutor, MetadataProvider metadataProvider,
-            IHyracksClientConnection hcc) throws AsterixException, Exception {
+            IHyracksClientConnection hcc) throws Exception {
 
-        Identifier subscriptionsTypeName = new Identifier(BADConstants.ChannelSubscriptionsType);
+        Identifier subscriptionsTypeName = new Identifier(BADConstants.METADATA_TYPENAME_SUBSCRIPTIONS);
         Identifier resultsTypeName = new Identifier(BADConstants.ChannelResultsType);
         //Setup the subscriptions dataset
         List<List<String>> partitionFields = new ArrayList<>();
@@ -232,18 +197,25 @@
         builder.append("select result, ");
         builder.append(BADConstants.ChannelExecutionTime + ", ");
         builder.append("sub." + BADConstants.SubscriptionId + " as " + BADConstants.SubscriptionId + ",");
+        // builder.append("b." + BADConstants.METADATA_TYPE_FIELD_NAME_BROKER_TYPE + " as "
+        //         + BADConstants.METADATA_TYPE_FIELD_NAME_BROKER_TYPE + ",");
+        // builder.append("b." + BADConstants.METADATA_TYPE_FIELD_NAME_BROKER_END_POINT + " as " + BADConstants.METADATA_TYPE_FIELD_NAME_BROKER_END_POINT + ",");
         builder.append("current_datetime() as " + BADConstants.DeliveryTime + "\n");
         builder.append("from " + dataverse + "." + subscriptionsTableName + " sub,\n");
-        builder.append(MetadataConstants.METADATA_DATAVERSE_NAME + "." + BADConstants.BROKER_KEYWORD + " b, \n");
-        //TODO(MULTI_PART_DATAVERSE_NAME):REVISIT
-        builder.append(function.getDataverseName().getCanonicalForm() + "." + function.getName() + "(");
-        int i = 0;
-        for (; i < function.getArity() - 1; i++) {
-            builder.append("sub.param" + i + ",");
+        builder.append(
+                MetadataConstants.METADATA_DATAVERSE_NAME + ".`" + BADConstants.METADATA_DATASET_BROKER + "` b, \n");
+        builder.append(function.getDataverseName() + "." + function.getName() + "(");
+        for (int iter1 = 0; iter1 < function.getArity(); iter1++) {
+            if (iter1 > 0) {
+                builder.append(", ");
+            }
+            builder.append("sub.param" + iter1);
         }
-        builder.append("sub.param" + i + ") result \n");
-        builder.append("where b." + BADConstants.BrokerName + " = sub." + BADConstants.BrokerName + "\n");
-        builder.append("and b." + BADConstants.DataverseName + " = sub." + BADConstants.DataverseName + "\n");
+        builder.append(") result \n");
+        builder.append("where sub." + BADConstants.METADATA_TYPE_FIELD_NAME_BROKERNAME + " /*+ bcast */ = b."
+                + BADConstants.METADATA_TYPE_FIELD_NAME_BROKERNAME + "\n");
+        builder.append("and sub." + BADConstants.METADATA_TYPE_NAME_DATAVERSENAME + " /*+ bcast */ = b."
+                + BADConstants.METADATA_TYPE_NAME_DATAVERSENAME + "\n");
         if (!push) {
             builder.append(")");
             builder.append(" returning a");
@@ -251,7 +223,7 @@
         builder.append(";");
         body = builder.toString();
         BADParserFactory factory = new BADParserFactory();
-        List<Statement> fStatements = factory.createParser(new StringReader(builder.toString())).parse();
+        List<Statement> fStatements = factory.createParser(builder.toString()).parse();
 
         SetStatement ss = (SetStatement) fStatements.get(0);
         metadataProvider.getConfig().put(ss.getPropName(), ss.getPropValue());
@@ -265,7 +237,7 @@
 
     @Override
     public String getName() {
-        return CreateChannelStatement.class.getName();
+        return AbstractCreateChannelStatement.class.getName();
     }
 
     @Override
@@ -283,7 +255,7 @@
         subscriptionsTableName = channelName + BADConstants.subscriptionEnding;
         resultsTableName = push ? "" : channelName + BADConstants.resultsEnding;
 
-        EntityId entityId = new EntityId(BADConstants.CHANNEL_EXTENSION_NAME, dataverseName, channelName.getValue());
+        EntityId entityId = new EntityId(BADConstants.RUNTIME_ENTITY_CHANNEL, dataverseName, channelName.getValue());
         ICcApplicationContext appCtx = metadataProvider.getApplicationContext();
         ActiveNotificationHandler activeEventHandler =
                 (ActiveNotificationHandler) appCtx.getActiveNotificationHandler();
@@ -305,7 +277,7 @@
             if (alreadyActive) {
                 throw new AsterixException("Channel " + channelName + " is already running");
             }
-            initialize(mdTxnCtx);
+            initialize(statementExecutor, metadataProvider, mdTxnCtx);
 
             //check if names are available before creating anything
             if (MetadataManager.INSTANCE.getDataset(mdTxnCtx, dataverseName, subscriptionsTableName) != null) {
@@ -314,11 +286,11 @@
             if (!push && MetadataManager.INSTANCE.getDataset(mdTxnCtx, dataverseName, resultsTableName) != null) {
                 throw new AsterixException("The channel name:" + channelName + " is not available.");
             }
-            MetadataProvider tempMdProvider = MetadataProvider.create(metadataProvider.getApplicationContext(),
-                    metadataProvider.getDefaultDataverse());
-            tempMdProvider.getConfig().putAll(metadataProvider.getConfig());
+            MetadataProvider tempMdProvider = BADUtils.replicateMetadataProvider(metadataProvider);
+            tempMdProvider.setMaxResultReads(requestContext.getResultProperties().getMaxReads());
             final IResultSet resultSet = requestContext.getResultSet();
             final Stats stats = requestContext.getStats();
+            tempMdProvider.getConfig().put(BADConstants.CONFIG_CHANNEL_NAME, channelName.getValue());
             //Create Channel Datasets
             createDatasets(statementExecutor, tempMdProvider, hcc);
             tempMdProvider.getLocks().reset();
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/BrokerDropStatement.java b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/BrokerDropStatement.java
index 9678b46..962b0d5 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/BrokerDropStatement.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/BrokerDropStatement.java
@@ -20,7 +20,7 @@
 
 import org.apache.asterix.algebra.extension.ExtensionStatement;
 import org.apache.asterix.app.translator.QueryTranslator;
-import org.apache.asterix.bad.lang.BADLangExtension;
+import org.apache.asterix.bad.extension.BADLangExtension;
 import org.apache.asterix.bad.metadata.Broker;
 import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.metadata.DataverseName;
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/ChannelDropStatement.java b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/ChannelDropStatement.java
index fb4fe47..34940a9 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/ChannelDropStatement.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/ChannelDropStatement.java
@@ -27,7 +27,7 @@
 import org.apache.asterix.app.active.ActiveNotificationHandler;
 import org.apache.asterix.app.translator.QueryTranslator;
 import org.apache.asterix.bad.BADConstants;
-import org.apache.asterix.bad.lang.BADLangExtension;
+import org.apache.asterix.bad.extension.BADLangExtension;
 import org.apache.asterix.bad.metadata.Channel;
 import org.apache.asterix.bad.metadata.DeployedJobSpecEventListener;
 import org.apache.asterix.common.dataflow.ICcApplicationContext;
@@ -92,7 +92,7 @@
             throws HyracksDataException, AlgebricksException {
         DataverseName dataverse = statementExecutor.getActiveDataverseName(dataverseName);
         boolean txnActive = false;
-        EntityId entityId = new EntityId(BADConstants.CHANNEL_EXTENSION_NAME, dataverse, channelName.getValue());
+        EntityId entityId = new EntityId(BADConstants.RUNTIME_ENTITY_CHANNEL, dataverse, channelName.getValue());
         ICcApplicationContext appCtx = metadataProvider.getApplicationContext();
         ActiveNotificationHandler activeEventHandler =
                 (ActiveNotificationHandler) appCtx.getActiveNotificationHandler();
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/ChannelSubscribeStatement.java b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/ChannelSubscribeStatement.java
index 60be430..4aa1959 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/ChannelSubscribeStatement.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/ChannelSubscribeStatement.java
@@ -24,7 +24,8 @@
 import org.apache.asterix.algebra.extension.ExtensionStatement;
 import org.apache.asterix.app.translator.QueryTranslator;
 import org.apache.asterix.bad.BADConstants;
-import org.apache.asterix.bad.lang.BADLangExtension;
+import org.apache.asterix.bad.BADUtils;
+import org.apache.asterix.bad.extension.BADLangExtension;
 import org.apache.asterix.bad.metadata.Broker;
 import org.apache.asterix.bad.metadata.Channel;
 import org.apache.asterix.common.exceptions.AsterixException;
@@ -154,11 +155,11 @@
             Query subscriptionTuple = new Query(false);
 
             List<FieldBinding> fb = new ArrayList<>();
-            LiteralExpr leftExpr = new LiteralExpr(new StringLiteral(BADConstants.DataverseName));
+            LiteralExpr leftExpr = new LiteralExpr(new StringLiteral(BADConstants.METADATA_TYPE_NAME_DATAVERSENAME));
             Expression rightExpr = new LiteralExpr(new StringLiteral(brokerDataverse.getCanonicalForm()));
             fb.add(new FieldBinding(leftExpr, rightExpr));
 
-            leftExpr = new LiteralExpr(new StringLiteral(BADConstants.BrokerName));
+            leftExpr = new LiteralExpr(new StringLiteral(BADConstants.METADATA_TYPE_FIELD_NAME_BROKERNAME));
             rightExpr = new LiteralExpr(new StringLiteral(broker.getBrokerName()));
             fb.add(new FieldBinding(leftExpr, rightExpr));
 
@@ -183,9 +184,9 @@
             RecordConstructor recordCon = new RecordConstructor(fb);
             subscriptionTuple.setBody(recordCon);
             subscriptionTuple.setVarCounter(varCounter);
-            MetadataProvider tempMdProvider = MetadataProvider.create(metadataProvider.getApplicationContext(),
-                    metadataProvider.getDefaultDataverse());
-            tempMdProvider.getConfig().putAll(metadataProvider.getConfig());
+
+            metadataProvider.setResultSetId(new ResultSetId(resultSetId));
+            MetadataProvider tempMdProvider = BADUtils.replicateMetadataProvider(metadataProvider);
 
             final ResultDelivery resultDelivery = requestParameters.getResultProperties().getDelivery();
             final IResultSet resultSet = requestParameters.getResultSet();
@@ -197,16 +198,10 @@
                 useResultVar.setIsNewVar(false);
                 FieldAccessor accessor = new FieldAccessor(useResultVar, new Identifier(BADConstants.SubscriptionId));
 
-                metadataProvider.setResultSetId(new ResultSetId(resultSetId));
                 boolean resultsAsync =
                         resultDelivery == ResultDelivery.ASYNC || resultDelivery == ResultDelivery.DEFERRED;
                 metadataProvider.setResultAsyncMode(resultsAsync);
-                tempMdProvider.setResultSetId(metadataProvider.getResultSetId());
                 tempMdProvider.setResultAsyncMode(resultsAsync);
-                tempMdProvider.setWriterFactory(metadataProvider.getWriterFactory());
-                tempMdProvider
-                        .setResultSerializerFactoryProvider(metadataProvider.getResultSerializerFactoryProvider());
-                tempMdProvider.setOutputFile(metadataProvider.getOutputFile());
                 tempMdProvider.setMaxResultReads(requestParameters.getResultProperties().getMaxReads());
 
                 InsertStatement insert = new InsertStatement(dataverse, subscriptionsDatasetName, subscriptionTuple,
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/ChannelUnsubscribeStatement.java b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/ChannelUnsubscribeStatement.java
index 298919f..93c27fa 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/ChannelUnsubscribeStatement.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/ChannelUnsubscribeStatement.java
@@ -24,7 +24,7 @@
 import org.apache.asterix.algebra.extension.ExtensionStatement;
 import org.apache.asterix.app.translator.QueryTranslator;
 import org.apache.asterix.bad.BADConstants;
-import org.apache.asterix.bad.lang.BADLangExtension;
+import org.apache.asterix.bad.extension.BADLangExtension;
 import org.apache.asterix.bad.metadata.Channel;
 import org.apache.asterix.common.exceptions.AsterixException;
 import org.apache.asterix.common.exceptions.CompilationException;
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/CreateBrokerStatement.java b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/CreateBrokerStatement.java
index 581b597..042d3dd 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/CreateBrokerStatement.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/CreateBrokerStatement.java
@@ -23,15 +23,19 @@
 
 import org.apache.asterix.algebra.extension.ExtensionStatement;
 import org.apache.asterix.app.translator.QueryTranslator;
-import org.apache.asterix.bad.lang.BADLangExtension;
+import org.apache.asterix.bad.BADConstants;
+import org.apache.asterix.bad.extension.BADLangExtension;
 import org.apache.asterix.bad.metadata.Broker;
 import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.metadata.DataverseName;
+import org.apache.asterix.lang.common.expression.RecordConstructor;
 import org.apache.asterix.lang.common.struct.Identifier;
+import org.apache.asterix.lang.common.util.ExpressionUtils;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
 import org.apache.asterix.metadata.MetadataManager;
 import org.apache.asterix.metadata.MetadataTransactionContext;
 import org.apache.asterix.metadata.declared.MetadataProvider;
+import org.apache.asterix.object.base.AdmObjectNode;
 import org.apache.asterix.translator.IRequestParameters;
 import org.apache.asterix.translator.IStatementExecutor;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
@@ -44,11 +48,19 @@
     private final DataverseName dataverseName;
     private final Identifier brokerName;
     private String endPointName;
+    private String brokerType;
+    private AdmObjectNode withObjectNode;
 
-    public CreateBrokerStatement(DataverseName dataverseName, Identifier brokerName, String endPointName) {
+    public CreateBrokerStatement(DataverseName dataverseName, Identifier brokerName, String endPointName,
+            RecordConstructor withRecord) throws CompilationException {
         this.brokerName = brokerName;
         this.dataverseName = dataverseName;
         this.endPointName = endPointName;
+        if (withRecord != null) {
+            this.withObjectNode = ExpressionUtils.toNode(withRecord);
+            this.brokerType = withObjectNode.getOptionalString(BADConstants.BAD_BROKER_FIELD_NAME_TYPE);
+        }
+        this.brokerType = brokerType == null ? BADConstants.GENERAL_BROKER_TYPE_NAME : brokerType.toLowerCase();
     }
 
     public String getEndPointName() {
@@ -91,7 +103,7 @@
             if (broker != null) {
                 throw new AlgebricksException("A broker with this name " + brokerName + " already exists.");
             }
-            broker = new Broker(dataverse, brokerName.getValue(), endPointName);
+            broker = new Broker(dataverse, brokerName.getValue(), endPointName, brokerType);
             MetadataManager.INSTANCE.addEntity(mdTxnCtx, broker);
             MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
         } catch (Exception e) {
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/CreateContinuousChannelStatement.java b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/CreateContinuousChannelStatement.java
new file mode 100644
index 0000000..fd14e27
--- /dev/null
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/CreateContinuousChannelStatement.java
@@ -0,0 +1,72 @@
+/*
+ * 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.bad.lang.statement;
+
+import org.apache.asterix.app.translator.QueryTranslator;
+import org.apache.asterix.common.exceptions.MetadataException;
+import org.apache.asterix.common.metadata.DataverseName;
+import org.apache.asterix.lang.common.base.Expression;
+import org.apache.asterix.lang.common.expression.LiteralExpr;
+import org.apache.asterix.lang.common.literal.StringLiteral;
+import org.apache.asterix.lang.common.statement.CreateFunctionStatement;
+import org.apache.asterix.lang.common.struct.Identifier;
+import org.apache.asterix.lang.sqlpp.parser.SqlppParserFactory;
+import org.apache.asterix.lang.sqlpp.rewrites.SqlppRewriterFactory;
+import org.apache.asterix.metadata.MetadataManager;
+import org.apache.asterix.metadata.MetadataTransactionContext;
+import org.apache.asterix.metadata.declared.MetadataProvider;
+import org.apache.asterix.metadata.entities.Function;
+import org.apache.asterix.translator.IStatementExecutor;
+
+public class CreateContinuousChannelStatement extends AbstractCreateChannelStatement {
+
+    private CreateFunctionStatement stmt;
+
+    public CreateContinuousChannelStatement(DataverseName dataverseName, Identifier channelName, Expression period,
+            boolean push, CreateFunctionStatement stmt) {
+        super(dataverseName, channelName, period, push);
+        this.stmt = stmt;
+    }
+
+    @Override
+    protected void initialize(IStatementExecutor statementExecutor, MetadataProvider metadataProvider,
+            MetadataTransactionContext mdTxnCtx) throws Exception {
+        // Creates function
+        SqlppRewriterFactory fact = new SqlppRewriterFactory(new SqlppParserFactory());
+        ((QueryTranslator) statementExecutor).handleCreateFunctionStatement(metadataProvider, stmt,
+                fact.createStatementRewriter());
+        this.function = stmt.getFunctionSignature();
+
+        // Check whether function exists
+        Function lookup = MetadataManager.INSTANCE.getFunction(mdTxnCtx, function);
+        if (lookup == null) {
+            throw new MetadataException(" Unknown function " + function.getName());
+        }
+
+        if (period != null) {
+            if (!period.getFunctionSignature().getName().equals("duration")) {
+                throw new MetadataException("Expected argument period as a duration, but got "
+                        + period.getFunctionSignature().getName() + ".");
+            }
+            duration = ((StringLiteral) ((LiteralExpr) period.getExprList().get(0)).getValue()).getValue();
+        } else {
+            duration = "";
+        }
+    }
+}
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/CreateProcedureStatement.java b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/CreateProcedureStatement.java
index c76385c..eb56e35 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/CreateProcedureStatement.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/CreateProcedureStatement.java
@@ -34,7 +34,7 @@
 import org.apache.asterix.app.translator.QueryTranslator;
 import org.apache.asterix.bad.BADConstants;
 import org.apache.asterix.bad.BADJobService;
-import org.apache.asterix.bad.lang.BADLangExtension;
+import org.apache.asterix.bad.extension.BADLangExtension;
 import org.apache.asterix.bad.lang.BADParserFactory;
 import org.apache.asterix.bad.metadata.DeployedJobSpecEventListener;
 import org.apache.asterix.bad.metadata.DeployedJobSpecEventListener.PrecompiledType;
@@ -240,7 +240,7 @@
                 (ActiveNotificationHandler) appCtx.getActiveNotificationHandler();
         initialize();
         DataverseName dataverse = statementExecutor.getActiveDataverseName(signature.getDataverseName());
-        EntityId entityId = new EntityId(BADConstants.PROCEDURE_KEYWORD, dataverse, signature.getName());
+        EntityId entityId = new EntityId(BADConstants.RUNTIME_ENTITY_PROCEDURE, dataverse, signature.getName());
         DeployedJobSpecEventListener listener = (DeployedJobSpecEventListener) activeEventHandler.getListener(entityId);
         boolean alreadyActive = false;
         Procedure procedure = null;
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/CreateRepetitiveChannelStatement.java b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/CreateRepetitiveChannelStatement.java
new file mode 100644
index 0000000..006535c
--- /dev/null
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/CreateRepetitiveChannelStatement.java
@@ -0,0 +1,66 @@
+/*
+ * 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.bad.lang.statement;
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+
+import org.apache.asterix.common.exceptions.MetadataException;
+import org.apache.asterix.common.functions.FunctionSignature;
+import org.apache.asterix.common.metadata.DataverseName;
+import org.apache.asterix.lang.common.base.Expression;
+import org.apache.asterix.lang.common.expression.LiteralExpr;
+import org.apache.asterix.lang.common.literal.StringLiteral;
+import org.apache.asterix.lang.common.struct.Identifier;
+import org.apache.asterix.metadata.MetadataManager;
+import org.apache.asterix.metadata.MetadataTransactionContext;
+import org.apache.asterix.metadata.declared.MetadataProvider;
+import org.apache.asterix.metadata.entities.Function;
+import org.apache.asterix.om.base.temporal.ADurationParserFactory;
+import org.apache.asterix.translator.IStatementExecutor;
+import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.dataflow.common.data.parsers.IValueParser;
+
+public class CreateRepetitiveChannelStatement extends AbstractCreateChannelStatement {
+    public CreateRepetitiveChannelStatement(DataverseName dataverseName, Identifier channelName,
+            FunctionSignature function, Expression period, boolean push) {
+        super(dataverseName, channelName, period, push);
+        this.function = function;
+    }
+
+    @Override
+    protected void initialize(IStatementExecutor statementExecutor, MetadataProvider metadataProvider,
+            MetadataTransactionContext mdTxnCtx) throws AlgebricksException, HyracksDataException {
+        Function lookup = MetadataManager.INSTANCE.getFunction(mdTxnCtx, function);
+        if (lookup == null) {
+            throw new MetadataException(" Unknown function " + function.getName());
+        }
+
+        if (!period.getFunctionSignature().getName().equals("duration")) {
+            throw new MetadataException(
+                    "Expected argument period as a duration, but got " + period.getFunctionSignature().getName() + ".");
+        }
+        duration = ((StringLiteral) ((LiteralExpr) period.getExprList().get(0)).getValue()).getValue();
+        IValueParser durationParser = ADurationParserFactory.INSTANCE.createValueParser();
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        DataOutputStream outputStream = new DataOutputStream(bos);
+        durationParser.parse(duration.toCharArray(), 0, duration.toCharArray().length, outputStream);
+    }
+}
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/ExecuteProcedureStatement.java b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/ExecuteProcedureStatement.java
index ca2435e..1083f8b 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/ExecuteProcedureStatement.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/ExecuteProcedureStatement.java
@@ -30,7 +30,7 @@
 import org.apache.asterix.app.translator.QueryTranslator;
 import org.apache.asterix.bad.BADConstants;
 import org.apache.asterix.bad.BADJobService;
-import org.apache.asterix.bad.lang.BADLangExtension;
+import org.apache.asterix.bad.extension.BADLangExtension;
 import org.apache.asterix.bad.metadata.DeployedJobSpecEventListener;
 import org.apache.asterix.bad.metadata.Procedure;
 import org.apache.asterix.common.dataflow.ICcApplicationContext;
@@ -109,7 +109,7 @@
                 (ActiveNotificationHandler) appCtx.getActiveNotificationHandler();
         DataverseName dataverse = statementExecutor.getActiveDataverseName(dataverseName);
         boolean txnActive = false;
-        EntityId entityId = new EntityId(BADConstants.PROCEDURE_KEYWORD, dataverse, procedureName);
+        EntityId entityId = new EntityId(BADConstants.RUNTIME_ENTITY_PROCEDURE, dataverse, procedureName);
         DeployedJobSpecEventListener listener = (DeployedJobSpecEventListener) activeEventHandler.getListener(entityId);
         Procedure procedure;
 
@@ -129,10 +129,11 @@
                         (QueryTranslator) statementExecutor);
 
             } else {
-                ScheduledExecutorService ses = BADJobService.startRepetitiveDeployedJobSpec(deployedJobSpecId, hcc,
+                ScheduledExecutorService ses = BADJobService.createExecutorServe();
+                listener.setExecutorService(ses);
+                BADJobService.startRepetitiveDeployedJobSpec(ses, deployedJobSpecId, hcc,
                         BADJobService.findPeriod(procedure.getDuration()), contextRuntimeVarMap, entityId,
                         metadataProvider.getTxnIdFactory(), listener);
-                listener.setExecutorService(ses);
             }
             MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
             txnActive = false;
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/ProcedureDropStatement.java b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/ProcedureDropStatement.java
index 9d5c901..16c2766 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/ProcedureDropStatement.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/lang/statement/ProcedureDropStatement.java
@@ -27,7 +27,7 @@
 import org.apache.asterix.app.active.ActiveNotificationHandler;
 import org.apache.asterix.app.translator.QueryTranslator;
 import org.apache.asterix.bad.BADConstants;
-import org.apache.asterix.bad.lang.BADLangExtension;
+import org.apache.asterix.bad.extension.BADLangExtension;
 import org.apache.asterix.bad.metadata.DeployedJobSpecEventListener;
 import org.apache.asterix.bad.metadata.Procedure;
 import org.apache.asterix.common.dataflow.ICcApplicationContext;
@@ -90,7 +90,7 @@
         DataverseName dataverseName = statementExecutor.getActiveDataverseName(signature.getDataverseName());
         signature.setDataverseName(dataverseName);
         boolean txnActive = false;
-        EntityId entityId = new EntityId(BADConstants.PROCEDURE_KEYWORD, dataverseName, signature.getName());
+        EntityId entityId = new EntityId(BADConstants.RUNTIME_ENTITY_PROCEDURE, dataverseName, signature.getName());
         DeployedJobSpecEventListener listener = (DeployedJobSpecEventListener) activeEventHandler.getListener(entityId);
 
         if (listener.isActive()) {
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/metadata/BADMetadataIndexes.java b/asterix-bad/src/main/java/org/apache/asterix/bad/metadata/BADMetadataIndexes.java
index 0722c48..5db98d3 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/metadata/BADMetadataIndexes.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/metadata/BADMetadataIndexes.java
@@ -21,6 +21,7 @@
 import java.util.Arrays;
 
 import org.apache.asterix.bad.BADConstants;
+import org.apache.asterix.bad.extension.BADMetadataExtension;
 import org.apache.asterix.common.metadata.MetadataIndexImmutableProperties;
 import org.apache.asterix.metadata.api.ExtensionMetadataDataset;
 import org.apache.asterix.metadata.api.ExtensionMetadataDatasetId;
@@ -32,23 +33,23 @@
 public class BADMetadataIndexes {
 
     public static final ExtensionMetadataDatasetId BAD_CHANNEL_INDEX_ID = new ExtensionMetadataDatasetId(
-            BADMetadataExtension.BAD_METADATA_EXTENSION_ID, BADConstants.CHANNEL_EXTENSION_NAME);
+            BADMetadataExtension.BAD_METADATA_EXTENSION_ID, BADConstants.METADATA_DATASET_CHANNEL);
     public static final MetadataIndexImmutableProperties PROPERTIES_CHANNEL =
-            new MetadataIndexImmutableProperties(BADConstants.CHANNEL_EXTENSION_NAME,
+            new MetadataIndexImmutableProperties(BADConstants.METADATA_DATASET_CHANNEL,
                     MetadataIndexImmutableProperties.FIRST_AVAILABLE_EXTENSION_METADATA_DATASET_ID,
                     MetadataIndexImmutableProperties.FIRST_AVAILABLE_EXTENSION_METADATA_DATASET_ID);
 
-    public static final ExtensionMetadataDatasetId BAD_BROKER_INDEX_ID =
-            new ExtensionMetadataDatasetId(BADMetadataExtension.BAD_METADATA_EXTENSION_ID, BADConstants.BROKER_KEYWORD);
+    public static final ExtensionMetadataDatasetId BAD_BROKER_INDEX_ID = new ExtensionMetadataDatasetId(
+            BADMetadataExtension.BAD_METADATA_EXTENSION_ID, BADConstants.METADATA_DATASET_BROKER);
     public static final MetadataIndexImmutableProperties PROPERTIES_BROKER =
-            new MetadataIndexImmutableProperties(BADConstants.BROKER_KEYWORD,
+            new MetadataIndexImmutableProperties(BADConstants.METADATA_DATASET_BROKER,
                     MetadataIndexImmutableProperties.FIRST_AVAILABLE_EXTENSION_METADATA_DATASET_ID + 1,
                     MetadataIndexImmutableProperties.FIRST_AVAILABLE_EXTENSION_METADATA_DATASET_ID + 1);
 
     public static final ExtensionMetadataDatasetId BAD_PROCEDURE_INDEX_ID = new ExtensionMetadataDatasetId(
-            BADMetadataExtension.BAD_METADATA_EXTENSION_ID, BADConstants.PROCEDURE_KEYWORD);
+            BADMetadataExtension.BAD_METADATA_EXTENSION_ID, BADConstants.METADATA_DATASET_PROCEDURE);
     public static final MetadataIndexImmutableProperties PROPERTIES_PROCEDURE =
-            new MetadataIndexImmutableProperties(BADConstants.PROCEDURE_KEYWORD,
+            new MetadataIndexImmutableProperties(BADConstants.METADATA_DATASET_PROCEDURE,
                     MetadataIndexImmutableProperties.FIRST_AVAILABLE_EXTENSION_METADATA_DATASET_ID + 2,
                     MetadataIndexImmutableProperties.FIRST_AVAILABLE_EXTENSION_METADATA_DATASET_ID + 2);
 
@@ -66,7 +67,7 @@
     public static final ExtensionMetadataDataset BROKER_DATASET = new ExtensionMetadataDataset<>(PROPERTIES_BROKER,
             NUM_FIELDS_BROKER_IDX, new IAType[] { BuiltinType.ASTRING, BuiltinType.ASTRING },
             Arrays.asList(Arrays.asList(MetadataRecordTypes.FIELD_NAME_DATAVERSE_NAME),
-                    Arrays.asList(BADConstants.BrokerName)),
+                    Arrays.asList(BADConstants.METADATA_TYPE_FIELD_NAME_BROKERNAME)),
             0, BADMetadataRecordTypes.BROKER_RECORDTYPE, true, new int[] { 0, 1 }, BAD_BROKER_INDEX_ID,
             (IMetadataEntityTupleTranslatorFactory<Broker>) BrokerTupleTranslator::new);
 
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/metadata/BADMetadataProvider.java b/asterix-bad/src/main/java/org/apache/asterix/bad/metadata/BADMetadataProvider.java
new file mode 100644
index 0000000..290db49
--- /dev/null
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/metadata/BADMetadataProvider.java
@@ -0,0 +1,148 @@
+/*
+ * 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.bad.metadata;
+
+import org.apache.asterix.bad.feed.operators.BADLSMPrimaryInsertOperatorDescriptor;
+import org.apache.asterix.bad.feed.operators.BADLSMPrimaryUpsertOperatorDescriptor;
+import org.apache.asterix.common.context.IStorageComponentProvider;
+import org.apache.asterix.common.dataflow.ICcApplicationContext;
+import org.apache.asterix.formats.base.IDataFormat;
+import org.apache.asterix.metadata.declared.MetadataProvider;
+import org.apache.asterix.metadata.entities.Dataset;
+import org.apache.asterix.metadata.entities.Dataverse;
+import org.apache.asterix.metadata.entities.Index;
+import org.apache.asterix.metadata.utils.DatasetUtil;
+import org.apache.asterix.om.types.ARecordType;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.runtime.operators.LSMPrimaryInsertOperatorDescriptor;
+import org.apache.asterix.runtime.operators.LSMPrimaryUpsertOperatorDescriptor;
+import org.apache.hyracks.algebricks.common.constraints.AlgebricksPartitionConstraint;
+import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.hyracks.algebricks.common.utils.Pair;
+import org.apache.hyracks.api.dataflow.IOperatorDescriptor;
+import org.apache.hyracks.api.dataflow.value.IMissingWriterFactory;
+import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
+import org.apache.hyracks.api.dataflow.value.ITypeTraits;
+import org.apache.hyracks.api.dataflow.value.RecordDescriptor;
+import org.apache.hyracks.api.job.JobSpecification;
+import org.apache.hyracks.dataflow.std.file.IFileSplitProvider;
+import org.apache.hyracks.storage.am.common.api.IModificationOperationCallbackFactory;
+import org.apache.hyracks.storage.am.common.api.ISearchOperationCallbackFactory;
+import org.apache.hyracks.storage.am.common.dataflow.IIndexDataflowHelperFactory;
+import org.apache.hyracks.storage.am.common.dataflow.IndexDataflowHelperFactory;
+import org.apache.hyracks.storage.am.common.ophelpers.IndexOperation;
+
+public class BADMetadataProvider extends MetadataProvider {
+
+    public static MetadataProvider create(ICcApplicationContext appCtx, Dataverse defaultDataverse) {
+        MetadataProvider mp = new BADMetadataProvider(appCtx);
+        mp.setDefaultDataverse(defaultDataverse);
+        return mp;
+    }
+
+    protected BADMetadataProvider(ICcApplicationContext appCtx) {
+        super(appCtx);
+    }
+
+    @Override
+    protected LSMPrimaryInsertOperatorDescriptor createLSMPrimaryInsertOperatorDescriptor(JobSpecification spec,
+            RecordDescriptor inputRecordDesc, int[] fieldPermutation, IIndexDataflowHelperFactory idfh,
+            IIndexDataflowHelperFactory pkidfh, IModificationOperationCallbackFactory modificationCallbackFactory,
+            ISearchOperationCallbackFactory searchCallbackFactory, int numKeys, int[] filterFields) {
+        return new BADLSMPrimaryInsertOperatorDescriptor(spec, inputRecordDesc, fieldPermutation, idfh, pkidfh,
+                modificationCallbackFactory, searchCallbackFactory, numKeys, filterFields);
+    }
+
+    // This method uses a static method from DatasetUtil, so it cannot be further simplified.
+    @Override
+    protected Pair<IOperatorDescriptor, AlgebricksPartitionConstraint> createPrimaryIndexUpsertOp(JobSpecification spec,
+            MetadataProvider metadataProvider, Dataset dataset, RecordDescriptor inputRecordDesc,
+            int[] fieldPermutation, IMissingWriterFactory missingWriterFactory) throws AlgebricksException {
+        int numKeys = dataset.getPrimaryKeys().size();
+        int numFilterFields = DatasetUtil.getFilterField(dataset) == null ? 0 : 1;
+        ARecordType itemType = (ARecordType) metadataProvider.findType(dataset);
+        ARecordType metaItemType = (ARecordType) metadataProvider.findMetaType(dataset);
+        Index primaryIndex = metadataProvider.getIndex(dataset.getDataverseName(), dataset.getDatasetName(),
+                dataset.getDatasetName());
+        Pair<IFileSplitProvider, AlgebricksPartitionConstraint> splitsAndConstraint =
+                metadataProvider.getSplitProviderAndConstraints(dataset);
+
+        // prepare callback
+        int[] primaryKeyFields = new int[numKeys];
+        for (int i = 0; i < numKeys; i++) {
+            primaryKeyFields[i] = i;
+        }
+        boolean hasSecondaries =
+                metadataProvider.getDatasetIndexes(dataset.getDataverseName(), dataset.getDatasetName()).size() > 1;
+        IStorageComponentProvider storageComponentProvider = metadataProvider.getStorageComponentProvider();
+        IModificationOperationCallbackFactory modificationCallbackFactory = dataset.getModificationCallbackFactory(
+                storageComponentProvider, primaryIndex, IndexOperation.UPSERT, primaryKeyFields);
+        ISearchOperationCallbackFactory searchCallbackFactory = dataset.getSearchCallbackFactory(
+                storageComponentProvider, primaryIndex, IndexOperation.UPSERT, primaryKeyFields);
+        IIndexDataflowHelperFactory idfh =
+                new IndexDataflowHelperFactory(storageComponentProvider.getStorageManager(), splitsAndConstraint.first);
+        LSMPrimaryUpsertOperatorDescriptor op;
+        ITypeTraits[] outputTypeTraits = new ITypeTraits[inputRecordDesc.getFieldCount() + 1
+                + (dataset.hasMetaPart() ? 2 : 1) + numFilterFields];
+        ISerializerDeserializer<?>[] outputSerDes = new ISerializerDeserializer[inputRecordDesc.getFieldCount() + 1
+                + (dataset.hasMetaPart() ? 2 : 1) + numFilterFields];
+        IDataFormat dataFormat = metadataProvider.getDataFormat();
+
+        int f = 0;
+        // add the upsert indicator var
+        outputSerDes[f] = dataFormat.getSerdeProvider().getSerializerDeserializer(BuiltinType.ABOOLEAN);
+        outputTypeTraits[f] = dataFormat.getTypeTraitProvider().getTypeTrait(BuiltinType.ABOOLEAN);
+        f++;
+        // add the previous record
+        outputSerDes[f] = dataFormat.getSerdeProvider().getSerializerDeserializer(itemType);
+        outputTypeTraits[f] = dataFormat.getTypeTraitProvider().getTypeTrait(itemType);
+        f++;
+        // add the previous meta second
+        if (dataset.hasMetaPart()) {
+            outputSerDes[f] = dataFormat.getSerdeProvider().getSerializerDeserializer(metaItemType);
+            outputTypeTraits[f] = dataFormat.getTypeTraitProvider().getTypeTrait(metaItemType);
+            f++;
+        }
+        // add the previous filter third
+        int fieldIdx = -1;
+        if (numFilterFields > 0) {
+            String filterField = DatasetUtil.getFilterField(dataset).get(0);
+            String[] fieldNames = itemType.getFieldNames();
+            int i = 0;
+            for (; i < fieldNames.length; i++) {
+                if (fieldNames[i].equals(filterField)) {
+                    break;
+                }
+            }
+            fieldIdx = i;
+            outputTypeTraits[f] = dataFormat.getTypeTraitProvider().getTypeTrait(itemType.getFieldTypes()[fieldIdx]);
+            outputSerDes[f] =
+                    dataFormat.getSerdeProvider().getSerializerDeserializer(itemType.getFieldTypes()[fieldIdx]);
+            f++;
+        }
+        for (int j = 0; j < inputRecordDesc.getFieldCount(); j++) {
+            outputTypeTraits[j + f] = inputRecordDesc.getTypeTraits()[j];
+            outputSerDes[j + f] = inputRecordDesc.getFields()[j];
+        }
+        RecordDescriptor outputRecordDesc = new RecordDescriptor(outputSerDes, outputTypeTraits);
+        op = new BADLSMPrimaryUpsertOperatorDescriptor(spec, outputRecordDesc, fieldPermutation, idfh,
+                missingWriterFactory, modificationCallbackFactory, searchCallbackFactory,
+                dataset.getFrameOpCallbackFactory(metadataProvider), numKeys, itemType, fieldIdx, hasSecondaries);
+        return new Pair<>(op, splitsAndConstraint.second);
+    }
+}
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/metadata/BADMetadataRecordTypes.java b/asterix-bad/src/main/java/org/apache/asterix/bad/metadata/BADMetadataRecordTypes.java
index a764a5a..0c11398 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/metadata/BADMetadataRecordTypes.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/metadata/BADMetadataRecordTypes.java
@@ -28,11 +28,11 @@
 public class BADMetadataRecordTypes {
 
     // -------------------------------------- Subscriptions --------------------------------------//
-    private static final String[] subTypeFieldNames =
-            { BADConstants.DataverseName, BADConstants.BrokerName, BADConstants.SubscriptionId };
+    private static final String[] subTypeFieldNames = { BADConstants.METADATA_TYPE_NAME_DATAVERSENAME,
+            BADConstants.METADATA_TYPE_FIELD_NAME_BROKERNAME, BADConstants.SubscriptionId };
     private static final IAType[] subTypeFieldTypes = { BuiltinType.ASTRING, BuiltinType.ASTRING, BuiltinType.AUUID };
     public static final ARecordType channelSubscriptionsType =
-            new ARecordType(BADConstants.ChannelSubscriptionsType, subTypeFieldNames, subTypeFieldTypes, true);
+            new ARecordType(BADConstants.METADATA_TYPENAME_SUBSCRIPTIONS, subTypeFieldNames, subTypeFieldTypes, true);
 
     // ---------------------------------------- Results --------------------------------------------//
     private static final String[] resultTypeFieldNames = { BADConstants.ResultId, BADConstants.ChannelExecutionTime,
@@ -53,11 +53,11 @@
     public static final int CHANNEL_ARECORD_BODY_FIELD_INDEX = 7;
     public static final ARecordType CHANNEL_RECORDTYPE = MetadataRecordTypes.createRecordType(
             // RecordTypeName
-            BADConstants.RECORD_TYPENAME_CHANNEL,
+            BADConstants.METADATA_TYPENAME_CHANNEL,
             // FieldNames
-            new String[] { BADConstants.DataverseName, BADConstants.ChannelName, BADConstants.SubscriptionsDatasetName,
-                    BADConstants.ResultsDatasetName, BADConstants.Function, BADConstants.Duration,
-                    BADConstants.FIELD_NAME_DEPENDENCIES, BADConstants.FIELD_NAME_BODY },
+            new String[] { BADConstants.METADATA_TYPE_NAME_DATAVERSENAME, BADConstants.ChannelName,
+                    BADConstants.SubscriptionsDatasetName, BADConstants.ResultsDatasetName, BADConstants.Function,
+                    BADConstants.Duration, BADConstants.FIELD_NAME_DEPENDENCIES, BADConstants.FIELD_NAME_BODY },
             // FieldTypes
             new IAType[] { BuiltinType.ASTRING, BuiltinType.ASTRING, BuiltinType.ASTRING, BuiltinType.ASTRING,
                     new AOrderedListType(BuiltinType.ASTRING, null), BuiltinType.ASTRING,
@@ -70,14 +70,18 @@
     public static final int BROKER_DATAVERSE_NAME_FIELD_INDEX = 0;
     public static final int BROKER_NAME_FIELD_INDEX = 1;
     public static final int BROKER_ENDPOINT_FIELD_INDEX = 2;
+    public static final int BROKER_TYPE_FIELD_INDEX = 3;
     public static final ARecordType BROKER_RECORDTYPE = MetadataRecordTypes.createRecordType(
             // RecordTypeName
-            BADConstants.RECORD_TYPENAME_BROKER,
+            BADConstants.METADATA_TYPENAME_BROKER,
             // FieldNames
-            new String[] { BADConstants.DataverseName, BADConstants.BrokerName, BADConstants.BrokerEndPoint },
+            new String[] { BADConstants.METADATA_TYPE_NAME_DATAVERSENAME,
+                    BADConstants.METADATA_TYPE_FIELD_NAME_BROKERNAME,
+                    BADConstants.METADATA_TYPE_FIELD_NAME_BROKER_END_POINT,
+                    BADConstants.METADATA_TYPE_FIELD_NAME_BROKER_TYPE },
             // FieldTypes
             new IAType[] { BuiltinType.ASTRING, BuiltinType.ASTRING, BuiltinType.ASTRING, BuiltinType.ASTRING,
-                    BuiltinType.ASTRING, BuiltinType.ASTRING },
+                    BuiltinType.ASTRING, BuiltinType.ASTRING, BuiltinType.ASTRING },
             //IsOpen?
             true);
 
@@ -93,11 +97,12 @@
     public static final int PROCEDURE_ARECORD_DEPENDENCIES_FIELD_INDEX = 8;
     public static final ARecordType PROCEDURE_RECORDTYPE = MetadataRecordTypes.createRecordType(
             // RecordTypeName
-            BADConstants.RECORD_TYPENAME_PROCEDURE,
+            BADConstants.METADATA_TYPENAME_PROCEDURE,
             // FieldNames
-            new String[] { BADConstants.DataverseName, BADConstants.ProcedureName, BADConstants.FIELD_NAME_ARITY,
-                    BADConstants.FIELD_NAME_PARAMS, BADConstants.FIELD_NAME_TYPE, BADConstants.FIELD_NAME_DEFINITION,
-                    BADConstants.FIELD_NAME_LANGUAGE, BADConstants.Duration, BADConstants.FIELD_NAME_DEPENDENCIES },
+            new String[] { BADConstants.METADATA_TYPE_NAME_DATAVERSENAME, BADConstants.ProcedureName,
+                    BADConstants.FIELD_NAME_ARITY, BADConstants.FIELD_NAME_PARAMS, BADConstants.FIELD_NAME_TYPE,
+                    BADConstants.FIELD_NAME_DEFINITION, BADConstants.FIELD_NAME_LANGUAGE, BADConstants.Duration,
+                    BADConstants.FIELD_NAME_DEPENDENCIES },
             // FieldTypes
             new IAType[] { BuiltinType.ASTRING, BuiltinType.ASTRING, BuiltinType.ASTRING,
                     new AOrderedListType(BuiltinType.ASTRING, null), BuiltinType.ASTRING, BuiltinType.ASTRING,
@@ -107,4 +112,15 @@
             //IsOpen?
             true);
 
+    //------------------------------------------ Active Timestamp ----------------------------------------//
+    public static final ARecordType ACTIVE_RECORD_RECORD_TYPE = MetadataRecordTypes.createRecordType(
+            // RecordTypeName
+            BADConstants.RECORD_TYPENAME_ACTIVE_RECORD,
+            // FieldNames
+            new String[] { BADConstants.FIELD_NAME_ACTIVE_TS },
+            // FieldTypes
+            new IAType[] { BuiltinType.ADATETIME },
+            //IsOpen?
+            true);
+
 }
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/metadata/Broker.java b/asterix-bad/src/main/java/org/apache/asterix/bad/metadata/Broker.java
index feabf3f..ef6cfbc 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/metadata/Broker.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/metadata/Broker.java
@@ -29,11 +29,13 @@
     private final DataverseName dataverseName;
     private final String brokerName;
     private final String endPointName;
+    private final String brokerType;
 
-    public Broker(DataverseName dataverseName, String brokerName, String endPointName) {
+    public Broker(DataverseName dataverseName, String brokerName, String endPointName, String brokerType) {
         this.endPointName = endPointName;
         this.dataverseName = dataverseName;
         this.brokerName = brokerName;
+        this.brokerType = brokerType;
     }
 
     public DataverseName getDataverseName() {
@@ -48,6 +50,10 @@
         return endPointName;
     }
 
+    public String getBrokerType() {
+        return brokerType;
+    }
+
     @Override
     public boolean equals(Object other) {
         if (this == other) {
@@ -67,4 +73,5 @@
     public ExtensionMetadataDatasetId getDatasetId() {
         return BADMetadataIndexes.BAD_BROKER_INDEX_ID;
     }
+
 }
\ No newline at end of file
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/metadata/BrokerTupleTranslator.java b/asterix-bad/src/main/java/org/apache/asterix/bad/metadata/BrokerTupleTranslator.java
index 1114d06..d71a1db 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/metadata/BrokerTupleTranslator.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/metadata/BrokerTupleTranslator.java
@@ -50,8 +50,10 @@
                 ((AString) brokerRecord.getValueByPos(BADMetadataRecordTypes.BROKER_NAME_FIELD_INDEX)).getStringValue();
         String endPointName = ((AString) brokerRecord.getValueByPos(BADMetadataRecordTypes.BROKER_ENDPOINT_FIELD_INDEX))
                 .getStringValue();
+        String brokerType =
+                ((AString) brokerRecord.getValueByPos(BADMetadataRecordTypes.BROKER_TYPE_FIELD_INDEX)).getStringValue();
 
-        return new Broker(dataverseName, brokerName, endPointName);
+        return new Broker(dataverseName, brokerName, endPointName, brokerType);
     }
 
     @Override
@@ -89,6 +91,12 @@
         stringSerde.serialize(aString, fieldValue.getDataOutput());
         recordBuilder.addField(BADMetadataRecordTypes.BROKER_ENDPOINT_FIELD_INDEX, fieldValue);
 
+        // write field 3
+        fieldValue.reset();
+        aString.setValue(broker.getBrokerType());
+        stringSerde.serialize(aString, fieldValue.getDataOutput());
+        recordBuilder.addField(BADMetadataRecordTypes.BROKER_TYPE_FIELD_INDEX, fieldValue);
+
         // write record
         recordBuilder.write(tupleBuilder.getDataOutput(), true);
 
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/metadata/Channel.java b/asterix-bad/src/main/java/org/apache/asterix/bad/metadata/Channel.java
index 9c5a1f0..a203468 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/metadata/Channel.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/metadata/Channel.java
@@ -44,16 +44,16 @@
     /*
     Dependencies are stored as an array of size two:
     element 0 is a list of dataset dependencies
-    -stored as triples of [DataverseName, Dataset, null] for the datasets
+    -stored as triples of [METADATA_TYPE_NAME_DATAVERSENAME, Dataset, null] for the datasets
     element 1 is a list of function dependencies
-    -stored as triples of [DataverseName, FunctionName, Arity] for the functions
+    -stored as triples of [METADATA_TYPE_NAME_DATAVERSENAME, FunctionName, Arity] for the functions
     */
     private final List<List<Triple<DataverseName, String, String>>> dependencies;
 
     public Channel(DataverseName dataverseName, String channelName, String subscriptionsDataset, String resultsDataset,
             FunctionSignature function, String duration, List<List<Triple<DataverseName, String, String>>> dependencies,
             String channelBody) {
-        this.channelId = new EntityId(BADConstants.CHANNEL_EXTENSION_NAME, dataverseName, channelName);
+        this.channelId = new EntityId(BADConstants.RUNTIME_ENTITY_CHANNEL, dataverseName, channelName);
         this.function = function;
         this.duration = duration;
         this.resultsDatasetName = resultsDataset;
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/metadata/Procedure.java b/asterix-bad/src/main/java/org/apache/asterix/bad/metadata/Procedure.java
index c989611..fcf5549 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/metadata/Procedure.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/metadata/Procedure.java
@@ -42,16 +42,16 @@
     /*
     Dependencies are stored as an array of size two:
     element 0 is a list of dataset dependencies
-    -stored as triples of [DataverseName, Dataset, null] for the datasets
+    -stored as triples of [METADATA_TYPE_NAME_DATAVERSENAME, Dataset, null] for the datasets
     element 1 is a list of function dependencies
-    -stored as triples of [DataverseName, FunctionName, Arity] for the functions
+    -stored as triples of [METADATA_TYPE_NAME_DATAVERSENAME, FunctionName, Arity] for the functions
      */
     private final List<List<Triple<DataverseName, String, String>>> dependencies;
 
     public Procedure(DataverseName dataverseName, String functionName, int arity, List<String> params, String type,
             String functionBody, String language, String duration,
             List<List<Triple<DataverseName, String, String>>> dependencies) {
-        this.procedureId = new EntityId(BADConstants.PROCEDURE_KEYWORD, dataverseName, functionName);
+        this.procedureId = new EntityId(BADConstants.RUNTIME_ENTITY_PROCEDURE, dataverseName, functionName);
         this.params = params;
         this.body = functionBody;
         this.type = type;
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/recovery/BADGlobalRecoveryManager.java b/asterix-bad/src/main/java/org/apache/asterix/bad/recovery/BADGlobalRecoveryManager.java
index b7f316e..b7d2f54 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/recovery/BADGlobalRecoveryManager.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/recovery/BADGlobalRecoveryManager.java
@@ -35,9 +35,9 @@
 import org.apache.asterix.app.translator.DefaultStatementExecutorFactory;
 import org.apache.asterix.app.translator.RequestParameters;
 import org.apache.asterix.bad.BADJobService;
+import org.apache.asterix.bad.extension.BADLangExtension;
 import org.apache.asterix.bad.lang.BADCompilationProvider;
-import org.apache.asterix.bad.lang.BADLangExtension;
-import org.apache.asterix.bad.lang.BADStatementExecutor;
+import org.apache.asterix.bad.lang.BADQueryTranslator;
 import org.apache.asterix.bad.metadata.Channel;
 import org.apache.asterix.bad.metadata.DeployedJobSpecEventListener;
 import org.apache.asterix.bad.metadata.DeployedJobSpecEventListener.PrecompiledType;
@@ -96,8 +96,8 @@
         SessionConfig sessionConfig =
                 new SessionConfig(SessionConfig.OutputFormat.ADM, true, true, true, SessionConfig.PlanFormat.STRING);
         final SessionOutput sessionOutput = new SessionOutput(sessionConfig, null);
-        BADStatementExecutor badStatementExecutor =
-                new BADStatementExecutor(appCtx, new ArrayList<>(), sessionOutput, new BADCompilationProvider(),
+        BADQueryTranslator badStatementExecutor =
+                new BADQueryTranslator(appCtx, new ArrayList<>(), sessionOutput, new BADCompilationProvider(),
                         Executors.newSingleThreadExecutor(
                                 new HyracksThreadFactory(DefaultStatementExecutorFactory.class.getSimpleName())),
                         new ResponsePrinter(sessionOutput));
@@ -133,10 +133,11 @@
                     new RequestParameters(requestReference, null, null, null, null, null, null, null, null, null, true),
                     true);
 
-            ScheduledExecutorService ses = BADJobService.startRepetitiveDeployedJobSpec(listener.getDeployedJobSpecId(),
-                    hcc, BADJobService.findPeriod(channel.getDuration()), new HashMap<>(), entityId,
-                    metadataProvider.getTxnIdFactory(), listener);
+            ScheduledExecutorService ses = BADJobService.createExecutorServe();
             listener.setExecutorService(ses);
+            BADJobService.startRepetitiveDeployedJobSpec(ses, listener.getDeployedJobSpecId(), hcc,
+                    BADJobService.findPeriod(channel.getDuration()), new HashMap<>(), entityId,
+                    metadataProvider.getTxnIdFactory(), listener);
             metadataProvider.getLocks().unlock();
 
             LOGGER.log(Level.SEVERE, entityId.getExtensionName() + " " + entityId.getDataverseName() + "."
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/rules/InsertBrokerNotifierForChannelRule.java b/asterix-bad/src/main/java/org/apache/asterix/bad/rules/InsertBrokerNotifierForChannelRule.java
index 6a0b31c..41393a4 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/rules/InsertBrokerNotifierForChannelRule.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/rules/InsertBrokerNotifierForChannelRule.java
@@ -24,8 +24,8 @@
 import org.apache.asterix.active.EntityId;
 import org.apache.asterix.algebra.operators.CommitOperator;
 import org.apache.asterix.bad.BADConstants;
-import org.apache.asterix.bad.runtime.NotifyBrokerOperator;
-import org.apache.asterix.bad.runtime.NotifyBrokerPOperator;
+import org.apache.asterix.bad.runtime.operators.NotifyBrokerOperator;
+import org.apache.asterix.bad.runtime.operators.NotifyBrokerPOperator;
 import org.apache.asterix.common.metadata.DataverseName;
 import org.apache.asterix.lang.common.util.FunctionUtil;
 import org.apache.asterix.metadata.declared.DatasetDataSource;
@@ -133,6 +133,8 @@
 
         //Now we need to get the broker EndPoint
         LogicalVariable brokerEndpointVar = context.newVar();
+        LogicalVariable brokerTypeVar = context.newVar();
+
         AbstractLogicalOperator opAboveBrokersScan = findOp(op, "brokers");
         if (opAboveBrokersScan == null) {
             return false;
@@ -155,8 +157,10 @@
             ((CommitOperator) ((DelegateOperator) op).getDelegate()).setSink(false);
         }
 
-        AssignOperator assignOp = createbrokerEndPointAssignOperator(brokerEndpointVar, opAboveBrokersScan);
-        //now brokerNameVar holds the brokerName for use farther up in the plan
+        AssignOperator assignOp =
+                createbrokerEndPointAssignOperator(brokerEndpointVar, brokerTypeVar, opAboveBrokersScan);
+
+        visitGroupBy(op, assignOp, brokerEndpointVar, brokerTypeVar);
 
         context.computeAndSetTypeEnvironmentForOperator(assignOp);
         context.computeAndSetTypeEnvironmentForOperator(opAboveBrokersScan);
@@ -166,25 +170,46 @@
         badProject.getVariables().add(subscriptionIdVar);
         badProject.getVariables().add(brokerEndpointVar);
         badProject.getVariables().add(channelExecutionVar);
+        badProject.getVariables().add(brokerTypeVar);
         context.computeAndSetTypeEnvironmentForOperator(badProject);
 
         //Create my brokerNotify plan above the extension Operator
         DelegateOperator dOp = push
                 ? createNotifyBrokerPushPlan(brokerEndpointVar, badProject.getVariables().get(0), channelExecutionVar,
-                        context, op, (DistributeResultOperator) op1, channelDataverse, channelName)
-                : createNotifyBrokerPullPlan(brokerEndpointVar, subscriptionIdVar, channelExecutionVar, context, op,
-                        (DistributeResultOperator) op1, channelDataverse, channelName);
+                        brokerTypeVar, context, op, (DistributeResultOperator) op1, channelDataverse, channelName)
+                : createNotifyBrokerPullPlan(brokerEndpointVar, subscriptionIdVar, channelExecutionVar, brokerTypeVar,
+                        context, op, (DistributeResultOperator) op1, channelDataverse, channelName);
 
         opRef.setValue(dOp);
 
         return true;
     }
 
+    private boolean visitGroupBy(ILogicalOperator currOp, ILogicalOperator brokerAssignOp, LogicalVariable endpointVar,
+            LogicalVariable typeVar) {
+        // this method makes sure even the broker information is not projected out
+        boolean containsBroker = false;
+        if (currOp == brokerAssignOp) {
+            return true;
+        } else {
+            for (Mutable<ILogicalOperator> input : currOp.getInputs()) {
+                containsBroker = containsBroker || visitGroupBy(input.getValue(), brokerAssignOp, endpointVar, typeVar);
+            }
+        }
+        if (currOp.getOperatorTag() == LogicalOperatorTag.GROUP && containsBroker) {
+            GroupByOperator groupByOperator = (GroupByOperator) currOp;
+            groupByOperator.addDecorExpression(null, new VariableReferenceExpression(endpointVar));
+            groupByOperator.addDecorExpression(null, new VariableReferenceExpression(typeVar));
+        }
+        return containsBroker;
+    }
+
     private DelegateOperator createBrokerOp(LogicalVariable brokerEndpointVar, LogicalVariable sendVar,
-            LogicalVariable channelExecutionVar, DataverseName channelDataverse, String channelName, boolean push) {
+            LogicalVariable channelExecutionVar, LogicalVariable brokerTypeVar, DataverseName channelDataverse,
+            String channelName, boolean push) {
         NotifyBrokerOperator notifyBrokerOp =
-                new NotifyBrokerOperator(brokerEndpointVar, sendVar, channelExecutionVar, push);
-        EntityId activeId = new EntityId(BADConstants.CHANNEL_EXTENSION_NAME, channelDataverse, channelName);
+                new NotifyBrokerOperator(brokerEndpointVar, sendVar, channelExecutionVar, brokerTypeVar, push);
+        EntityId activeId = new EntityId(BADConstants.RUNTIME_ENTITY_CHANNEL, channelDataverse, channelName);
         NotifyBrokerPOperator notifyBrokerPOp = new NotifyBrokerPOperator(activeId);
         notifyBrokerOp.setPhysicalOperator(notifyBrokerPOp);
         DelegateOperator extensionOp = new DelegateOperator(notifyBrokerOp);
@@ -193,9 +218,9 @@
     }
 
     private DelegateOperator createNotifyBrokerPushPlan(LogicalVariable brokerEndpointVar, LogicalVariable sendVar,
-            LogicalVariable channelExecutionVar, IOptimizationContext context, ILogicalOperator eOp,
-            DistributeResultOperator distributeOp, DataverseName channelDataverse, String channelName)
-            throws AlgebricksException {
+            LogicalVariable channelExecutionVar, LogicalVariable brokerTypeVar, IOptimizationContext context,
+            ILogicalOperator eOp, DistributeResultOperator distributeOp, DataverseName channelDataverse,
+            String channelName) throws AlgebricksException {
         //Find the assign operator to get the result type that we need
         AbstractLogicalOperator assign = (AbstractLogicalOperator) eOp.getInputs().get(0).getValue();
         while (assign.getOperatorTag() != LogicalOperatorTag.ASSIGN) {
@@ -203,8 +228,8 @@
         }
 
         //Create the NotifyBrokerOperator
-        DelegateOperator extensionOp =
-                createBrokerOp(brokerEndpointVar, sendVar, channelExecutionVar, channelDataverse, channelName, true);
+        DelegateOperator extensionOp = createBrokerOp(brokerEndpointVar, sendVar, channelExecutionVar, brokerTypeVar,
+                channelDataverse, channelName, true);
 
         extensionOp.getInputs().add(new MutableObject<>(eOp));
         context.computeAndSetTypeEnvironmentForOperator(extensionOp);
@@ -214,9 +239,9 @@
     }
 
     private DelegateOperator createNotifyBrokerPullPlan(LogicalVariable brokerEndpointVar, LogicalVariable sendVar,
-            LogicalVariable channelExecutionVar, IOptimizationContext context, ILogicalOperator eOp,
-            DistributeResultOperator distributeOp, DataverseName channelDataverse, String channelName)
-            throws AlgebricksException {
+            LogicalVariable channelExecutionVar, LogicalVariable brokerTypeVar, IOptimizationContext context,
+            ILogicalOperator eOp, DistributeResultOperator distributeOp, DataverseName channelDataverse,
+            String channelName) throws AlgebricksException {
 
         //Create the Distinct Op
         ArrayList<Mutable<ILogicalExpression>> expressions = new ArrayList<>();
@@ -231,6 +256,7 @@
         //Create GroupBy operator
         GroupByOperator groupbyOp = new GroupByOperator(groupByList, groupByDecorList, nestedPlans);
         groupbyOp.addGbyExpression(null, new VariableReferenceExpression(brokerEndpointVar));
+        groupbyOp.addGbyExpression(null, new VariableReferenceExpression(brokerTypeVar));
         groupbyOp.addGbyExpression(null, new VariableReferenceExpression(channelExecutionVar));
 
         //Set the distinct as input
@@ -254,7 +280,7 @@
 
         //Create the NotifyBrokerOperator
         DelegateOperator extensionOp = createBrokerOp(brokerEndpointVar, sendListVar, channelExecutionVar,
-                channelDataverse, channelName, false);
+                brokerTypeVar, channelDataverse, channelName, false);
 
         //Set the input for the distinct as the old top
         extensionOp.getInputs().add(new MutableObject<>(groupbyOp));
@@ -262,9 +288,9 @@
 
         //compute environment bottom up
         context.computeAndSetTypeEnvironmentForOperator(distinctOp);
-        context.computeAndSetTypeEnvironmentForOperator(groupbyOp);
         context.computeAndSetTypeEnvironmentForOperator(nestedTupleSourceOp);
         context.computeAndSetTypeEnvironmentForOperator(listifyOp);
+        context.computeAndSetTypeEnvironmentForOperator(groupbyOp);
         context.computeAndSetTypeEnvironmentForOperator(extensionOp);
 
         return extensionOp;
@@ -272,9 +298,11 @@
     }
 
     private AssignOperator createbrokerEndPointAssignOperator(LogicalVariable brokerEndpointVar,
-            AbstractLogicalOperator opAboveBrokersScan) {
-        Mutable<ILogicalExpression> fieldRef = new MutableObject<ILogicalExpression>(
-                new ConstantExpression(new AsterixConstantValue(new AString(BADConstants.BrokerEndPoint))));
+            LogicalVariable brokerTypeVar, AbstractLogicalOperator opAboveBrokersScan) {
+        Mutable<ILogicalExpression> endpointFieldName = new MutableObject<ILogicalExpression>(new ConstantExpression(
+                new AsterixConstantValue(new AString(BADConstants.METADATA_TYPE_FIELD_NAME_BROKER_END_POINT))));
+        Mutable<ILogicalExpression> brokerTypeFieldName = new MutableObject<ILogicalExpression>(new ConstantExpression(
+                new AsterixConstantValue(new AString(BADConstants.METADATA_TYPE_FIELD_NAME_BROKER_TYPE))));
         DataSourceScanOperator brokerScan = null;
         int index = 0;
         for (Mutable<ILogicalOperator> subOp : opAboveBrokersScan.getInputs()) {
@@ -287,18 +315,24 @@
         Mutable<ILogicalExpression> varRef = new MutableObject<ILogicalExpression>(
                 new VariableReferenceExpression(brokerScan.getVariables().get(2)));
 
-        ScalarFunctionCallExpression fieldAccessByName = new ScalarFunctionCallExpression(
-                FunctionUtil.getFunctionInfo(BuiltinFunctions.FIELD_ACCESS_BY_NAME), varRef, fieldRef);
-        ArrayList<LogicalVariable> varArray = new ArrayList<LogicalVariable>(1);
+        ScalarFunctionCallExpression brokerEndpointFieldAccessor = new ScalarFunctionCallExpression(
+                FunctionUtil.getFunctionInfo(BuiltinFunctions.FIELD_ACCESS_BY_NAME), varRef, endpointFieldName);
+        ScalarFunctionCallExpression brokerTYpeFieldAccessor = new ScalarFunctionCallExpression(
+                FunctionUtil.getFunctionInfo(BuiltinFunctions.FIELD_ACCESS_BY_NAME), varRef, brokerTypeFieldName);
+
+        ArrayList<LogicalVariable> varArray = new ArrayList<LogicalVariable>(2);
         varArray.add(brokerEndpointVar);
-        ArrayList<Mutable<ILogicalExpression>> exprArray = new ArrayList<Mutable<ILogicalExpression>>(1);
-        exprArray.add(new MutableObject<ILogicalExpression>(fieldAccessByName));
+        varArray.add(brokerTypeVar);
+
+        ArrayList<Mutable<ILogicalExpression>> exprArray = new ArrayList<Mutable<ILogicalExpression>>(2);
+        exprArray.add(new MutableObject<>(brokerEndpointFieldAccessor));
+        exprArray.add(new MutableObject<>(brokerTYpeFieldAccessor));
 
         AssignOperator assignOp = new AssignOperator(varArray, exprArray);
 
         //Place assignOp between the scan and the op above it
-        assignOp.getInputs().add(new MutableObject<ILogicalOperator>(brokerScan));
-        opAboveBrokersScan.getInputs().set(index, new MutableObject<ILogicalOperator>(assignOp));
+        assignOp.getInputs().add(new MutableObject<>(brokerScan));
+        opAboveBrokersScan.getInputs().set(index, new MutableObject<>(assignOp));
 
         return assignOp;
     }
@@ -313,40 +347,18 @@
             return null;
         }
         for (Mutable<ILogicalOperator> subOp : op.getInputs()) {
-            if (lookingForString.equals("brokers")) {
-                if (isBrokerScan((AbstractLogicalOperator) subOp.getValue())) {
-                    return op;
-                } else {
-                    AbstractLogicalOperator nestedOp =
-                            findOp((AbstractLogicalOperator) subOp.getValue(), lookingForString);
-                    if (nestedOp != null) {
-                        return nestedOp;
-                    }
+            if (lookingForString.equals("brokers") && isBrokerScan((AbstractLogicalOperator) subOp.getValue())) {
+                return op;
+            } else if (lookingForString.equals("project")
+                    && subOp.getValue().getOperatorTag() == LogicalOperatorTag.PROJECT) {
+                return (AbstractLogicalOperator) subOp.getValue();
+            } else if (isSubscriptionsScan((AbstractLogicalOperator) subOp.getValue(), lookingForString)) {
+                return (AbstractLogicalOperator) subOp.getValue();
+            } else {
+                AbstractLogicalOperator nestedOp = findOp((AbstractLogicalOperator) subOp.getValue(), lookingForString);
+                if (nestedOp != null) {
+                    return nestedOp;
                 }
-
-            } else if (lookingForString.equals("project")) {
-                if (subOp.getValue().getOperatorTag() == LogicalOperatorTag.PROJECT) {
-                    return (AbstractLogicalOperator) subOp.getValue();
-                } else {
-                    AbstractLogicalOperator nestedOp =
-                            findOp((AbstractLogicalOperator) subOp.getValue(), lookingForString);
-                    if (nestedOp != null) {
-                        return nestedOp;
-                    }
-                }
-            }
-
-            else {
-                if (isSubscriptionsScan((AbstractLogicalOperator) subOp.getValue(), lookingForString)) {
-                    return (AbstractLogicalOperator) subOp.getValue();
-                } else {
-                    AbstractLogicalOperator nestedOp =
-                            findOp((AbstractLogicalOperator) subOp.getValue(), lookingForString);
-                    if (nestedOp != null) {
-                        return nestedOp;
-                    }
-                }
-
             }
         }
         return null;
@@ -356,10 +368,8 @@
         if (op instanceof DataSourceScanOperator) {
             if (((DataSourceScanOperator) op).getDataSource() instanceof DatasetDataSource) {
                 DatasetDataSource dds = (DatasetDataSource) ((DataSourceScanOperator) op).getDataSource();
-                if (dds.getDataset().getDataverseName().equals(MetadataConstants.METADATA_DATAVERSE_NAME)
-                        && dds.getDataset().getDatasetName().equals("Broker")) {
-                    return true;
-                }
+                return dds.getDataset().getDataverseName().equals(MetadataConstants.METADATA_DATAVERSE_NAME)
+                        && dds.getDataset().getDatasetName().equals(BADConstants.METADATA_DATASET_BROKER);
             }
         }
         return false;
@@ -370,10 +380,8 @@
             if (((DataSourceScanOperator) op).getDataSource() instanceof DatasetDataSource) {
                 DatasetDataSource dds = (DatasetDataSource) ((DataSourceScanOperator) op).getDataSource();
                 if (dds.getDataset().getItemTypeDataverseName().equals(MetadataConstants.METADATA_DATAVERSE_NAME)
-                        && dds.getDataset().getItemTypeName().equals("ChannelSubscriptionsType")) {
-                    if (subscriptionsName.equals("") || dds.getDataset().getDatasetName().equals(subscriptionsName)) {
-                        return true;
-                    }
+                        && dds.getDataset().getItemTypeName().equals(BADConstants.METADATA_TYPENAME_SUBSCRIPTIONS)) {
+                    return subscriptionsName.equals("") || dds.getDataset().getDatasetName().equals(subscriptionsName);
                 }
             }
         }
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/rules/RewriteChannelTimeFunctionToLocalVarRule.java b/asterix-bad/src/main/java/org/apache/asterix/bad/rules/RewriteChannelTimeFunctionToLocalVarRule.java
new file mode 100644
index 0000000..ec922e7
--- /dev/null
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/rules/RewriteChannelTimeFunctionToLocalVarRule.java
@@ -0,0 +1,213 @@
+/*
+ *
+ *  * 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.bad.rules;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.asterix.bad.BADConstants;
+import org.apache.asterix.bad.function.BADFunctions;
+import org.apache.asterix.lang.common.util.FunctionUtil;
+import org.apache.asterix.metadata.declared.DataSource;
+import org.apache.asterix.om.base.AString;
+import org.apache.asterix.om.constants.AsterixConstantValue;
+import org.apache.asterix.om.functions.BuiltinFunctions;
+import org.apache.commons.lang3.mutable.Mutable;
+import org.apache.commons.lang3.mutable.MutableObject;
+import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
+import org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator;
+import org.apache.hyracks.algebricks.core.algebra.base.IOptimizationContext;
+import org.apache.hyracks.algebricks.core.algebra.base.LogicalExpressionTag;
+import org.apache.hyracks.algebricks.core.algebra.base.LogicalOperatorTag;
+import org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable;
+import org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression;
+import org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression;
+import org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression;
+import org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression;
+import org.apache.hyracks.algebricks.core.algebra.functions.AlgebricksBuiltinFunctions;
+import org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator;
+import org.apache.hyracks.algebricks.core.algebra.operators.logical.DataSourceScanOperator;
+import org.apache.hyracks.algebricks.core.algebra.operators.logical.InnerJoinOperator;
+import org.apache.hyracks.algebricks.core.algebra.operators.logical.SelectOperator;
+import org.apache.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
+
+public class RewriteChannelTimeFunctionToLocalVarRule implements IAlgebraicRewriteRule {
+
+    @Override
+    public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
+            throws AlgebricksException {
+
+        Mutable<ILogicalExpression> exprRef;
+        if (opRef.getValue().getOperatorTag() == LogicalOperatorTag.INNERJOIN) {
+            InnerJoinOperator selectOp = (InnerJoinOperator) opRef.getValue();
+            exprRef = selectOp.getCondition();
+        } else if (opRef.getValue().getOperatorTag() == LogicalOperatorTag.SELECT) {
+            SelectOperator selectOp = (SelectOperator) opRef.getValue();
+            exprRef = selectOp.getCondition();
+        } else {
+            return false;
+        }
+
+        Set<Mutable<ILogicalExpression>> activeFunctionSet = new HashSet<>();
+        Set<LogicalVariable> needPrevDsSet = new HashSet<>();
+        Set<LogicalVariable> needCurrDsSet = new HashSet<>();
+        Set<LogicalVariable> needActiveDsSet = new HashSet<>();
+
+        // collect active functions
+        collectChannelTimeFunctions(exprRef, activeFunctionSet, needPrevDsSet, needCurrDsSet, needActiveDsSet);
+        if (activeFunctionSet.size() == 0) {
+            return false;
+        }
+
+        // add assigns for active functions
+        Map<LogicalVariable, LogicalVariable> prevMap = new HashMap<>();
+        Map<LogicalVariable, LogicalVariable> currMap = new HashMap<>();
+        Map<LogicalVariable, LogicalVariable> activeMap = new HashMap<>();
+        createChannelTimeAssignOps(opRef, needPrevDsSet, needCurrDsSet, needActiveDsSet, prevMap, currMap, activeMap,
+                context);
+
+        // update expressions with new vars
+        updateActiveFuncExprsWithVars(prevMap, currMap, activeMap, activeFunctionSet);
+
+        context.computeAndSetTypeEnvironmentForOperator(opRef.getValue());
+        return true;
+    }
+
+    private void updateActiveFuncExprsWithVars(Map<LogicalVariable, LogicalVariable> prevMap,
+            Map<LogicalVariable, LogicalVariable> currMap, Map<LogicalVariable, LogicalVariable> activeMap,
+            Set<Mutable<ILogicalExpression>> activeFuncExprs) {
+
+        for (Mutable<ILogicalExpression> expr : activeFuncExprs) {
+            AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) expr.getValue();
+            LogicalVariable dsVar = ((VariableReferenceExpression) ((AbstractFunctionCallExpression) expr.getValue())
+                    .getArguments().get(0).getValue()).getVariableReference();
+            if (funcExpr.getFunctionIdentifier() == BADFunctions.CURRENT_CHANNEL_TIME) {
+                expr.setValue(new VariableReferenceExpression(currMap.get(dsVar)));
+            } else if (funcExpr.getFunctionIdentifier() == BADFunctions.PREVIOUS_CHANNEL_TIME) {
+                expr.setValue(new VariableReferenceExpression(prevMap.get(dsVar)));
+            } else {
+                ILogicalExpression lessThanExpr =
+                        new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(AlgebricksBuiltinFunctions.LT),
+                                new MutableObject<>(new VariableReferenceExpression(activeMap.get(dsVar))),
+                                new MutableObject<>(new VariableReferenceExpression(currMap.get(dsVar))));
+                ILogicalExpression greaterThanExpr =
+                        new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(AlgebricksBuiltinFunctions.GT),
+                                new MutableObject<>(new VariableReferenceExpression(activeMap.get(dsVar))),
+                                new MutableObject<>(new VariableReferenceExpression(prevMap.get(dsVar))));
+                ScalarFunctionCallExpression andExpr =
+                        new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.AND),
+                                new MutableObject<>(lessThanExpr), new MutableObject<>(greaterThanExpr));
+                expr.setValue(andExpr);
+            }
+        }
+    }
+
+    private void createChannelTimeAssignOps(Mutable<ILogicalOperator> opRef, Set<LogicalVariable> needPrevDsSet,
+            Set<LogicalVariable> needCurrDsSet, Set<LogicalVariable> needActiveDsSet,
+            Map<LogicalVariable, LogicalVariable> prevMap, Map<LogicalVariable, LogicalVariable> currMap,
+            Map<LogicalVariable, LogicalVariable> activeMap, IOptimizationContext context) {
+        ILogicalOperator currOp = opRef.getValue();
+        String channelName =
+                (String) context.getMetadataProvider().getConfig().getOrDefault(BADConstants.CONFIG_CHANNEL_NAME, "");
+        if (opRef.getValue().getOperatorTag() == LogicalOperatorTag.DATASOURCESCAN) {
+            DataSourceScanOperator dataScanOp = (DataSourceScanOperator) opRef.getValue();
+            DataSource ds = (DataSource) dataScanOp.getDataSource();
+            LogicalVariable dsVar = ds.getDataRecordVariable(dataScanOp.getScanVariables());
+
+            if (needPrevDsSet.contains(dsVar) || needActiveDsSet.contains(dsVar)) {
+                LogicalVariable channelTimeVar = context.newVar();
+                ILogicalExpression previousChannelTimeExpr = new ScalarFunctionCallExpression(
+                        BuiltinFunctions.getAsterixFunctionInfo(BADFunctions.PREVIOUS_CHANNEL_TIME),
+                        new MutableObject<>(
+                                new ConstantExpression(new AsterixConstantValue(new AString(channelName)))));
+                AssignOperator assignOp =
+                        new AssignOperator(channelTimeVar, new MutableObject<>(previousChannelTimeExpr));
+                assignOp.getInputs().add(new MutableObject<>(opRef.getValue()));
+                opRef.setValue(assignOp);
+                prevMap.put(dsVar, channelTimeVar);
+            }
+
+            if (needCurrDsSet.contains(dsVar) || needActiveDsSet.contains(dsVar)) {
+                LogicalVariable channelTimeVar = context.newVar();
+                ILogicalExpression previousChannelTimeExpr = new ScalarFunctionCallExpression(
+                        BuiltinFunctions.getAsterixFunctionInfo(BADFunctions.CURRENT_CHANNEL_TIME), new MutableObject<>(
+                                new ConstantExpression(new AsterixConstantValue(new AString(channelName)))));
+                AssignOperator assignOp =
+                        new AssignOperator(channelTimeVar, new MutableObject<>(previousChannelTimeExpr));
+                assignOp.getInputs().add(new MutableObject<>(opRef.getValue()));
+                opRef.setValue(assignOp);
+                currMap.put(dsVar, channelTimeVar);
+            }
+
+            if (needActiveDsSet.contains(dsVar)) {
+                LogicalVariable channelTimeVar = context.newVar();
+
+                ILogicalExpression activeTsFunc =
+                        new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.META),
+                                new MutableObject<>(new VariableReferenceExpression(dsVar)));
+                ScalarFunctionCallExpression faExpr = new ScalarFunctionCallExpression(
+                        FunctionUtil.getFunctionInfo(BuiltinFunctions.FIELD_ACCESS_BY_NAME),
+                        new MutableObject<>(activeTsFunc), new MutableObject<>(new ConstantExpression(
+                                new AsterixConstantValue(new AString(BADConstants.FIELD_NAME_ACTIVE_TS)))));
+                AssignOperator assignOp = new AssignOperator(channelTimeVar, new MutableObject<>(faExpr));
+                assignOp.getInputs().add(new MutableObject<>(opRef.getValue()));
+                opRef.setValue(assignOp);
+                activeMap.put(dsVar, channelTimeVar);
+            }
+        }
+        for (Mutable<ILogicalOperator> input : currOp.getInputs()) {
+            createChannelTimeAssignOps(input, needPrevDsSet, needCurrDsSet, needActiveDsSet, prevMap, currMap,
+                    activeMap, context);
+        }
+    }
+
+    private void collectChannelTimeFunctions(Mutable<ILogicalExpression> exprRef,
+            Set<Mutable<ILogicalExpression>> activeFunctionSet, Set<LogicalVariable> needPrevDsSet,
+            Set<LogicalVariable> needCurrDsSet, Set<LogicalVariable> needActive) {
+        if (exprRef.getValue().getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
+            AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) exprRef.getValue();
+            if (funcExpr.getFunctionIdentifier() == BADFunctions.IS_NEW
+                    || funcExpr.getFunctionIdentifier() == BADFunctions.PREVIOUS_CHANNEL_TIME
+                    || funcExpr.getFunctionIdentifier() == BADFunctions.CURRENT_CHANNEL_TIME) {
+                // add to active func set for later replacement
+                activeFunctionSet.add(exprRef);
+                // collect ds var to see what assign op needs to be added
+                LogicalVariable dsVar = ((VariableReferenceExpression) funcExpr.getArguments().get(0).getValue())
+                        .getVariableReference();
+                if (funcExpr.getFunctionIdentifier() == BADFunctions.PREVIOUS_CHANNEL_TIME) {
+                    needPrevDsSet.add(dsVar);
+                } else if (funcExpr.getFunctionIdentifier() == BADFunctions.CURRENT_CHANNEL_TIME) {
+                    needCurrDsSet.add(dsVar);
+                } else {
+                    needActive.add(dsVar);
+                }
+            } else {
+                for (Mutable<ILogicalExpression> argExpr : funcExpr.getArguments()) {
+                    collectChannelTimeFunctions(argExpr, activeFunctionSet, needPrevDsSet, needCurrDsSet, needActive);
+                }
+            }
+        }
+    }
+
+}
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/runtime/ActiveTimestampManager.java b/asterix-bad/src/main/java/org/apache/asterix/bad/runtime/ActiveTimestampManager.java
new file mode 100644
index 0000000..adbbd03
--- /dev/null
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/runtime/ActiveTimestampManager.java
@@ -0,0 +1,97 @@
+/*
+ *
+ *  * 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.bad.runtime;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.hyracks.api.job.JobId;
+
+/*
+ * This only supports one channel currently. Can be extended to multiple channels.
+ * */
+public class ActiveTimestampManager {
+
+    static class ChannelTimeState {
+        long previousChannelExecutionTimestamp;
+        long currentChannelExecutionTimestamp;
+        JobId maxJobId;
+
+        public ChannelTimeState(long prev, long curr, JobId jobId) {
+            this.previousChannelExecutionTimestamp = prev;
+            this.currentChannelExecutionTimestamp = curr;
+            this.maxJobId = jobId;
+        }
+    }
+
+    private static Map<String, ChannelTimeState> channelTimeStateMap = new ConcurrentHashMap<>();
+    private static Logger LOGGER = Logger.getLogger(ActiveTimestampManager.class.getName());
+
+    public static synchronized boolean progressChannelExecutionTimestamps(JobId jobId, String channelName,
+            String nodeId) {
+        if (channelName.equals("")) {
+            return false;
+        }
+        // In distributed cases, channel name would be sufficient. Since in BADExecutionTest, all nodes share the same
+        // JVM, we would need to add the node id as part of the key
+        String channelTimeKey = nodeId + channelName;
+        if (channelTimeStateMap.containsKey(channelTimeKey)) {
+            ChannelTimeState state = channelTimeStateMap.get(channelTimeKey);
+            if (state.maxJobId.compareTo(jobId) < 0) {
+                state.previousChannelExecutionTimestamp = state.currentChannelExecutionTimestamp;
+                state.currentChannelExecutionTimestamp = System.currentTimeMillis();
+                state.maxJobId = jobId;
+                LOGGER.log(Level.FINE, "CHN TS UPD " + channelName + " at " + jobId + " on " + nodeId + " "
+                        + state.previousChannelExecutionTimestamp + "  -  " + state.currentChannelExecutionTimestamp);
+                // System.err.println("CHN TS UPD " + channelName + " at " + jobId + " on " + nodeId + " "
+                //         + state.previousChannelExecutionTimestamp + "  -  " + state.currentChannelExecutionTimestamp);
+                return true;
+            }
+        } else {
+            LOGGER.log(Level.FINE,
+                    "CHN TS INIT " + channelName + " at " + jobId + " 0 - " + System.currentTimeMillis());
+            // System.err.println("CHN TS INIT " + channelName + " at " + jobId + " on node " + nodeId + " 0 - "
+            //         + System.currentTimeMillis());
+            channelTimeStateMap.put(channelTimeKey, new ChannelTimeState(0, System.currentTimeMillis(), jobId));
+        }
+        return false;
+    }
+
+    public static long getPreviousChannelExecutionTimestamp(String channelName, String nodeId) {
+        String channelTimeKey = nodeId + channelName;
+        if (channelTimeStateMap.containsKey(channelTimeKey)) {
+            return channelTimeStateMap.get(channelTimeKey).previousChannelExecutionTimestamp;
+        } else {
+            return 0;
+        }
+    }
+
+    public static long getCurrentChannelExecutionTimestamp(String channelName, String nodeId) {
+        String channelTimeKey = nodeId + channelName;
+        if (channelTimeStateMap.containsKey(channelTimeKey)) {
+            return channelTimeStateMap.get(channelTimeKey).currentChannelExecutionTimestamp;
+        } else {
+            return System.currentTimeMillis();
+        }
+    }
+}
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/runtime/ActiveTimestampState.java b/asterix-bad/src/main/java/org/apache/asterix/bad/runtime/ActiveTimestampState.java
new file mode 100644
index 0000000..ad7e424
--- /dev/null
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/runtime/ActiveTimestampState.java
@@ -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.
+ *
+ */
+package org.apache.asterix.bad.runtime;
+
+import org.apache.hyracks.api.job.JobId;
+import org.apache.hyracks.dataflow.std.base.AbstractStateObject;
+
+public class ActiveTimestampState extends AbstractStateObject {
+
+    private long previousChannelExecutionTime = -1;
+    private long currentChannelExecutionTime = -1;
+
+    public ActiveTimestampState(JobId jobId, Object id) {
+        super(jobId, id);
+    }
+
+    public void setExecutionTime(long prev, long curr) {
+        previousChannelExecutionTime = prev;
+        currentChannelExecutionTime = curr;
+    }
+
+    public long getCurrentChannelExecutionTime() {
+        return currentChannelExecutionTime;
+    }
+
+    public long getPreviousChannelExecutionTime() {
+        return previousChannelExecutionTime;
+    }
+}
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/runtime/NotifyBrokerOperator.java b/asterix-bad/src/main/java/org/apache/asterix/bad/runtime/operators/NotifyBrokerOperator.java
similarity index 86%
rename from asterix-bad/src/main/java/org/apache/asterix/bad/runtime/NotifyBrokerOperator.java
rename to asterix-bad/src/main/java/org/apache/asterix/bad/runtime/operators/NotifyBrokerOperator.java
index 5fc9b22..5425e71 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/runtime/NotifyBrokerOperator.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/runtime/operators/NotifyBrokerOperator.java
@@ -6,9 +6,7 @@
  * 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
@@ -16,7 +14,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.asterix.bad.runtime;
+package org.apache.asterix.bad.runtime.operators;
 
 import java.util.Collection;
 
@@ -33,13 +31,15 @@
     private final LogicalVariable brokerEndpointVar;
     private final LogicalVariable channelExecutionVar;
     private final LogicalVariable pushListVar;
+    private final LogicalVariable brokerTypeVar;
     private final boolean push;
 
     public NotifyBrokerOperator(LogicalVariable brokerEndpointVar, LogicalVariable pushListVar,
-            LogicalVariable resultSetVar, boolean push) {
+            LogicalVariable resultSetVar, LogicalVariable brokerTypeVar, boolean push) {
         this.brokerEndpointVar = brokerEndpointVar;
         this.channelExecutionVar = resultSetVar;
         this.pushListVar = pushListVar;
+        this.brokerTypeVar = brokerTypeVar;
         this.push = push;
     }
 
@@ -55,6 +55,10 @@
         return channelExecutionVar;
     }
 
+    public LogicalVariable getBrokerTypeVar() {
+        return brokerTypeVar;
+    }
+
     public boolean getPush() {
         return push;
     }
@@ -62,7 +66,7 @@
     @Override
     public String toString() {
         return "notify-brokers (" + brokerEndpointVar.toString() + "," + channelExecutionVar.toString() + ","
-                + pushListVar.toString() + ")";
+                + pushListVar.toString() + "," + brokerTypeVar + ")";
     }
 
     @Override
@@ -72,7 +76,7 @@
 
     @Override
     public IOperatorDelegate newInstance() {
-        return new NotifyBrokerOperator(brokerEndpointVar, pushListVar, channelExecutionVar, push);
+        return new NotifyBrokerOperator(brokerEndpointVar, pushListVar, channelExecutionVar, brokerTypeVar, push);
     }
 
     @Override
@@ -86,6 +90,7 @@
         usedVars.add(pushListVar);
         usedVars.add(brokerEndpointVar);
         usedVars.add(channelExecutionVar);
+        usedVars.add(brokerTypeVar);
     }
 
     @Override
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/runtime/NotifyBrokerPOperator.java b/asterix-bad/src/main/java/org/apache/asterix/bad/runtime/operators/NotifyBrokerPOperator.java
similarity index 92%
rename from asterix-bad/src/main/java/org/apache/asterix/bad/runtime/NotifyBrokerPOperator.java
rename to asterix-bad/src/main/java/org/apache/asterix/bad/runtime/operators/NotifyBrokerPOperator.java
index 13cd166..c063f8e 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/runtime/NotifyBrokerPOperator.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/runtime/operators/NotifyBrokerPOperator.java
@@ -6,9 +6,7 @@
  * 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
@@ -17,7 +15,7 @@
  * under the License.
  */
 
-package org.apache.asterix.bad.runtime;
+package org.apache.asterix.bad.runtime.operators;
 
 import org.apache.asterix.active.EntityId;
 import org.apache.asterix.om.types.IAType;
@@ -79,6 +77,7 @@
         LogicalVariable pushListVar = ((NotifyBrokerOperator) notify.getDelegate()).getPushListVar();
         LogicalVariable brokerVar = ((NotifyBrokerOperator) notify.getDelegate()).getBrokerEndpointVariable();
         LogicalVariable executionVar = ((NotifyBrokerOperator) notify.getDelegate()).getChannelExecutionVariable();
+        LogicalVariable brokerTypeVar = ((NotifyBrokerOperator) notify.getDelegate()).getBrokerTypeVar();
 
         IVariableTypeEnvironment env = context.getTypeEnvironment(op.getInputs().get(0).getValue());
         IAType recordType = (IAType) env.getVarType(pushListVar);
@@ -88,13 +87,15 @@
         int brokerColumn = inputSchemas[0].findVariable(brokerVar);
         int pushColumn = inputSchemas[0].findVariable(pushListVar);
         int executionColumn = inputSchemas[0].findVariable(executionVar);
+        int brokerTypeColumn = inputSchemas[0].findVariable(brokerTypeVar);
 
         IScalarEvaluatorFactory brokerEvalFactory = new ColumnAccessEvalFactory(brokerColumn);
         IScalarEvaluatorFactory pushListEvalFactory = new ColumnAccessEvalFactory(pushColumn);
         IScalarEvaluatorFactory channelExecutionEvalFactory = new ColumnAccessEvalFactory(executionColumn);
+        IScalarEvaluatorFactory brokerTypeEvalFactory = new ColumnAccessEvalFactory(brokerTypeColumn);
 
         NotifyBrokerRuntimeFactory runtime = new NotifyBrokerRuntimeFactory(brokerEvalFactory, pushListEvalFactory,
-                channelExecutionEvalFactory, entityId, push, recordType);
+                channelExecutionEvalFactory, brokerTypeEvalFactory, entityId, push, recordType);
 
         RecordDescriptor recDesc =
                 JobGenHelper.mkRecordDescriptor(context.getTypeEnvironment(op), propagatedSchema, context);
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/runtime/NotifyBrokerRuntime.java b/asterix-bad/src/main/java/org/apache/asterix/bad/runtime/operators/NotifyBrokerRuntime.java
similarity index 65%
rename from asterix-bad/src/main/java/org/apache/asterix/bad/runtime/NotifyBrokerRuntime.java
rename to asterix-bad/src/main/java/org/apache/asterix/bad/runtime/operators/NotifyBrokerRuntime.java
index 69fb7d4..14d1500 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/runtime/NotifyBrokerRuntime.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/runtime/operators/NotifyBrokerRuntime.java
@@ -6,9 +6,7 @@
  * 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
@@ -17,7 +15,7 @@
  * under the License.
  */
 
-package org.apache.asterix.bad.runtime;
+package org.apache.asterix.bad.runtime.operators;
 
 import java.io.ByteArrayOutputStream;
 import java.io.DataInputStream;
@@ -31,13 +29,14 @@
 import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import org.apache.asterix.active.EntityId;
 import org.apache.asterix.bad.BADConstants;
 import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.AOrderedlistPrinterFactory;
-import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ARecordPrinterFactory;
 import org.apache.asterix.dataflow.data.nontagged.serde.ADateTimeSerializerDeserializer;
 import org.apache.asterix.dataflow.data.nontagged.serde.AStringSerializerDeserializer;
 import org.apache.asterix.om.base.ADateTime;
@@ -70,45 +69,55 @@
     private static final AStringSerializerDeserializer stringSerDes =
             new AStringSerializerDeserializer(new UTF8StringWriter(), new UTF8StringReader());
 
-    private final IPrinter recordPrinterFactory;
+    private final IPrinter jsonRecordPrinter;
+    private final IPrinter admRecordPrinter;
     private final IPrinter subscriptionIdListPrinterFactory;
 
     private IPointable inputArg0 = new VoidPointable();
     private IPointable inputArg1 = new VoidPointable();
     private IPointable inputArg2 = new VoidPointable();
+    private IPointable inputArg3 = new VoidPointable();
     private IScalarEvaluator eval0;
     private IScalarEvaluator eval1;
     private IScalarEvaluator eval2;
+    private IScalarEvaluator eval3;
+
     private final EntityId entityId;
     private final boolean push;
     private final Map<String, String> sendData = new HashMap<>();
     private final Map<String, ByteArrayOutputStream> sendbaos = new HashMap<>();
     private final Map<String, PrintStream> sendStreams = new HashMap<>();
-    private String executionTimeString;
-    private boolean firstResult = true;
-    String endpoint;
+    private final Map<String, String> brokerTypes = new HashMap<>();
+    private Long executionTimeMili = (long) -1;
 
     public NotifyBrokerRuntime(IHyracksTaskContext ctx, IScalarEvaluatorFactory brokerEvalFactory,
             IScalarEvaluatorFactory pushListEvalFactory, IScalarEvaluatorFactory channelExecutionEvalFactory,
-            EntityId activeJobId, boolean push, IAType recordType) throws HyracksDataException {
+            IScalarEvaluatorFactory brokerTypeEvalFactory, EntityId activeJobId, boolean push, IAType recordType)
+            throws HyracksDataException {
         this.tRef = new FrameTupleReference();
         IEvaluatorContext evalCtx = new EvaluatorContext(ctx);
         eval0 = brokerEvalFactory.createScalarEvaluator(evalCtx);
         eval1 = pushListEvalFactory.createScalarEvaluator(evalCtx);
         eval2 = channelExecutionEvalFactory.createScalarEvaluator(evalCtx);
+        eval3 = brokerTypeEvalFactory.createScalarEvaluator(evalCtx);
+
         this.entityId = activeJobId;
         this.push = push;
         if (push) {
             //for push-based channel, the recordType is the result record type (records are sent directly)
-            recordPrinterFactory = new ARecordPrinterFactory((ARecordType) recordType).createPrinter();
+            jsonRecordPrinter =
+                    new org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ARecordPrinterFactory(
+                            (ARecordType) recordType).createPrinter();
+            admRecordPrinter = new org.apache.asterix.dataflow.data.nontagged.printers.adm.ARecordPrinterFactory(
+                    (ARecordType) recordType).createPrinter();
         } else {
             //for pull-based channels, the recordType is a list of subscription ids
             //the subscriptionIdListPrinterFactory is used instead
-            recordPrinterFactory = null;
+            jsonRecordPrinter = null;
+            admRecordPrinter = null;
         }
         subscriptionIdListPrinterFactory =
                 new AOrderedlistPrinterFactory(new AOrderedListType(BuiltinType.AUUID, null)).createPrinter();
-        executionTimeString = null;
     }
 
     @Override
@@ -117,48 +126,46 @@
     }
 
     public String createData(String endpoint) {
-        String resultTitle = "\"subscriptionIds\"";
-        if (push) {
-            resultTitle = "\"results\"";
-        }
+        String resultTitle = push ? "\"results\"" : "\"subscriptionIds\"";
         String jsonStr = "{ \"dataverseName\":\"" + entityId.getDataverseName().getCanonicalForm()
-                + "\", \"channelName\":\"" + entityId.getEntityName() + "\", \"" + BADConstants.ChannelExecutionTime
-                + "\":\"" + executionTimeString + "\", " + resultTitle + ":[";
+                + "\", \"channelName\":\"" + entityId.getEntityName() + "\", \""
+                + BADConstants.CHANNEL_EXECUTION_EPOCH_TIME + "\":" + executionTimeMili + ", " + resultTitle + ":[";
         jsonStr += sendData.get(endpoint);
-        jsonStr = jsonStr.substring(0, jsonStr.length());
         jsonStr += "]}";
         return jsonStr;
-
     }
 
     private void sendGroupOfResults(String endpoint) {
         String urlParameters = createData(endpoint);
-        try {
-            //Create connection
-            URL url = new URL(endpoint);
-            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
-            connection.setRequestMethod("POST");
-            connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
+        ExecutorService executor = Executors.newSingleThreadExecutor();
+        executor.submit(() -> {
+            try {
+                //Create connection
+                URL url = new URL(endpoint);
+                HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+                connection.setRequestMethod("POST");
+                connection.setRequestProperty("Content-Type", "application/json");
 
-            connection.setRequestProperty("Content-Length", Integer.toString(urlParameters.getBytes().length));
-            connection.setRequestProperty("Content-Language", "en-US");
+                connection.setRequestProperty("Content-Length", Integer.toString(urlParameters.getBytes().length));
+                connection.setRequestProperty("Content-Language", "en-US");
 
-            connection.setUseCaches(false);
-            connection.setDoOutput(true);
-            connection.setConnectTimeout(500);
-            DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
-            wr.writeBytes(urlParameters);
-            if (LOGGER.isLoggable(Level.INFO)) {
-                int responseCode = connection.getResponseCode();
-                LOGGER.info("\nSending 'POST' request to URL : " + url);
-                LOGGER.info("Post parameters : " + urlParameters);
-                LOGGER.info("Response Code : " + responseCode);
+                connection.setUseCaches(false);
+                connection.setDoOutput(true);
+                connection.setConnectTimeout(500);
+                DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
+                wr.writeBytes(urlParameters);
+                if (LOGGER.isLoggable(Level.INFO)) {
+                    int responseCode = connection.getResponseCode();
+                    LOGGER.info("\nSending 'POST' request to URL : " + url);
+                    LOGGER.info("Post parameters : " + urlParameters);
+                    LOGGER.info("Response Code : " + responseCode);
+                }
+                wr.close();
+                connection.disconnect();
+            } catch (Exception e) {
+                LOGGER.log(Level.WARNING, "Channel Failed to connect to Broker.");
             }
-            wr.close();
-            connection.disconnect();
-        } catch (Exception e) {
-            LOGGER.log(Level.WARNING, "Channel Failed to connect to Broker.");
-        }
+        });
     }
 
     @Override
@@ -171,47 +178,55 @@
             eval0.evaluate(tRef, inputArg0);
             eval1.evaluate(tRef, inputArg1);
             eval2.evaluate(tRef, inputArg2);
+            eval3.evaluate(tRef, inputArg3);
 
             /*The incoming tuples have three fields:
              1. eval0 will get the serialized broker endpoint string
              2. eval1 will get the payload (either the subscriptionIds or entire results)
              3. eval2 will get the channel execution time stamp (the same for all tuples)
             */
-            if (executionTimeString == null) {
+            if (executionTimeMili == -1) {
                 int resultSetOffset = inputArg2.getStartOffset();
                 bbis.setByteBuffer(tRef.getFrameTupleAccessor().getBuffer(), resultSetOffset + 1);
                 ADateTime executionTime = ADateTimeSerializerDeserializer.INSTANCE.deserialize(di);
-                executionTimeString = executionTime.toSimpleString();
+                executionTimeMili = executionTime.getChrononTime();
             }
 
+            // Get HTTP endpoint
             int serBrokerOffset = inputArg0.getStartOffset();
             bbis.setByteBuffer(tRef.getFrameTupleAccessor().getBuffer(), serBrokerOffset + 1);
-            endpoint = stringSerDes.deserialize(di).getStringValue();
-            sendbaos.putIfAbsent(endpoint, new ByteArrayOutputStream());
-            try {
-                sendStreams.putIfAbsent(endpoint,
-                        new PrintStream(sendbaos.get(endpoint), true, StandardCharsets.UTF_8.name()));
-            } catch (UnsupportedEncodingException e) {
-                throw new HyracksDataException(e.getMessage());
+            String endpoint = stringSerDes.deserialize(di).getStringValue();
+
+            // Get broker type
+            int serTypeOffset = inputArg3.getStartOffset();
+            bbis.setByteBuffer(tRef.getFrameTupleAccessor().getBuffer(), serTypeOffset + 1);
+            String brokerType = stringSerDes.deserialize(di).getStringValue();
+            IPrinter currPrinter =
+                    brokerType.equals(BADConstants.BAD_BROKER_TYPE_NAME) ? admRecordPrinter : jsonRecordPrinter;
+
+            PrintStream currPrintStream = sendStreams.getOrDefault(endpoint, null);
+            if (currPrintStream == null) {
+                try {
+                    ByteArrayOutputStream newOutput = new ByteArrayOutputStream();
+                    sendbaos.putIfAbsent(endpoint, newOutput);
+                    sendStreams.put(endpoint, new PrintStream(newOutput, true, StandardCharsets.UTF_8.name()));
+                } catch (UnsupportedEncodingException e) {
+                    throw new HyracksDataException(e.getMessage());
+                }
+                currPrintStream = sendStreams.get(endpoint);
+            } else {
+                currPrintStream.append(',');
             }
 
             if (push) {
                 int pushOffset = inputArg1.getStartOffset();
                 bbis.setByteBuffer(tRef.getFrameTupleAccessor().getBuffer(), pushOffset + 1);
-                if (!firstResult) {
-                    sendStreams.get(endpoint).append(',');
-                }
-                recordPrinterFactory.print(inputArg1.getByteArray(), inputArg1.getStartOffset(), inputArg1.getLength(),
-                        sendStreams.get(endpoint));
-
+                currPrinter.print(inputArg1.getByteArray(), inputArg1.getStartOffset(), inputArg1.getLength(),
+                        currPrintStream);
             } else {
-                if (!firstResult) {
-                    sendStreams.get(endpoint).append(',');
-                }
                 subscriptionIdListPrinterFactory.print(inputArg1.getByteArray(), inputArg1.getStartOffset(),
-                        inputArg1.getLength(), sendStreams.get(endpoint));
+                        inputArg1.getLength(), currPrintStream);
             }
-            firstResult = false;
         }
 
     }
diff --git a/asterix-bad/src/main/java/org/apache/asterix/bad/runtime/NotifyBrokerRuntimeFactory.java b/asterix-bad/src/main/java/org/apache/asterix/bad/runtime/operators/NotifyBrokerRuntimeFactory.java
similarity index 86%
rename from asterix-bad/src/main/java/org/apache/asterix/bad/runtime/NotifyBrokerRuntimeFactory.java
rename to asterix-bad/src/main/java/org/apache/asterix/bad/runtime/operators/NotifyBrokerRuntimeFactory.java
index a7f12ba..b4c11ca 100644
--- a/asterix-bad/src/main/java/org/apache/asterix/bad/runtime/NotifyBrokerRuntimeFactory.java
+++ b/asterix-bad/src/main/java/org/apache/asterix/bad/runtime/operators/NotifyBrokerRuntimeFactory.java
@@ -6,9 +6,7 @@
  * 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
@@ -17,7 +15,7 @@
  * under the License.
  */
 
-package org.apache.asterix.bad.runtime;
+package org.apache.asterix.bad.runtime.operators;
 
 import org.apache.asterix.active.EntityId;
 import org.apache.asterix.om.types.IAType;
@@ -34,16 +32,18 @@
     private final IScalarEvaluatorFactory brokerEvalFactory;
     private final IScalarEvaluatorFactory pushListEvalFactory;
     private final IScalarEvaluatorFactory channelExecutionEvalFactory;
+    private final IScalarEvaluatorFactory brokerTypeEvalFactory;
     private final EntityId entityId;
     private final boolean push;
     private final IAType recordType;
 
     public NotifyBrokerRuntimeFactory(IScalarEvaluatorFactory brokerEvalFactory,
             IScalarEvaluatorFactory pushListEvalFactory, IScalarEvaluatorFactory channelExecutionEvalFactory,
-            EntityId entityId, boolean push, IAType recordType) {
+            IScalarEvaluatorFactory brokerTypeEvalFactory, EntityId entityId, boolean push, IAType recordType) {
         this.brokerEvalFactory = brokerEvalFactory;
         this.pushListEvalFactory = pushListEvalFactory;
         this.channelExecutionEvalFactory = channelExecutionEvalFactory;
+        this.brokerTypeEvalFactory = brokerTypeEvalFactory;
         this.entityId = entityId;
         this.push = push;
         this.recordType = recordType;
@@ -57,6 +57,6 @@
     @Override
     public IPushRuntime[] createPushRuntime(IHyracksTaskContext ctx) throws HyracksDataException {
         return new IPushRuntime[] { new NotifyBrokerRuntime(ctx, brokerEvalFactory, pushListEvalFactory,
-                channelExecutionEvalFactory, entityId, push, recordType) };
+                channelExecutionEvalFactory, brokerTypeEvalFactory, entityId, push, recordType) };
     }
 }
diff --git a/asterix-bad/src/main/resources/META-INF/services/org.apache.asterix.om.functions.IFunctionRegistrant b/asterix-bad/src/main/resources/META-INF/services/org.apache.asterix.om.functions.IFunctionRegistrant
new file mode 100644
index 0000000..fdb3724
--- /dev/null
+++ b/asterix-bad/src/main/resources/META-INF/services/org.apache.asterix.om.functions.IFunctionRegistrant
@@ -0,0 +1,20 @@
+#
+# 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.
+#
+
+org.apache.asterix.bad.function.BADFunctionRegistrant
\ No newline at end of file
diff --git a/asterix-bad/src/main/resources/asterix-build-configuration.xml b/asterix-bad/src/main/resources/asterix-build-configuration.xml
index 6007416..0f3cec9 100644
--- a/asterix-bad/src/main/resources/asterix-build-configuration.xml
+++ b/asterix-bad/src/main/resources/asterix-build-configuration.xml
@@ -36,13 +36,13 @@
   </transactionLogDir>
   <extensions>
     <extension>
-      <extensionClassName>org.apache.asterix.bad.lang.BADQueryTranslatorExtension</extensionClassName>
+      <extensionClassName>org.apache.asterix.bad.extension.BADQueryTranslatorExtension</extensionClassName>
     </extension>
     <extension>
-      <extensionClassName>org.apache.asterix.bad.lang.BADLangExtension</extensionClassName>
+      <extensionClassName>org.apache.asterix.bad.extension.BADLangExtension</extensionClassName>
     </extension>
     <extension>
-      <extensionClassName>org.apache.asterix.bad.metadata.BADMetadataExtension</extensionClassName>
+      <extensionClassName>org.apache.asterix.bad.extension.BADMetadataExtension</extensionClassName>
     </extension>
   </extensions>
   <property>
diff --git a/asterix-bad/src/main/resources/cc.conf b/asterix-bad/src/main/resources/cc.conf
index 371cbe8..9e9d26b 100644
--- a/asterix-bad/src/main/resources/cc.conf
+++ b/asterix-bad/src/main/resources/cc.conf
@@ -53,11 +53,11 @@
 messaging.frame.size=4096
 messaging.frame.count=512
 
-[extension/org.apache.asterix.bad.lang.BADQueryTranslatorExtension]
+[extension/org.apache.asterix.bad.extension.BADQueryTranslatorExtension]
 enabled = true
-[extension/org.apache.asterix.bad.lang.BADLangExtension]
+[extension/org.apache.asterix.bad.extension.BADLangExtension]
 enabled = true
-[extension/org.apache.asterix.bad.metadata.BADMetadataExtension]
+[extension/org.apache.asterix.bad.extension.BADMetadataExtension]
 enabled = true
-[extension/org.apache.asterix.bad.recovery.BADRecoveryExtension]
+[extension/org.apache.asterix.bad.extension.BADRecoveryExtension]
 enabled = true
\ No newline at end of file
diff --git a/asterix-bad/src/main/resources/lang-extension/lang.txt b/asterix-bad/src/main/resources/lang-extension/lang.txt
index 59e1a8d..f2b6410 100644
--- a/asterix-bad/src/main/resources/lang-extension/lang.txt
+++ b/asterix-bad/src/main/resources/lang-extension/lang.txt
@@ -22,7 +22,9 @@
 import org.apache.asterix.bad.lang.statement.ChannelSubscribeStatement;
 import org.apache.asterix.bad.lang.statement.ChannelUnsubscribeStatement;
 import org.apache.asterix.bad.lang.statement.CreateBrokerStatement;
-import org.apache.asterix.bad.lang.statement.CreateChannelStatement;
+import org.apache.asterix.bad.lang.statement.AbstractCreateChannelStatement;
+import org.apache.asterix.bad.lang.statement.CreateRepetitiveChannelStatement;
+import org.apache.asterix.bad.lang.statement.CreateContinuousChannelStatement;
 import org.apache.asterix.bad.lang.statement.CreateProcedureStatement;
 import org.apache.asterix.bad.lang.statement.ExecuteProcedureStatement;
 import org.apache.asterix.bad.lang.statement.ProcedureDropStatement;
@@ -30,6 +32,21 @@
 import org.apache.asterix.lang.sqlpp.parser.SqlppParseException;
 import org.apache.asterix.lang.sqlpp.parser.Token;
 
+@new
+<DEFAULT,IN_DBL_BRACE>
+TOKEN [IGNORE_CASE]:
+{
+  <BROKER : "broker">
+  |  <CHANNEL : "channel">
+  |  <PROCEDURE : "procedure">
+  |  <SUBSCRIBE : "subscribe">
+  |  <ACTIVE : "active">
+  | <UNSUBSCRIBE : "unsubscribe">
+  | <REPETITIVE : "repetitive">
+  | <CONTINUOUS : "continuous">
+  | <PERIOD : "period">
+  | <PUSH : "push">
+}
 
 @merge
 Statement SingleStatement() throws ParseException:
@@ -59,9 +76,10 @@
   (
     // merge area 2
     before:
-    after:    | stmt = CreateChannelStatement()
-              | stmt = CreateBrokerStatement()
+    after:    | stmt = CreateChannelStatement(startToken)
+              | stmt = CreateBrokerStatement(startToken)
               | stmt = CreateProcedureStatement()
+              | stmt = ActiveStatementSpecification(startToken)
   )
   {
     // merge area 3
@@ -89,29 +107,160 @@
 }
 
 @new
-CreateChannelStatement CreateChannelStatement() throws ParseException:
+Statement ActiveStatementSpecification(Token startStmtToken) throws ParseException:
+{
+    Statement stmt = null;
+}
+{
+  "ACTIVE"
+   stmt = ActiveDatasetSpecification(startStmtToken)
+  {
+      return stmt;
+  }
+}
+
+@new
+DatasetDecl ActiveDatasetSpecification(Token startStmtToken) throws ParseException:
+{
+  Pair<DataverseName,Identifier> nameComponents = null;
+  TypeExpression activeRecordTypeExpr = new TypeReferenceExpression(
+                new Pair<DataverseName,Identifier>(DataverseName.createBuiltinDataverseName("Metadata"), new Identifier("ActiveRecordType")));
+  TypeExpression datasetTypeExpr = null;
+  boolean ifNotExists = false;
+  Map<String,String> properties = null;
+  Pair<List<Integer>, List<List<String>>> primaryKeyFields = null;
+  String nodeGroupName = null;
+  Map<String,String> hints = new HashMap<String,String>();
+  DatasetDecl stmt = null;
+  boolean autogenerated = false;
+  RecordConstructor withRecord = null;
+
+}
+{
+    Dataset() nameComponents = QualifiedName()
+    datasetTypeExpr = DatasetTypeSpecification()
+    ifNotExists = IfNotExists()
+    primaryKeyFields = PrimaryKey()
+    (<AUTOGENERATED> { autogenerated = true; } )?
+    (<ON> nodeGroupName = Identifier() )?
+    ( <HINTS> hints = Properties() )?
+    ( <WITH> withRecord = RecordConstructor() )?
+      {
+        // TODO: add filters on meta records
+        InternalDetailsDecl idd = new InternalDetailsDecl(primaryKeyFields.second,
+                                                          primaryKeyFields.first,
+                                                          autogenerated,
+                                                          null);
+        try{
+        stmt = new DatasetDecl(nameComponents.first,
+                                   nameComponents.second,
+                                   datasetTypeExpr,
+                                   activeRecordTypeExpr,
+                                   nodeGroupName != null ? new Identifier(nodeGroupName) : null,
+                                   hints,
+                                   DatasetType.INTERNAL,
+                                   idd,
+                                   withRecord,
+                                   ifNotExists);
+
+        } catch (CompilationException e){
+           throw new SqlppParseException(getSourceLocation(startStmtToken), e.getMessage());
+        }
+      }
+    {
+      return addSourceLocation(stmt, startStmtToken);
+    }
+}
+
+
+@new
+AbstractCreateChannelStatement CreateChannelStatement(Token startStmtToken) throws ParseException:
+{
+  AbstractCreateChannelStatement ccs = null;
+}
+{
+  (
+    <REPETITIVE> { ccs = CreateRepetitiveChannel(startStmtToken); }
+    | <CONTINUOUS> { ccs = CreateContinuousChannel(startStmtToken); }
+  )
+  {
+    return ccs;
+  }
+}
+
+@new
+CreateRepetitiveChannelStatement CreateRepetitiveChannel(Token startStmtToken) throws ParseException:
 {
   Pair<DataverseName,Identifier> nameComponents = null;
   FunctionSignature appliedFunction = null;
-  CreateChannelStatement ccs = null;
+  CreateRepetitiveChannelStatement ccs = null;
   String fqFunctionName = null;
   Expression period = null;
   boolean push = false;
 }
 {
-  (
-    "repetitive"
-    ( "push" { push = true; } )?
-     "channel"  nameComponents = QualifiedName()
-    <USING> appliedFunction = FunctionSignature()
-    "period" period = FunctionCallExpr()
+  ( <PUSH> { push = true; } )?
+  <CHANNEL>  nameComponents = QualifiedName()
+  <USING> appliedFunction = FunctionSignature()
+  <PERIOD> period = FunctionCallExpr()
+  {
+    ccs = new CreateRepetitiveChannelStatement(nameComponents.first,
+                                 nameComponents.second, appliedFunction, period, push);
+  }
+  {
+    return ccs;
+  }
+}
+
+
+@new
+CreateContinuousChannelStatement CreateContinuousChannel(Token startStmtToken) throws ParseException:
+{
+  // Channel related
+  CreateContinuousChannelStatement ccs = null;
+  Expression period = null;
+  boolean push = false;
+  boolean ifNotExists = false;
+  // Function related
+  FunctionSignature signature;
+  String functionBody;
+  Expression functionBodyExpr;
+  Token beginPos;
+  Token endPos;
+  FunctionName fctName = null;
+  TypeExpression returnType = null;
+  List<Pair<VarIdentifier,TypeExpression>> params = null;
+  DataverseName currentDataverse = defaultDataverse;
+}
+{
+     ( <PUSH> { push = true; } )?
+     <CHANNEL>
+     fctName = FunctionName()
+     {
+        defaultDataverse = fctName.dataverse;
+     }
+     ifNotExists = IfNotExists()
+     params = FunctionParameters()
+     <PERIOD> period = FunctionCallExpr()
+    <LEFTBRACE>
+      {
+        createNewScope();
+        beginPos = token;
+      }
+      functionBodyExpr = FunctionBody()
+      returnType = FunctionReturnType()
+    <RIGHTBRACE>
     {
-      ccs = new CreateChannelStatement(nameComponents.first,
-                                   nameComponents.second, appliedFunction, period, push);
-    }
-  )
-    {
-      return ccs;
+      endPos = token;
+      functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
+      signature = new FunctionSignature(fctName.dataverse, fctName.function, params.size());
+      getCurrentScope().addFunctionDescriptor(signature, false);
+      removeCurrentScope();
+      defaultDataverse = currentDataverse;
+      ensureNoTypeDeclsInFunction(fctName.function, params, returnType, startStmtToken);
+      CreateFunctionStatement stmt = new CreateFunctionStatement(signature, params, functionBody, functionBodyExpr, false);
+      ccs =  new CreateContinuousChannelStatement(fctName.dataverse, new Identifier(fctName.function), period, push, stmt);
+      return addSourceLocation(ccs, startStmtToken);
     }
 }
 
@@ -131,7 +280,7 @@
   createNewScope();
 }
 {
-     "procedure" fctName = FunctionName()
+     <PROCEDURE> fctName = FunctionName()
      {
         defaultDataverse = fctName.dataverse;
      }
@@ -154,7 +303,7 @@
       removeCurrentScope();
       defaultDataverse = currentDataverse;
     }
-  ("period" period = FunctionCallExpr())?
+  (<PERIOD> period = FunctionCallExpr())?
   {
   List<VarIdentifier> paramListVariablesOnly = new ArrayList<VarIdentifier>();
   for(Pair<VarIdentifier,TypeExpression> p: paramList){
@@ -195,18 +344,24 @@
 }
 
 @new
-CreateBrokerStatement CreateBrokerStatement() throws ParseException:
+CreateBrokerStatement CreateBrokerStatement(Token startStmtToken) throws ParseException:
 {
   CreateBrokerStatement cbs = null;
   Pair<DataverseName,Identifier> name = null;
   String endPoint = null;
+  RecordConstructor withRecord = null;
 }
 {
   (
-    "broker"  name = QualifiedName()
+    <BROKER>  name = QualifiedName()
     <AT>  endPoint = StringLiteral()
+    ( <WITH> withRecord = RecordConstructor() )?
     {
-      cbs = new CreateBrokerStatement(name.first, name.second,endPoint);
+      try {
+        cbs = new CreateBrokerStatement(name.first, name.second, endPoint, withRecord);
+      } catch (CompilationException e) {
+        throw new SqlppParseException(getSourceLocation(startStmtToken), e.getMessage());
+      }
     }
   )
     {
@@ -227,7 +382,7 @@
 }
 {
   (
-  "subscribe" <TO> nameComponents = QualifiedName()
+  <SUBSCRIBE> <TO> nameComponents = QualifiedName()
    <LEFTPAREN> (tmp = Expression()
    {
       argList.add(tmp);
@@ -240,7 +395,7 @@
    {
       stmt = new ChannelSubscribeStatement(nameComponents.first, nameComponents.second, argList, getVarCounter(), brokerName.first, brokerName.second, subscriptionId);
    }
-   | "unsubscribe" id = StringLiteral() <FROM> nameComponents = QualifiedName()
+   | <UNSUBSCRIBE> id = StringLiteral() <FROM> nameComponents = QualifiedName()
       {
         VariableExpr varExp = new VariableExpr(new VarIdentifier("$subscriptionPlaceholder"));
         getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
@@ -274,7 +429,7 @@
   boolean ifExists = false;
 }
 {
-  "channel" pairId = QualifiedName() ifExists = IfExists()
+  <CHANNEL> pairId = QualifiedName() ifExists = IfExists()
   {
     stmt = new ChannelDropStatement(pairId.first, pairId.second, ifExists);
     return addSourceLocation(stmt, startStmtToken);
@@ -289,7 +444,7 @@
   boolean ifExists = false;
 }
 {
-  "broker" pairId = QualifiedName() ifExists = IfExists()
+  <BROKER> pairId = QualifiedName() ifExists = IfExists()
   {
     stmt = new BrokerDropStatement(pairId.first, pairId.second, ifExists);
     return addSourceLocation(stmt, startStmtToken);
@@ -304,7 +459,7 @@
   boolean ifExists = false;
 }
 {
-  "procedure" funcSig = FunctionSignature() ifExists = IfExists()
+  <PROCEDURE> funcSig = FunctionSignature() ifExists = IfExists()
   {
     stmt = new ProcedureDropStatement(funcSig, ifExists);
     return addSourceLocation(stmt, startStmtToken);
diff --git a/asterix-bad/src/main/resources/log4j2-bad.xml b/asterix-bad/src/main/resources/log4j2-bad.xml
new file mode 100644
index 0000000..fcbb6bb
--- /dev/null
+++ b/asterix-bad/src/main/resources/log4j2-bad.xml
@@ -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.
+ !-->
+<Configuration status="WARN">
+  <Appenders>
+    <Console name="Console" target="SYSTEM_OUT">
+      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
+    </Console>
+    <File name="InfoLog" fileName="target/info.log">
+        <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
+    </File>
+  </Appenders>
+  <Loggers>
+    <Root level="INFO">
+      <AppenderRef ref="InfoLog"/>
+    </Root>
+    <Logger name="org.apache.hyracks.control.nc.service" level="INFO"/>
+    <Logger name="org.apache.hyracks" level="INFO"/>
+    <Logger name="org.apache.asterix" level="INFO"/>
+    <Logger name="org.apache.hyracks.algebricks" level="TRACE">
+      <AppenderRef ref="Console"/>
+    </Logger>
+    <Logger name="org.apache.hyracks.algebricks" level="TRACE">
+      <AppenderRef ref="InfoLog"/>
+    </Logger>
+    <Logger name="org.apache.asterix.bad.metadata" level="WARN">
+      <AppenderRef ref="Console"/>
+    </Logger>
+  </Loggers>
+</Configuration>
diff --git a/asterix-bad/src/test/java/org/apache/asterix/bad/test/BADAsterixHyracksIntegrationUtil.java b/asterix-bad/src/test/java/org/apache/asterix/bad/test/BADAsterixHyracksIntegrationUtil.java
index aa1f17b..fcaa67b 100644
--- a/asterix-bad/src/test/java/org/apache/asterix/bad/test/BADAsterixHyracksIntegrationUtil.java
+++ b/asterix-bad/src/test/java/org/apache/asterix/bad/test/BADAsterixHyracksIntegrationUtil.java
@@ -19,6 +19,7 @@
 package org.apache.asterix.bad.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;
 
@@ -26,31 +27,14 @@
 public class BADAsterixHyracksIntegrationUtil extends AsterixHyracksIntegrationUtil {
 
     public static void main(String[] args) throws Exception {
+        TestUtils.redirectLoggingToConsole();
         BADAsterixHyracksIntegrationUtil integrationUtil = new BADAsterixHyracksIntegrationUtil();
         try {
-            integrationUtil.run(Boolean.getBoolean("cleanup.start"), Boolean.getBoolean("cleanup.shutdown"),
-                    System.getProperty("external.lib", ""));
+            integrationUtil.run(true, Boolean.getBoolean("cleanup.shutdown"),
+                    System.getProperty("external.lib", "asterixdb/asterix-opt/asterix-bad/src/main/resources/cc.conf"));
         } catch (Exception e) {
+            e.printStackTrace();
             System.exit(1);
         }
     }
-
-    @Override
-    protected void run(boolean cleanupOnStart, boolean cleanupOnShutdown, String loadExternalLibs) throws Exception {
-        Runtime.getRuntime().addShutdownHook(new Thread() {
-            @Override
-            public void run() {
-                try {
-                    deinit(cleanupOnShutdown);
-                } catch (Exception e) {
-
-                }
-            }
-        });
-        init(cleanupOnStart, "asterixdb/asterix-opt/asterix-bad/src/main/resources/cc.conf");
-        while (true) {
-            Thread.sleep(10000);
-        }
-    }
-
 }
diff --git a/asterix-bad/src/test/java/org/apache/asterix/bad/test/BADExecutionTest.java b/asterix-bad/src/test/java/org/apache/asterix/bad/test/BADExecutionTest.java
index f88a327..3153907 100644
--- a/asterix-bad/src/test/java/org/apache/asterix/bad/test/BADExecutionTest.java
+++ b/asterix-bad/src/test/java/org/apache/asterix/bad/test/BADExecutionTest.java
@@ -23,7 +23,6 @@
 import java.util.Collection;
 import java.util.logging.Logger;
 
-import org.apache.asterix.api.common.AsterixHyracksIntegrationUtil;
 import org.apache.asterix.common.config.TransactionProperties;
 import org.apache.asterix.test.common.TestExecutor;
 import org.apache.asterix.test.runtime.ExecutionTestUtil;
@@ -56,6 +55,8 @@
     private static final TestExecutor testExecutor = new TestExecutor();
     private static final boolean cleanupOnStart = true;
     private static final boolean cleanupOnStop = true;
+    private static final String TEST_SUITE_FILE = "testsuite_bad.xml";
+    private static final String ONLY_SUITE_FILE = "only_bad.xml";
 
     protected static TestGroup FailedGroup;
     protected TestLsmBtreeLocalResource resource = null;
@@ -64,7 +65,7 @@
     public static void setUp() throws Exception {
         File outdir = new File(PATH_ACTUAL);
         outdir.mkdirs();
-        ExecutionTestUtil.setUp(cleanupOnStart, TEST_CONFIG_FILE_NAME, new AsterixHyracksIntegrationUtil(), false,
+        ExecutionTestUtil.setUp(cleanupOnStart, TEST_CONFIG_FILE_NAME, new BADAsterixHyracksIntegrationUtil(), false,
                 null);
     }
 
@@ -76,7 +77,11 @@
 
     @Parameters(name = "BADExecutionTest {index}: {0}")
     public static Collection<Object[]> tests() throws Exception {
-        return buildTestsInXml("testsuite.xml");
+        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 {
diff --git a/asterix-bad/src/test/java/org/apache/asterix/bad/test/BADListenerTest.java b/asterix-bad/src/test/java/org/apache/asterix/bad/test/BADListenerTest.java
index 09dc38c..8c6fa75 100644
--- a/asterix-bad/src/test/java/org/apache/asterix/bad/test/BADListenerTest.java
+++ b/asterix-bad/src/test/java/org/apache/asterix/bad/test/BADListenerTest.java
@@ -68,7 +68,7 @@
     @BeforeClass
     public static void init() {
         djsel = new DeployedJobSpecEventListener(null,
-                new EntityId(BADConstants.CHANNEL_EXTENSION_NAME, DataverseName.createSinglePartName("test"), "test"),
+                new EntityId(BADConstants.RUNTIME_ENTITY_CHANNEL, DataverseName.createSinglePartName("test"), "test"),
                 DeployedJobSpecEventListener.PrecompiledType.CHANNEL);
     }
 
diff --git a/asterix-bad/src/test/java/org/apache/asterix/bad/test/BADMetadataTest.java b/asterix-bad/src/test/java/org/apache/asterix/bad/test/BADMetadataTest.java
new file mode 100644
index 0000000..3448331
--- /dev/null
+++ b/asterix-bad/src/test/java/org/apache/asterix/bad/test/BADMetadataTest.java
@@ -0,0 +1,86 @@
+/*
+ * 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.bad.test;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.asterix.api.common.AsterixHyracksIntegrationUtil;
+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;
+
+/**
+ * Executes the Metadata tests.
+ */
+@RunWith(Parameterized.class)
+public class BADMetadataTest {
+
+    private TestCaseContext tcCtx;
+
+    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);
+    protected static final String TEST_CONFIG_FILE_NAME = "src/main/resources/cc.conf";
+
+    private static final TestExecutor testExecutor = new TestExecutor();
+    private static AsterixHyracksIntegrationUtil integrationUtil = new AsterixHyracksIntegrationUtil();
+
+    @BeforeClass
+    public static void setUp() throws Exception {
+        File outdir = new File(PATH_ACTUAL);
+        outdir.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) {
+            outdir.delete();
+        }
+    }
+
+    @Parameters(name = "MetadataTest {index}: {0}")
+    public static Collection<Object[]> tests() throws Exception {
+        Collection<Object[]> testArgs = new ArrayList<Object[]>();
+        TestCaseContext.Builder b = new TestCaseContext.Builder();
+        for (TestCaseContext ctx : b.build(new File(PATH_BASE))) {
+            testArgs.add(new Object[] { ctx });
+        }
+        return testArgs;
+    }
+
+    public BADMetadataTest(TestCaseContext tcCtx) {
+        this.tcCtx = tcCtx;
+    }
+
+    @Test
+    public void test() throws Exception {
+        testExecutor.executeTest(PATH_ACTUAL, tcCtx, null, false);
+    }
+
+}
diff --git a/asterix-bad/src/test/java/org/apache/asterix/bad/test/BADOptimizerTest.java b/asterix-bad/src/test/java/org/apache/asterix/bad/test/BADOptimizerTest.java
index 6c409a1..16602be 100644
--- a/asterix-bad/src/test/java/org/apache/asterix/bad/test/BADOptimizerTest.java
+++ b/asterix-bad/src/test/java/org/apache/asterix/bad/test/BADOptimizerTest.java
@@ -39,9 +39,9 @@
     public static void setUp() throws Exception {
         final File outdir = new File(PATH_ACTUAL);
         outdir.mkdirs();
-
         extensionLangCompilationProvider = new BADCompilationProvider();
         statementExecutorFactory = new BADQueryTranslatorFactory();
+        integrationUtil = new BADAsterixHyracksIntegrationUtil();
 
         integrationUtil.init(true, TEST_CONFIG_FILE_NAME);
         // Set the node resolver to be the identity resolver that expects node names
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp b/asterix-bad/src/test/resources/metadata/queries/bad_cq/continuous_channel/continuous_channel.1.ddl.sqlpp
similarity index 68%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
copy to asterix-bad/src/test/resources/metadata/queries/bad_cq/continuous_channel/continuous_channel.1.ddl.sqlpp
index b1a132b..6f47dd1 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
+++ b/asterix-bad/src/test/resources/metadata/queries/bad_cq/continuous_channel/continuous_channel.1.ddl.sqlpp
@@ -16,12 +16,23 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Disasters with friends
-* Expected Res : Success
-* Date         : May 17
-* Author       : Steven Jacobs
-*/
-use channels;
+DROP DATAVERSE test IF EXISTS;
+CREATE DATAVERSE test;
+USE test;
 
-subscribe to EmergenciesNearMeChannel("tornado", 1) on brokerA;
+CREATE TYPE Tweet AS OPEN {
+ tid: bigint,
+ area_code: string,
+ text: string,
+ location: point,
+ timestamp: datetime
+};
+
+CREATE ACTIVE DATASET Tweets(Tweet) PRIMARY KEY tid;
+
+CREATE TYPE School AS OPEN {
+  sid: bigint,
+  area_code: string,
+  name: string
+};
+CREATE DATASET Schools(School) PRIMARY KEY sid;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp b/asterix-bad/src/test/resources/metadata/queries/bad_cq/continuous_channel/continuous_channel.2.update.sqlpp
similarity index 74%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
copy to asterix-bad/src/test/resources/metadata/queries/bad_cq/continuous_channel/continuous_channel.2.update.sqlpp
index b1a132b..39eef7a 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
+++ b/asterix-bad/src/test/resources/metadata/queries/bad_cq/continuous_channel/continuous_channel.2.update.sqlpp
@@ -16,12 +16,14 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Disasters with friends
-* Expected Res : Success
-* Date         : May 17
-* Author       : Steven Jacobs
-*/
-use channels;
+USE test;
 
-subscribe to EmergenciesNearMeChannel("tornado", 1) on brokerA;
+CREATE FEED TweetFeed WITH {
+  "adapter-name" : "localfs",
+  "path" : "asterix_nc1:///Users/xikuiw/Projects/NotBAD/tweets_publisher/output/tweets.txt",
+  "type-name":"Tweet",
+  "format" : "adm",
+  "insert-feed" : true
+};
+
+CONNECT FEED TweetFeed TO DATASET Tweets;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp b/asterix-bad/src/test/resources/metadata/queries/bad_cq/continuous_channel/continuous_channel.3.update.sqlpp
similarity index 76%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
copy to asterix-bad/src/test/resources/metadata/queries/bad_cq/continuous_channel/continuous_channel.3.update.sqlpp
index b1a132b..b9f8643 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
+++ b/asterix-bad/src/test/resources/metadata/queries/bad_cq/continuous_channel/continuous_channel.3.update.sqlpp
@@ -16,12 +16,12 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Disasters with friends
-* Expected Res : Success
-* Date         : May 17
-* Author       : Steven Jacobs
-*/
-use channels;
+USE test;
 
-subscribe to EmergenciesNearMeChannel("tornado", 1) on brokerA;
+CREATE CONTINUOUS CHANNEL TweetsWithSchools(code) PERIOD duration("PT3S")
+{
+  SELECT t
+  FROM Tweets t WHERE area_code = t.area_code  AND current_channel_time(t) > current_datetime()
+};
+
+CREATE BROKER brokerA AT "http://127.0.0.1:10100";
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/metadata/queries/bad_cq/continuous_channel/continuous_channel.4.query.sqlpp
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/metadata/queries/bad_cq/continuous_channel/continuous_channel.4.query.sqlpp
index b7bb951..04917e0 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/metadata/queries/bad_cq/continuous_channel/continuous_channel.4.query.sqlpp
@@ -16,10 +16,4 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+SELECT VALUE d FROM Metadata.`Dataset` d WHERE d.DataverseName = "test";
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp b/asterix-bad/src/test/resources/metadata/queries/bad_cq/create_active_datasets/create_active_datasets.1.ddl.sqlpp
similarity index 72%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
copy to asterix-bad/src/test/resources/metadata/queries/bad_cq/create_active_datasets/create_active_datasets.1.ddl.sqlpp
index b1a132b..2fc3783 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
+++ b/asterix-bad/src/test/resources/metadata/queries/bad_cq/create_active_datasets/create_active_datasets.1.ddl.sqlpp
@@ -16,12 +16,19 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Disasters with friends
-* Expected Res : Success
-* Date         : May 17
-* Author       : Steven Jacobs
-*/
-use channels;
+DROP DATAVERSE test IF EXISTS;
+CREATE DATAVERSE test;
+USE test;
 
-subscribe to EmergenciesNearMeChannel("tornado", 1) on brokerA;
+DROP DATASET Tweets IF EXISTS;
+DROP TYPE Tweet IF EXISTS;
+
+CREATE TYPE Tweet AS OPEN {
+ tid: bigint,
+ area_code: string,
+ text: string,
+ location: point,
+ timestamp: datetime
+};
+
+CREATE ACTIVE DATASET Tweets(Tweet) PRIMARY KEY tid;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/metadata/queries/bad_cq/create_active_datasets/create_active_datasets.2.query.sqlpp
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/metadata/queries/bad_cq/create_active_datasets/create_active_datasets.2.query.sqlpp
index b7bb951..81589bd 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/metadata/queries/bad_cq/create_active_datasets/create_active_datasets.2.query.sqlpp
@@ -16,10 +16,5 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+USE test;
+SELECT VALUE d FROM Metadata.`Dataset` d WHERE d.DatasetName = "Tweets";
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp b/asterix-bad/src/test/resources/metadata/queries/bad_cq/create_bad_broker/create_bad_broker.1.ddl.sqlpp
similarity index 79%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
copy to asterix-bad/src/test/resources/metadata/queries/bad_cq/create_bad_broker/create_bad_broker.1.ddl.sqlpp
index b1a132b..5a6ba82 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
+++ b/asterix-bad/src/test/resources/metadata/queries/bad_cq/create_bad_broker/create_bad_broker.1.ddl.sqlpp
@@ -16,12 +16,12 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Disasters with friends
-* Expected Res : Success
-* Date         : May 17
-* Author       : Steven Jacobs
-*/
-use channels;
+drop dataverse test if exists;
+create dataverse test;
+use test;
 
-subscribe to EmergenciesNearMeChannel("tornado", 1) on brokerA;
+CREATE BROKER brokerA AT "http://127.0.0.1:10100" with {
+  "broker-type" : "BAD"
+};
+
+CREATE BROKER brokerB AT "http://127.0.0.1:10100";
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/metadata/queries/bad_cq/create_bad_broker/create_bad_broker.2.query.sqlpp
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/metadata/queries/bad_cq/create_bad_broker/create_bad_broker.2.query.sqlpp
index b7bb951..549c59c 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/metadata/queries/bad_cq/create_bad_broker/create_bad_broker.2.query.sqlpp
@@ -16,10 +16,4 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+SELECT * FROM Metadata.`Broker`;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp b/asterix-bad/src/test/resources/metadata/queries/bad_cq/create_bad_feed/create_bad_feed.1.ddl.sqlpp
similarity index 60%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
copy to asterix-bad/src/test/resources/metadata/queries/bad_cq/create_bad_feed/create_bad_feed.1.ddl.sqlpp
index b1a132b..0e7495d 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
+++ b/asterix-bad/src/test/resources/metadata/queries/bad_cq/create_bad_feed/create_bad_feed.1.ddl.sqlpp
@@ -16,12 +16,24 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Disasters with friends
-* Expected Res : Success
-* Date         : May 17
-* Author       : Steven Jacobs
-*/
-use channels;
+drop dataverse test if exists;
+create dataverse test;
+use test;
 
-subscribe to EmergenciesNearMeChannel("tornado", 1) on brokerA;
+CREATE TYPE LocalThreateningTweet AS {
+  channelExecutionEpochTime: bigint,
+  dataverseName: string,
+  channelName: string
+};
+
+CREATE FEED LocalThreateningTweetFeed WITH {
+  "adapter-name" : "http_adapter",
+  "addresses" : "127.0.0.1:10013",
+  "address-type" : "IP",
+  "type-name" : "LocalThreateningTweet",
+  "format" : "ADM",
+  "bad-host" : "127.0.0.1",
+  "bad-channel" : "ThreateningTweetsAt",
+  "bad-channel-parameters": "OC",
+  "bad-dataverse": "test"
+};
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/metadata/queries/bad_cq/create_bad_feed/create_bad_feed.2.query.sqlpp
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/metadata/queries/bad_cq/create_bad_feed/create_bad_feed.2.query.sqlpp
index b7bb951..d29e4d2 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/metadata/queries/bad_cq/create_bad_feed/create_bad_feed.2.query.sqlpp
@@ -16,10 +16,4 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+SELECT * FROM Metadata.`Feed`;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/metadata/results/bad_cq/continuous_channel/continuous_channel.1.adm b/asterix-bad/src/test/resources/metadata/results/bad_cq/continuous_channel/continuous_channel.1.adm
new file mode 100644
index 0000000..ba2bf9a
--- /dev/null
+++ b/asterix-bad/src/test/resources/metadata/results/bad_cq/continuous_channel/continuous_channel.1.adm
@@ -0,0 +1,4 @@
+{ "DataverseName": "test", "DatasetName": "Schools", "DatatypeDataverseName": "test", "DatatypeName": "School", "DatasetType": "INTERNAL", "GroupName": "test.Schools", "CompactionPolicy": "concurrent", "CompactionPolicyProperties": [ { "Name": "max-component-count", "Value": "30" }, { "Name": "min-merge-component-count", "Value": "3" }, { "Name": "max-merge-component-count", "Value": "10" }, { "Name": "size-ratio", "Value": "1.2" } ], "InternalDetails": { "FileStructure": "BTREE", "PartitioningStrategy": "HASH", "PartitioningKey": [ [ "sid" ] ], "PrimaryKey": [ [ "sid" ] ], "Autogenerated": false }, "Hints": {{  }}, "Timestamp": "Wed May 27 19:01:09 PDT 2020", "DatasetId": 102, "PendingOp": 0, "BlockLevelStorageCompression": { "DatasetCompressionScheme": "snappy" } }
+{ "DataverseName": "test", "DatasetName": "Tweets", "DatatypeDataverseName": "test", "DatatypeName": "Tweet", "DatasetType": "INTERNAL", "GroupName": "test.Tweets", "CompactionPolicy": "concurrent", "CompactionPolicyProperties": [ { "Name": "max-component-count", "Value": "30" }, { "Name": "min-merge-component-count", "Value": "3" }, { "Name": "max-merge-component-count", "Value": "10" }, { "Name": "size-ratio", "Value": "1.2" } ], "InternalDetails": { "FileStructure": "BTREE", "PartitioningStrategy": "HASH", "PartitioningKey": [ [ "tid" ] ], "PrimaryKey": [ [ "tid" ] ], "Autogenerated": false }, "Hints": {{  }}, "Timestamp": "Wed May 27 19:01:09 PDT 2020", "DatasetId": 101, "PendingOp": 0, "MetatypeDataverseName": "Metadata", "MetatypeName": "ActiveRecordType", "BlockLevelStorageCompression": { "DatasetCompressionScheme": "snappy" } }
+{ "DataverseName": "test", "DatasetName": "TweetsWithSchoolsResults", "DatatypeDataverseName": "Metadata", "DatatypeName": "ChannelResultsType", "DatasetType": "INTERNAL", "GroupName": "test.TweetsWithSchoolsResults", "CompactionPolicy": "concurrent", "CompactionPolicyProperties": [ { "Name": "max-component-count", "Value": "30" }, { "Name": "min-merge-component-count", "Value": "3" }, { "Name": "max-merge-component-count", "Value": "10" }, { "Name": "size-ratio", "Value": "1.2" } ], "InternalDetails": { "FileStructure": "BTREE", "PartitioningStrategy": "HASH", "PartitioningKey": [ [ "resultId" ] ], "PrimaryKey": [ [ "resultId" ] ], "Autogenerated": true }, "Hints": {{  }}, "Timestamp": "Wed May 27 19:01:09 PDT 2020", "DatasetId": 104, "PendingOp": 0, "BlockLevelStorageCompression": { "DatasetCompressionScheme": "snappy" } }
+{ "DataverseName": "test", "DatasetName": "TweetsWithSchoolsSubscriptions", "DatatypeDataverseName": "Metadata", "DatatypeName": "ChannelSubscriptionsType", "DatasetType": "INTERNAL", "GroupName": "test.TweetsWithSchoolsSubscriptions", "CompactionPolicy": "concurrent", "CompactionPolicyProperties": [ { "Name": "max-component-count", "Value": "30" }, { "Name": "min-merge-component-count", "Value": "3" }, { "Name": "max-merge-component-count", "Value": "10" }, { "Name": "size-ratio", "Value": "1.2" } ], "InternalDetails": { "FileStructure": "BTREE", "PartitioningStrategy": "HASH", "PartitioningKey": [ [ "subscriptionId" ] ], "PrimaryKey": [ [ "subscriptionId" ] ], "Autogenerated": true }, "Hints": {{  }}, "Timestamp": "Wed May 27 19:01:09 PDT 2020", "DatasetId": 103, "PendingOp": 0, "BlockLevelStorageCompression": { "DatasetCompressionScheme": "snappy" } }
diff --git a/asterix-bad/src/test/resources/metadata/results/bad_cq/create_active_datasets/create_active_datasets.1.adm b/asterix-bad/src/test/resources/metadata/results/bad_cq/create_active_datasets/create_active_datasets.1.adm
new file mode 100644
index 0000000..da2fdfb
--- /dev/null
+++ b/asterix-bad/src/test/resources/metadata/results/bad_cq/create_active_datasets/create_active_datasets.1.adm
@@ -0,0 +1 @@
+{ "DataverseName": "test", "DatasetName": "Tweets", "DatatypeDataverseName": "test", "DatatypeName": "Tweet", "DatasetType": "INTERNAL", "GroupName": "test.Tweets", "CompactionPolicy": "concurrent", "CompactionPolicyProperties": [ { "Name": "max-component-count", "Value": "30" }, { "Name": "min-merge-component-count", "Value": "3" }, { "Name": "max-merge-component-count", "Value": "10" }, { "Name": "size-ratio", "Value": "1.2" } ], "InternalDetails": { "FileStructure": "BTREE", "PartitioningStrategy": "HASH", "PartitioningKey": [ [ "tid" ] ], "PrimaryKey": [ [ "tid" ] ], "Autogenerated": false }, "Hints": {{  }}, "Timestamp": "Mon Aug 17 10:23:56 PDT 2020", "DatasetId": 101, "PendingOp": 0, "MetatypeDataverseName": "Metadata", "MetatypeName": "ActiveRecordType", "BlockLevelStorageCompression": { "DatasetCompressionScheme": "snappy" } }
diff --git a/asterix-bad/src/test/resources/metadata/results/bad_cq/create_bad_broker/create_bad_broker.1.adm b/asterix-bad/src/test/resources/metadata/results/bad_cq/create_bad_broker/create_bad_broker.1.adm
new file mode 100644
index 0000000..d939759
--- /dev/null
+++ b/asterix-bad/src/test/resources/metadata/results/bad_cq/create_bad_broker/create_bad_broker.1.adm
@@ -0,0 +1,2 @@
+{ "Broker": { "DataverseName": "test", "BrokerName": "brokerA", "BrokerEndPoint": "http://127.0.0.1:10100", "BrokerType": "bad" } }
+{ "Broker": { "DataverseName": "test", "BrokerName": "brokerB", "BrokerEndPoint": "http://127.0.0.1:10100", "BrokerType": "general" } }
diff --git a/asterix-bad/src/test/resources/metadata/results/bad_cq/create_bad_feed/create_bad_feed.1.adm b/asterix-bad/src/test/resources/metadata/results/bad_cq/create_bad_feed/create_bad_feed.1.adm
new file mode 100644
index 0000000..f498a0d
--- /dev/null
+++ b/asterix-bad/src/test/resources/metadata/results/bad_cq/create_bad_feed/create_bad_feed.1.adm
@@ -0,0 +1 @@
+{ "Feed": { "DataverseName": "test", "FeedName": "LocalThreateningTweetFeed", "AdapterConfiguration": {{ { "Name": "addresses", "Value": "127.0.0.1:10013" }, { "Name": "reader", "Value": "http_adapter" }, { "Name": "bad-channel", "Value": "ThreateningTweetsAt" }, { "Name": "format", "Value": "adm" }, { "Name": "bad-dataverse", "Value": "test" }, { "Name": "type-name", "Value": "LocalThreateningTweet" }, { "Name": "bad-host", "Value": "127.0.0.1" }, { "Name": "feed", "Value": "LocalThreateningTweetFeed" }, { "Name": "address-type", "Value": "IP" }, { "Name": "adapter-name", "Value": "http_adapter" }, { "Name": "is-feed", "Value": "true" }, { "Name": "parser", "Value": "adm" }, { "Name": "bad-channel-parameters", "Value": "OC" }, { "Name": "dataverse", "Value": "test" } }}, "Timestamp": "Mon Aug 17 10:35:46 PDT 2020" } }
diff --git a/asterix-bad/src/test/resources/metadata/testsuite.xml b/asterix-bad/src/test/resources/metadata/testsuite.xml
new file mode 100644
index 0000000..e12cd7b
--- /dev/null
+++ b/asterix-bad/src/test/resources/metadata/testsuite.xml
@@ -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.
+  -->
+<test-suite  xmlns="urn:xml.testframework.asterix.apache.org"
+             ResultOffsetPath="results"
+             QueryOffsetPath="queries"
+             QueryFileExtension=".sqlpp">
+  <test-group name="bad_cq">
+    <test-case FilePath="bad_cq">
+      <compilation-unit name="create_active_datasets">
+        <output-dir compare="Text">create_active_datasets</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="bad_cq">
+      <compilation-unit name="create_bad_broker">
+        <output-dir compare="Text">create_bad_broker</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="bad_cq">
+      <compilation-unit name="create_bad_feed">
+        <output-dir compare="Text">create_bad_feed</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="bad_cq">
+      <compilation-unit name="continuous_channel">
+        <output-dir compare="Text">continuous_channel</output-dir>
+      </compilation-unit>
+    </test-case>
+  </test-group>
+</test-suite>
diff --git a/asterix-bad/src/test/resources/optimizerts/ignore.txt b/asterix-bad/src/test/resources/optimizerts/ignore.txt
new file mode 100644
index 0000000..fe95886
--- /dev/null
+++ b/asterix-bad/src/test/resources/optimizerts/ignore.txt
@@ -0,0 +1,18 @@
+#
+# 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.
+#
diff --git a/asterix-bad/src/test/resources/optimizerts/only.txt b/asterix-bad/src/test/resources/optimizerts/only.txt
new file mode 100644
index 0000000..5fb2552
--- /dev/null
+++ b/asterix-bad/src/test/resources/optimizerts/only.txt
@@ -0,0 +1,18 @@
+#
+# 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.
+#
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/optimizerts/queries/bad_cq/cq_udf_test.sqlpp b/asterix-bad/src/test/resources/optimizerts/queries/bad_cq/cq_udf_test.sqlpp
new file mode 100644
index 0000000..7a6ac4d
--- /dev/null
+++ b/asterix-bad/src/test/resources/optimizerts/queries/bad_cq/cq_udf_test.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.
+ */
+DROP DATAVERSE test IF EXISTS;
+CREATE DATAVERSE test;
+USE test;
+
+CREATE TYPE Tweet AS OPEN {
+ tid: bigint,
+ area_code: string,
+ text: string,
+ location: point,
+ timestamp: datetime
+};
+
+CREATE TYPE OfficerLocation AS {
+  oid: int,
+  location: point,
+  vehicle: string
+};
+
+CREATE DATASET Tweets(Tweet) PRIMARY KEY tid;
+CREATE DATASET OfficerLocations(OfficerLocation) PRIMARY KEY oid;
+
+CREATE INDEX s_location ON Tweets(location) type RTREE;
+CREATE INDEX o_location ON OfficerLocations(location) type RTREE;
+
+CREATE FUNCTION NearbyTweets(oid)
+{
+ SELECT t FROM Tweets t, OfficerLocations o
+ WHERE spatial_intersect(create_circle(t.location, 100.0), o.location) AND o.oid = oid
+  AND t.hateful_flag = true
+};
+
+NearbyTweets("01");
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/optimizerts/queries/bad_cq/new_nearby_tweets.sqlpp b/asterix-bad/src/test/resources/optimizerts/queries/bad_cq/new_nearby_tweets.sqlpp
new file mode 100644
index 0000000..4405542
--- /dev/null
+++ b/asterix-bad/src/test/resources/optimizerts/queries/bad_cq/new_nearby_tweets.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 test IF EXISTS;
+CREATE DATAVERSE test;
+USE test;
+
+CREATE TYPE Tweet AS OPEN {
+ tid: bigint,
+ area_code: string,
+ text: string,
+ location: point,
+ timestamp: datetime
+};
+
+CREATE TYPE OfficerLocation AS {
+  oid: int,
+  location: point,
+  vehicle: string
+};
+
+CREATE ACTIVE DATASET Tweets(Tweet) PRIMARY KEY tid;
+CREATE ACTIVE DATASET OfficerLocations(OfficerLocation) PRIMARY KEY oid;
+
+CREATE INDEX s_location ON Tweets(location) type RTREE;
+CREATE INDEX o_location ON OfficerLocations(location) type RTREE;
+
+write output to nc1:"rttest/unseen_nearby_tweets.sqlpp";
+set `compiler.indexonly` "false";
+
+CREATE CONTINUOUS CHANNEL NearbyTweets(oid) PERIOD duration("PT3S")
+{
+ SELECT t FROM Tweets t, OfficerLocations o
+ WHERE spatial_intersect(create_circle(t.location, 100.0), o.location) AND o.oid = oid AND is_new(t)
+  AND t.hateful_flag = true
+};
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp b/asterix-bad/src/test/resources/optimizerts/queries/bad_cq/new_tweets.sqlpp
similarity index 63%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
copy to asterix-bad/src/test/resources/optimizerts/queries/bad_cq/new_tweets.sqlpp
index b1a132b..2c677c6 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
+++ b/asterix-bad/src/test/resources/optimizerts/queries/bad_cq/new_tweets.sqlpp
@@ -16,12 +16,25 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Disasters with friends
-* Expected Res : Success
-* Date         : May 17
-* Author       : Steven Jacobs
-*/
-use channels;
+DROP DATAVERSE test IF EXISTS;
+CREATE DATAVERSE test;
+USE test;
 
-subscribe to EmergenciesNearMeChannel("tornado", 1) on brokerA;
+CREATE TYPE Tweet AS OPEN {
+ tid: bigint,
+ area_code: string,
+ text: string,
+ location: point,
+ timestamp: datetime
+};
+
+
+CREATE ACTIVE DATASET Tweets(Tweet) PRIMARY KEY tid;
+
+write output to nc1:"rttest/new_tweets.sqlpp";
+set `compiler.indexonly` "false";
+
+CREATE CONTINUOUS CHANNEL NearbyTweets(oid) PERIOD duration("PT3S")
+{
+ SELECT t FROM Tweets t WHERE is_new(t) AND t.hateful_flag = true
+};
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp b/asterix-bad/src/test/resources/optimizerts/queries/bad_cq/new_tweets_push.sqlpp
similarity index 63%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
copy to asterix-bad/src/test/resources/optimizerts/queries/bad_cq/new_tweets_push.sqlpp
index b1a132b..2c677c6 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
+++ b/asterix-bad/src/test/resources/optimizerts/queries/bad_cq/new_tweets_push.sqlpp
@@ -16,12 +16,25 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Disasters with friends
-* Expected Res : Success
-* Date         : May 17
-* Author       : Steven Jacobs
-*/
-use channels;
+DROP DATAVERSE test IF EXISTS;
+CREATE DATAVERSE test;
+USE test;
 
-subscribe to EmergenciesNearMeChannel("tornado", 1) on brokerA;
+CREATE TYPE Tweet AS OPEN {
+ tid: bigint,
+ area_code: string,
+ text: string,
+ location: point,
+ timestamp: datetime
+};
+
+
+CREATE ACTIVE DATASET Tweets(Tweet) PRIMARY KEY tid;
+
+write output to nc1:"rttest/new_tweets.sqlpp";
+set `compiler.indexonly` "false";
+
+CREATE CONTINUOUS CHANNEL NearbyTweets(oid) PERIOD duration("PT3S")
+{
+ SELECT t FROM Tweets t WHERE is_new(t) AND t.hateful_flag = true
+};
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/optimizerts/queries/bad_cq/threatening_event_near.sqlpp b/asterix-bad/src/test/resources/optimizerts/queries/bad_cq/threatening_event_near.sqlpp
new file mode 100644
index 0000000..58ab664
--- /dev/null
+++ b/asterix-bad/src/test/resources/optimizerts/queries/bad_cq/threatening_event_near.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.
+ */
+DROP DATAVERSE ocpd IF EXISTS;
+CREATE DATAVERSE ocpd;
+USE ocpd;
+CREATE TYPE LocalThreateningTweet AS {
+  nid: uuid
+};
+
+CREATE ACTIVE DATASET LocalThreateningTweets(LocalThreateningTweet) PRIMARY KEY nid autogenerated;
+
+CREATE TYPE OfficerLocation AS {
+  oid: bigint,
+  location: point
+};
+
+CREATE ACTIVE DATASET OfficerLocations(OfficerLocation) PRIMARY KEY oid;
+
+USE ocpd;
+SELECT threateningTweet.result
+  FROM LocalThreateningTweets tn
+  UNNEST tn.results threateningTweet
+  WHERE 1 = (SELECT VALUE o.oid FROM OfficerLocations o ORDER BY spatial_distance(o.location, create_point(threateningTweet.result.location[0], threateningTweet.result.location[1])) ASC)[0];
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/optimizerts/queries/bad_cq/unseen_nearby_tweets.sqlpp b/asterix-bad/src/test/resources/optimizerts/queries/bad_cq/unseen_nearby_tweets.sqlpp
new file mode 100644
index 0000000..3a8af7b
--- /dev/null
+++ b/asterix-bad/src/test/resources/optimizerts/queries/bad_cq/unseen_nearby_tweets.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.
+ */
+DROP DATAVERSE test IF EXISTS;
+CREATE DATAVERSE test;
+USE test;
+
+CREATE TYPE Tweet AS OPEN {
+ tid: bigint,
+ area_code: string,
+ text: string,
+ location: point,
+ timestamp: datetime
+};
+
+CREATE TYPE OfficerLocation AS {
+  oid: int,
+  location: point,
+  vehicle: string
+};
+
+CREATE ACTIVE DATASET Tweets(Tweet) PRIMARY KEY tid;
+CREATE ACTIVE DATASET OfficerLocations(OfficerLocation) PRIMARY KEY oid;
+
+write output to nc1:"rttest/unseen_nearby_tweets.sqlpp";
+set `compiler.indexonly` "false";
+
+CREATE CONTINUOUS CHANNEL NearbyTweets(oid) PERIOD duration("PT3S")
+{
+ SELECT t FROM Tweets t, OfficerLocations o
+     WHERE spatial_intersect(create_circle(t.location, 100.0), o.location) AND o.oid = oid AND (is_new(t) OR is_new(o))
+      AND t.hateful_flag = true
+};
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/optimizerts/queries/channel/channel-advanced-index-only.sqlpp b/asterix-bad/src/test/resources/optimizerts/queries/bad_rq/channel-advanced-index-only.sqlpp
similarity index 100%
rename from asterix-bad/src/test/resources/optimizerts/queries/channel/channel-advanced-index-only.sqlpp
rename to asterix-bad/src/test/resources/optimizerts/queries/bad_rq/channel-advanced-index-only.sqlpp
diff --git a/asterix-bad/src/test/resources/optimizerts/queries/channel/channel-advanced.sqlpp b/asterix-bad/src/test/resources/optimizerts/queries/bad_rq/channel-advanced.sqlpp
similarity index 100%
rename from asterix-bad/src/test/resources/optimizerts/queries/channel/channel-advanced.sqlpp
rename to asterix-bad/src/test/resources/optimizerts/queries/bad_rq/channel-advanced.sqlpp
diff --git a/asterix-bad/src/test/resources/optimizerts/queries/channel/channel-create.sqlpp b/asterix-bad/src/test/resources/optimizerts/queries/bad_rq/channel-create.sqlpp
similarity index 100%
rename from asterix-bad/src/test/resources/optimizerts/queries/channel/channel-create.sqlpp
rename to asterix-bad/src/test/resources/optimizerts/queries/bad_rq/channel-create.sqlpp
diff --git a/asterix-bad/src/test/resources/optimizerts/queries/channel/channel-push.sqlpp b/asterix-bad/src/test/resources/optimizerts/queries/bad_rq/channel-push.sqlpp
similarity index 100%
rename from asterix-bad/src/test/resources/optimizerts/queries/channel/channel-push.sqlpp
rename to asterix-bad/src/test/resources/optimizerts/queries/bad_rq/channel-push.sqlpp
diff --git a/asterix-bad/src/test/resources/optimizerts/queries/channel/channel-subscribe.sqlpp b/asterix-bad/src/test/resources/optimizerts/queries/bad_rq/channel-subscribe.sqlpp
similarity index 100%
rename from asterix-bad/src/test/resources/optimizerts/queries/channel/channel-subscribe.sqlpp
rename to asterix-bad/src/test/resources/optimizerts/queries/bad_rq/channel-subscribe.sqlpp
diff --git a/asterix-bad/src/test/resources/optimizerts/queries/channel/channel-unsubscribe.sqlpp b/asterix-bad/src/test/resources/optimizerts/queries/bad_rq/channel-unsubscribe.sqlpp
similarity index 100%
rename from asterix-bad/src/test/resources/optimizerts/queries/channel/channel-unsubscribe.sqlpp
rename to asterix-bad/src/test/resources/optimizerts/queries/bad_rq/channel-unsubscribe.sqlpp
diff --git a/asterix-bad/src/test/resources/optimizerts/results/bad_cq/cq_udf_test.plan b/asterix-bad/src/test/resources/optimizerts/results/bad_cq/cq_udf_test.plan
new file mode 100644
index 0000000..388e356
--- /dev/null
+++ b/asterix-bad/src/test/resources/optimizerts/results/bad_cq/cq_udf_test.plan
@@ -0,0 +1,24 @@
+-- DISTRIBUTE_RESULT  |PARTITIONED|
+  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    -- STREAM_PROJECT  |PARTITIONED|
+      -- ASSIGN  |PARTITIONED|
+        -- STREAM_PROJECT  |PARTITIONED|
+          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            -- NESTED_LOOP  |PARTITIONED|
+              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                -- STREAM_SELECT  |PARTITIONED|
+                  -- ASSIGN  |PARTITIONED|
+                    -- STREAM_PROJECT  |PARTITIONED|
+                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              -- BROADCAST_EXCHANGE  |PARTITIONED|
+                -- STREAM_PROJECT  |PARTITIONED|
+                  -- ASSIGN  |PARTITIONED|
+                    -- STREAM_PROJECT  |PARTITIONED|
+                      -- STREAM_SELECT  |PARTITIONED|
+                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterix-bad/src/test/resources/optimizerts/results/bad_cq/new_nearby_tweets.plan b/asterix-bad/src/test/resources/optimizerts/results/bad_cq/new_nearby_tweets.plan
new file mode 100644
index 0000000..e4c1ec7
--- /dev/null
+++ b/asterix-bad/src/test/resources/optimizerts/results/bad_cq/new_nearby_tweets.plan
@@ -0,0 +1,78 @@
+-- NOTIFY_BROKERS  |PARTITIONED|
+  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    -- PRE_CLUSTERED_GROUP_BY[$$120, $$121, $$channelExecutionTime]  |PARTITIONED|
+            {
+              -- AGGREGATE  |LOCAL|
+                -- NESTED_TUPLE_SOURCE  |LOCAL|
+            }
+      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        -- STABLE_SORT [$$120(ASC), $$121(ASC), $$channelExecutionTime(ASC)]  |PARTITIONED|
+          -- HASH_PARTITION_EXCHANGE [$$120, $$121, $$channelExecutionTime]  |PARTITIONED|
+            -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                -- STABLE_SORT [$$97(ASC)]  |PARTITIONED|
+                  -- HASH_PARTITION_EXCHANGE [$$97]  |PARTITIONED|
+                    -- STREAM_PROJECT  |PARTITIONED|
+                      -- COMMIT  |PARTITIONED|
+                        -- STREAM_PROJECT  |PARTITIONED|
+                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            -- INDEX_INSERT_DELETE  |PARTITIONED|
+                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                -- STREAM_PROJECT  |PARTITIONED|
+                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    -- INSERT_DELETE  |PARTITIONED|
+                                      -- HASH_PARTITION_EXCHANGE [$$92]  |PARTITIONED|
+                                        -- ASSIGN  |PARTITIONED|
+                                          -- STREAM_PROJECT  |PARTITIONED|
+                                            -- ASSIGN  |PARTITIONED|
+                                              -- STREAM_PROJECT  |PARTITIONED|
+                                                -- ASSIGN  |PARTITIONED|
+                                                  -- STREAM_PROJECT  |PARTITIONED|
+                                                    -- ASSIGN  |PARTITIONED|
+                                                      -- STREAM_PROJECT  |PARTITIONED|
+                                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          -- HYBRID_HASH_JOIN [$$109][$$102]  |PARTITIONED|
+                                                            -- HASH_PARTITION_EXCHANGE [$$109]  |PARTITIONED|
+                                                              -- STREAM_PROJECT  |PARTITIONED|
+                                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  -- HYBRID_HASH_JOIN [$$106, $$104][$$98, $$99]  |PARTITIONED|
+                                                                    -- HASH_PARTITION_EXCHANGE [$$106, $$104]  |PARTITIONED|
+                                                                      -- STREAM_PROJECT  |PARTITIONED|
+                                                                        -- ASSIGN  |PARTITIONED|
+                                                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                              -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                -- ASSIGN  |UNPARTITIONED|
+                                                                                  -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                                                    -- HASH_PARTITION_EXCHANGE [$$98, $$99]  |PARTITIONED|
+                                                                      -- STREAM_PROJECT  |PARTITIONED|
+                                                                        -- ASSIGN  |PARTITIONED|
+                                                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                            -- HASH_PARTITION_EXCHANGE [$$102]  |PARTITIONED|
+                                                              -- STREAM_PROJECT  |PARTITIONED|
+                                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  -- NESTED_LOOP  |PARTITIONED|
+                                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      -- STREAM_PROJECT  |PARTITIONED|
+                                                                        -- STREAM_SELECT  |PARTITIONED|
+                                                                          -- ASSIGN  |PARTITIONED|
+                                                                            -- ASSIGN  |PARTITIONED|
+                                                                              -- ASSIGN  |PARTITIONED|
+                                                                                -- STREAM_PROJECT  |PARTITIONED|
+                                                                                  -- ASSIGN  |PARTITIONED|
+                                                                                    -- STREAM_PROJECT  |PARTITIONED|
+                                                                                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                    -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                      -- STREAM_PROJECT  |PARTITIONED|
+                                                                        -- ASSIGN  |PARTITIONED|
+                                                                          -- STREAM_PROJECT  |PARTITIONED|
+                                                                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterix-bad/src/test/resources/optimizerts/results/bad_cq/new_tweets.plan b/asterix-bad/src/test/resources/optimizerts/results/bad_cq/new_tweets.plan
new file mode 100644
index 0000000..ebf5624
--- /dev/null
+++ b/asterix-bad/src/test/resources/optimizerts/results/bad_cq/new_tweets.plan
@@ -0,0 +1,66 @@
+-- NOTIFY_BROKERS  |PARTITIONED|
+  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    -- PRE_CLUSTERED_GROUP_BY[$$93, $$94, $$channelExecutionTime]  |PARTITIONED|
+            {
+              -- AGGREGATE  |LOCAL|
+                -- NESTED_TUPLE_SOURCE  |LOCAL|
+            }
+      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        -- STABLE_SORT [$$93(ASC), $$94(ASC), $$channelExecutionTime(ASC)]  |PARTITIONED|
+          -- HASH_PARTITION_EXCHANGE [$$93, $$94, $$channelExecutionTime]  |PARTITIONED|
+            -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                -- STABLE_SORT [$$79(ASC)]  |PARTITIONED|
+                  -- HASH_PARTITION_EXCHANGE [$$79]  |PARTITIONED|
+                    -- STREAM_PROJECT  |PARTITIONED|
+                      -- COMMIT  |PARTITIONED|
+                        -- STREAM_PROJECT  |PARTITIONED|
+                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            -- INDEX_INSERT_DELETE  |PARTITIONED|
+                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                -- STREAM_PROJECT  |PARTITIONED|
+                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    -- INSERT_DELETE  |PARTITIONED|
+                                      -- HASH_PARTITION_EXCHANGE [$$74]  |PARTITIONED|
+                                        -- ASSIGN  |PARTITIONED|
+                                          -- STREAM_PROJECT  |PARTITIONED|
+                                            -- ASSIGN  |PARTITIONED|
+                                              -- STREAM_PROJECT  |PARTITIONED|
+                                                -- ASSIGN  |PARTITIONED|
+                                                  -- STREAM_PROJECT  |PARTITIONED|
+                                                    -- ASSIGN  |PARTITIONED|
+                                                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        -- NESTED_LOOP  |PARTITIONED|
+                                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            -- STREAM_PROJECT  |PARTITIONED|
+                                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                -- HYBRID_HASH_JOIN [$$86, $$84][$$80, $$81]  |PARTITIONED|
+                                                                  -- HASH_PARTITION_EXCHANGE [$$86, $$84]  |PARTITIONED|
+                                                                    -- STREAM_PROJECT  |PARTITIONED|
+                                                                      -- ASSIGN  |PARTITIONED|
+                                                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                            -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                              -- ASSIGN  |UNPARTITIONED|
+                                                                                -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                                                  -- HASH_PARTITION_EXCHANGE [$$80, $$81]  |PARTITIONED|
+                                                                    -- STREAM_PROJECT  |PARTITIONED|
+                                                                      -- ASSIGN  |PARTITIONED|
+                                                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                          -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                            -- STREAM_PROJECT  |PARTITIONED|
+                                                              -- ASSIGN  |PARTITIONED|
+                                                                -- STREAM_PROJECT  |PARTITIONED|
+                                                                  -- STREAM_SELECT  |PARTITIONED|
+                                                                    -- ASSIGN  |PARTITIONED|
+                                                                      -- ASSIGN  |PARTITIONED|
+                                                                        -- STREAM_PROJECT  |PARTITIONED|
+                                                                          -- ASSIGN  |PARTITIONED|
+                                                                            -- STREAM_PROJECT  |PARTITIONED|
+                                                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterix-bad/src/test/resources/optimizerts/results/bad_cq/new_tweets_push.plan b/asterix-bad/src/test/resources/optimizerts/results/bad_cq/new_tweets_push.plan
new file mode 100644
index 0000000..ebf5624
--- /dev/null
+++ b/asterix-bad/src/test/resources/optimizerts/results/bad_cq/new_tweets_push.plan
@@ -0,0 +1,66 @@
+-- NOTIFY_BROKERS  |PARTITIONED|
+  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    -- PRE_CLUSTERED_GROUP_BY[$$93, $$94, $$channelExecutionTime]  |PARTITIONED|
+            {
+              -- AGGREGATE  |LOCAL|
+                -- NESTED_TUPLE_SOURCE  |LOCAL|
+            }
+      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        -- STABLE_SORT [$$93(ASC), $$94(ASC), $$channelExecutionTime(ASC)]  |PARTITIONED|
+          -- HASH_PARTITION_EXCHANGE [$$93, $$94, $$channelExecutionTime]  |PARTITIONED|
+            -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                -- STABLE_SORT [$$79(ASC)]  |PARTITIONED|
+                  -- HASH_PARTITION_EXCHANGE [$$79]  |PARTITIONED|
+                    -- STREAM_PROJECT  |PARTITIONED|
+                      -- COMMIT  |PARTITIONED|
+                        -- STREAM_PROJECT  |PARTITIONED|
+                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            -- INDEX_INSERT_DELETE  |PARTITIONED|
+                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                -- STREAM_PROJECT  |PARTITIONED|
+                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    -- INSERT_DELETE  |PARTITIONED|
+                                      -- HASH_PARTITION_EXCHANGE [$$74]  |PARTITIONED|
+                                        -- ASSIGN  |PARTITIONED|
+                                          -- STREAM_PROJECT  |PARTITIONED|
+                                            -- ASSIGN  |PARTITIONED|
+                                              -- STREAM_PROJECT  |PARTITIONED|
+                                                -- ASSIGN  |PARTITIONED|
+                                                  -- STREAM_PROJECT  |PARTITIONED|
+                                                    -- ASSIGN  |PARTITIONED|
+                                                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        -- NESTED_LOOP  |PARTITIONED|
+                                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            -- STREAM_PROJECT  |PARTITIONED|
+                                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                -- HYBRID_HASH_JOIN [$$86, $$84][$$80, $$81]  |PARTITIONED|
+                                                                  -- HASH_PARTITION_EXCHANGE [$$86, $$84]  |PARTITIONED|
+                                                                    -- STREAM_PROJECT  |PARTITIONED|
+                                                                      -- ASSIGN  |PARTITIONED|
+                                                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                            -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                              -- ASSIGN  |UNPARTITIONED|
+                                                                                -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                                                  -- HASH_PARTITION_EXCHANGE [$$80, $$81]  |PARTITIONED|
+                                                                    -- STREAM_PROJECT  |PARTITIONED|
+                                                                      -- ASSIGN  |PARTITIONED|
+                                                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                          -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                            -- STREAM_PROJECT  |PARTITIONED|
+                                                              -- ASSIGN  |PARTITIONED|
+                                                                -- STREAM_PROJECT  |PARTITIONED|
+                                                                  -- STREAM_SELECT  |PARTITIONED|
+                                                                    -- ASSIGN  |PARTITIONED|
+                                                                      -- ASSIGN  |PARTITIONED|
+                                                                        -- STREAM_PROJECT  |PARTITIONED|
+                                                                          -- ASSIGN  |PARTITIONED|
+                                                                            -- STREAM_PROJECT  |PARTITIONED|
+                                                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterix-bad/src/test/resources/optimizerts/results/bad_cq/threatening_event_near.plan b/asterix-bad/src/test/resources/optimizerts/results/bad_cq/threatening_event_near.plan
new file mode 100644
index 0000000..3696f5b
--- /dev/null
+++ b/asterix-bad/src/test/resources/optimizerts/results/bad_cq/threatening_event_near.plan
@@ -0,0 +1,111 @@
+-- DISTRIBUTE_RESULT  |PARTITIONED|
+  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    -- STREAM_PROJECT  |PARTITIONED|
+      -- ASSIGN  |PARTITIONED|
+        -- STREAM_PROJECT  |PARTITIONED|
+          -- STREAM_SELECT  |PARTITIONED|
+            -- STREAM_PROJECT  |PARTITIONED|
+              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                -- PRE_CLUSTERED_GROUP_BY[$$59]  |PARTITIONED|
+                        {
+                          -- AGGREGATE  |LOCAL|
+                            -- STREAM_SELECT  |LOCAL|
+                              -- NESTED_TUPLE_SOURCE  |LOCAL|
+                        }
+                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    -- STABLE_SORT [$$59(ASC), $$48(ASC)]  |PARTITIONED|
+                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        -- STREAM_PROJECT  |PARTITIONED|
+                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            -- HYBRID_HASH_JOIN [$$59][$$60]  |PARTITIONED|
+                              -- HASH_PARTITION_EXCHANGE [$$59]  |PARTITIONED|
+                                -- ASSIGN  |PARTITIONED|
+                                  -- STREAM_PROJECT  |PARTITIONED|
+                                    -- ASSIGN  |PARTITIONED|
+                                      -- STREAM_PROJECT  |PARTITIONED|
+                                        -- ASSIGN  |PARTITIONED|
+                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            -- REPLICATE  |PARTITIONED|
+                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                -- STREAM_PROJECT  |PARTITIONED|
+                                                  -- UNNEST  |PARTITIONED|
+                                                    -- STREAM_PROJECT  |PARTITIONED|
+                                                      -- ASSIGN  |PARTITIONED|
+                                                        -- STREAM_PROJECT  |PARTITIONED|
+                                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              -- HASH_PARTITION_EXCHANGE [$$60]  |PARTITIONED|
+                                -- ASSIGN  |PARTITIONED|
+                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    -- STABLE_SORT [$$60(ASC), $$48(ASC)]  |PARTITIONED|
+                                      -- RANGE_PARTITION_EXCHANGE [$$60(ASC), $$48(ASC)]  |PARTITIONED|
+                                        -- FORWARD  |PARTITIONED|
+                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            -- REPLICATE  |PARTITIONED|
+                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                -- STREAM_PROJECT  |PARTITIONED|
+                                                  -- ASSIGN  |PARTITIONED|
+                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      -- NESTED_LOOP  |PARTITIONED|
+                                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          -- ASSIGN  |PARTITIONED|
+                                                            -- STREAM_PROJECT  |PARTITIONED|
+                                                              -- ASSIGN  |PARTITIONED|
+                                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  -- REPLICATE  |PARTITIONED|
+                                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      -- STREAM_PROJECT  |PARTITIONED|
+                                                                        -- UNNEST  |PARTITIONED|
+                                                                          -- STREAM_PROJECT  |PARTITIONED|
+                                                                            -- ASSIGN  |PARTITIONED|
+                                                                              -- STREAM_PROJECT  |PARTITIONED|
+                                                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                      -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                        -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                          -- STREAM_PROJECT  |PARTITIONED|
+                                                            -- ASSIGN  |PARTITIONED|
+                                                              -- STREAM_PROJECT  |PARTITIONED|
+                                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                          -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                            -- AGGREGATE  |UNPARTITIONED|
+                                              -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                                                -- AGGREGATE  |PARTITIONED|
+                                                  -- STREAM_PROJECT  |PARTITIONED|
+                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      -- REPLICATE  |PARTITIONED|
+                                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          -- STREAM_PROJECT  |PARTITIONED|
+                                                            -- ASSIGN  |PARTITIONED|
+                                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                -- NESTED_LOOP  |PARTITIONED|
+                                                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    -- ASSIGN  |PARTITIONED|
+                                                                      -- STREAM_PROJECT  |PARTITIONED|
+                                                                        -- ASSIGN  |PARTITIONED|
+                                                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            -- REPLICATE  |PARTITIONED|
+                                                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                -- STREAM_PROJECT  |PARTITIONED|
+                                                                                  -- UNNEST  |PARTITIONED|
+                                                                                    -- STREAM_PROJECT  |PARTITIONED|
+                                                                                      -- ASSIGN  |PARTITIONED|
+                                                                                        -- STREAM_PROJECT  |PARTITIONED|
+                                                                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                  -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                    -- STREAM_PROJECT  |PARTITIONED|
+                                                                      -- ASSIGN  |PARTITIONED|
+                                                                        -- STREAM_PROJECT  |PARTITIONED|
+                                                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterix-bad/src/test/resources/optimizerts/results/bad_cq/unseen_nearby_tweets.plan b/asterix-bad/src/test/resources/optimizerts/results/bad_cq/unseen_nearby_tweets.plan
new file mode 100644
index 0000000..5bf7f10
--- /dev/null
+++ b/asterix-bad/src/test/resources/optimizerts/results/bad_cq/unseen_nearby_tweets.plan
@@ -0,0 +1,80 @@
+-- NOTIFY_BROKERS  |PARTITIONED|
+  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    -- PRE_CLUSTERED_GROUP_BY[$$125, $$126, $$channelExecutionTime]  |PARTITIONED|
+            {
+              -- AGGREGATE  |LOCAL|
+                -- NESTED_TUPLE_SOURCE  |LOCAL|
+            }
+      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        -- STABLE_SORT [$$125(ASC), $$126(ASC), $$channelExecutionTime(ASC)]  |PARTITIONED|
+          -- HASH_PARTITION_EXCHANGE [$$125, $$126, $$channelExecutionTime]  |PARTITIONED|
+            -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                -- STABLE_SORT [$$99(ASC)]  |PARTITIONED|
+                  -- HASH_PARTITION_EXCHANGE [$$99]  |PARTITIONED|
+                    -- STREAM_PROJECT  |PARTITIONED|
+                      -- COMMIT  |PARTITIONED|
+                        -- STREAM_PROJECT  |PARTITIONED|
+                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            -- INDEX_INSERT_DELETE  |PARTITIONED|
+                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                -- STREAM_PROJECT  |PARTITIONED|
+                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    -- INSERT_DELETE  |PARTITIONED|
+                                      -- HASH_PARTITION_EXCHANGE [$$94]  |PARTITIONED|
+                                        -- ASSIGN  |PARTITIONED|
+                                          -- STREAM_PROJECT  |PARTITIONED|
+                                            -- ASSIGN  |PARTITIONED|
+                                              -- STREAM_PROJECT  |PARTITIONED|
+                                                -- ASSIGN  |PARTITIONED|
+                                                  -- STREAM_PROJECT  |PARTITIONED|
+                                                    -- ASSIGN  |PARTITIONED|
+                                                      -- STREAM_PROJECT  |PARTITIONED|
+                                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          -- HYBRID_HASH_JOIN [$$111][$$104]  |PARTITIONED|
+                                                            -- HASH_PARTITION_EXCHANGE [$$111]  |PARTITIONED|
+                                                              -- STREAM_PROJECT  |PARTITIONED|
+                                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  -- HYBRID_HASH_JOIN [$$108, $$106][$$100, $$101]  |PARTITIONED|
+                                                                    -- HASH_PARTITION_EXCHANGE [$$108, $$106]  |PARTITIONED|
+                                                                      -- STREAM_PROJECT  |PARTITIONED|
+                                                                        -- ASSIGN  |PARTITIONED|
+                                                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                              -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                -- ASSIGN  |UNPARTITIONED|
+                                                                                  -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                                                    -- HASH_PARTITION_EXCHANGE [$$100, $$101]  |PARTITIONED|
+                                                                      -- STREAM_PROJECT  |PARTITIONED|
+                                                                        -- ASSIGN  |PARTITIONED|
+                                                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                            -- HASH_PARTITION_EXCHANGE [$$104]  |PARTITIONED|
+                                                              -- STREAM_PROJECT  |PARTITIONED|
+                                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  -- NESTED_LOOP  |PARTITIONED|
+                                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      -- STREAM_SELECT  |PARTITIONED|
+                                                                        -- ASSIGN  |PARTITIONED|
+                                                                          -- ASSIGN  |PARTITIONED|
+                                                                            -- ASSIGN  |PARTITIONED|
+                                                                              -- STREAM_PROJECT  |PARTITIONED|
+                                                                                -- ASSIGN  |PARTITIONED|
+                                                                                  -- STREAM_PROJECT  |PARTITIONED|
+                                                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                          -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                    -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                      -- STREAM_PROJECT  |PARTITIONED|
+                                                                        -- ASSIGN  |PARTITIONED|
+                                                                          -- ASSIGN  |PARTITIONED|
+                                                                            -- ASSIGN  |PARTITIONED|
+                                                                              -- STREAM_PROJECT  |PARTITIONED|
+                                                                                -- ASSIGN  |PARTITIONED|
+                                                                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterix-bad/src/test/resources/optimizerts/results/channel/channel-advanced-index-only.plan b/asterix-bad/src/test/resources/optimizerts/results/bad_rq/channel-advanced-index-only.plan
similarity index 66%
rename from asterix-bad/src/test/resources/optimizerts/results/channel/channel-advanced-index-only.plan
rename to asterix-bad/src/test/resources/optimizerts/results/bad_rq/channel-advanced-index-only.plan
index 8786d79..4134a0a 100644
--- a/asterix-bad/src/test/resources/optimizerts/results/channel/channel-advanced-index-only.plan
+++ b/asterix-bad/src/test/resources/optimizerts/results/bad_rq/channel-advanced-index-only.plan
@@ -1,13 +1,13 @@
 -- NOTIFY_BROKERS  |PARTITIONED|
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- PRE_CLUSTERED_GROUP_BY[$$150, $$channelExecutionTime]  |PARTITIONED|
+    -- PRE_CLUSTERED_GROUP_BY[$$150, $$151, $$channelExecutionTime]  |PARTITIONED|
             {
               -- AGGREGATE  |LOCAL|
                 -- NESTED_TUPLE_SOURCE  |LOCAL|
             }
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-        -- STABLE_SORT [$$150(ASC), $$channelExecutionTime(ASC)]  |PARTITIONED|
-          -- HASH_PARTITION_EXCHANGE [$$150, $$channelExecutionTime]  |PARTITIONED|
+        -- STABLE_SORT [$$150(ASC), $$151(ASC), $$channelExecutionTime(ASC)]  |PARTITIONED|
+          -- HASH_PARTITION_EXCHANGE [$$150, $$151, $$channelExecutionTime]  |PARTITIONED|
             -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                 -- STABLE_SORT [$$125(ASC)]  |PARTITIONED|
@@ -30,101 +30,100 @@
                                                   -- STREAM_PROJECT  |PARTITIONED|
                                                     -- ASSIGN  |PARTITIONED|
                                                       -- STREAM_PROJECT  |PARTITIONED|
-                                                        -- STREAM_SELECT  |PARTITIONED|
-                                                          -- STREAM_PROJECT  |PARTITIONED|
-                                                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- HYBRID_HASH_JOIN [$$135][$$134]  |PARTITIONED|
-                                                                -- HASH_PARTITION_EXCHANGE [$$135]  |PARTITIONED|
-                                                                  -- STREAM_PROJECT  |PARTITIONED|
+                                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          -- HYBRID_HASH_JOIN [$$135][$$134]  |PARTITIONED|
+                                                            -- HASH_PARTITION_EXCHANGE [$$135]  |PARTITIONED|
+                                                              -- STREAM_PROJECT  |PARTITIONED|
+                                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  -- HYBRID_HASH_JOIN [$$132, $$130][$$126, $$127]  |PARTITIONED|
+                                                                    -- HASH_PARTITION_EXCHANGE [$$132, $$130]  |PARTITIONED|
+                                                                      -- STREAM_PROJECT  |PARTITIONED|
+                                                                        -- ASSIGN  |PARTITIONED|
+                                                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                              -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                -- ASSIGN  |UNPARTITIONED|
+                                                                                  -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                                                    -- HASH_PARTITION_EXCHANGE [$$126, $$127]  |PARTITIONED|
+                                                                      -- STREAM_PROJECT  |PARTITIONED|
+                                                                        -- ASSIGN  |PARTITIONED|
+                                                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                            -- HASH_PARTITION_EXCHANGE [$$134]  |PARTITIONED|
+                                                              -- STREAM_PROJECT  |PARTITIONED|
+                                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  -- HYBRID_HASH_JOIN [$$128][$$144]  |PARTITIONED|
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- HYBRID_HASH_JOIN [$$133, $$131][$$126, $$127]  |PARTITIONED|
-                                                                        -- HASH_PARTITION_EXCHANGE [$$133, $$131]  |PARTITIONED|
-                                                                          -- STREAM_PROJECT  |PARTITIONED|
-                                                                            -- ASSIGN  |PARTITIONED|
-                                                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                -- DATASOURCE_SCAN  |PARTITIONED|
-                                                                                  -- BROADCAST_EXCHANGE  |PARTITIONED|
-                                                                                    -- ASSIGN  |UNPARTITIONED|
-                                                                                      -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
-                                                                        -- HASH_PARTITION_EXCHANGE [$$126, $$127]  |PARTITIONED|
-                                                                          -- STREAM_PROJECT  |PARTITIONED|
-                                                                            -- ASSIGN  |PARTITIONED|
-                                                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                -- DATASOURCE_SCAN  |PARTITIONED|
-                                                                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                                -- HASH_PARTITION_EXCHANGE [$$134]  |PARTITIONED|
-                                                                  -- STREAM_PROJECT  |PARTITIONED|
-                                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- HYBRID_HASH_JOIN [$$128][$$144]  |PARTITIONED|
-                                                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                          -- STREAM_SELECT  |PARTITIONED|
-                                                                            -- ASSIGN  |PARTITIONED|
-                                                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                -- BTREE_SEARCH  |PARTITIONED|
-                                                                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                    -- STABLE_SORT [$$154(ASC)]  |PARTITIONED|
-                                                                                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                        -- STREAM_PROJECT  |PARTITIONED|
-                                                                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                            -- BTREE_SEARCH  |PARTITIONED|
-                                                                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                -- ASSIGN  |PARTITIONED|
-                                                                                                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                                        -- HASH_PARTITION_EXCHANGE [$$144]  |PARTITIONED|
-                                                                          -- NESTED_LOOP  |PARTITIONED|
+                                                                      -- STREAM_PROJECT  |PARTITIONED|
+                                                                        -- STREAM_SELECT  |PARTITIONED|
+                                                                          -- ASSIGN  |PARTITIONED|
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                              -- UNION_ALL  |PARTITIONED|
+                                                                              -- BTREE_SEARCH  |PARTITIONED|
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                  -- STREAM_PROJECT  |PARTITIONED|
-                                                                                    -- STREAM_SELECT  |PARTITIONED|
-                                                                                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                        -- BTREE_SEARCH  |PARTITIONED|
-                                                                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                            -- SPLIT  |PARTITIONED|
-                                                                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                -- STREAM_PROJECT  |PARTITIONED|
-                                                                                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                    -- BTREE_SEARCH  |PARTITIONED|
-                                                                                                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                        -- ASSIGN  |PARTITIONED|
-                                                                                                          -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                  -- STREAM_PROJECT  |PARTITIONED|
+                                                                                  -- STABLE_SORT [$$155(ASC)]  |PARTITIONED|
                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                      -- SPLIT  |PARTITIONED|
-                                                                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                          -- STREAM_PROJECT  |PARTITIONED|
-                                                                                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                              -- BTREE_SEARCH  |PARTITIONED|
-                                                                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                  -- ASSIGN  |PARTITIONED|
-                                                                                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                                            -- BROADCAST_EXCHANGE  |PARTITIONED|
-                                                                              -- UNION_ALL  |PARTITIONED|
-                                                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                  -- STREAM_PROJECT  |PARTITIONED|
-                                                                                    -- STREAM_SELECT  |PARTITIONED|
                                                                                       -- STREAM_PROJECT  |PARTITIONED|
                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                                                           -- BTREE_SEARCH  |PARTITIONED|
                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                              -- SPLIT  |PARTITIONED|
-                                                                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                  -- STREAM_PROJECT  |PARTITIONED|
-                                                                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                      -- BTREE_SEARCH  |PARTITIONED|
-                                                                                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                          -- ASSIGN  |PARTITIONED|
-                                                                                                            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                              -- ASSIGN  |PARTITIONED|
+                                                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                    -- HASH_PARTITION_EXCHANGE [$$144]  |PARTITIONED|
+                                                                      -- NESTED_LOOP  |PARTITIONED|
+                                                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          -- UNION_ALL  |PARTITIONED|
+                                                                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              -- STREAM_PROJECT  |PARTITIONED|
+                                                                                -- STREAM_SELECT  |PARTITIONED|
+                                                                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                                                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                        -- SPLIT  |PARTITIONED|
+                                                                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                            -- STREAM_PROJECT  |PARTITIONED|
+                                                                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                                                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                    -- ASSIGN  |PARTITIONED|
+                                                                                                      -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              -- STREAM_PROJECT  |PARTITIONED|
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  -- SPLIT  |PARTITIONED|
+                                                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                      -- STREAM_PROJECT  |PARTITIONED|
+                                                                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                                                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                              -- ASSIGN  |PARTITIONED|
+                                                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                        -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                          -- UNION_ALL  |PARTITIONED|
+                                                                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              -- STREAM_PROJECT  |PARTITIONED|
+                                                                                -- STREAM_SELECT  |PARTITIONED|
                                                                                   -- STREAM_PROJECT  |PARTITIONED|
                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                      -- SPLIT  |PARTITIONED|
+                                                                                      -- BTREE_SEARCH  |PARTITIONED|
                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                          -- STREAM_PROJECT  |PARTITIONED|
+                                                                                          -- SPLIT  |PARTITIONED|
                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                                                              -- STREAM_PROJECT  |PARTITIONED|
                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                  -- ASSIGN  |PARTITIONED|
-                                                                                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                      -- ASSIGN  |PARTITIONED|
+                                                                                                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              -- STREAM_PROJECT  |PARTITIONED|
+                                                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  -- SPLIT  |PARTITIONED|
+                                                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                      -- STREAM_PROJECT  |PARTITIONED|
+                                                                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                                                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                              -- ASSIGN  |PARTITIONED|
+                                                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterix-bad/src/test/resources/optimizerts/results/channel/channel-advanced.plan b/asterix-bad/src/test/resources/optimizerts/results/bad_rq/channel-advanced.plan
similarity index 67%
rename from asterix-bad/src/test/resources/optimizerts/results/channel/channel-advanced.plan
rename to asterix-bad/src/test/resources/optimizerts/results/bad_rq/channel-advanced.plan
index fc49ea9..18946c6 100644
--- a/asterix-bad/src/test/resources/optimizerts/results/channel/channel-advanced.plan
+++ b/asterix-bad/src/test/resources/optimizerts/results/bad_rq/channel-advanced.plan
@@ -1,13 +1,13 @@
 -- NOTIFY_BROKERS  |PARTITIONED|
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- PRE_CLUSTERED_GROUP_BY[$$150, $$channelExecutionTime]  |PARTITIONED|
+    -- PRE_CLUSTERED_GROUP_BY[$$150, $$151, $$channelExecutionTime]  |PARTITIONED|
             {
               -- AGGREGATE  |LOCAL|
                 -- NESTED_TUPLE_SOURCE  |LOCAL|
             }
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-        -- STABLE_SORT [$$150(ASC), $$channelExecutionTime(ASC)]  |PARTITIONED|
-          -- HASH_PARTITION_EXCHANGE [$$150, $$channelExecutionTime]  |PARTITIONED|
+        -- STABLE_SORT [$$150(ASC), $$151(ASC), $$channelExecutionTime(ASC)]  |PARTITIONED|
+          -- HASH_PARTITION_EXCHANGE [$$150, $$151, $$channelExecutionTime]  |PARTITIONED|
             -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                 -- STABLE_SORT [$$125(ASC)]  |PARTITIONED|
@@ -30,40 +30,55 @@
                                                   -- STREAM_PROJECT  |PARTITIONED|
                                                     -- ASSIGN  |PARTITIONED|
                                                       -- STREAM_PROJECT  |PARTITIONED|
-                                                        -- STREAM_SELECT  |PARTITIONED|
-                                                          -- STREAM_PROJECT  |PARTITIONED|
-                                                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- HYBRID_HASH_JOIN [$$135][$$134]  |PARTITIONED|
-                                                                -- HASH_PARTITION_EXCHANGE [$$135]  |PARTITIONED|
-                                                                  -- STREAM_PROJECT  |PARTITIONED|
-                                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- HYBRID_HASH_JOIN [$$133, $$131][$$126, $$127]  |PARTITIONED|
-                                                                        -- HASH_PARTITION_EXCHANGE [$$133, $$131]  |PARTITIONED|
-                                                                          -- STREAM_PROJECT  |PARTITIONED|
-                                                                            -- ASSIGN  |PARTITIONED|
+                                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          -- HYBRID_HASH_JOIN [$$135][$$134]  |PARTITIONED|
+                                                            -- HASH_PARTITION_EXCHANGE [$$135]  |PARTITIONED|
+                                                              -- STREAM_PROJECT  |PARTITIONED|
+                                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  -- HYBRID_HASH_JOIN [$$132, $$130][$$126, $$127]  |PARTITIONED|
+                                                                    -- HASH_PARTITION_EXCHANGE [$$132, $$130]  |PARTITIONED|
+                                                                      -- STREAM_PROJECT  |PARTITIONED|
+                                                                        -- ASSIGN  |PARTITIONED|
+                                                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                              -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                -- ASSIGN  |UNPARTITIONED|
+                                                                                  -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                                                    -- HASH_PARTITION_EXCHANGE [$$126, $$127]  |PARTITIONED|
+                                                                      -- STREAM_PROJECT  |PARTITIONED|
+                                                                        -- ASSIGN  |PARTITIONED|
+                                                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                -- DATASOURCE_SCAN  |PARTITIONED|
-                                                                                  -- BROADCAST_EXCHANGE  |PARTITIONED|
-                                                                                    -- ASSIGN  |UNPARTITIONED|
-                                                                                      -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
-                                                                        -- HASH_PARTITION_EXCHANGE [$$126, $$127]  |PARTITIONED|
-                                                                          -- STREAM_PROJECT  |PARTITIONED|
-                                                                            -- ASSIGN  |PARTITIONED|
-                                                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                -- DATASOURCE_SCAN  |PARTITIONED|
-                                                                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                                -- HASH_PARTITION_EXCHANGE [$$134]  |PARTITIONED|
-                                                                  -- STREAM_PROJECT  |PARTITIONED|
+                                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                            -- HASH_PARTITION_EXCHANGE [$$134]  |PARTITIONED|
+                                                              -- STREAM_PROJECT  |PARTITIONED|
+                                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  -- HYBRID_HASH_JOIN [$$128][$$144]  |PARTITIONED|
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- HYBRID_HASH_JOIN [$$128][$$144]  |PARTITIONED|
+                                                                      -- STREAM_PROJECT  |PARTITIONED|
+                                                                        -- STREAM_SELECT  |PARTITIONED|
+                                                                          -- ASSIGN  |PARTITIONED|
+                                                                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  -- STABLE_SORT [$$155(ASC)]  |PARTITIONED|
+                                                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                      -- STREAM_PROJECT  |PARTITIONED|
+                                                                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                                                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                              -- ASSIGN  |PARTITIONED|
+                                                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                    -- HASH_PARTITION_EXCHANGE [$$144]  |PARTITIONED|
+                                                                      -- NESTED_LOOP  |PARTITIONED|
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                          -- STREAM_SELECT  |PARTITIONED|
-                                                                            -- ASSIGN  |PARTITIONED|
+                                                                          -- STREAM_PROJECT  |PARTITIONED|
+                                                                            -- STREAM_SELECT  |PARTITIONED|
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                                                 -- BTREE_SEARCH  |PARTITIONED|
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                    -- STABLE_SORT [$$154(ASC)]  |PARTITIONED|
+                                                                                    -- STABLE_SORT [$$159(ASC)]  |PARTITIONED|
                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                                                         -- STREAM_PROJECT  |PARTITIONED|
                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
@@ -71,34 +86,18 @@
                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                                                                 -- ASSIGN  |PARTITIONED|
                                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                                        -- HASH_PARTITION_EXCHANGE [$$144]  |PARTITIONED|
-                                                                          -- NESTED_LOOP  |PARTITIONED|
-                                                                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                          -- STREAM_PROJECT  |PARTITIONED|
+                                                                            -- STREAM_SELECT  |PARTITIONED|
                                                                               -- STREAM_PROJECT  |PARTITIONED|
-                                                                                -- STREAM_SELECT  |PARTITIONED|
-                                                                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                    -- BTREE_SEARCH  |PARTITIONED|
-                                                                                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                        -- STABLE_SORT [$$158(ASC)]  |PARTITIONED|
-                                                                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                            -- STREAM_PROJECT  |PARTITIONED|
-                                                                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                -- BTREE_SEARCH  |PARTITIONED|
-                                                                                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                    -- ASSIGN  |PARTITIONED|
-                                                                                                      -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                                            -- BROADCAST_EXCHANGE  |PARTITIONED|
-                                                                              -- STREAM_PROJECT  |PARTITIONED|
-                                                                                -- STREAM_SELECT  |PARTITIONED|
-                                                                                  -- STREAM_PROJECT  |PARTITIONED|
+                                                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  -- BTREE_SEARCH  |PARTITIONED|
                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                      -- BTREE_SEARCH  |PARTITIONED|
+                                                                                      -- STABLE_SORT [$$162(ASC)]  |PARTITIONED|
                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                          -- STABLE_SORT [$$161(ASC)]  |PARTITIONED|
+                                                                                          -- STREAM_PROJECT  |PARTITIONED|
                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                              -- STREAM_PROJECT  |PARTITIONED|
+                                                                                              -- BTREE_SEARCH  |PARTITIONED|
                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                  -- BTREE_SEARCH  |PARTITIONED|
-                                                                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                      -- ASSIGN  |PARTITIONED|
-                                                                                                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                  -- ASSIGN  |PARTITIONED|
+                                                                                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterix-bad/src/test/resources/optimizerts/results/channel/channel-create.plan b/asterix-bad/src/test/resources/optimizerts/results/bad_rq/channel-create.plan
similarity index 92%
rename from asterix-bad/src/test/resources/optimizerts/results/channel/channel-create.plan
rename to asterix-bad/src/test/resources/optimizerts/results/bad_rq/channel-create.plan
index 78c599a..c8dc3ef 100644
--- a/asterix-bad/src/test/resources/optimizerts/results/channel/channel-create.plan
+++ b/asterix-bad/src/test/resources/optimizerts/results/bad_rq/channel-create.plan
@@ -1,13 +1,13 @@
 -- NOTIFY_BROKERS  |PARTITIONED|
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- PRE_CLUSTERED_GROUP_BY[$$100, $$channelExecutionTime]  |PARTITIONED|
+    -- PRE_CLUSTERED_GROUP_BY[$$100, $$101, $$channelExecutionTime]  |PARTITIONED|
             {
               -- AGGREGATE  |LOCAL|
                 -- NESTED_TUPLE_SOURCE  |LOCAL|
             }
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-        -- STABLE_SORT [$$100(ASC), $$channelExecutionTime(ASC)]  |PARTITIONED|
-          -- HASH_PARTITION_EXCHANGE [$$100, $$channelExecutionTime]  |PARTITIONED|
+        -- STABLE_SORT [$$100(ASC), $$101(ASC), $$channelExecutionTime(ASC)]  |PARTITIONED|
+          -- HASH_PARTITION_EXCHANGE [$$100, $$101, $$channelExecutionTime]  |PARTITIONED|
             -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                 -- STABLE_SORT [$$85(ASC)]  |PARTITIONED|
@@ -35,8 +35,8 @@
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                               -- STREAM_PROJECT  |PARTITIONED|
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- HYBRID_HASH_JOIN [$$92, $$90][$$86, $$87]  |PARTITIONED|
-                                                                    -- HASH_PARTITION_EXCHANGE [$$92, $$90]  |PARTITIONED|
+                                                                  -- HYBRID_HASH_JOIN [$$91, $$89][$$86, $$87]  |PARTITIONED|
+                                                                    -- HASH_PARTITION_EXCHANGE [$$91, $$89]  |PARTITIONED|
                                                                       -- STREAM_PROJECT  |PARTITIONED|
                                                                         -- ASSIGN  |PARTITIONED|
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
diff --git a/asterix-bad/src/test/resources/optimizerts/results/bad_rq/channel-push.plan b/asterix-bad/src/test/resources/optimizerts/results/bad_rq/channel-push.plan
new file mode 100644
index 0000000..36d6517
--- /dev/null
+++ b/asterix-bad/src/test/resources/optimizerts/results/bad_rq/channel-push.plan
@@ -0,0 +1,92 @@
+-- NOTIFY_BROKERS  |PARTITIONED|
+  -- STREAM_PROJECT  |PARTITIONED|
+    -- STREAM_PROJECT  |PARTITIONED|
+      -- ASSIGN  |PARTITIONED|
+        -- STREAM_PROJECT  |PARTITIONED|
+          -- STREAM_SELECT  |PARTITIONED|
+            -- STREAM_PROJECT  |PARTITIONED|
+              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                -- HYBRID_HASH_JOIN [$$138][$$145]  |PARTITIONED|
+                  -- HASH_PARTITION_EXCHANGE [$$138]  |PARTITIONED|
+                    -- NESTED_LOOP  |PARTITIONED|
+                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        -- STREAM_PROJECT  |PARTITIONED|
+                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            -- HYBRID_HASH_JOIN [$$135, $$133][$$126, $$127]  |PARTITIONED|
+                              -- HASH_PARTITION_EXCHANGE [$$135, $$133]  |PARTITIONED|
+                                -- STREAM_PROJECT  |PARTITIONED|
+                                  -- ASSIGN  |PARTITIONED|
+                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                          -- ASSIGN  |UNPARTITIONED|
+                                            -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                              -- HASH_PARTITION_EXCHANGE [$$126, $$127]  |PARTITIONED|
+                                -- STREAM_PROJECT  |PARTITIONED|
+                                  -- ASSIGN  |PARTITIONED|
+                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                      -- BROADCAST_EXCHANGE  |PARTITIONED|
+                        -- STREAM_SELECT  |PARTITIONED|
+                          -- ASSIGN  |PARTITIONED|
+                            -- STREAM_PROJECT  |PARTITIONED|
+                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    -- PRE_CLUSTERED_GROUP_BY[$$178]  |PARTITIONED|
+                            {
+                              -- AGGREGATE  |LOCAL|
+                                -- STREAM_SELECT  |LOCAL|
+                                  -- NESTED_TUPLE_SOURCE  |LOCAL|
+                            }
+                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        -- STABLE_SORT [$$178(ASC)]  |PARTITIONED|
+                          -- HASH_PARTITION_EXCHANGE [$$178]  |PARTITIONED|
+                            -- UNION_ALL  |PARTITIONED|
+                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                -- STREAM_PROJECT  |PARTITIONED|
+                                  -- STREAM_SELECT  |PARTITIONED|
+                                    -- STREAM_PROJECT  |PARTITIONED|
+                                      -- ASSIGN  |PARTITIONED|
+                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              -- STREAM_PROJECT  |PARTITIONED|
+                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  -- SPLIT  |PARTITIONED|
+                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      -- STREAM_PROJECT  |PARTITIONED|
+                                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          -- RTREE_SEARCH  |PARTITIONED|
+                                                            -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                              -- ASSIGN  |PARTITIONED|
+                                                                -- STREAM_PROJECT  |PARTITIONED|
+                                                                  -- ASSIGN  |PARTITIONED|
+                                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                -- STREAM_PROJECT  |PARTITIONED|
+                                  -- STREAM_SELECT  |PARTITIONED|
+                                    -- STREAM_PROJECT  |PARTITIONED|
+                                      -- ASSIGN  |PARTITIONED|
+                                        -- STREAM_PROJECT  |PARTITIONED|
+                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            -- SPLIT  |PARTITIONED|
+                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                -- STREAM_PROJECT  |PARTITIONED|
+                                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    -- RTREE_SEARCH  |PARTITIONED|
+                                                      -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                        -- ASSIGN  |PARTITIONED|
+                                                          -- STREAM_PROJECT  |PARTITIONED|
+                                                            -- ASSIGN  |PARTITIONED|
+                                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterix-bad/src/test/resources/optimizerts/results/channel/channel-subscribe.plan b/asterix-bad/src/test/resources/optimizerts/results/bad_rq/channel-subscribe.plan
similarity index 92%
rename from asterix-bad/src/test/resources/optimizerts/results/channel/channel-subscribe.plan
rename to asterix-bad/src/test/resources/optimizerts/results/bad_rq/channel-subscribe.plan
index 8fa535c..a5a40c1 100644
--- a/asterix-bad/src/test/resources/optimizerts/results/channel/channel-subscribe.plan
+++ b/asterix-bad/src/test/resources/optimizerts/results/bad_rq/channel-subscribe.plan
@@ -1,13 +1,13 @@
 -- NOTIFY_BROKERS  |PARTITIONED|
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- PRE_CLUSTERED_GROUP_BY[$$100, $$channelExecutionTime]  |PARTITIONED|
+    -- PRE_CLUSTERED_GROUP_BY[$$100, $$101, $$channelExecutionTime]  |PARTITIONED|
             {
               -- AGGREGATE  |LOCAL|
                 -- NESTED_TUPLE_SOURCE  |LOCAL|
             }
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-        -- STABLE_SORT [$$100(ASC), $$channelExecutionTime(ASC)]  |PARTITIONED|
-          -- HASH_PARTITION_EXCHANGE [$$100, $$channelExecutionTime]  |PARTITIONED|
+        -- STABLE_SORT [$$100(ASC), $$101(ASC), $$channelExecutionTime(ASC)]  |PARTITIONED|
+          -- HASH_PARTITION_EXCHANGE [$$100, $$101, $$channelExecutionTime]  |PARTITIONED|
             -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                 -- STABLE_SORT [$$85(ASC)]  |PARTITIONED|
@@ -35,8 +35,8 @@
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                               -- STREAM_PROJECT  |PARTITIONED|
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- HYBRID_HASH_JOIN [$$92, $$90][$$86, $$87]  |PARTITIONED|
-                                                                    -- HASH_PARTITION_EXCHANGE [$$92, $$90]  |PARTITIONED|
+                                                                  -- HYBRID_HASH_JOIN [$$91, $$89][$$86, $$87]  |PARTITIONED|
+                                                                    -- HASH_PARTITION_EXCHANGE [$$91, $$89]  |PARTITIONED|
                                                                       -- STREAM_PROJECT  |PARTITIONED|
                                                                         -- ASSIGN  |PARTITIONED|
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
diff --git a/asterix-bad/src/test/resources/optimizerts/results/channel/channel-unsubscribe.plan b/asterix-bad/src/test/resources/optimizerts/results/bad_rq/channel-unsubscribe.plan
similarity index 92%
rename from asterix-bad/src/test/resources/optimizerts/results/channel/channel-unsubscribe.plan
rename to asterix-bad/src/test/resources/optimizerts/results/bad_rq/channel-unsubscribe.plan
index c66b5ca..6fe8ed6 100644
--- a/asterix-bad/src/test/resources/optimizerts/results/channel/channel-unsubscribe.plan
+++ b/asterix-bad/src/test/resources/optimizerts/results/bad_rq/channel-unsubscribe.plan
@@ -1,13 +1,13 @@
 -- NOTIFY_BROKERS  |PARTITIONED|
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- PRE_CLUSTERED_GROUP_BY[$$100, $$channelExecutionTime]  |PARTITIONED|
+    -- PRE_CLUSTERED_GROUP_BY[$$100, $$101, $$channelExecutionTime]  |PARTITIONED|
             {
               -- AGGREGATE  |LOCAL|
                 -- NESTED_TUPLE_SOURCE  |LOCAL|
             }
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-        -- STABLE_SORT [$$100(ASC), $$channelExecutionTime(ASC)]  |PARTITIONED|
-          -- HASH_PARTITION_EXCHANGE [$$100, $$channelExecutionTime]  |PARTITIONED|
+        -- STABLE_SORT [$$100(ASC), $$101(ASC), $$channelExecutionTime(ASC)]  |PARTITIONED|
+          -- HASH_PARTITION_EXCHANGE [$$100, $$101, $$channelExecutionTime]  |PARTITIONED|
             -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                 -- STABLE_SORT [$$85(ASC)]  |PARTITIONED|
@@ -35,8 +35,8 @@
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                               -- STREAM_PROJECT  |PARTITIONED|
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- HYBRID_HASH_JOIN [$$92, $$90][$$86, $$87]  |PARTITIONED|
-                                                                    -- HASH_PARTITION_EXCHANGE [$$92, $$90]  |PARTITIONED|
+                                                                  -- HYBRID_HASH_JOIN [$$91, $$89][$$86, $$87]  |PARTITIONED|
+                                                                    -- HASH_PARTITION_EXCHANGE [$$91, $$89]  |PARTITIONED|
                                                                       -- STREAM_PROJECT  |PARTITIONED|
                                                                         -- ASSIGN  |PARTITIONED|
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
diff --git a/asterix-bad/src/test/resources/optimizerts/results/channel/channel-push.plan b/asterix-bad/src/test/resources/optimizerts/results/channel/channel-push.plan
deleted file mode 100644
index b79afd7..0000000
--- a/asterix-bad/src/test/resources/optimizerts/results/channel/channel-push.plan
+++ /dev/null
@@ -1,92 +0,0 @@
--- NOTIFY_BROKERS  |PARTITIONED|
-  -- STREAM_PROJECT  |PARTITIONED|
-    -- STREAM_PROJECT  |PARTITIONED|
-      -- ASSIGN  |PARTITIONED|
-        -- STREAM_PROJECT  |PARTITIONED|
-          -- STREAM_SELECT  |PARTITIONED|
-            -- STREAM_PROJECT  |PARTITIONED|
-              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- HYBRID_HASH_JOIN [$$137][$$144]  |PARTITIONED|
-                  -- HASH_PARTITION_EXCHANGE [$$137]  |PARTITIONED|
-                    -- STREAM_PROJECT  |PARTITIONED|
-                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- HYBRID_HASH_JOIN [$$135, $$133][$$126, $$127]  |PARTITIONED|
-                          -- HASH_PARTITION_EXCHANGE [$$135, $$133]  |PARTITIONED|
-                            -- STREAM_PROJECT  |PARTITIONED|
-                              -- ASSIGN  |PARTITIONED|
-                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN  |PARTITIONED|
-                                    -- BROADCAST_EXCHANGE  |PARTITIONED|
-                                      -- ASSIGN  |UNPARTITIONED|
-                                        -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
-                          -- HASH_PARTITION_EXCHANGE [$$126, $$127]  |PARTITIONED|
-                            -- STREAM_PROJECT  |PARTITIONED|
-                              -- ASSIGN  |PARTITIONED|
-                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN  |PARTITIONED|
-                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                  -- HASH_PARTITION_EXCHANGE [$$144]  |PARTITIONED|
-                    -- NESTED_LOOP  |PARTITIONED|
-                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- STREAM_SELECT  |PARTITIONED|
-                          -- ASSIGN  |PARTITIONED|
-                            -- STREAM_PROJECT  |PARTITIONED|
-                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN  |PARTITIONED|
-                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                      -- BROADCAST_EXCHANGE  |PARTITIONED|
-                        -- PRE_CLUSTERED_GROUP_BY[$$176]  |PARTITIONED|
-                                {
-                                  -- AGGREGATE  |LOCAL|
-                                    -- STREAM_SELECT  |LOCAL|
-                                      -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                }
-                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- STABLE_SORT [$$176(ASC)]  |PARTITIONED|
-                              -- HASH_PARTITION_EXCHANGE [$$176]  |PARTITIONED|
-                                -- UNION_ALL  |PARTITIONED|
-                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- STREAM_PROJECT  |PARTITIONED|
-                                      -- STREAM_SELECT  |PARTITIONED|
-                                        -- STREAM_PROJECT  |PARTITIONED|
-                                          -- ASSIGN  |PARTITIONED|
-                                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- BTREE_SEARCH  |PARTITIONED|
-                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- STREAM_PROJECT  |PARTITIONED|
-                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- SPLIT  |PARTITIONED|
-                                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- STREAM_PROJECT  |PARTITIONED|
-                                                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- RTREE_SEARCH  |PARTITIONED|
-                                                                -- BROADCAST_EXCHANGE  |PARTITIONED|
-                                                                  -- ASSIGN  |PARTITIONED|
-                                                                    -- STREAM_PROJECT  |PARTITIONED|
-                                                                      -- ASSIGN  |PARTITIONED|
-                                                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
-                                                                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- STREAM_PROJECT  |PARTITIONED|
-                                      -- STREAM_SELECT  |PARTITIONED|
-                                        -- STREAM_PROJECT  |PARTITIONED|
-                                          -- ASSIGN  |PARTITIONED|
-                                            -- STREAM_PROJECT  |PARTITIONED|
-                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- SPLIT  |PARTITIONED|
-                                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- STREAM_PROJECT  |PARTITIONED|
-                                                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- RTREE_SEARCH  |PARTITIONED|
-                                                          -- BROADCAST_EXCHANGE  |PARTITIONED|
-                                                            -- ASSIGN  |PARTITIONED|
-                                                              -- STREAM_PROJECT  |PARTITIONED|
-                                                                -- ASSIGN  |PARTITIONED|
-                                                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
-                                                                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterix-bad/src/test/resources/runtimets/only_bad.xml b/asterix-bad/src/test/resources/runtimets/only_bad.xml
new file mode 100644
index 0000000..d6e89bb
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/only_bad.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-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_delete/active_dataset_delete.1.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_delete/active_dataset_delete.1.ddl.sqlpp
new file mode 100644
index 0000000..9f938f7
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_delete/active_dataset_delete.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.
+ */
+DROP DATAVERSE test IF EXISTS;
+CREATE DATAVERSE test;
+USE test;
+
+DROP DATASET Tweets IF EXISTS;
+DROP TYPE Tweet IF EXISTS;
+
+CREATE TYPE Tweet AS OPEN {
+ tid: bigint,
+ area_code: string,
+ text: string,
+ location: point,
+ timestamp: datetime
+};
+
+CREATE ACTIVE DATASET Tweets(Tweet) PRIMARY KEY tid;
+CREATE DATASET Tweets2(Tweet) PRIMARY KEY tid;
+
+CREATE INDEX s_rating ON Tweets(area_code);
+CREATE INDEX s_location ON Tweets(location) type RTREE;
+
+
+CREATE INDEX s_rating2 ON Tweets2(area_code);
+CREATE INDEX s_location2 ON Tweets2(location) type RTREE;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_delete/active_dataset_delete.2.update.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_delete/active_dataset_delete.2.update.sqlpp
new file mode 100644
index 0000000..961a587
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_delete/active_dataset_delete.2.update.sqlpp
@@ -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.
+ */
+use test;
+
+INSERT INTO Tweets([{"tid" : 999, "area_code": "45", "text": "Tweet 1.", "location": point("1998078.3009357268, 1998011.0235705695"), "timestamp": datetime("2019-12-03T17:59:52.041Z"), "hatefulFlag": False}]);
+UPSERT INTO Tweets([{"tid" : 1000, "area_code": "46", "text": "Tweet 2", "location": point("1998078.3009357268, 1998011.0235705695"), "timestamp": datetime("2019-12-03T17:59:52.041Z"), "hatefulFlag": False}]);
+
+INSERT INTO Tweets2([{"tid" : 999, "area_code": "45", "text": "Tweet 1.", "location": point("1998078.3009357268, 1998011.0235705695"), "timestamp": datetime("2019-12-03T17:59:52.041Z"), "hatefulFlag": False}]);
+UPSERT INTO Tweets2([{"tid" : 1000, "area_code": "45", "text": "Tweet 2", "location": point("1998078.3009357268, 1998011.0235705695"), "timestamp": datetime("2019-12-03T17:59:52.041Z"), "hatefulFlag": False}]);
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_delete/active_dataset_delete.3.update.sqlpp
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_delete/active_dataset_delete.3.update.sqlpp
index b7bb951..a566da2 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_delete/active_dataset_delete.3.update.sqlpp
@@ -16,10 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+use test;
+DELETE FROM Tweets t WHERE t.tid = 1000;
+DELETE FROM Tweets2 t2 WHERE t2.tid = 1000;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_delete/active_dataset_delete.4.query.sqlpp
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_delete/active_dataset_delete.4.query.sqlpp
index b7bb951..2d6b123 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_delete/active_dataset_delete.4.query.sqlpp
@@ -16,10 +16,5 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+USE test;
+SELECT t FROM Tweets2 t ORDER BY t.tid;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_delete/active_dataset_delete.5.query.sqlpp
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_delete/active_dataset_delete.5.query.sqlpp
index b7bb951..a266db3 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_delete/active_dataset_delete.5.query.sqlpp
@@ -16,10 +16,5 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+USE test;
+SELECT t, meta(t).`_active_timestamp` as Time FROM Tweets t ORDER BY t.tid;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_insert/active_dataset_insert.1.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_insert/active_dataset_insert.1.ddl.sqlpp
new file mode 100644
index 0000000..9f938f7
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_insert/active_dataset_insert.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.
+ */
+DROP DATAVERSE test IF EXISTS;
+CREATE DATAVERSE test;
+USE test;
+
+DROP DATASET Tweets IF EXISTS;
+DROP TYPE Tweet IF EXISTS;
+
+CREATE TYPE Tweet AS OPEN {
+ tid: bigint,
+ area_code: string,
+ text: string,
+ location: point,
+ timestamp: datetime
+};
+
+CREATE ACTIVE DATASET Tweets(Tweet) PRIMARY KEY tid;
+CREATE DATASET Tweets2(Tweet) PRIMARY KEY tid;
+
+CREATE INDEX s_rating ON Tweets(area_code);
+CREATE INDEX s_location ON Tweets(location) type RTREE;
+
+
+CREATE INDEX s_rating2 ON Tweets2(area_code);
+CREATE INDEX s_location2 ON Tweets2(location) type RTREE;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_insert/active_dataset_insert.2.update.sqlpp
similarity index 78%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_insert/active_dataset_insert.2.update.sqlpp
index b1a132b..42a5a10 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_insert/active_dataset_insert.2.update.sqlpp
@@ -16,12 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Disasters with friends
-* Expected Res : Success
-* Date         : May 17
-* Author       : Steven Jacobs
-*/
-use channels;
+use test;
 
-subscribe to EmergenciesNearMeChannel("tornado", 1) on brokerA;
+INSERT INTO Tweets([{"tid" : 999, "area_code": "45", "text": "Tweet 1.", "location": point("1998078.3009357268, 1998011.0235705695"), "timestamp": datetime("2019-12-03T17:59:52.041Z"), "hatefulFlag": False}]);
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_insert/active_dataset_insert.3.update.sqlpp
similarity index 78%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_insert/active_dataset_insert.3.update.sqlpp
index b1a132b..55bec97 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_insert/active_dataset_insert.3.update.sqlpp
@@ -16,12 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Disasters with friends
-* Expected Res : Success
-* Date         : May 17
-* Author       : Steven Jacobs
-*/
-use channels;
+use test;
 
-subscribe to EmergenciesNearMeChannel("tornado", 1) on brokerA;
+INSERT INTO Tweets2([{"tid" : 999, "area_code": "45", "text": "Tweet 1.", "location": point("1998078.3009357268, 1998011.0235705695"), "timestamp": datetime("2019-12-03T17:59:52.041Z"), "hatefulFlag": False}]);
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_insert/active_dataset_insert.4.query.sqlpp
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_insert/active_dataset_insert.4.query.sqlpp
index b7bb951..a266db3 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_insert/active_dataset_insert.4.query.sqlpp
@@ -16,10 +16,5 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+USE test;
+SELECT t, meta(t).`_active_timestamp` as Time FROM Tweets t ORDER BY t.tid;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_insert/active_dataset_insert.5.query.sqlpp
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_insert/active_dataset_insert.5.query.sqlpp
index b7bb951..2d6b123 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_insert/active_dataset_insert.5.query.sqlpp
@@ -16,10 +16,5 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+USE test;
+SELECT t FROM Tweets2 t ORDER BY t.tid;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_upsert/active_dataset_upsert.1.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_upsert/active_dataset_upsert.1.ddl.sqlpp
new file mode 100644
index 0000000..9f938f7
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_upsert/active_dataset_upsert.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.
+ */
+DROP DATAVERSE test IF EXISTS;
+CREATE DATAVERSE test;
+USE test;
+
+DROP DATASET Tweets IF EXISTS;
+DROP TYPE Tweet IF EXISTS;
+
+CREATE TYPE Tweet AS OPEN {
+ tid: bigint,
+ area_code: string,
+ text: string,
+ location: point,
+ timestamp: datetime
+};
+
+CREATE ACTIVE DATASET Tweets(Tweet) PRIMARY KEY tid;
+CREATE DATASET Tweets2(Tweet) PRIMARY KEY tid;
+
+CREATE INDEX s_rating ON Tweets(area_code);
+CREATE INDEX s_location ON Tweets(location) type RTREE;
+
+
+CREATE INDEX s_rating2 ON Tweets2(area_code);
+CREATE INDEX s_location2 ON Tweets2(location) type RTREE;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_upsert/active_dataset_upsert.2.update.sqlpp
similarity index 78%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_upsert/active_dataset_upsert.2.update.sqlpp
index b1a132b..7e94456 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_upsert/active_dataset_upsert.2.update.sqlpp
@@ -16,12 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Disasters with friends
-* Expected Res : Success
-* Date         : May 17
-* Author       : Steven Jacobs
-*/
-use channels;
+use test;
 
-subscribe to EmergenciesNearMeChannel("tornado", 1) on brokerA;
+UPSERT INTO Tweets([{"tid" : 1000, "area_code": "45", "text": "Tweet 2", "location": point("1998078.3009357268, 1998011.0235705695"), "timestamp": datetime("2019-12-03T17:59:52.041Z"), "hatefulFlag": False}]);
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_upsert/active_dataset_upsert.3.update.sqlpp
similarity index 78%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_upsert/active_dataset_upsert.3.update.sqlpp
index b1a132b..2e97f48 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_upsert/active_dataset_upsert.3.update.sqlpp
@@ -16,12 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Disasters with friends
-* Expected Res : Success
-* Date         : May 17
-* Author       : Steven Jacobs
-*/
-use channels;
+use test;
 
-subscribe to EmergenciesNearMeChannel("tornado", 1) on brokerA;
+UPSERT INTO Tweets2([{"tid" : 1000, "area_code": "45", "text": "Tweet 2", "location": point("1998078.3009357268, 1998011.0235705695"), "timestamp": datetime("2019-12-03T17:59:52.041Z"), "hatefulFlag": False}]);
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_upsert/active_dataset_upsert.4.query.sqlpp
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_upsert/active_dataset_upsert.4.query.sqlpp
index b7bb951..a266db3 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_upsert/active_dataset_upsert.4.query.sqlpp
@@ -16,10 +16,5 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+USE test;
+SELECT t, meta(t).`_active_timestamp` as Time FROM Tweets t ORDER BY t.tid;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_upsert/active_dataset_upsert.5.query.sqlpp
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_upsert/active_dataset_upsert.5.query.sqlpp
index b7bb951..2d6b123 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_dataset_upsert/active_dataset_upsert.5.query.sqlpp
@@ -16,10 +16,5 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+USE test;
+SELECT t FROM Tweets2 t ORDER BY t.tid;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_feeds/active_feeds.1.ddl.sqlpp
similarity index 70%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_feeds/active_feeds.1.ddl.sqlpp
index b1a132b..936b50c 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_feeds/active_feeds.1.ddl.sqlpp
@@ -16,12 +16,18 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Disasters with friends
-* Expected Res : Success
-* Date         : May 17
-* Author       : Steven Jacobs
-*/
-use channels;
+DROP DATAVERSE test IF EXISTS;
+CREATE DATAVERSE test;
+USE test;
 
-subscribe to EmergenciesNearMeChannel("tornado", 1) on brokerA;
+DROP DATASET Tweets IF EXISTS;
+DROP TYPE Tweet IF EXISTS;
+
+CREATE TYPE Tweet AS OPEN {
+ tid: bigint
+};
+
+CREATE ACTIVE DATASET Tweets(Tweet) PRIMARY KEY tid;
+
+//CREATE INDEX s_rating ON Tweets(hateful_rating);
+//CREATE INDEX s_location ON Tweets(location) type RTREE;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_feeds/active_feeds.2.update.sqlpp
similarity index 78%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_feeds/active_feeds.2.update.sqlpp
index b1a132b..83c892d 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_feeds/active_feeds.2.update.sqlpp
@@ -16,12 +16,15 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Disasters with friends
-* Expected Res : Success
-* Date         : May 17
-* Author       : Steven Jacobs
-*/
-use channels;
+USE test;
 
-subscribe to EmergenciesNearMeChannel("tornado", 1) on brokerA;
+CREATE FEED TweetFeed WITH {
+  "adapter-name" : "localfs",
+  "path" : "asterix_nc1://data/tweets.txt",
+  "type-name":"Tweet",
+  "format": "adm"
+};
+
+CONNECT FEED TweetFeed TO DATASET Tweets;
+
+START FEED TweetFeed;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_feeds/active_feeds.3.query.sqlpp
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_feeds/active_feeds.3.query.sqlpp
index b7bb951..28ba203 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_feeds/active_feeds.3.query.sqlpp
@@ -16,10 +16,5 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+USE test;
+SELECT t, meta(t).`_active_timestamp` as Time FROM Tweets t where t.threatening_flag = true ORDER BY t.tid;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.6.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_function_in_udf/active_function_in_udf.1.ddl.sqlpp
similarity index 77%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.6.ddl.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_function_in_udf/active_function_in_udf.1.ddl.sqlpp
index 220f05a..d37cd2c 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.6.ddl.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_function_in_udf/active_function_in_udf.1.ddl.sqlpp
@@ -16,13 +16,16 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Disasters with friends
-* Expected Res : Success
-* Date         : May 17
-* Author       : Steven Jacobs
-*/
+DROP DATAVERSE test IF EXISTS;
+CREATE DATAVERSE test;
+USE test;
 
-use channels;
+CREATE TYPE Tweet AS OPEN {
+ tid: bigint,
+ area_code: string,
+ text: string,
+ location: point,
+ timestamp: datetime
+};
 
-drop channel EmergenciesNearMeChannel;
+CREATE ACTIVE DATASET Tweets(Tweet) PRIMARY KEY tid;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_function_in_udf/active_function_in_udf.2.update.sqlpp
similarity index 75%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_function_in_udf/active_function_in_udf.2.update.sqlpp
index b1a132b..d174faf 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_function_in_udf/active_function_in_udf.2.update.sqlpp
@@ -16,12 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Disasters with friends
-* Expected Res : Success
-* Date         : May 17
-* Author       : Steven Jacobs
-*/
-use channels;
+use test;
 
-subscribe to EmergenciesNearMeChannel("tornado", 1) on brokerA;
+INSERT INTO Tweets([{"tid" : 999, "area_code": "45", "text": "Xikui likes Google, but Mike likes AsterixDB.", "location": point("1998078.3009357268, 1998011.0235705695"), "timestamp": datetime("2019-12-03T17:59:52.041Z"), "hatefulFlag": False}]);
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_function_in_udf/active_function_in_udf.3.update.sqlpp
similarity index 83%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_function_in_udf/active_function_in_udf.3.update.sqlpp
index b7bb951..227bebd 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_function_in_udf/active_function_in_udf.3.update.sqlpp
@@ -16,10 +16,10 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+USE test;
+
+CREATE FUNCTION Tweets(code)
+{
+  SELECT t
+  FROM Tweets t WHERE area_code = t.area_code AND previous_channel_time(t) < current_datetime()
+};
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_function_in_udf/active_function_in_udf.4.query.sqlpp
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_function_in_udf/active_function_in_udf.4.query.sqlpp
index b7bb951..5f67a9b 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_function_in_udf/active_function_in_udf.4.query.sqlpp
@@ -16,10 +16,5 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+USE test;
+Tweets("45");
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_functions/active_functions.1.ddl.sqlpp
similarity index 72%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_functions/active_functions.1.ddl.sqlpp
index b1a132b..2fc3783 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_functions/active_functions.1.ddl.sqlpp
@@ -16,12 +16,19 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Disasters with friends
-* Expected Res : Success
-* Date         : May 17
-* Author       : Steven Jacobs
-*/
-use channels;
+DROP DATAVERSE test IF EXISTS;
+CREATE DATAVERSE test;
+USE test;
 
-subscribe to EmergenciesNearMeChannel("tornado", 1) on brokerA;
+DROP DATASET Tweets IF EXISTS;
+DROP TYPE Tweet IF EXISTS;
+
+CREATE TYPE Tweet AS OPEN {
+ tid: bigint,
+ area_code: string,
+ text: string,
+ location: point,
+ timestamp: datetime
+};
+
+CREATE ACTIVE DATASET Tweets(Tweet) PRIMARY KEY tid;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_functions/active_functions.2.update.sqlpp
similarity index 73%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_functions/active_functions.2.update.sqlpp
index b1a132b..8945806 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_functions/active_functions.2.update.sqlpp
@@ -16,12 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Disasters with friends
-* Expected Res : Success
-* Date         : May 17
-* Author       : Steven Jacobs
-*/
-use channels;
+use test;
 
-subscribe to EmergenciesNearMeChannel("tornado", 1) on brokerA;
+INSERT INTO Tweets([{"tid" : 999, "area_code": "45", "text": "Jia sells Google, and Xikui likes Facebook, but Mike betrays AsterixDB.", "location": point("1998078.3009357268, 1998011.0235705695"), "timestamp": datetime("2019-12-03T17:59:52.041Z"), "hatefulFlag": False}]);
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_functions/active_functions.3.query.sqlpp
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_functions/active_functions.3.query.sqlpp
index b7bb951..0d719c7 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/active_functions/active_functions.3.query.sqlpp
@@ -16,10 +16,5 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+USE test;
+SELECT current_channel_time(t) as Time_current_channel, previous_channel_time(t) as previous_channel_time FROM Tweets t;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.2.update.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_http_feed/bad_http_feed.1.ddl.sqlpp
similarity index 65%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.2.update.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_http_feed/bad_http_feed.1.ddl.sqlpp
index 3e2d5c0..5624725 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.2.update.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_http_feed/bad_http_feed.1.ddl.sqlpp
@@ -16,14 +16,21 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
+drop dataverse experiments if exists;
+create dataverse experiments;
+use experiments;
 
+create type TweetMessageType as open {
+    id : string
+};
 
-use channels;
+create ACTIVE dataset Tweets(TweetMessageType) primary key id;
 
-subscribe to roomRecords (123) on brokerA;
+create feed TweetFeed with {
+  "adapter-name" : "http_adapter",
+  "addresses" : "asterix_nc2:10002,asterix_nc1:10001",
+  "address-type" : "NC",
+  "type-name" : "TweetMessageType",
+  "format" : "adm",
+  "dynamic" : true
+};
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_http_feed/bad_http_feed.2.update.sqlpp
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_http_feed/bad_http_feed.2.update.sqlpp
index b7bb951..75f92d5 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_http_feed/bad_http_feed.2.update.sqlpp
@@ -16,10 +16,9 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+
+use experiments;
+set `wait-for-completion-feed` "false";
+
+connect feed TweetFeed to dataset Tweets;
+start feed TweetFeed;
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_http_feed/bad_http_feed.3.post.http
similarity index 67%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_http_feed/bad_http_feed.3.post.http
index b1a132b..38d2959 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_http_feed/bad_http_feed.3.post.http
@@ -16,12 +16,5 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Disasters with friends
-* Expected Res : Success
-* Date         : May 17
-* Author       : Steven Jacobs
-*/
-use channels;
-
-subscribe to EmergenciesNearMeChannel("tornado", 1) on brokerA;
+nc:asterix_nc2:10002 /
+--body={ "id": "nc2:1", "username": "magarika", "location": "", "text": "RT @ken24xavier: Obama tells SOROS - our plan is ALMOST finished http://t.co/WvzK0GtU", "timestamp": "Thu Dec 06 16:53:05 PST 2012" }{ "id": "nc2:2", "username": "jaysauce82", "location": "", "text": "Not voting for President Obama #BadDecision", "timestamp": "Thu Dec 06 16:53:16 PST 2012" }
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_http_feed/bad_http_feed.4.post.http
similarity index 77%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_http_feed/bad_http_feed.4.post.http
index b1a132b..b5632d2 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_http_feed/bad_http_feed.4.post.http
@@ -16,12 +16,5 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Disasters with friends
-* Expected Res : Success
-* Date         : May 17
-* Author       : Steven Jacobs
-*/
-use channels;
-
-subscribe to EmergenciesNearMeChannel("tornado", 1) on brokerA;
+nc:asterix_nc1:10001 /
+--body={ "id": "nc1:1", "username": "magarika", "location": "", "text": "RT @ken24xavier: Obama tells SOROS - our plan is ALMOST finished http://t.co/WvzK0GtU", "timestamp": "Thu Dec 06 16:53:05 PST 2012" }
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_http_feed/bad_http_feed.5.sleep.sqlpp
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_http_feed/bad_http_feed.5.sleep.sqlpp
index b7bb951..2ea09b0 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_http_feed/bad_http_feed.5.sleep.sqlpp
@@ -16,10 +16,4 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+1500
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_http_feed/bad_http_feed.6.update.sqlpp
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_http_feed/bad_http_feed.6.update.sqlpp
index b7bb951..48690f3 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_http_feed/bad_http_feed.6.update.sqlpp
@@ -16,10 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+
+use experiments;
+stop feed TweetFeed;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_http_feed/bad_http_feed.7.query.sqlpp
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_http_feed/bad_http_feed.7.query.sqlpp
index b7bb951..bcddf7a 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_http_feed/bad_http_feed.7.query.sqlpp
@@ -16,10 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+
+use experiments;
+
+select value count(t) from Tweets as t;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_http_feed/bad_http_feed.8.ddl.sqlpp
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_http_feed/bad_http_feed.8.ddl.sqlpp
index b7bb951..e4d2615 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_http_feed/bad_http_feed.8.ddl.sqlpp
@@ -16,10 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+
+use experiments;
+drop dataverse experiments;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_islands/bad_islands.1.ddl.sqlpp
similarity index 65%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_islands/bad_islands.1.ddl.sqlpp
index b1a132b..39a6908 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_islands/bad_islands.1.ddl.sqlpp
@@ -16,12 +16,24 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Disasters with friends
-* Expected Res : Success
-* Date         : May 17
-* Author       : Steven Jacobs
-*/
-use channels;
+DROP DATAVERSE test if exists;
+CREATE DATAVERSE test;
+USE test;
 
-subscribe to EmergenciesNearMeChannel("tornado", 1) on brokerA;
+create type Tweet as open {
+  tid : bigint
+};
+
+CREATE ACTIVE DATASET Tweets(Tweet) primary key tid;
+
+CREATE FEED TweetFeed with {
+  "adapter-name" : "http_adapter",
+  "addresses" : "127.0.0.1:10001",
+  "address-type" : "IP",
+  "type-name" : "Tweet",
+  "format" : "adm",
+  "dynamic" : "false"
+};
+
+CONNECT FEED TweetFeed to dataset Tweets;
+START FEED TweetFeed;
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_islands/bad_islands.10.query.sqlpp
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_islands/bad_islands.10.query.sqlpp
index b7bb951..0959ad1 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_islands/bad_islands.10.query.sqlpp
@@ -16,10 +16,8 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+use test;
+
+FROM LocalThreateningTweets l
+UNNEST l.results r
+SELECT VALUE r.result.t ORDER BY r.result.t.tid;
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.6.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_islands/bad_islands.2.ddl.sqlpp
similarity index 81%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.6.ddl.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_islands/bad_islands.2.ddl.sqlpp
index 220f05a..d3fe34e 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.6.ddl.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_islands/bad_islands.2.ddl.sqlpp
@@ -16,13 +16,10 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Disasters with friends
-* Expected Res : Success
-* Date         : May 17
-* Author       : Steven Jacobs
-*/
+use test;
 
-use channels;
-
-drop channel EmergenciesNearMeChannel;
+CREATE CONTINUOUS PUSH CHANNEL ThreateningTweetsAt(area_name) PERIOD duration("PT2S") {
+    SELECT t
+    FROM Tweets t
+    WHERE t.area_name = area_name AND is_new(t)
+};
diff --git a/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_islands/bad_islands.3.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_islands/bad_islands.3.ddl.sqlpp
new file mode 100644
index 0000000..4d4bc1a
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_islands/bad_islands.3.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.
+ */
+use test;
+
+CREATE TYPE LocalThreateningTweet AS {
+  channelExecutionEpochTime: bigint,
+  dataverseName: string,
+  channelName: string
+};
+
+CREATE DATASET LocalThreateningTweets(LocalThreateningTweet) PRIMARY KEY channelExecutionEpochTime;
+
+// Here we cannot use BAD feeds, since the remote calls in BAD feeds causes test cases to halt
+CREATE FEED LocalThreateningTweetFeed WITH {
+  "adapter-name" : "http_adapter",
+  "addresses" : "127.0.0.1:10002",
+  "address-type" : "IP",
+  "type-name" : "LocalThreateningTweet",
+  "format" : "adm"
+};
+
+CONNECT FEED LocalThreateningTweetFeed TO DATASET LocalThreateningTweets;
+START FEED LocalThreateningTweetFeed;
+
+CREATE BROKER OCPD_BAD_Broker AT "http://127.0.0.1:10002" with {
+  "broker-type" : "BAD"
+};
+SUBSCRIBE TO ThreateningTweetsAt("OC") on OCPD_BAD_Broker;
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_islands/bad_islands.4.post.http
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_islands/bad_islands.4.post.http
index b7bb951..0f4f9e7 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_islands/bad_islands.4.post.http
@@ -16,10 +16,5 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+nc:asterix_nc1:10001 /
+--body={"tid" : 0, "area_name": "OC", "text": "OC Tweet"}{"tid" : 1, "area_name": "UCI", "text": "UCI Tweet"}
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_islands/bad_islands.5.sleep.sqlpp
similarity index 86%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_islands/bad_islands.5.sleep.sqlpp
index b7bb951..5f299bc 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_islands/bad_islands.5.sleep.sqlpp
@@ -16,10 +16,4 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+5000
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_islands/bad_islands.6.query.sqlpp
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_islands/bad_islands.6.query.sqlpp
index b7bb951..0959ad1 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_islands/bad_islands.6.query.sqlpp
@@ -16,10 +16,8 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+use test;
+
+FROM LocalThreateningTweets l
+UNNEST l.results r
+SELECT VALUE r.result.t ORDER BY r.result.t.tid;
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_islands/bad_islands.7.ddl.sqlpp
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_islands/bad_islands.7.ddl.sqlpp
index b7bb951..788507c 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_islands/bad_islands.7.ddl.sqlpp
@@ -16,10 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+use test;
+
+STOP FEED LocalThreateningTweetFeed;
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_islands/bad_islands.8.post.http
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_islands/bad_islands.8.post.http
index b7bb951..c146b00 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_islands/bad_islands.8.post.http
@@ -16,10 +16,5 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+nc:asterix_nc1:10001 /
+--body={"tid" : 2, "area_name": "OC", "text": "OC Tweet"}{"tid" : 3, "area_name": "UCI", "text": "UCI Tweet"}
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_islands/bad_islands.9.sleep.sqlpp
similarity index 86%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_islands/bad_islands.9.sleep.sqlpp
index b7bb951..5f299bc 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/bad_islands/bad_islands.9.sleep.sqlpp
@@ -16,10 +16,4 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+5000
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/new_tweets_from_area/new_tweets_from_area.1.ddl.sqlpp
similarity index 82%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/new_tweets_from_area/new_tweets_from_area.1.ddl.sqlpp
index b7bb951..e30e8e9 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/new_tweets_from_area/new_tweets_from_area.1.ddl.sqlpp
@@ -16,10 +16,12 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+DROP DATAVERSE test IF EXISTS;
+CREATE DATAVERSE test;
+USE test;
+
+CREATE TYPE Tweet AS OPEN {
+ tid: bigint
+};
+
+CREATE ACTIVE DATASET Tweets(Tweet) PRIMARY KEY tid;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/new_tweets_from_area/new_tweets_from_area.2.update.sqlpp
similarity index 76%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/new_tweets_from_area/new_tweets_from_area.2.update.sqlpp
index b1a132b..0ab3f13 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/new_tweets_from_area/new_tweets_from_area.2.update.sqlpp
@@ -16,12 +16,16 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Disasters with friends
-* Expected Res : Success
-* Date         : May 17
-* Author       : Steven Jacobs
-*/
-use channels;
+USE test;
 
-subscribe to EmergenciesNearMeChannel("tornado", 1) on brokerA;
+CREATE FEED TweetFeed WITH {
+  "adapter-name" : "localfs",
+  "path" : "asterix_nc1://data/tweets.txt",
+  "type-name":"Tweet",
+  "format" : "adm",
+  "insert-feed" : true
+};
+
+CONNECT FEED TweetFeed TO DATASET Tweets;
+
+START FEED TweetFeed;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/new_tweets_from_area/new_tweets_from_area.3.update.sqlpp
similarity index 69%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/new_tweets_from_area/new_tweets_from_area.3.update.sqlpp
index b1a132b..45cc2f5 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/new_tweets_from_area/new_tweets_from_area.3.update.sqlpp
@@ -16,12 +16,15 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Disasters with friends
-* Expected Res : Success
-* Date         : May 17
-* Author       : Steven Jacobs
-*/
-use channels;
 
-subscribe to EmergenciesNearMeChannel("tornado", 1) on brokerA;
+USE test;
+
+CREATE CONTINUOUS CHANNEL ThreateningTweetsAt(area_name) PERIOD duration("PT2S") {
+    SELECT t, current_channel_time("ThreateningTweetsAt") as TimeCurrent , previous_channel_time("ThreateningTweetsAt") as TimePrevious
+    FROM Tweets t
+    WHERE t.area_name = area_name
+      AND is_new(t)
+};
+
+
+CREATE BROKER brokerA AT "http://127.0.0.1:10100";
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/new_tweets_from_area/new_tweets_from_area.4.update.sqlpp
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/new_tweets_from_area/new_tweets_from_area.4.update.sqlpp
index b7bb951..fc9d1af 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/new_tweets_from_area/new_tweets_from_area.4.update.sqlpp
@@ -16,10 +16,5 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+USE test;
+SUBSCRIBE TO ThreateningTweetsAt("LA") on brokerA;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/new_tweets_from_area/new_tweets_from_area.5.sleep.sqlpp
similarity index 86%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/new_tweets_from_area/new_tweets_from_area.5.sleep.sqlpp
index b7bb951..5f299bc 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/new_tweets_from_area/new_tweets_from_area.5.sleep.sqlpp
@@ -16,10 +16,4 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+5000
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/new_tweets_from_area/new_tweets_from_area.6.query.sqlpp
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_cq/new_tweets_from_area/new_tweets_from_area.6.query.sqlpp
index b7bb951..289d213 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_cq/new_tweets_from_area/new_tweets_from_area.6.query.sqlpp
@@ -16,10 +16,5 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+use test;
+SELECT VALUE r.result from ThreateningTweetsAtResults r ORDER BY r.result.t.tid;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/add_index/add_index.1.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/add_index/add_index.1.ddl.sqlpp
similarity index 89%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/add_index/add_index.1.ddl.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/add_index/add_index.1.ddl.sqlpp
index 819d052..5badc4c 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/add_index/add_index.1.ddl.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/add_index/add_index.1.ddl.sqlpp
@@ -16,13 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Check Whether a Channel works after adding a new Index
-* Expected Res : Success
-* Date         : Apr 2018
-* Author       : Steven Jacobs
-*/
-
 drop dataverse channels if exists;
 create dataverse channels;
 use channels;
@@ -56,14 +49,12 @@
 
 
 create function RecentEmergenciesNearUser(userName) {
-  (
   select report, shelters from
-   ( select value r from Reports r)report,
+   (select value r from Reports r)report,
   UserLocations u
     let shelters = (select s.location from Shelters s where spatial_intersect(s.location,u.location))
   where u.userName = userName
   and spatial_intersect(report.location,u.location)
-  )
 };
 
 create repetitive channel EmergencyChannel using RecentEmergenciesNearUser@1 period duration("PT10S");
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/add_index/add_index.2.update.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/add_index/add_index.2.update.sqlpp
similarity index 99%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/add_index/add_index.2.update.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/add_index/add_index.2.update.sqlpp
index 0a38e41..dbd8cf4 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/add_index/add_index.2.update.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/add_index/add_index.2.update.sqlpp
@@ -16,12 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Check Whether a Channel works after adding a new Index
-* Expected Res : Success
-* Date         : Apr 2018
-* Author       : channels Jacobs
-*/
 
 use channels;
 
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/add_index/add_index.3.update.sqlpp
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_rq/add_index/add_index.3.update.sqlpp
index b7bb951..52cd9a9 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/add_index/add_index.3.update.sqlpp
@@ -16,10 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+
+use channels;
+
+create index delivery on EmergencyChannelResults(deliveryTime);
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/add_index/add_index.4.sleep.sqlpp
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_rq/add_index/add_index.4.sleep.sqlpp
index b7bb951..06985bd 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/add_index/add_index.4.sleep.sqlpp
@@ -16,10 +16,5 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+
+15000
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/add_index/add_index.5.query.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/add_index/add_index.5.query.sqlpp
similarity index 85%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/add_index/add_index.5.query.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/add_index/add_index.5.query.sqlpp
index dd6e1ca..eebfbc4 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/add_index/add_index.5.query.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/add_index/add_index.5.query.sqlpp
@@ -16,13 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Check Whether a Channel works after adding a new Index
-* Expected Res : Success
-* Date         : Apr 2018
-* Author       : Steven Jacobs
-*/
-
 use channels;
 
 select value array_count(
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/add_index/add_index.6.ddl.sqlpp
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_rq/add_index/add_index.6.ddl.sqlpp
index b7bb951..45b1194 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/add_index/add_index.6.ddl.sqlpp
@@ -16,10 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+
+use channels;
+
+drop channel EmergencyChannel;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/create_channel_check_metadata/create_channel_check_metadata.1.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/create_channel_check_datasets/create_channel_check_datasets.1.ddl.sqlpp
similarity index 91%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/create_channel_check_metadata/create_channel_check_metadata.1.ddl.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/create_channel_check_datasets/create_channel_check_datasets.1.ddl.sqlpp
index b85ba91..addc85f 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/create_channel_check_metadata/create_channel_check_metadata.1.ddl.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/create_channel_check_datasets/create_channel_check_datasets.1.ddl.sqlpp
@@ -16,12 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Create Channel Test
-* Expected Res : Success
-* Date         : March 2015
-* Author       : Steven Jacobs
-*/
 
 drop dataverse channels if exists;
 create dataverse channels;
@@ -48,4 +42,4 @@
   and spatial_intersect(m.sender_location, place))
 };
 
-create repetitive channel nearbyTweetChannel using NearbyTweetsContainingText@2 period duration("PT10M");
\ No newline at end of file
+create repetitive channel nearbyTweetChannel using NearbyTweetsContainingText@2 period duration("PT10M");
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/create_channel_check_datasets/create_channel_check_datasets.3.query.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/create_channel_check_datasets/create_channel_check_datasets.3.query.sqlpp
similarity index 100%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/create_channel_check_datasets/create_channel_check_datasets.3.query.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/create_channel_check_datasets/create_channel_check_datasets.3.query.sqlpp
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/create_channel_check_metadata/create_channel_check_metadata.1.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/create_channel_check_metadata/create_channel_check_metadata.1.ddl.sqlpp
similarity index 91%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/create_channel_check_metadata/create_channel_check_metadata.1.ddl.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_rq/create_channel_check_metadata/create_channel_check_metadata.1.ddl.sqlpp
index b85ba91..7e314d5 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/create_channel_check_metadata/create_channel_check_metadata.1.ddl.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/create_channel_check_metadata/create_channel_check_metadata.1.ddl.sqlpp
@@ -16,13 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Create Channel Test
-* Expected Res : Success
-* Date         : March 2015
-* Author       : Steven Jacobs
-*/
-
 drop dataverse channels if exists;
 create dataverse channels;
 use channels;
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/create_channel_check_metadata/create_channel_check_metadata.3.query.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/create_channel_check_metadata/create_channel_check_metadata.3.query.sqlpp
similarity index 100%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/create_channel_check_metadata/create_channel_check_metadata.3.query.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/create_channel_check_metadata/create_channel_check_metadata.3.query.sqlpp
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.1.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/disasters_with_friends/disasters_with_friends.1.ddl.sqlpp
similarity index 90%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.1.ddl.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/disasters_with_friends/disasters_with_friends.1.ddl.sqlpp
index e8d57a6..fb4b81e 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.1.ddl.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/disasters_with_friends/disasters_with_friends.1.ddl.sqlpp
@@ -16,13 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Disasters with friends
-* Expected Res : Success
-* Date         : May 17
-* Author       : Steven Jacobs
-*/
-
 drop dataverse channels if exists;
 create dataverse channels;
 use channels;
@@ -54,15 +47,16 @@
 
 create broker brokerA at "http://www.notifyA.com";
 
+// since BAD-RQ doesn't provide continuous semantics, adding temporal predicate would cause test case to fail randomly
 create function EmergenciesNearMe(emergencyType, uid){
-  (with tenMinutesAgo as current_datetime() - day_time_duration("PT10S")
+  (with tenMinutesAgo as current_datetime() - day_time_duration("PT5S")
   select report as report, shelters as shelters
   from EmergencyReports report, UserLocations user
   let shelters = (select * from EmergencyShelters shelter
     where spatial_intersect(report.impactZone,shelter.location))
   where user.user_id = uid
-    and report.timestamp >= tenMinutesAgo
-    and user.timestamp >= tenMinutesAgo
+    //and report.timestamp >= tenMinutesAgo
+    //and user.timestamp >= tenMinutesAgo
     and report.emergencyType = emergencyType
     and spatial_intersect(report.impactZone,create_point(user.latitude,user.longitude)))
 };
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/disasters_with_friends/disasters_with_friends.2.update.sqlpp
similarity index 87%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/disasters_with_friends/disasters_with_friends.2.update.sqlpp
index b1a132b..44c13df 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/disasters_with_friends/disasters_with_friends.2.update.sqlpp
@@ -16,12 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Disasters with friends
-* Expected Res : Success
-* Date         : May 17
-* Author       : Steven Jacobs
-*/
 use channels;
 
 subscribe to EmergenciesNearMeChannel("tornado", 1) on brokerA;
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.3.update.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/disasters_with_friends/disasters_with_friends.3.update.sqlpp
similarity index 79%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.3.update.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/disasters_with_friends/disasters_with_friends.3.update.sqlpp
index 292151e..b3d2f6c 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.3.update.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/disasters_with_friends/disasters_with_friends.3.update.sqlpp
@@ -16,18 +16,12 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Disasters with friends
-* Expected Res : Success
-* Date         : May 17
-* Author       : Steven Jacobs
-*/
 
 use channels;
 upsert into UserLocations([
-{"user_id":1, "latitude":5, "longitude":5, "timestamp":current_datetime()},
-{"user_id":2, "latitude":10, "longitude":10, "timestamp":current_datetime()},
-{"user_id":3, "latitude":15, "longitude":15, "timestamp":current_datetime()}]
+{"user_id":1, "latitude":5.0, "longitude":5.0, "timestamp":current_datetime()},
+{"user_id":2, "latitude":10.0, "longitude":10.0, "timestamp":current_datetime()},
+{"user_id":3, "latitude":15.0, "longitude":15.0, "timestamp":current_datetime()}]
 );
 upsert into EmergencyShelters([
 {"name":"A", "location":create_point(5.0,5.0)},
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/disasters_with_friends/disasters_with_friends.4.sleep.sqlpp
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_rq/disasters_with_friends/disasters_with_friends.4.sleep.sqlpp
index b7bb951..af2f691 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/disasters_with_friends/disasters_with_friends.4.sleep.sqlpp
@@ -16,10 +16,4 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+10000
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/disasters_with_friends/disasters_with_friends.5.query.sqlpp
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_rq/disasters_with_friends/disasters_with_friends.5.query.sqlpp
index b7bb951..626ec87 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/disasters_with_friends/disasters_with_friends.5.query.sqlpp
@@ -16,10 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+use channels;
+select value array_count (result.result.shelters)
+from EmergenciesNearMeChannelResults result
+limit 1;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.6.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/disasters_with_friends/disasters_with_friends.6.ddl.sqlpp
similarity index 87%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.6.ddl.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/disasters_with_friends/disasters_with_friends.6.ddl.sqlpp
index 220f05a..0be897c 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.6.ddl.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/disasters_with_friends/disasters_with_friends.6.ddl.sqlpp
@@ -16,12 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Disasters with friends
-* Expected Res : Success
-* Date         : May 17
-* Author       : Steven Jacobs
-*/
 
 use channels;
 
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/drop_channel_check_datasets/drop_channel_check_datasets.1.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/drop_channel_check_datasets/drop_channel_check_datasets.1.ddl.sqlpp
similarity index 92%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/drop_channel_check_datasets/drop_channel_check_datasets.1.ddl.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/drop_channel_check_datasets/drop_channel_check_datasets.1.ddl.sqlpp
index 1c7fdcc..6aad378 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/drop_channel_check_datasets/drop_channel_check_datasets.1.ddl.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/drop_channel_check_datasets/drop_channel_check_datasets.1.ddl.sqlpp
@@ -16,12 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Drop Channel Test. Check Metadata
-* Expected Res : Success
-* Date         : March 2015
-* Author       : Steven Jacobs
-*/
 
 drop dataverse channels if exists;
 create dataverse channels;
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/drop_channel_check_datasets/drop_channel_check_datasets.2.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/drop_channel_check_datasets/drop_channel_check_datasets.2.ddl.sqlpp
similarity index 100%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/drop_channel_check_datasets/drop_channel_check_datasets.2.ddl.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/drop_channel_check_datasets/drop_channel_check_datasets.2.ddl.sqlpp
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/drop_channel_check_datasets/drop_channel_check_datasets.3.query.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/drop_channel_check_datasets/drop_channel_check_datasets.3.query.sqlpp
similarity index 100%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/drop_channel_check_datasets/drop_channel_check_datasets.3.query.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/drop_channel_check_datasets/drop_channel_check_datasets.3.query.sqlpp
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/drop_channel_check_metadata/drop_channel_check_metadata.1.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/drop_channel_check_metadata/drop_channel_check_metadata.1.ddl.sqlpp
similarity index 92%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/drop_channel_check_metadata/drop_channel_check_metadata.1.ddl.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/drop_channel_check_metadata/drop_channel_check_metadata.1.ddl.sqlpp
index 1c7fdcc..dbd4d6d 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/drop_channel_check_metadata/drop_channel_check_metadata.1.ddl.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/drop_channel_check_metadata/drop_channel_check_metadata.1.ddl.sqlpp
@@ -16,13 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Drop Channel Test. Check Metadata
-* Expected Res : Success
-* Date         : March 2015
-* Author       : Steven Jacobs
-*/
-
 drop dataverse channels if exists;
 create dataverse channels;
 use channels;
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/drop_channel_check_metadata/drop_channel_check_metadata.2.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/drop_channel_check_metadata/drop_channel_check_metadata.2.ddl.sqlpp
similarity index 100%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/drop_channel_check_metadata/drop_channel_check_metadata.2.ddl.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/drop_channel_check_metadata/drop_channel_check_metadata.2.ddl.sqlpp
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/drop_channel_check_metadata/drop_channel_check_metadata.3.query.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/drop_channel_check_metadata/drop_channel_check_metadata.3.query.sqlpp
similarity index 100%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/drop_channel_check_metadata/drop_channel_check_metadata.3.query.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/drop_channel_check_metadata/drop_channel_check_metadata.3.query.sqlpp
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/bad_rq/drop_function/drop_function.1.ddl.sqlpp
similarity index 92%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/drop_function/drop_function.1.ddl.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/drop_function/drop_function.1.ddl.sqlpp
index a5d3775..8e20d86 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/drop_function/drop_function.1.ddl.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/drop_function/drop_function.1.ddl.sqlpp
@@ -16,12 +16,6 @@
  * 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;
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/bad_rq/drop_function_dataverse/drop_function_dataverse.1.ddl.sqlpp
similarity index 91%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/drop_function_dataverse/drop_function_dataverse.1.ddl.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/drop_function_dataverse/drop_function_dataverse.1.ddl.sqlpp
index d1047b0..e22deb1 100644
--- 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/bad_rq/drop_function_dataverse/drop_function_dataverse.1.ddl.sqlpp
@@ -16,13 +16,6 @@
  * 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;
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/drop_index/drop_index.1.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/drop_index/drop_index.1.ddl.sqlpp
similarity index 94%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/drop_index/drop_index.1.ddl.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/drop_index/drop_index.1.ddl.sqlpp
index ca01dd7..38a70fb 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/drop_index/drop_index.1.ddl.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/drop_index/drop_index.1.ddl.sqlpp
@@ -16,13 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Drop Function Dataset Index
-* Expected Res : Error
-* Date         : Jan 2018
-* Author       : Steven Jacobs
-*/
-
 drop dataverse two if exists;
 drop dataverse channels if exists;
 create dataverse channels;
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/bad_rq/drop_results/drop_results.1.ddl.sqlpp
similarity index 92%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/drop_results/drop_results.1.ddl.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/drop_results/drop_results.1.ddl.sqlpp
index 432f3c5..f61f050 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/drop_results/drop_results.1.ddl.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/drop_results/drop_results.1.ddl.sqlpp
@@ -16,13 +16,6 @@
  * 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;
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/bad_rq/drop_subscriptions/drop_subscriptions.1.ddl.sqlpp
similarity index 92%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/drop_subscriptions/drop_subscriptions.1.ddl.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/drop_subscriptions/drop_subscriptions.1.ddl.sqlpp
index f6dc2bf..b33d7c4 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/drop_subscriptions/drop_subscriptions.1.ddl.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/drop_subscriptions/drop_subscriptions.1.ddl.sqlpp
@@ -16,13 +16,6 @@
  * 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;
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/bad_rq/room_occupants/room_occupants.1.ddl.sqlpp
similarity index 93%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.1.ddl.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/room_occupants/room_occupants.1.ddl.sqlpp
index 638f7b5..d4f2b01 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/bad_rq/room_occupants/room_occupants.1.ddl.sqlpp
@@ -16,13 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-
 drop dataverse two if exists;
 drop dataverse channels if exists;
 create dataverse channels;
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.2.update.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/room_occupants/room_occupants.2.update.sqlpp
similarity index 87%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.2.update.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/room_occupants/room_occupants.2.update.sqlpp
index 3e2d5c0..1ab9c30 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.2.update.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/room_occupants/room_occupants.2.update.sqlpp
@@ -16,14 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-
-
 use channels;
 
 subscribe to roomRecords (123) on brokerA;
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.3.update.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/room_occupants/room_occupants.3.update.sqlpp
similarity index 87%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.3.update.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/room_occupants/room_occupants.3.update.sqlpp
index 2e00f6a..8754dc1 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.3.update.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/room_occupants/room_occupants.3.update.sqlpp
@@ -16,14 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-
-
 use channels;
 
 subscribe to roomRecords (350) on brokerB;
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.4.query.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/room_occupants/room_occupants.4.query.sqlpp
similarity index 87%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.4.query.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/room_occupants/room_occupants.4.query.sqlpp
index 8612077..a83e597 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.4.query.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/room_occupants/room_occupants.4.query.sqlpp
@@ -16,13 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-
 use channels;
 
 select test.BrokerName, test.param0
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.5.update.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/room_occupants/room_occupants.5.update.sqlpp
similarity index 88%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.5.update.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/room_occupants/room_occupants.5.update.sqlpp
index 2499ac7..56ecc59 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.5.update.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/room_occupants/room_occupants.5.update.sqlpp
@@ -16,14 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-
-
 use channels;
 
 
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/room_occupants/room_occupants.6.sleep.sqlpp
similarity index 86%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/room_occupants/room_occupants.6.sleep.sqlpp
index b7bb951..18865b0 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/room_occupants/room_occupants.6.sleep.sqlpp
@@ -16,10 +16,4 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
 5000
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.7.update.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/room_occupants/room_occupants.7.update.sqlpp
similarity index 88%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.7.update.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/room_occupants/room_occupants.7.update.sqlpp
index eb7ee2e..c5db418 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.7.update.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/room_occupants/room_occupants.7.update.sqlpp
@@ -16,13 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-
 use channels;
 
 upsert into UserLocations([
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.8.query.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/room_occupants/room_occupants.8.query.sqlpp
similarity index 87%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.8.query.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/room_occupants/room_occupants.8.query.sqlpp
index 91473b9..a6c284c 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.8.query.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/room_occupants/room_occupants.8.query.sqlpp
@@ -16,13 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-
 use channels;
 
 select result.result.userId
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.9.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/room_occupants/room_occupants.9.ddl.sqlpp
similarity index 100%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.9.ddl.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/room_occupants/room_occupants.9.ddl.sqlpp
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/create_channel_check_metadata/create_channel_check_metadata.1.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/subscribe_channel_check_subscriptions/subscribe_channel_check_subscriptions.1.ddl.sqlpp
similarity index 91%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/create_channel_check_metadata/create_channel_check_metadata.1.ddl.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_rq/subscribe_channel_check_subscriptions/subscribe_channel_check_subscriptions.1.ddl.sqlpp
index b85ba91..bfc8d0e 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/create_channel_check_metadata/create_channel_check_metadata.1.ddl.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/subscribe_channel_check_subscriptions/subscribe_channel_check_subscriptions.1.ddl.sqlpp
@@ -16,13 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Create Channel Test
-* Expected Res : Success
-* Date         : March 2015
-* Author       : Steven Jacobs
-*/
-
 drop dataverse channels if exists;
 create dataverse channels;
 use channels;
@@ -48,4 +41,6 @@
   and spatial_intersect(m.sender_location, place))
 };
 
-create repetitive channel nearbyTweetChannel using NearbyTweetsContainingText@2 period duration("PT10M");
\ No newline at end of file
+create broker brokerA at "http://www.notifyA.com";
+
+create repetitive channel nearbyTweetChannel using NearbyTweetsContainingText@2 period duration("PT10M");
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/subscribe_channel_check_subscriptions/subscribe_channel_check_subscriptions.2.update.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/subscribe_channel_check_subscriptions/subscribe_channel_check_subscriptions.2.update.sqlpp
similarity index 100%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/subscribe_channel_check_subscriptions/subscribe_channel_check_subscriptions.2.update.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/subscribe_channel_check_subscriptions/subscribe_channel_check_subscriptions.2.update.sqlpp
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/subscribe_channel_check_subscriptions/subscribe_channel_check_subscriptions.3.update.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/subscribe_channel_check_subscriptions/subscribe_channel_check_subscriptions.3.update.sqlpp
similarity index 100%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/subscribe_channel_check_subscriptions/subscribe_channel_check_subscriptions.3.update.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/subscribe_channel_check_subscriptions/subscribe_channel_check_subscriptions.3.update.sqlpp
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/subscribe_channel_check_subscriptions/subscribe_channel_check_subscriptions.4.update.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/subscribe_channel_check_subscriptions/subscribe_channel_check_subscriptions.4.update.sqlpp
similarity index 100%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/subscribe_channel_check_subscriptions/subscribe_channel_check_subscriptions.4.update.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/subscribe_channel_check_subscriptions/subscribe_channel_check_subscriptions.4.update.sqlpp
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/subscribe_channel_check_subscriptions/subscribe_channel_check_subscriptions.5.query.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/subscribe_channel_check_subscriptions/subscribe_channel_check_subscriptions.5.query.sqlpp
similarity index 100%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/subscribe_channel_check_subscriptions/subscribe_channel_check_subscriptions.5.query.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/subscribe_channel_check_subscriptions/subscribe_channel_check_subscriptions.5.query.sqlpp
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/ten_minute_channel/ten_minute_channel.1.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/ten_minute_channel/ten_minute_channel.1.ddl.sqlpp
similarity index 80%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/ten_minute_channel/ten_minute_channel.1.ddl.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/ten_minute_channel/ten_minute_channel.1.ddl.sqlpp
index a21a4be..6475001 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/ten_minute_channel/ten_minute_channel.1.ddl.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/ten_minute_channel/ten_minute_channel.1.ddl.sqlpp
@@ -16,12 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Long Term Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
 
 drop dataverse channels if exists;
 create dataverse channels;
@@ -41,6 +35,6 @@
   where location.roomNumber = room)
 };
 
-create broker brokerA at "http://www.notifyA.com";
+CREATE BROKER brokerA at "http://127.0.0.1:5020/echo";
 
-create repetitive channel roomRecords using RoomOccupants@1 period duration("PT10S");
+CREATE REPETITIVE CHANNEL roomRecords USING RoomOccupants@1 PERIOD duration("PT3S");
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/ten_minute_channel/ten_minute_channel.2.update.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/ten_minute_channel/ten_minute_channel.2.update.sqlpp
similarity index 87%
rename from asterix-bad/src/test/resources/runtimets/queries/channel/ten_minute_channel/ten_minute_channel.2.update.sqlpp
rename to asterix-bad/src/test/resources/runtimets/queries/bad_rq/ten_minute_channel/ten_minute_channel.2.update.sqlpp
index 3e2d5c0..063b13c 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/ten_minute_channel/ten_minute_channel.2.update.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/ten_minute_channel/ten_minute_channel.2.update.sqlpp
@@ -16,13 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-
 
 use channels;
 
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.5.update.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/ten_minute_channel/ten_minute_channel.3.update.sqlpp
similarity index 87%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.5.update.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_rq/ten_minute_channel/ten_minute_channel.3.update.sqlpp
index 2499ac7..d4deb02 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.5.update.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/ten_minute_channel/ten_minute_channel.3.update.sqlpp
@@ -16,17 +16,8 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-
-
 use channels;
 
-
 upsert into UserLocations([
 {"userId":1, "roomNumber":123},
 {"userId":2, "roomNumber":222},
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/ten_minute_channel/ten_minute_channel.4.sleep.sqlpp
similarity index 85%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_rq/ten_minute_channel/ten_minute_channel.4.sleep.sqlpp
index b7bb951..a3490bb 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/room_occupants/room_occupants.6.sleep.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/ten_minute_channel/ten_minute_channel.4.sleep.sqlpp
@@ -16,10 +16,4 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-5000
+10000
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/ten_minute_channel/ten_minute_channel.5.query.sqlpp
similarity index 76%
copy from asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
copy to asterix-bad/src/test/resources/runtimets/queries/bad_rq/ten_minute_channel/ten_minute_channel.5.query.sqlpp
index b1a132b..c8d736f 100644
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.2.update.sqlpp
+++ b/asterix-bad/src/test/resources/runtimets/queries/bad_rq/ten_minute_channel/ten_minute_channel.5.query.sqlpp
@@ -16,12 +16,12 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 /*
-* Description  : Disasters with friends
-* Expected Res : Success
-* Date         : May 17
-* Author       : Steven Jacobs
+ Sample Notification:
+ {'dataverseName': 'channels', 'channelName': 'roomRecords', 'channelExecutionEpochTime': 1594924658617, 'subscriptionIds': [['dbf4b346-5fb5-8589-eb67-6a7465060ec7']]}
 */
+
 use channels;
 
-subscribe to EmergenciesNearMeChannel("tornado", 1) on brokerA;
+(select value count(result) from roomRecordsResults)[0] > 2;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/add_index/add_index.3.update.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/channel/add_index/add_index.3.update.sqlpp
deleted file mode 100644
index d0f65e5..0000000
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/add_index/add_index.3.update.sqlpp
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-/*
-* Description  : Check Whether a Channel works after adding a new Index
-* Expected Res : Success
-* Date         : Apr 2018
-* Author       : Steven Jacobs
-*/
-
-use channels;
-
-create index delivery on EmergencyChannelResults(deliveryTime);
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/add_index/add_index.4.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/channel/add_index/add_index.4.sleep.sqlpp
deleted file mode 100644
index 5f764b3..0000000
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/add_index/add_index.4.sleep.sqlpp
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-/*
-* Description  : Check Whether a Channel works after adding a new Index
-* Expected Res : Success
-* Date         : Apr 2018
-* Author       : Steven Jacobs
-*/
-
-15000
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/add_index/add_index.6.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/channel/add_index/add_index.6.ddl.sqlpp
deleted file mode 100644
index 54075e5..0000000
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/add_index/add_index.6.ddl.sqlpp
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-/*
-* Description  : Check Whether a Channel works after adding a new Index
-* Expected Res : Success
-* Date         : Apr 2018
-* Author       : Steven Jacobs
-*/
-
-use channels;
-
-drop channel EmergencyChannel;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/create_channel_check_datasets/create_channel_check_datasets.1.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/channel/create_channel_check_datasets/create_channel_check_datasets.1.ddl.sqlpp
deleted file mode 100644
index 8e20dcb..0000000
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/create_channel_check_datasets/create_channel_check_datasets.1.ddl.sqlpp
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-/*
-* Description  : Create Channel Test. Confirms that the subscription and result datasets are created
-* Expected Res : Success
-* Date         : March 2015
-* 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 repetitive channel nearbyTweetChannel using NearbyTweetsContainingText@2 period duration("PT10M");
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.4.pollquery.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.4.pollquery.sqlpp
deleted file mode 100644
index 0c8ea0c..0000000
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/disasters_with_friends/disasters_with_friends.4.pollquery.sqlpp
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-/*
-* Description  : Disasters with friends
-* Expected Res : Success
-* Date         : May 17
-* Author       : Steven Jacobs
-*/
-// polltimeoutsecs=15
-
-use channels;
-select value array_count (result.result.shelters)
-from EmergenciesNearMeChannelResults result
-limit 1;
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/subscribe_channel_check_subscriptions/subscribe_channel_check_subscriptions.1.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/channel/subscribe_channel_check_subscriptions/subscribe_channel_check_subscriptions.1.ddl.sqlpp
deleted file mode 100644
index 09a74e3..0000000
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/subscribe_channel_check_subscriptions/subscribe_channel_check_subscriptions.1.ddl.sqlpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-/*
-* Description  : Create Channel Test. Confirms that the subscription and result datasets are created
-* Expected Res : Success
-* Date         : March 2015
-* 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 broker brokerA at "http://www.notifyA.com";
-
-create repetitive channel nearbyTweetChannel using NearbyTweetsContainingText@2 period duration("PT10M");
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/ten_minute_channel/ten_minute_channel.3.update.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/channel/ten_minute_channel/ten_minute_channel.3.update.sqlpp
deleted file mode 100644
index 2499ac7..0000000
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/ten_minute_channel/ten_minute_channel.3.update.sqlpp
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-
-
-use channels;
-
-
-upsert into UserLocations([
-{"userId":1, "roomNumber":123},
-{"userId":2, "roomNumber":222},
-{"userId":3, "roomNumber":350}]
-);
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/ten_minute_channel/ten_minute_channel.4.sleep.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/channel/ten_minute_channel/ten_minute_channel.4.sleep.sqlpp
deleted file mode 100644
index c750707..0000000
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/ten_minute_channel/ten_minute_channel.4.sleep.sqlpp
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-110000
diff --git a/asterix-bad/src/test/resources/runtimets/queries/channel/ten_minute_channel/ten_minute_channel.5.query.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/channel/ten_minute_channel/ten_minute_channel.5.query.sqlpp
deleted file mode 100644
index b9282fe..0000000
--- a/asterix-bad/src/test/resources/runtimets/queries/channel/ten_minute_channel/ten_minute_channel.5.query.sqlpp
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-/*
-* Description  : Room Occupants Test
-* Expected Res : Success
-* Date         : Sep 2016
-* Author       : Steven Jacobs
-*/
-
-use channels;
-
-(select value count(result) from roomRecordsResults)[0] > 9;
\ 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.1.ddl.sqlpp b/asterix-bad/src/test/resources/runtimets/queries/procedure/create_procedure_check_metadata/create_procedure_check_metadata.1.ddl.sqlpp
index 71b2ed4..9e7e817 100644
--- 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
@@ -16,13 +16,6 @@
  * 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;
diff --git a/asterix-bad/src/test/resources/runtimets/results/bad_cq/active_dataset_delete/active_datasets.4.adm b/asterix-bad/src/test/resources/runtimets/results/bad_cq/active_dataset_delete/active_datasets.4.adm
new file mode 100644
index 0000000..f942886
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/results/bad_cq/active_dataset_delete/active_datasets.4.adm
@@ -0,0 +1 @@
+{ "t": { "tid": 999, "area_code": "45", "text": "Tweet 1.", "location": point("1998078.3009357268,1998011.0235705695"), "timestamp": datetime("2019-12-03T17:59:52.041Z"), "hatefulFlag": false } }
diff --git a/asterix-bad/src/test/resources/runtimets/results/bad_cq/active_dataset_delete/active_datasets.5.adm b/asterix-bad/src/test/resources/runtimets/results/bad_cq/active_dataset_delete/active_datasets.5.adm
new file mode 100644
index 0000000..39ec400
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/results/bad_cq/active_dataset_delete/active_datasets.5.adm
@@ -0,0 +1 @@
+{ "t": { "tid": 999, "area_code": "45", "text": "Tweet 1.", "location": point("1998078.3009357268,1998011.0235705695"), "timestamp": datetime("2019-12-03T17:59:52.041Z"), "hatefulFlag": false }, "Time": datetime("2020-08-18T06:46:51.696Z") }
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/results/bad_cq/active_dataset_insert/active_datasets.4.adm b/asterix-bad/src/test/resources/runtimets/results/bad_cq/active_dataset_insert/active_datasets.4.adm
new file mode 100644
index 0000000..fd14e79
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/results/bad_cq/active_dataset_insert/active_datasets.4.adm
@@ -0,0 +1 @@
+{ "t": { "tid": 999, "area_code": "45", "text": "Tweet 1.", "location": point("1998078.3009357268,1998011.0235705695"), "timestamp": datetime("2019-12-03T17:59:52.041Z"), "hatefulFlag": false }, "Time": datetime("2020-08-18T06:46:51.696Z") }
diff --git a/asterix-bad/src/test/resources/runtimets/results/bad_cq/active_dataset_insert/active_datasets.5.adm b/asterix-bad/src/test/resources/runtimets/results/bad_cq/active_dataset_insert/active_datasets.5.adm
new file mode 100644
index 0000000..f942886
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/results/bad_cq/active_dataset_insert/active_datasets.5.adm
@@ -0,0 +1 @@
+{ "t": { "tid": 999, "area_code": "45", "text": "Tweet 1.", "location": point("1998078.3009357268,1998011.0235705695"), "timestamp": datetime("2019-12-03T17:59:52.041Z"), "hatefulFlag": false } }
diff --git a/asterix-bad/src/test/resources/runtimets/results/bad_cq/active_dataset_upsert/active_datasets.4.adm b/asterix-bad/src/test/resources/runtimets/results/bad_cq/active_dataset_upsert/active_datasets.4.adm
new file mode 100644
index 0000000..75265d3
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/results/bad_cq/active_dataset_upsert/active_datasets.4.adm
@@ -0,0 +1 @@
+{ "t": { "tid": 1000, "area_code": "45", "text": "Tweet 2", "location": point("1998078.3009357268,1998011.0235705695"), "timestamp": datetime("2019-12-03T17:59:52.041Z"), "hatefulFlag": false }, "Time": datetime("2020-08-18T06:46:51.782Z") }
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/results/bad_cq/active_dataset_upsert/active_datasets.5.adm b/asterix-bad/src/test/resources/runtimets/results/bad_cq/active_dataset_upsert/active_datasets.5.adm
new file mode 100644
index 0000000..120a825
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/results/bad_cq/active_dataset_upsert/active_datasets.5.adm
@@ -0,0 +1 @@
+{ "t": { "tid": 1000, "area_code": "45", "text": "Tweet 2", "location": point("1998078.3009357268,1998011.0235705695"), "timestamp": datetime("2019-12-03T17:59:52.041Z"), "hatefulFlag": false } }
diff --git a/asterix-bad/src/test/resources/runtimets/results/bad_cq/active_feeds/active_feeds.1.adm b/asterix-bad/src/test/resources/runtimets/results/bad_cq/active_feeds/active_feeds.1.adm
new file mode 100644
index 0000000..9d1182c
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/results/bad_cq/active_feeds/active_feeds.1.adm
@@ -0,0 +1,6 @@
+{ "t": { "tid": 0, "area_name": "UCI", "suspicious_level": 9, "text": "Tweet 1", "location": point("68.41629186478751,44.631424133284966"), "timestamp": datetime("2018-11-09T00:00:00.000Z"), "threatening_flag": true }, "Time": datetime("2020-08-18T04:06:15.641Z") }
+{ "t": { "tid": 2, "area_name": "LA", "suspicious_level": 10, "text": "Tweet 3", "location": point("4037.165975321966,4020.6200896429373"), "timestamp": datetime("2018-08-14T00:00:00.000Z"), "threatening_flag": true }, "Time": datetime("2020-08-18T04:06:15.641Z") }
+{ "t": { "tid": 3, "area_name": "UCI", "suspicious_level": 5, "text": "Tweet 4", "location": point("6011.1101544678095,6033.86438259922"), "timestamp": datetime("2018-05-18T00:00:00.000Z"), "threatening_flag": true }, "Time": datetime("2020-08-18T04:06:15.641Z") }
+{ "t": { "tid": 6, "area_name": "LA", "suspicious_level": 9, "text": "Tweet 7", "location": point("12074.059527318483,12008.549148129303"), "timestamp": datetime("2017-04-23T00:00:00.000Z"), "threatening_flag": true }, "Time": datetime("2020-08-18T04:06:15.641Z") }
+{ "t": { "tid": 8, "area_name": "LA", "suspicious_level": 8, "text": "Tweet 9", "location": point("16051.9846352692,16078.599078960015"), "timestamp": datetime("2018-03-27T00:00:00.000Z"), "threatening_flag": true }, "Time": datetime("2020-08-18T04:06:15.641Z") }
+{ "t": { "tid": 10, "area_name": "SD", "suspicious_level": 0, "text": "Tweet 11", "location": point("20088.467372365518,20051.89371416724"), "timestamp": datetime("2017-10-01T00:00:00.000Z"), "threatening_flag": true }, "Time": datetime("2020-08-18T04:06:15.641Z") }
diff --git a/asterix-bad/src/test/resources/runtimets/results/bad_cq/active_function_in_udf/active_function_in_udf.1.adm b/asterix-bad/src/test/resources/runtimets/results/bad_cq/active_function_in_udf/active_function_in_udf.1.adm
new file mode 100644
index 0000000..3693880
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/results/bad_cq/active_function_in_udf/active_function_in_udf.1.adm
@@ -0,0 +1 @@
+{ "t": { "tid": 999, "area_code": "45", "text": "Xikui likes Google, but Mike likes AsterixDB.", "location": point("1998078.3009357268,1998011.0235705695"), "timestamp": datetime("2019-12-03T17:59:52.041Z"), "hatefulFlag": false } }
diff --git a/asterix-bad/src/test/resources/runtimets/results/bad_cq/active_functions/active_functions.1.adm b/asterix-bad/src/test/resources/runtimets/results/bad_cq/active_functions/active_functions.1.adm
new file mode 100644
index 0000000..e9c0934
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/results/bad_cq/active_functions/active_functions.1.adm
@@ -0,0 +1 @@
+{ "Time_current_channel": datetime("2020-05-28T02:23:55.887Z"), "previous_channel_time": datetime("1970-01-01T00:00:00.000Z") }
diff --git a/asterix-bad/src/test/resources/runtimets/results/channel/disasters_with_friends/disasters_with_friends.1.adm b/asterix-bad/src/test/resources/runtimets/results/bad_cq/bad_http_feed/bad_http_feed.3.adm
similarity index 100%
copy from asterix-bad/src/test/resources/runtimets/results/channel/disasters_with_friends/disasters_with_friends.1.adm
copy to asterix-bad/src/test/resources/runtimets/results/bad_cq/bad_http_feed/bad_http_feed.3.adm
diff --git a/asterix-bad/src/test/resources/runtimets/results/bad_cq/bad_http_feed/bad_http_feed.4.adm b/asterix-bad/src/test/resources/runtimets/results/bad_cq/bad_http_feed/bad_http_feed.4.adm
new file mode 100644
index 0000000..56a6051
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/results/bad_cq/bad_http_feed/bad_http_feed.4.adm
@@ -0,0 +1 @@
+1
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/results/bad_cq/bad_http_feed/bad_http_feed.7.adm b/asterix-bad/src/test/resources/runtimets/results/bad_cq/bad_http_feed/bad_http_feed.7.adm
new file mode 100644
index 0000000..e440e5c
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/results/bad_cq/bad_http_feed/bad_http_feed.7.adm
@@ -0,0 +1 @@
+3
\ No newline at end of file
diff --git a/asterix-bad/src/test/resources/runtimets/results/bad_cq/bad_islands/bad_islands.10.adm b/asterix-bad/src/test/resources/runtimets/results/bad_cq/bad_islands/bad_islands.10.adm
new file mode 100644
index 0000000..353400f
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/results/bad_cq/bad_islands/bad_islands.10.adm
@@ -0,0 +1,2 @@
+{ "tid": 0, "area_name": "OC", "text": "OC Tweet" }
+{ "tid": 2, "area_name": "OC", "text": "OC Tweet" }
diff --git a/asterix-bad/src/test/resources/runtimets/results/channel/disasters_with_friends/disasters_with_friends.1.adm b/asterix-bad/src/test/resources/runtimets/results/bad_cq/bad_islands/bad_islands.4.adm
similarity index 100%
copy from asterix-bad/src/test/resources/runtimets/results/channel/disasters_with_friends/disasters_with_friends.1.adm
copy to asterix-bad/src/test/resources/runtimets/results/bad_cq/bad_islands/bad_islands.4.adm
diff --git a/asterix-bad/src/test/resources/runtimets/results/bad_cq/bad_islands/bad_islands.6.adm b/asterix-bad/src/test/resources/runtimets/results/bad_cq/bad_islands/bad_islands.6.adm
new file mode 100644
index 0000000..9dffebb
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/results/bad_cq/bad_islands/bad_islands.6.adm
@@ -0,0 +1 @@
+{ "tid": 0, "area_name": "OC", "text": "OC Tweet" }
diff --git a/asterix-bad/src/test/resources/runtimets/results/channel/disasters_with_friends/disasters_with_friends.1.adm b/asterix-bad/src/test/resources/runtimets/results/bad_cq/bad_islands/bad_islands.8.adm
similarity index 100%
copy from asterix-bad/src/test/resources/runtimets/results/channel/disasters_with_friends/disasters_with_friends.1.adm
copy to asterix-bad/src/test/resources/runtimets/results/bad_cq/bad_islands/bad_islands.8.adm
diff --git a/asterix-bad/src/test/resources/runtimets/results/bad_cq/new_tweets_from_area/new_tweets_from_area.1.adm b/asterix-bad/src/test/resources/runtimets/results/bad_cq/new_tweets_from_area/new_tweets_from_area.1.adm
new file mode 100644
index 0000000..23c8e2e
--- /dev/null
+++ b/asterix-bad/src/test/resources/runtimets/results/bad_cq/new_tweets_from_area/new_tweets_from_area.1.adm
@@ -0,0 +1,4 @@
+{ "t": { "tid": 2, "area_name": "LA", "suspicious_level": 10, "text": "Tweet 3", "location": point("4037.165975321966,4020.6200896429373"), "timestamp": datetime("2018-08-14T00:00:00.000Z"), "threatening_flag": true }, "TimeCurrent": datetime("2020-08-18T05:03:42.096Z"), "TimePrevious": datetime("1970-01-01T00:00:00.000Z") }
+{ "t": { "tid": 5, "area_name": "LA", "suspicious_level": 8, "text": "Tweet 6", "location": point("10030.582330779562,10035.23466920704"), "timestamp": datetime("2017-04-11T00:00:00.000Z"), "threatening_flag": false }, "TimeCurrent": datetime("2020-08-18T05:03:42.096Z"), "TimePrevious": datetime("1970-01-01T00:00:00.000Z") }
+{ "t": { "tid": 6, "area_name": "LA", "suspicious_level": 9, "text": "Tweet 7", "location": point("12074.059527318483,12008.549148129303"), "timestamp": datetime("2017-04-23T00:00:00.000Z"), "threatening_flag": true }, "TimeCurrent": datetime("2020-08-18T05:03:42.096Z"), "TimePrevious": datetime("1970-01-01T00:00:00.000Z") }
+{ "t": { "tid": 8, "area_name": "LA", "suspicious_level": 8, "text": "Tweet 9", "location": point("16051.9846352692,16078.599078960015"), "timestamp": datetime("2018-03-27T00:00:00.000Z"), "threatening_flag": true }, "TimeCurrent": datetime("2020-08-18T05:03:42.096Z"), "TimePrevious": datetime("1970-01-01T00:00:00.000Z") }
diff --git a/asterix-bad/src/test/resources/runtimets/results/channel/add_index/add_index.1.adm b/asterix-bad/src/test/resources/runtimets/results/bad_rq/add_index/add_index.1.adm
similarity index 100%
rename from asterix-bad/src/test/resources/runtimets/results/channel/add_index/add_index.1.adm
rename to asterix-bad/src/test/resources/runtimets/results/bad_rq/add_index/add_index.1.adm
diff --git a/asterix-bad/src/test/resources/runtimets/results/channel/create_channel_check_datasets/create_channel_check_datasets.1.adm b/asterix-bad/src/test/resources/runtimets/results/bad_rq/create_channel_check_datasets/create_channel_check_datasets.1.adm
similarity index 100%
rename from asterix-bad/src/test/resources/runtimets/results/channel/create_channel_check_datasets/create_channel_check_datasets.1.adm
rename to asterix-bad/src/test/resources/runtimets/results/bad_rq/create_channel_check_datasets/create_channel_check_datasets.1.adm
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/bad_rq/create_channel_check_metadata/create_channel_check_metadata.1.adm
similarity index 73%
rename from asterix-bad/src/test/resources/runtimets/results/channel/create_channel_check_metadata/create_channel_check_metadata.1.adm
rename to asterix-bad/src/test/resources/runtimets/results/bad_rq/create_channel_check_metadata/create_channel_check_metadata.1.adm
index bd1933c..0748789 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/bad_rq/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", "Dependencies": [ [ [ "channels", "nearbyTweetChannelResults" ], [ "channels", "nearbyTweetChannelSubscriptions" ] ], [ [ "channels", "NearbyTweetsContainingText", "2" ] ] ], "Body": "SET inline_with \"false\";\ninsert into `channels`.nearbyTweetChannelResults as a (\nwith channelExecutionTime as current_datetime() \nselect result, channelExecutionTime, sub.subscriptionId as subscriptionId,current_datetime() as deliveryTime\nfrom `channels`.nearbyTweetChannelSubscriptions sub,\nMetadata.Broker b, \nchannels.NearbyTweetsContainingText(sub.param0,sub.param1) result \nwhere b.BrokerName = sub.BrokerName\nand b.DataverseName = sub.DataverseName\n) returning a;" }
\ 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" ] ] ], "Body": "SET inline_with \"false\";\ninsert into `channels`.nearbyTweetChannelResults as a (\nwith channelExecutionTime as current_datetime() \nselect result, channelExecutionTime, sub.subscriptionId as subscriptionId,current_datetime() as deliveryTime\nfrom `channels`.nearbyTweetChannelSubscriptions sub,\nMetadata.`Broker` b, \nchannels.NearbyTweetsContainingText(sub.param0, sub.param1) result \nwhere sub.BrokerName /*+ bcast */ = b.BrokerName\nand sub.DataverseName /*+ bcast */ = b.DataverseName\n) returning a;" }
diff --git a/asterix-bad/src/test/resources/runtimets/results/channel/disasters_with_friends/disasters_with_friends.1.adm b/asterix-bad/src/test/resources/runtimets/results/bad_rq/disasters_with_friends/disasters_with_friends.5.adm
similarity index 100%
rename from asterix-bad/src/test/resources/runtimets/results/channel/disasters_with_friends/disasters_with_friends.1.adm
rename to asterix-bad/src/test/resources/runtimets/results/bad_rq/disasters_with_friends/disasters_with_friends.5.adm
diff --git a/asterix-bad/src/test/resources/runtimets/results/channel/drop_channel_check_datasets/drop_channel_check_datasets.1.adm b/asterix-bad/src/test/resources/runtimets/results/bad_rq/drop_channel_check_datasets/drop_channel_check_datasets.1.adm
similarity index 100%
rename from asterix-bad/src/test/resources/runtimets/results/channel/drop_channel_check_datasets/drop_channel_check_datasets.1.adm
rename to asterix-bad/src/test/resources/runtimets/results/bad_rq/drop_channel_check_datasets/drop_channel_check_datasets.1.adm
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/bad_rq/drop_channel_check_metadata/drop_channel_check_metadata.1.adm
similarity index 72%
rename from asterix-bad/src/test/resources/runtimets/results/channel/drop_channel_check_metadata/drop_channel_check_metadata.1.adm
rename to asterix-bad/src/test/resources/runtimets/results/bad_rq/drop_channel_check_metadata/drop_channel_check_metadata.1.adm
index 5ec9e7c..7dcff54 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/bad_rq/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", "Dependencies": [ [ [ "channels", "nearbyTweetChannel1Results" ], [ "channels", "nearbyTweetChannel1Subscriptions" ] ], [ [ "channels", "NearbyTweetsContainingText", "2" ] ] ], "Body": "SET inline_with \"false\";\ninsert into `channels`.nearbyTweetChannel1Results as a (\nwith channelExecutionTime as current_datetime() \nselect result, channelExecutionTime, sub.subscriptionId as subscriptionId,current_datetime() as deliveryTime\nfrom `channels`.nearbyTweetChannel1Subscriptions sub,\nMetadata.Broker b, \nchannels.NearbyTweetsContainingText(sub.param0,sub.param1) result \nwhere b.BrokerName = sub.BrokerName\nand b.DataverseName = sub.DataverseName\n) returning a;" }
-{ "DataverseName": "channels", "ChannelName": "nearbyTweetChannel3", "SubscriptionsDatasetName": "nearbyTweetChannel3Subscriptions", "ResultsDatasetName": "nearbyTweetChannel3Results", "Function": [ "channels", "NearbyTweetsContainingText", "2" ], "Duration": "PT10M", "Dependencies": [ [ [ "channels", "nearbyTweetChannel3Results" ], [ "channels", "nearbyTweetChannel3Subscriptions" ] ], [ [ "channels", "NearbyTweetsContainingText", "2" ] ] ], "Body": "SET inline_with \"false\";\ninsert into `channels`.nearbyTweetChannel3Results as a (\nwith channelExecutionTime as current_datetime() \nselect result, channelExecutionTime, sub.subscriptionId as subscriptionId,current_datetime() as deliveryTime\nfrom `channels`.nearbyTweetChannel3Subscriptions sub,\nMetadata.Broker b, \nchannels.NearbyTweetsContainingText(sub.param0,sub.param1) result \nwhere b.BrokerName = sub.BrokerName\nand b.DataverseName = sub.DataverseName\n) returning a;" }
\ 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" ] ] ], "Body": "SET inline_with \"false\";\ninsert into `channels`.nearbyTweetChannel1Results as a (\nwith channelExecutionTime as current_datetime() \nselect result, channelExecutionTime, sub.subscriptionId as subscriptionId,current_datetime() as deliveryTime\nfrom `channels`.nearbyTweetChannel1Subscriptions sub,\nMetadata.`Broker` b, \nchannels.NearbyTweetsContainingText(sub.param0, sub.param1) result \nwhere sub.BrokerName /*+ bcast */ = b.BrokerName\nand sub.DataverseName /*+ bcast */ = b.DataverseName\n) returning a;" }
+{ "DataverseName": "channels", "ChannelName": "nearbyTweetChannel3", "SubscriptionsDatasetName": "nearbyTweetChannel3Subscriptions", "ResultsDatasetName": "nearbyTweetChannel3Results", "Function": [ "channels", "NearbyTweetsContainingText", "2" ], "Duration": "PT10M", "Dependencies": [ [ [ "channels", "nearbyTweetChannel3Results" ], [ "channels", "nearbyTweetChannel3Subscriptions" ] ], [ [ "channels", "NearbyTweetsContainingText", "2" ] ] ], "Body": "SET inline_with \"false\";\ninsert into `channels`.nearbyTweetChannel3Results as a (\nwith channelExecutionTime as current_datetime() \nselect result, channelExecutionTime, sub.subscriptionId as subscriptionId,current_datetime() as deliveryTime\nfrom `channels`.nearbyTweetChannel3Subscriptions sub,\nMetadata.`Broker` b, \nchannels.NearbyTweetsContainingText(sub.param0, sub.param1) result \nwhere sub.BrokerName /*+ bcast */ = b.BrokerName\nand sub.DataverseName /*+ bcast */ = b.DataverseName\n) returning a;" }
diff --git a/asterix-bad/src/test/resources/runtimets/results/channel/room_occupants/room_occupants.1.adm b/asterix-bad/src/test/resources/runtimets/results/bad_rq/room_occupants/room_occupants.1.adm
similarity index 100%
rename from asterix-bad/src/test/resources/runtimets/results/channel/room_occupants/room_occupants.1.adm
rename to asterix-bad/src/test/resources/runtimets/results/bad_rq/room_occupants/room_occupants.1.adm
diff --git a/asterix-bad/src/test/resources/runtimets/results/channel/room_occupants/room_occupants.2.adm b/asterix-bad/src/test/resources/runtimets/results/bad_rq/room_occupants/room_occupants.2.adm
similarity index 100%
rename from asterix-bad/src/test/resources/runtimets/results/channel/room_occupants/room_occupants.2.adm
rename to asterix-bad/src/test/resources/runtimets/results/bad_rq/room_occupants/room_occupants.2.adm
diff --git a/asterix-bad/src/test/resources/runtimets/results/channel/subscribe_channel_check_subscriptions/subscribe_channel_check_subscriptions.1.adm b/asterix-bad/src/test/resources/runtimets/results/bad_rq/subscribe_channel_check_subscriptions/subscribe_channel_check_subscriptions.1.adm
similarity index 100%
rename from asterix-bad/src/test/resources/runtimets/results/channel/subscribe_channel_check_subscriptions/subscribe_channel_check_subscriptions.1.adm
rename to asterix-bad/src/test/resources/runtimets/results/bad_rq/subscribe_channel_check_subscriptions/subscribe_channel_check_subscriptions.1.adm
diff --git a/asterix-bad/src/test/resources/runtimets/results/channel/ten_minute_channel/ten_minute_channel.5.adm b/asterix-bad/src/test/resources/runtimets/results/bad_rq/ten_minute_channel/ten_minute_channel.5.adm
similarity index 100%
rename from asterix-bad/src/test/resources/runtimets/results/channel/ten_minute_channel/ten_minute_channel.5.adm
rename to asterix-bad/src/test/resources/runtimets/results/bad_rq/ten_minute_channel/ten_minute_channel.5.adm
diff --git a/asterix-bad/src/test/resources/runtimets/testsuite.xml b/asterix-bad/src/test/resources/runtimets/testsuite_bad.xml
similarity index 77%
rename from asterix-bad/src/test/resources/runtimets/testsuite.xml
rename to asterix-bad/src/test/resources/runtimets/testsuite_bad.xml
index 4640af1..5f130e9 100644
--- a/asterix-bad/src/test/resources/runtimets/testsuite.xml
+++ b/asterix-bad/src/test/resources/runtimets/testsuite_bad.xml
@@ -20,7 +20,7 @@
              ResultOffsetPath="results"
              QueryOffsetPath="queries"
              QueryFileExtension=".sqlpp">
-  <test-group name="channel">
+  <test-group name="procedure">
     <test-case FilePath="procedure">
       <compilation-unit name="create_procedure_check_metadata">
         <output-dir compare="Text">create_procedure_check_metadata</output-dir>
@@ -103,80 +103,129 @@
         <output-dir compare="Text">repetitive_insert_procedure</output-dir>
       </compilation-unit>
     </test-case>
-    <test-case FilePath="channel">
+  </test-group>
+  <test-group name="bad_rq">
+    <test-case FilePath="bad_rq">
       <compilation-unit name="create_channel_check_datasets">
         <output-dir compare="Text">create_channel_check_datasets</output-dir>
       </compilation-unit>
     </test-case>
-    <test-case FilePath="channel">
+    <test-case FilePath="bad_rq">
       <compilation-unit name="create_channel_check_metadata">
         <output-dir compare="Text">create_channel_check_metadata</output-dir>
       </compilation-unit>
     </test-case>
-    <test-case FilePath="channel">
+    <test-case FilePath="bad_rq">
       <compilation-unit name="drop_channel_check_datasets">
         <output-dir compare="Text">drop_channel_check_datasets</output-dir>
       </compilation-unit>
     </test-case>
-    <test-case FilePath="channel">
+    <test-case FilePath="bad_rq">
       <compilation-unit name="drop_channel_check_metadata">
         <output-dir compare="Text">drop_channel_check_metadata</output-dir>
       </compilation-unit>
     </test-case>
-    <test-case FilePath="channel">
+    <test-case FilePath="bad_rq">
       <compilation-unit name="subscribe_channel_check_subscriptions">
         <output-dir compare="Text">subscribe_channel_check_subscriptions</output-dir>
       </compilation-unit>
     </test-case>
-    <test-case FilePath="channel">
+    <test-case FilePath="bad_rq">
       <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">
+    <test-case FilePath="bad_rq">
       <compilation-unit name="drop_index">
         <output-dir compare="Text">drop_index</output-dir>
         <expected-error>Cannot drop index. channels.EmergencyChannel(Channel) depends on it!</expected-error>
       </compilation-unit>
     </test-case>
-    <test-case FilePath="channel">
+    <test-case FilePath="bad_rq">
       <compilation-unit name="add_index">
         <output-dir compare="Text">add_index</output-dir>
       </compilation-unit>
     </test-case>
-    <test-case FilePath="channel">
+    <test-case FilePath="bad_rq">
       <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">
+    <test-case FilePath="bad_rq">
       <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">
+    <test-case FilePath="bad_rq">
       <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">
+    <test-case FilePath="bad_rq">
       <compilation-unit name="room_occupants">
         <output-dir compare="Text">room_occupants</output-dir>
       </compilation-unit>
     </test-case>
-    <test-case FilePath="channel">
+    <test-case FilePath="bad_rq">
       <compilation-unit name="disasters_with_friends">
         <output-dir compare="Text">disasters_with_friends</output-dir>
       </compilation-unit>
     </test-case>
-    <test-case FilePath="channel">
+    <test-case FilePath="bad_rq">
       <compilation-unit name="ten_minute_channel">
         <output-dir compare="Text">ten_minute_channel</output-dir>
       </compilation-unit>
     </test-case>
   </test-group>
+  <test-group name="bad_cq">
+    <test-case FilePath="bad_cq">
+      <compilation-unit name="active_dataset_insert">
+        <output-dir compare="Text">active_dataset_insert</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="bad_cq">
+      <compilation-unit name="active_dataset_upsert">
+        <output-dir compare="Text">active_dataset_upsert</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="bad_cq">
+      <compilation-unit name="active_dataset_delete">
+        <output-dir compare="Text">active_dataset_delete</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="bad_cq">
+      <compilation-unit name="active_feeds">
+        <output-dir compare="Text">active_feeds</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="bad_cq">
+      <compilation-unit name="active_function_in_udf">
+        <output-dir compare="Text">active_function_in_udf</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="bad_cq">
+      <compilation-unit name="active_functions">
+        <output-dir compare="Text">active_functions</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="bad_cq">
+      <compilation-unit name="bad_http_feed">
+        <output-dir compare="Text">bad_http_feed</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="bad_cq">
+      <compilation-unit name="bad_islands">
+        <output-dir compare="Text">bad_islands</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="bad_cq">
+      <compilation-unit name="new_tweets_from_area">
+        <output-dir compare="Text">new_tweets_from_area</output-dir>
+      </compilation-unit>
+    </test-case>
+  </test-group>
 </test-suite>