You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by mh...@apache.org on 2019/09/12 14:24:59 UTC

[asterixdb] branch master updated (a9e9992 -> 3491584)

This is an automated email from the ASF dual-hosted git repository.

mhubail pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git.


    from a9e9992  [NO ISSUE][COMP] Remove listify() when iterating over aggregate
     new 9554871  [NO ISSUE][NET] Ensure Recycling Buffer and Notifying Sender is Atomic
     new fd0f4ce  [NO ISSUE][*DB][REPL] Identifier comparability of unknown hosts
     new cba9cbe  [NO ISSUE][CLUS] Attempt To Get Node IP From Existing Nodes
     new d292d99  [NO ISSUE][COMP] Fix index selection for datasets with meta
     new 8930f0d  [NO ISSUE][ING][EXT] Handle filters on meta() fields for feeds
     new 3491584  Merge commit '8930f0d' from stabilization-f69489

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../asterix/optimizer/base/RuleCollections.java    |  1 -
 .../am/AbstractIntroduceAccessMethodRule.java      | 82 ++++++++++++++++------
 .../optimizer/rules/am/BTreeAccessMethod.java      | 17 +++--
 .../optimizer/rules/am/IOptimizableFuncExpr.java   |  4 +-
 .../rules/am/IntroduceLSMComponentFilterRule.java  | 23 ++++--
 .../optimizer/rules/am/OptimizableFuncExpr.java    | 11 ++-
 .../rules/am/OptimizableOperatorSubTree.java       |  1 +
 asterixdb/asterix-app/data/csv/people3.csv         |  9 +++
 .../meta/indexes_on_dataset_with_meta_01.sqlpp}    | 26 ++++++-
 .../meta/indexes_on_dataset_with_meta_02.sqlpp}    | 26 ++++++-
 .../meta/indexes_on_dataset_with_meta_03.sqlpp}    | 26 ++++++-
 .../meta/indexes_on_dataset_with_meta_04.sqlpp}    | 26 ++++++-
 .../meta/indexes_on_dataset_with_meta_05.sqlpp}    | 30 +++++++-
 .../meta/indexes_on_dataset_with_meta_06.sqlpp}    | 30 +++++++-
 .../meta/indexes_on_dataset_with_meta_07.sqlpp}    | 30 +++++++-
 .../meta/indexes_on_dataset_with_meta_08.sqlpp}    | 28 +++++++-
 .../meta/indexes_on_dataset_with_meta_09.sqlpp}    | 27 ++++++-
 .../meta/indexes_on_dataset_with_meta_10.sqlpp}    | 29 +++++++-
 .../meta/indexes_on_dataset_with_meta_11.sqlpp}    | 29 +++++++-
 .../meta/field_access_with_data_and_meta_1.plan    |  2 +-
 .../meta/field_access_with_data_and_meta_2.plan    |  2 +-
 .../meta/field_access_with_data_and_meta_3.plan    |  2 +-
 .../meta/field_access_with_data_and_meta_4.plan    |  2 +-
 .../meta/indexes_on_dataset_with_meta_01.plan      | 10 +++
 .../indexes_on_dataset_with_meta_02.plan}          |  0
 .../indexes_on_dataset_with_meta_03.plan}          |  0
 .../meta/indexes_on_dataset_with_meta_04.plan      | 11 +++
 .../meta/indexes_on_dataset_with_meta_05.plan      | 24 +++++++
 .../meta/indexes_on_dataset_with_meta_06.plan      | 17 +++++
 .../meta/indexes_on_dataset_with_meta_07.plan      | 18 +++++
 .../meta/indexes_on_dataset_with_meta_08.plan      | 17 +++++
 .../indexes_on_dataset_with_meta_09.plan}          |  0
 .../meta/indexes_on_dataset_with_meta_10.plan      | 24 +++++++
 .../meta/indexes_on_dataset_with_meta_11.plan      | 17 +++++
 .../dataset-with-meta.01.ddl.sqlpp                 | 68 ++++++++++++++++++
 .../dataset-with-meta.02.update.sqlpp}             |  9 ++-
 .../dataset-with-meta.03.query.sqlpp}              | 11 ++-
 .../dataset-with-meta.04.query.sqlpp}              | 11 ++-
 .../dataset-with-meta.05.query.sqlpp}              | 11 ++-
 .../dataset-with-meta.06.query.sqlpp}              | 11 ++-
 .../dataset-with-meta.07.query.sqlpp}              | 12 +++-
 .../dataset-with-meta.08.query.sqlpp}              | 12 +++-
 .../dataset-with-meta.09.query.sqlpp}              | 12 +++-
 .../dataset-with-meta.10.ddl.sqlpp}                |  4 +-
 .../dataset-with-meta.11.query.sqlpp}              | 11 ++-
 .../dataset-with-meta.12.query.sqlpp}              | 11 ++-
 .../dataset-with-meta.13.query.sqlpp}              | 12 +++-
 .../dataset-with-meta.14.query.sqlpp}              | 12 +++-
 .../dataset-with-meta.15.ddl.sqlpp}                |  0
 .../resolving_pk_with_meta.7.ddl.sqlpp             |  2 +-
 .../change-feed-with-filter-on-meta.11.adm         |  2 +-
 .../change-feed-with-filter-on-meta.12.adm         |  2 +-
 .../change-feed-with-filter-on-meta.13.adm         |  2 +-
 .../change-feed-with-filter-on-meta.14.adm         |  2 +-
 .../change-feed-with-filter-on-meta.15.adm         |  2 +-
 .../change-feed-with-filter-on-meta.16.adm         |  2 +-
 .../change-feed-with-filter-on-meta.17.adm         |  2 +-
 .../change-feed-with-filter-on-meta.6.adm          |  2 +-
 .../change-feed-with-filter-on-meta.7.adm          |  2 +-
 .../dataset-with-meta/dataset-with-meta.03.adm     |  1 +
 .../dataset-with-meta/dataset-with-meta.04.adm     |  1 +
 .../dataset-with-meta/dataset-with-meta.05.adm     |  1 +
 .../dataset-with-meta/dataset-with-meta.06.adm     |  1 +
 .../dataset-with-meta/dataset-with-meta.07.adm     |  9 +++
 .../dataset-with-meta/dataset-with-meta.08.adm     |  2 +
 .../dataset-with-meta/dataset-with-meta.09.adm     |  9 +++
 .../dataset-with-meta/dataset-with-meta.11.adm     |  1 +
 .../dataset-with-meta/dataset-with-meta.12.adm     |  1 +
 .../dataset-with-meta/dataset-with-meta.13.adm     |  9 +++
 .../dataset-with-meta/dataset-with-meta.14.adm     |  2 +
 .../meta_in_with_clause/meta_in_with_clause.6.adm  |  2 +-
 .../test/resources/runtimets/testsuite_sqlpp.xml   |  5 ++
 .../asterix/common/storage/ReplicaIdentifier.java  |  2 +-
 .../apache/asterix/metadata/utils/DatasetUtil.java | 12 ++++
 .../hyracks/control/cc/cluster/NodeManager.java    | 24 ++++++-
 .../muxdemux/FullFrameChannelReadInterface.java    |  1 -
 76 files changed, 833 insertions(+), 78 deletions(-)
 create mode 100644 asterixdb/asterix-app/data/csv/people3.csv
 copy asterixdb/asterix-app/src/test/resources/{runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.7.ddl.sqlpp => optimizerts/queries/meta/indexes_on_dataset_with_meta_01.sqlpp} (64%)
 copy asterixdb/asterix-app/src/test/resources/{runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.7.ddl.sqlpp => optimizerts/queries/meta/indexes_on_dataset_with_meta_02.sqlpp} (65%)
 copy asterixdb/asterix-app/src/test/resources/{runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.7.ddl.sqlpp => optimizerts/queries/meta/indexes_on_dataset_with_meta_03.sqlpp} (66%)
 copy asterixdb/asterix-app/src/test/resources/{runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.7.ddl.sqlpp => optimizerts/queries/meta/indexes_on_dataset_with_meta_04.sqlpp} (66%)
 copy asterixdb/asterix-app/src/test/resources/{runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.7.ddl.sqlpp => optimizerts/queries/meta/indexes_on_dataset_with_meta_05.sqlpp} (57%)
 copy asterixdb/asterix-app/src/test/resources/{runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.7.ddl.sqlpp => optimizerts/queries/meta/indexes_on_dataset_with_meta_06.sqlpp} (56%)
 copy asterixdb/asterix-app/src/test/resources/{runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.7.ddl.sqlpp => optimizerts/queries/meta/indexes_on_dataset_with_meta_07.sqlpp} (57%)
 copy asterixdb/asterix-app/src/test/resources/{runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.7.ddl.sqlpp => optimizerts/queries/meta/indexes_on_dataset_with_meta_08.sqlpp} (61%)
 copy asterixdb/asterix-app/src/test/resources/{runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.7.ddl.sqlpp => optimizerts/queries/meta/indexes_on_dataset_with_meta_09.sqlpp} (61%)
 copy asterixdb/asterix-app/src/test/resources/{runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.7.ddl.sqlpp => optimizerts/queries/meta/indexes_on_dataset_with_meta_10.sqlpp} (55%)
 copy asterixdb/asterix-app/src/test/resources/{runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.7.ddl.sqlpp => optimizerts/queries/meta/indexes_on_dataset_with_meta_11.sqlpp} (53%)
 create mode 100644 asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_01.plan
 copy asterixdb/asterix-app/src/test/resources/optimizerts/results/{nested-index/btree-index/btree-primary-06.plan => meta/indexes_on_dataset_with_meta_02.plan} (100%)
 copy asterixdb/asterix-app/src/test/resources/optimizerts/results/{nested-index/btree-index/btree-primary-06.plan => meta/indexes_on_dataset_with_meta_03.plan} (100%)
 create mode 100644 asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_04.plan
 create mode 100644 asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_05.plan
 create mode 100644 asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_06.plan
 create mode 100644 asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_07.plan
 create mode 100644 asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_08.plan
 copy asterixdb/asterix-app/src/test/resources/optimizerts/results/{nested-index/btree-index/btree-primary-06.plan => meta/indexes_on_dataset_with_meta_09.plan} (100%)
 create mode 100644 asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_10.plan
 create mode 100644 asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_11.plan
 create mode 100644 asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.01.ddl.sqlpp
 copy asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/{meta/resolving_pk_with_meta/resolving_pk_with_meta.7.ddl.sqlpp => index-selection/dataset-with-meta/dataset-with-meta.02.update.sqlpp} (82%)
 copy asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/{meta/resolving_pk_with_meta/resolving_pk_with_meta.7.ddl.sqlpp => index-selection/dataset-with-meta/dataset-with-meta.03.query.sqlpp} (80%)
 copy asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/{meta/resolving_pk_with_meta/resolving_pk_with_meta.7.ddl.sqlpp => index-selection/dataset-with-meta/dataset-with-meta.04.query.sqlpp} (82%)
 copy asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/{meta/resolving_pk_with_meta/resolving_pk_with_meta.7.ddl.sqlpp => index-selection/dataset-with-meta/dataset-with-meta.05.query.sqlpp} (83%)
 copy asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/{meta/resolving_pk_with_meta/resolving_pk_with_meta.7.ddl.sqlpp => index-selection/dataset-with-meta/dataset-with-meta.06.query.sqlpp} (83%)
 copy asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/{meta/resolving_pk_with_meta/resolving_pk_with_meta.7.ddl.sqlpp => index-selection/dataset-with-meta/dataset-with-meta.07.query.sqlpp} (75%)
 copy asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/{meta/resolving_pk_with_meta/resolving_pk_with_meta.7.ddl.sqlpp => index-selection/dataset-with-meta/dataset-with-meta.08.query.sqlpp} (72%)
 copy asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/{meta/resolving_pk_with_meta/resolving_pk_with_meta.7.ddl.sqlpp => index-selection/dataset-with-meta/dataset-with-meta.09.query.sqlpp} (75%)
 copy asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/{meta/resolving_pk_with_meta/resolving_pk_with_meta.7.ddl.sqlpp => index-selection/dataset-with-meta/dataset-with-meta.10.ddl.sqlpp} (94%)
 copy asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/{meta/resolving_pk_with_meta/resolving_pk_with_meta.7.ddl.sqlpp => index-selection/dataset-with-meta/dataset-with-meta.11.query.sqlpp} (79%)
 copy asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/{meta/resolving_pk_with_meta/resolving_pk_with_meta.7.ddl.sqlpp => index-selection/dataset-with-meta/dataset-with-meta.12.query.sqlpp} (79%)
 copy asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/{meta/resolving_pk_with_meta/resolving_pk_with_meta.7.ddl.sqlpp => index-selection/dataset-with-meta/dataset-with-meta.13.query.sqlpp} (72%)
 copy asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/{meta/resolving_pk_with_meta/resolving_pk_with_meta.7.ddl.sqlpp => index-selection/dataset-with-meta/dataset-with-meta.14.query.sqlpp} (70%)
 copy asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/{warnings/warnings_limit/warnings_limit.06.ddl.sqlpp => index-selection/dataset-with-meta/dataset-with-meta.15.ddl.sqlpp} (100%)
 create mode 100644 asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.03.adm
 create mode 100644 asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.04.adm
 create mode 100644 asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.05.adm
 create mode 100644 asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.06.adm
 create mode 100644 asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.07.adm
 create mode 100644 asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.08.adm
 create mode 100644 asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.09.adm
 create mode 100644 asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.11.adm
 create mode 100644 asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.12.adm
 create mode 100644 asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.13.adm
 create mode 100644 asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.14.adm


[asterixdb] 06/06: Merge commit '8930f0d' from stabilization-f69489

Posted by mh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mhubail pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git

commit 34915843d619e07b95f34458ae2e0992f44ff379
Merge: a9e9992 8930f0d
Author: Murtadha Hubail <mh...@apache.org>
AuthorDate: Thu Sep 12 05:59:40 2019 +0300

    Merge commit '8930f0d' from stabilization-f69489
    
    Change-Id: I64cf862bc5ebe19a24acbccf821f68556699222e

 .../asterix/optimizer/base/RuleCollections.java    |  1 -
 .../am/AbstractIntroduceAccessMethodRule.java      | 82 ++++++++++++++++------
 .../optimizer/rules/am/BTreeAccessMethod.java      | 17 +++--
 .../optimizer/rules/am/IOptimizableFuncExpr.java   |  4 +-
 .../rules/am/IntroduceLSMComponentFilterRule.java  | 23 ++++--
 .../optimizer/rules/am/OptimizableFuncExpr.java    | 11 ++-
 .../rules/am/OptimizableOperatorSubTree.java       |  1 +
 asterixdb/asterix-app/data/csv/people3.csv         |  9 +++
 .../meta/indexes_on_dataset_with_meta_01.sqlpp}    | 26 ++++++-
 .../meta/indexes_on_dataset_with_meta_02.sqlpp}    | 26 ++++++-
 .../meta/indexes_on_dataset_with_meta_03.sqlpp}    | 26 ++++++-
 .../meta/indexes_on_dataset_with_meta_04.sqlpp}    | 26 ++++++-
 .../meta/indexes_on_dataset_with_meta_05.sqlpp}    | 30 +++++++-
 .../meta/indexes_on_dataset_with_meta_06.sqlpp}    | 30 +++++++-
 .../meta/indexes_on_dataset_with_meta_07.sqlpp}    | 30 +++++++-
 .../meta/indexes_on_dataset_with_meta_08.sqlpp}    | 28 +++++++-
 .../meta/indexes_on_dataset_with_meta_09.sqlpp}    | 27 ++++++-
 .../meta/indexes_on_dataset_with_meta_10.sqlpp}    | 29 +++++++-
 .../meta/indexes_on_dataset_with_meta_11.sqlpp}    | 29 +++++++-
 .../meta/field_access_with_data_and_meta_1.plan    |  2 +-
 .../meta/field_access_with_data_and_meta_2.plan    |  2 +-
 .../meta/field_access_with_data_and_meta_3.plan    |  2 +-
 .../meta/field_access_with_data_and_meta_4.plan    |  2 +-
 .../meta/indexes_on_dataset_with_meta_01.plan      | 10 +++
 .../meta/indexes_on_dataset_with_meta_02.plan      | 10 +++
 .../meta/indexes_on_dataset_with_meta_03.plan      | 10 +++
 .../meta/indexes_on_dataset_with_meta_04.plan      | 11 +++
 .../meta/indexes_on_dataset_with_meta_05.plan      | 24 +++++++
 .../meta/indexes_on_dataset_with_meta_06.plan      | 17 +++++
 .../meta/indexes_on_dataset_with_meta_07.plan      | 18 +++++
 .../meta/indexes_on_dataset_with_meta_08.plan      | 17 +++++
 .../meta/indexes_on_dataset_with_meta_09.plan      | 10 +++
 .../meta/indexes_on_dataset_with_meta_10.plan      | 24 +++++++
 .../meta/indexes_on_dataset_with_meta_11.plan      | 17 +++++
 .../dataset-with-meta.01.ddl.sqlpp                 | 68 ++++++++++++++++++
 .../dataset-with-meta.02.update.sqlpp}             |  9 ++-
 .../dataset-with-meta.03.query.sqlpp}              | 11 ++-
 .../dataset-with-meta.04.query.sqlpp}              | 11 ++-
 .../dataset-with-meta.05.query.sqlpp}              | 11 ++-
 .../dataset-with-meta.06.query.sqlpp}              | 11 ++-
 .../dataset-with-meta.07.query.sqlpp}              | 12 +++-
 .../dataset-with-meta.08.query.sqlpp}              | 12 +++-
 .../dataset-with-meta.09.query.sqlpp}              | 12 +++-
 .../dataset-with-meta.10.ddl.sqlpp}                |  4 +-
 .../dataset-with-meta.11.query.sqlpp}              | 11 ++-
 .../dataset-with-meta.12.query.sqlpp}              | 11 ++-
 .../dataset-with-meta.13.query.sqlpp}              | 12 +++-
 .../dataset-with-meta.14.query.sqlpp}              | 12 +++-
 .../dataset-with-meta.15.ddl.sqlpp}                |  2 +-
 .../resolving_pk_with_meta.7.ddl.sqlpp             |  2 +-
 .../change-feed-with-filter-on-meta.11.adm         |  2 +-
 .../change-feed-with-filter-on-meta.12.adm         |  2 +-
 .../change-feed-with-filter-on-meta.13.adm         |  2 +-
 .../change-feed-with-filter-on-meta.14.adm         |  2 +-
 .../change-feed-with-filter-on-meta.15.adm         |  2 +-
 .../change-feed-with-filter-on-meta.16.adm         |  2 +-
 .../change-feed-with-filter-on-meta.17.adm         |  2 +-
 .../change-feed-with-filter-on-meta.6.adm          |  2 +-
 .../change-feed-with-filter-on-meta.7.adm          |  2 +-
 .../dataset-with-meta/dataset-with-meta.03.adm     |  1 +
 .../dataset-with-meta/dataset-with-meta.04.adm     |  1 +
 .../dataset-with-meta/dataset-with-meta.05.adm     |  1 +
 .../dataset-with-meta/dataset-with-meta.06.adm     |  1 +
 .../dataset-with-meta/dataset-with-meta.07.adm     |  9 +++
 .../dataset-with-meta/dataset-with-meta.08.adm     |  2 +
 .../dataset-with-meta/dataset-with-meta.09.adm     |  9 +++
 .../dataset-with-meta/dataset-with-meta.11.adm     |  1 +
 .../dataset-with-meta/dataset-with-meta.12.adm     |  1 +
 .../dataset-with-meta/dataset-with-meta.13.adm     |  9 +++
 .../dataset-with-meta/dataset-with-meta.14.adm     |  2 +
 .../meta_in_with_clause/meta_in_with_clause.6.adm  |  2 +-
 .../test/resources/runtimets/testsuite_sqlpp.xml   |  5 ++
 .../asterix/common/storage/ReplicaIdentifier.java  |  2 +-
 .../apache/asterix/metadata/utils/DatasetUtil.java | 12 ++++
 .../hyracks/control/cc/cluster/NodeManager.java    | 24 ++++++-
 .../muxdemux/FullFrameChannelReadInterface.java    |  1 -
 76 files changed, 864 insertions(+), 79 deletions(-)

diff --cc asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_05.plan
index 0000000,83d3362..f275419
mode 000000,100644..100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_05.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_05.plan
@@@ -1,0 -1,24 +1,24 @@@
+ -- DISTRIBUTE_RESULT  |PARTITIONED|
+   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+     -- STREAM_PROJECT  |PARTITIONED|
+       -- ASSIGN  |PARTITIONED|
+         -- STREAM_PROJECT  |PARTITIONED|
 -          -- SORT_MERGE_EXCHANGE [$$25(ASC) ]  |PARTITIONED|
 -            -- STABLE_SORT [$$25(ASC)]  |PARTITIONED|
++          -- SORT_MERGE_EXCHANGE [$$27(ASC) ]  |PARTITIONED|
++            -- STABLE_SORT [$$27(ASC)]  |PARTITIONED|
+               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                 -- STREAM_PROJECT  |PARTITIONED|
+                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
 -                    -- HYBRID_HASH_JOIN [$$25][$$30]  |PARTITIONED|
++                    -- HYBRID_HASH_JOIN [$$27][$$32]  |PARTITIONED|
+                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                         -- STREAM_PROJECT  |PARTITIONED|
+                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                             -- DATASOURCE_SCAN  |PARTITIONED|
+                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
 -                      -- HASH_PARTITION_EXCHANGE [$$30]  |PARTITIONED|
++                      -- HASH_PARTITION_EXCHANGE [$$32]  |PARTITIONED|
+                         -- ASSIGN  |PARTITIONED|
+                           -- STREAM_PROJECT  |PARTITIONED|
+                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                               -- DATASOURCE_SCAN  |PARTITIONED|
+                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --cc asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_06.plan
index 0000000,2273bfd..c5d6e9f
mode 000000,100644..100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_06.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_06.plan
@@@ -1,0 -1,17 +1,17 @@@
+ -- DISTRIBUTE_RESULT  |PARTITIONED|
+   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+     -- STREAM_PROJECT  |PARTITIONED|
+       -- ASSIGN  |PARTITIONED|
+         -- STREAM_PROJECT  |PARTITIONED|
 -          -- SORT_MERGE_EXCHANGE [$$29(ASC) ]  |PARTITIONED|
 -            -- STABLE_SORT [$$29(ASC)]  |PARTITIONED|
++          -- SORT_MERGE_EXCHANGE [$$31(ASC) ]  |PARTITIONED|
++            -- STABLE_SORT [$$31(ASC)]  |PARTITIONED|
+               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                 -- STREAM_PROJECT  |PARTITIONED|
+                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                     -- BTREE_SEARCH  |PARTITIONED|
+                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                         -- STREAM_PROJECT  |PARTITIONED|
+                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                             -- DATASOURCE_SCAN  |PARTITIONED|
+                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --cc asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_07.plan
index 0000000,6e0b4cd..c129ee0
mode 000000,100644..100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_07.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_07.plan
@@@ -1,0 -1,18 +1,18 @@@
+ -- DISTRIBUTE_RESULT  |PARTITIONED|
+   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+     -- STREAM_PROJECT  |PARTITIONED|
+       -- ASSIGN  |PARTITIONED|
+         -- STREAM_PROJECT  |PARTITIONED|
 -          -- SORT_MERGE_EXCHANGE [$$27(ASC) ]  |PARTITIONED|
++          -- SORT_MERGE_EXCHANGE [$$29(ASC) ]  |PARTITIONED|
+             -- STREAM_PROJECT  |PARTITIONED|
+               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                 -- BTREE_SEARCH  |PARTITIONED|
+                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
 -                    -- STABLE_SORT [$$29(ASC)]  |PARTITIONED|
 -                      -- HASH_PARTITION_EXCHANGE [$$29]  |PARTITIONED|
++                    -- STABLE_SORT [$$31(ASC)]  |PARTITIONED|
++                      -- HASH_PARTITION_EXCHANGE [$$31]  |PARTITIONED|
+                         -- ASSIGN  |PARTITIONED|
+                           -- STREAM_PROJECT  |PARTITIONED|
+                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                               -- DATASOURCE_SCAN  |PARTITIONED|
+                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --cc asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_08.plan
index 0000000,04dcc66..05f667d
mode 000000,100644..100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_08.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_08.plan
@@@ -1,0 -1,17 +1,17 @@@
+ -- DISTRIBUTE_RESULT  |PARTITIONED|
+   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+     -- STREAM_PROJECT  |PARTITIONED|
+       -- ASSIGN  |PARTITIONED|
+         -- STREAM_SELECT  |PARTITIONED|
+           -- STREAM_PROJECT  |PARTITIONED|
+             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+               -- BTREE_SEARCH  |PARTITIONED|
+                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
 -                  -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
++                  -- STABLE_SORT [$$21(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|
diff --cc asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_10.plan
index 0000000,b518b83..0ac8731
mode 000000,100644..100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_10.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_10.plan
@@@ -1,0 -1,24 +1,24 @@@
+ -- DISTRIBUTE_RESULT  |PARTITIONED|
+   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+     -- STREAM_PROJECT  |PARTITIONED|
+       -- ASSIGN  |PARTITIONED|
+         -- STREAM_PROJECT  |PARTITIONED|
 -          -- SORT_MERGE_EXCHANGE [$$25(ASC) ]  |PARTITIONED|
 -            -- STABLE_SORT [$$25(ASC)]  |PARTITIONED|
++          -- SORT_MERGE_EXCHANGE [$$27(ASC) ]  |PARTITIONED|
++            -- STABLE_SORT [$$27(ASC)]  |PARTITIONED|
+               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                 -- STREAM_SELECT  |PARTITIONED|
+                   -- STREAM_PROJECT  |PARTITIONED|
+                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                       -- BTREE_SEARCH  |PARTITIONED|
+                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
 -                          -- STABLE_SORT [$$33(ASC)]  |PARTITIONED|
++                          -- STABLE_SORT [$$35(ASC)]  |PARTITIONED|
+                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                               -- STREAM_PROJECT  |PARTITIONED|
+                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                   -- BTREE_SEARCH  |PARTITIONED|
+                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                       -- STREAM_PROJECT  |PARTITIONED|
+                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                           -- DATASOURCE_SCAN  |PARTITIONED|
+                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --cc asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_11.plan
index 0000000,2273bfd..c5d6e9f
mode 000000,100644..100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_11.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_11.plan
@@@ -1,0 -1,17 +1,17 @@@
+ -- DISTRIBUTE_RESULT  |PARTITIONED|
+   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+     -- STREAM_PROJECT  |PARTITIONED|
+       -- ASSIGN  |PARTITIONED|
+         -- STREAM_PROJECT  |PARTITIONED|
 -          -- SORT_MERGE_EXCHANGE [$$29(ASC) ]  |PARTITIONED|
 -            -- STABLE_SORT [$$29(ASC)]  |PARTITIONED|
++          -- SORT_MERGE_EXCHANGE [$$31(ASC) ]  |PARTITIONED|
++            -- STABLE_SORT [$$31(ASC)]  |PARTITIONED|
+               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                 -- STREAM_PROJECT  |PARTITIONED|
+                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                     -- BTREE_SEARCH  |PARTITIONED|
+                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                         -- STREAM_PROJECT  |PARTITIONED|
+                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                             -- DATASOURCE_SCAN  |PARTITIONED|
+                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --cc asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.7.ddl.sqlpp
index f12a2b7,40f14ae..821b1a7
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.7.ddl.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.7.ddl.sqlpp
@@@ -16,5 -16,12 +16,5 @@@
   * specific language governing permissions and limitations
   * under the License.
   */
 -/*
 - * Description: tests resolving primary key correctly
 - */
 -
 -use test;
  
- drop dataverse test;
 -from DS2
 -select id as i
 -order by i;
++drop dataverse test;
diff --cc asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.11.adm
index 375d551,cf5fe4a..a7bb19e
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.11.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.11.adm
@@@ -1,9 -1,9 +1,9 @@@
 -{ "rec": { "id": 1, "name": "John Mad", "age": 29, "hobby": "reading" }, "meta": { "id": "rec1_US", "class_type": 1, "updated_date": "2007-02-02" } }
 -{ "rec": { "id": 2, "name": "Scott Scott", "age": 30, "hobby": "hiking" }, "meta": { "id": "rec2_US", "class_type": 1, "updated_date": "2008-02-04" } }
 -{ "rec": { "id": 4, "name": "Robert Moore", "age": 32, "hobby": "reading" }, "meta": { "id": "rec4_US", "class_type": 1, "updated_date": "2006-01-04" } }
 -{ "rec": { "id": 6, "name": "Joe Dana", "age": 24, "hobby": "tennis" }, "meta": { "id": "rec6_US", "class_type": 2, "updated_date": "2018-06-05" } }
 -{ "rec": { "id": 7, "name": "Watson Jordon", "age": 28, "hobby": "basketball" }, "meta": { "id": "rec7_US", "class_type": 1, "updated_date": "2018-06-07" } }
 -{ "rec": { "id": 9, "name": "Sandra Pec", "age": 36, "hobby": "hiking" }, "meta": { "id": "rec9_US", "class_type": 3, "updated_date": "2018-06-09" } }
 -{ "rec": { "id": 10, "name": "Sandra Lan", "age": 36, "hobby": "football" }, "meta": { "id": "rec10_US", "class_type": 3, "updated_date": "2017-06-09" } }
 -{ "rec": { "id": 13, "name": "Sally Bush", "age": 29, "hobby": "reading" }, "meta": { "id": "rec13_US", "class_type": 2, "updated_date": "2014-09-01" } }
 -{ "rec": { "id": 14, "name": "Sarah Tran", "age": 20, "hobby": "reading" }, "meta": { "id": "rec14_US", "class_type": 1, "updated_date": "2010-09-01" } }
 +{ "rec": { "id": 1, "name": "John Mad", "age": 29, "hobby": "reading" }, "meta": { "id": "rec1_US", "class_type": 1, "updated_date": "2007-02-02" }, "count": [ 9 ] }
 +{ "rec": { "id": 2, "name": "Scott Scott", "age": 30, "hobby": "hiking" }, "meta": { "id": "rec2_US", "class_type": 1, "updated_date": "2008-02-04" }, "count": [ 9 ] }
 +{ "rec": { "id": 4, "name": "Robert Moore", "age": 32, "hobby": "reading" }, "meta": { "id": "rec4_US", "class_type": 1, "updated_date": "2006-01-04" }, "count": [ 9 ] }
 +{ "rec": { "id": 6, "name": "Joe Dana", "age": 24, "hobby": "tennis" }, "meta": { "id": "rec6_US", "class_type": 2, "updated_date": "2018-06-05" }, "count": [ 9 ] }
 +{ "rec": { "id": 7, "name": "Watson Jordon", "age": 28, "hobby": "basketball" }, "meta": { "id": "rec7_US", "class_type": 1, "updated_date": "2018-06-07" }, "count": [ 9 ] }
 +{ "rec": { "id": 9, "name": "Sandra Pec", "age": 36, "hobby": "hiking" }, "meta": { "id": "rec9_US", "class_type": 3, "updated_date": "2018-06-09" }, "count": [ 9 ] }
 +{ "rec": { "id": 10, "name": "Sandra Lan", "age": 36, "hobby": "football" }, "meta": { "id": "rec10_US", "class_type": 3, "updated_date": "2017-06-09" }, "count": [ 9 ] }
 +{ "rec": { "id": 13, "name": "Sally Bush", "age": 29, "hobby": "reading" }, "meta": { "id": "rec13_US", "class_type": 2, "updated_date": "2014-09-01" }, "count": [ 9 ] }
- { "rec": { "id": 14, "name": "Sarah Tran", "age": 20, "hobby": "reading" }, "meta": { "id": "rec14_US", "class_type": 1, "updated_date": "2010-09-01" }, "count": [ 9 ] }
++{ "rec": { "id": 14, "name": "Sarah Tran", "age": 20, "hobby": "reading" }, "meta": { "id": "rec14_US", "class_type": 1, "updated_date": "2010-09-01" }, "count": [ 9 ] }
diff --cc asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.12.adm
index 79062f5,9fb07fe..e21ab6a
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.12.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.12.adm
@@@ -1,5 -1,5 +1,5 @@@
 -{ "rec": { "id": 3, "name": "Dan David", "age": 40, "hobby": "bowling" }, "meta": { "id": "rec3_UK", "class_type": 2, "updated_date": "2018-02-02" } }
 -{ "rec": { "id": 5, "name": "Sandy Donald", "age": 35, "hobby": "soccer" }, "meta": { "id": "rec5_UK", "class_type": 2, "updated_date": "2018-01-04" } }
 -{ "rec": { "id": 8, "name": "Mat Steve", "age": 45, "hobby": "tennis" }, "meta": { "id": "rec8_UK", "class_type": 2, "updated_date": "2018-06-05" } }
 -{ "rec": { "id": 11, "name": "Trever Jones", "age": 36, "hobby": "hiking" }, "meta": { "id": "rec11_UK", "class_type": 3, "updated_date": "2018-09-09" } }
 -{ "rec": { "id": 12, "name": "Ruth Pec", "age": 36, "hobby": "swimming" }, "meta": { "id": "rec12_UK", "class_type": 3, "updated_date": "2016-09-01" } }
 +{ "rec": { "id": 3, "name": "Dan David", "age": 40, "hobby": "bowling" }, "meta": { "id": "rec3_UK", "class_type": 2, "updated_date": "2018-02-02" }, "count": [ 5 ] }
 +{ "rec": { "id": 5, "name": "Sandy Donald", "age": 35, "hobby": "soccer" }, "meta": { "id": "rec5_UK", "class_type": 2, "updated_date": "2018-01-04" }, "count": [ 5 ] }
 +{ "rec": { "id": 8, "name": "Mat Steve", "age": 45, "hobby": "tennis" }, "meta": { "id": "rec8_UK", "class_type": 2, "updated_date": "2018-06-05" }, "count": [ 5 ] }
 +{ "rec": { "id": 11, "name": "Trever Jones", "age": 36, "hobby": "hiking" }, "meta": { "id": "rec11_UK", "class_type": 3, "updated_date": "2018-09-09" }, "count": [ 5 ] }
- { "rec": { "id": 12, "name": "Ruth Pec", "age": 36, "hobby": "swimming" }, "meta": { "id": "rec12_UK", "class_type": 3, "updated_date": "2016-09-01" }, "count": [ 5 ] }
++{ "rec": { "id": 12, "name": "Ruth Pec", "age": 36, "hobby": "swimming" }, "meta": { "id": "rec12_UK", "class_type": 3, "updated_date": "2016-09-01" }, "count": [ 5 ] }
diff --cc asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.13.adm
index 18202fc,2cd20f2..6b30bb0
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.13.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.13.adm
@@@ -1,5 -1,5 +1,5 @@@
 -{ "rec": { "id": 1, "name": "John Mad", "age": 29, "hobby": "reading" }, "meta": { "id": "rec1_US", "class_type": 1, "updated_date": "2007-02-02" } }
 -{ "rec": { "id": 2, "name": "Scott Scott", "age": 30, "hobby": "hiking" }, "meta": { "id": "rec2_US", "class_type": 1, "updated_date": "2008-02-04" } }
 -{ "rec": { "id": 4, "name": "Robert Moore", "age": 32, "hobby": "reading" }, "meta": { "id": "rec4_US", "class_type": 1, "updated_date": "2006-01-04" } }
 -{ "rec": { "id": 7, "name": "Watson Jordon", "age": 28, "hobby": "basketball" }, "meta": { "id": "rec7_US", "class_type": 1, "updated_date": "2018-06-07" } }
 -{ "rec": { "id": 14, "name": "Sarah Tran", "age": 20, "hobby": "reading" }, "meta": { "id": "rec14_US", "class_type": 1, "updated_date": "2010-09-01" } }
 +{ "rec": { "id": 1, "name": "John Mad", "age": 29, "hobby": "reading" }, "meta": { "id": "rec1_US", "class_type": 1, "updated_date": "2007-02-02" }, "count": [ 5 ] }
 +{ "rec": { "id": 2, "name": "Scott Scott", "age": 30, "hobby": "hiking" }, "meta": { "id": "rec2_US", "class_type": 1, "updated_date": "2008-02-04" }, "count": [ 5 ] }
 +{ "rec": { "id": 4, "name": "Robert Moore", "age": 32, "hobby": "reading" }, "meta": { "id": "rec4_US", "class_type": 1, "updated_date": "2006-01-04" }, "count": [ 5 ] }
 +{ "rec": { "id": 7, "name": "Watson Jordon", "age": 28, "hobby": "basketball" }, "meta": { "id": "rec7_US", "class_type": 1, "updated_date": "2018-06-07" }, "count": [ 5 ] }
- { "rec": { "id": 14, "name": "Sarah Tran", "age": 20, "hobby": "reading" }, "meta": { "id": "rec14_US", "class_type": 1, "updated_date": "2010-09-01" }, "count": [ 5 ] }
++{ "rec": { "id": 14, "name": "Sarah Tran", "age": 20, "hobby": "reading" }, "meta": { "id": "rec14_US", "class_type": 1, "updated_date": "2010-09-01" }, "count": [ 5 ] }
diff --cc asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.14.adm
index 533eee0,4a0957e..47827a9
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.14.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.14.adm
@@@ -1,5 -1,5 +1,5 @@@
 -{ "rec": { "id": 3, "name": "Dan David", "age": 40, "hobby": "bowling" }, "meta": { "id": "rec3_UK", "class_type": 2, "updated_date": "2018-02-02" } }
 -{ "rec": { "id": 5, "name": "Sandy Donald", "age": 35, "hobby": "soccer" }, "meta": { "id": "rec5_UK", "class_type": 2, "updated_date": "2018-01-04" } }
 -{ "rec": { "id": 6, "name": "Joe Dana", "age": 24, "hobby": "tennis" }, "meta": { "id": "rec6_US", "class_type": 2, "updated_date": "2018-06-05" } }
 -{ "rec": { "id": 8, "name": "Mat Steve", "age": 45, "hobby": "tennis" }, "meta": { "id": "rec8_UK", "class_type": 2, "updated_date": "2018-06-05" } }
 -{ "rec": { "id": 13, "name": "Sally Bush", "age": 29, "hobby": "reading" }, "meta": { "id": "rec13_US", "class_type": 2, "updated_date": "2014-09-01" } }
 +{ "rec": { "id": 3, "name": "Dan David", "age": 40, "hobby": "bowling" }, "meta": { "id": "rec3_UK", "class_type": 2, "updated_date": "2018-02-02" }, "count": [ 5 ] }
 +{ "rec": { "id": 5, "name": "Sandy Donald", "age": 35, "hobby": "soccer" }, "meta": { "id": "rec5_UK", "class_type": 2, "updated_date": "2018-01-04" }, "count": [ 5 ] }
 +{ "rec": { "id": 6, "name": "Joe Dana", "age": 24, "hobby": "tennis" }, "meta": { "id": "rec6_US", "class_type": 2, "updated_date": "2018-06-05" }, "count": [ 5 ] }
 +{ "rec": { "id": 8, "name": "Mat Steve", "age": 45, "hobby": "tennis" }, "meta": { "id": "rec8_UK", "class_type": 2, "updated_date": "2018-06-05" }, "count": [ 5 ] }
- { "rec": { "id": 13, "name": "Sally Bush", "age": 29, "hobby": "reading" }, "meta": { "id": "rec13_US", "class_type": 2, "updated_date": "2014-09-01" }, "count": [ 5 ] }
++{ "rec": { "id": 13, "name": "Sally Bush", "age": 29, "hobby": "reading" }, "meta": { "id": "rec13_US", "class_type": 2, "updated_date": "2014-09-01" }, "count": [ 5 ] }
diff --cc asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.15.adm
index 3f25df9,5f119c2..2422d52
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.15.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.15.adm
@@@ -1,4 -1,4 +1,4 @@@
 -{ "rec": { "id": 9, "name": "Sandra Pec", "age": 36, "hobby": "hiking" }, "meta": { "id": "rec9_US", "class_type": 3, "updated_date": "2018-06-09" } }
 -{ "rec": { "id": 10, "name": "Sandra Lan", "age": 36, "hobby": "football" }, "meta": { "id": "rec10_US", "class_type": 3, "updated_date": "2017-06-09" } }
 -{ "rec": { "id": 11, "name": "Trever Jones", "age": 36, "hobby": "hiking" }, "meta": { "id": "rec11_UK", "class_type": 3, "updated_date": "2018-09-09" } }
 -{ "rec": { "id": 12, "name": "Ruth Pec", "age": 36, "hobby": "swimming" }, "meta": { "id": "rec12_UK", "class_type": 3, "updated_date": "2016-09-01" } }
 +{ "rec": { "id": 9, "name": "Sandra Pec", "age": 36, "hobby": "hiking" }, "meta": { "id": "rec9_US", "class_type": 3, "updated_date": "2018-06-09" }, "count": [ 4 ] }
 +{ "rec": { "id": 10, "name": "Sandra Lan", "age": 36, "hobby": "football" }, "meta": { "id": "rec10_US", "class_type": 3, "updated_date": "2017-06-09" }, "count": [ 4 ] }
 +{ "rec": { "id": 11, "name": "Trever Jones", "age": 36, "hobby": "hiking" }, "meta": { "id": "rec11_UK", "class_type": 3, "updated_date": "2018-09-09" }, "count": [ 4 ] }
- { "rec": { "id": 12, "name": "Ruth Pec", "age": 36, "hobby": "swimming" }, "meta": { "id": "rec12_UK", "class_type": 3, "updated_date": "2016-09-01" }, "count": [ 4 ] }
++{ "rec": { "id": 12, "name": "Ruth Pec", "age": 36, "hobby": "swimming" }, "meta": { "id": "rec12_UK", "class_type": 3, "updated_date": "2016-09-01" }, "count": [ 4 ] }
diff --cc asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.16.adm
index b2b76f2,303b8b5..20bf380
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.16.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.16.adm
@@@ -1,5 -1,5 +1,5 @@@
 -{ "rec": { "id": 1, "name": "John Mad", "age": 29, "hobby": "reading" }, "meta": { "id": "rec1_US", "class_type": 1, "updated_date": "2007-02-02" } }
 -{ "rec": { "id": 2, "name": "Scott Scott", "age": 30, "hobby": "hiking" }, "meta": { "id": "rec2_US", "class_type": 1, "updated_date": "2008-02-04" } }
 -{ "rec": { "id": 4, "name": "Robert Moore", "age": 32, "hobby": "reading" }, "meta": { "id": "rec4_US", "class_type": 1, "updated_date": "2006-01-04" } }
 -{ "rec": { "id": 13, "name": "Sally Bush", "age": 29, "hobby": "reading" }, "meta": { "id": "rec13_US", "class_type": 2, "updated_date": "2014-09-01" } }
 -{ "rec": { "id": 14, "name": "Sarah Tran", "age": 20, "hobby": "reading" }, "meta": { "id": "rec14_US", "class_type": 1, "updated_date": "2010-09-01" } }
 +{ "rec": { "id": 1, "name": "John Mad", "age": 29, "hobby": "reading" }, "meta": { "id": "rec1_US", "class_type": 1, "updated_date": "2007-02-02" }, "count": [ 5 ] }
 +{ "rec": { "id": 2, "name": "Scott Scott", "age": 30, "hobby": "hiking" }, "meta": { "id": "rec2_US", "class_type": 1, "updated_date": "2008-02-04" }, "count": [ 5 ] }
 +{ "rec": { "id": 4, "name": "Robert Moore", "age": 32, "hobby": "reading" }, "meta": { "id": "rec4_US", "class_type": 1, "updated_date": "2006-01-04" }, "count": [ 5 ] }
 +{ "rec": { "id": 13, "name": "Sally Bush", "age": 29, "hobby": "reading" }, "meta": { "id": "rec13_US", "class_type": 2, "updated_date": "2014-09-01" }, "count": [ 5 ] }
- { "rec": { "id": 14, "name": "Sarah Tran", "age": 20, "hobby": "reading" }, "meta": { "id": "rec14_US", "class_type": 1, "updated_date": "2010-09-01" }, "count": [ 5 ] }
++{ "rec": { "id": 14, "name": "Sarah Tran", "age": 20, "hobby": "reading" }, "meta": { "id": "rec14_US", "class_type": 1, "updated_date": "2010-09-01" }, "count": [ 5 ] }
diff --cc asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.17.adm
index 79e173d,0a93b0b..07bbe09
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.17.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.17.adm
@@@ -1,9 -1,9 +1,9 @@@
 -{ "rec": { "id": 3, "name": "Dan David", "age": 40, "hobby": "bowling" }, "meta": { "id": "rec3_UK", "class_type": 2, "updated_date": "2018-02-02" } }
 -{ "rec": { "id": 5, "name": "Sandy Donald", "age": 35, "hobby": "soccer" }, "meta": { "id": "rec5_UK", "class_type": 2, "updated_date": "2018-01-04" } }
 -{ "rec": { "id": 6, "name": "Joe Dana", "age": 24, "hobby": "tennis" }, "meta": { "id": "rec6_US", "class_type": 2, "updated_date": "2018-06-05" } }
 -{ "rec": { "id": 7, "name": "Watson Jordon", "age": 28, "hobby": "basketball" }, "meta": { "id": "rec7_US", "class_type": 1, "updated_date": "2018-06-07" } }
 -{ "rec": { "id": 8, "name": "Mat Steve", "age": 45, "hobby": "tennis" }, "meta": { "id": "rec8_UK", "class_type": 2, "updated_date": "2018-06-05" } }
 -{ "rec": { "id": 9, "name": "Sandra Pec", "age": 36, "hobby": "hiking" }, "meta": { "id": "rec9_US", "class_type": 3, "updated_date": "2018-06-09" } }
 -{ "rec": { "id": 10, "name": "Sandra Lan", "age": 36, "hobby": "football" }, "meta": { "id": "rec10_US", "class_type": 3, "updated_date": "2017-06-09" } }
 -{ "rec": { "id": 11, "name": "Trever Jones", "age": 36, "hobby": "hiking" }, "meta": { "id": "rec11_UK", "class_type": 3, "updated_date": "2018-09-09" } }
 -{ "rec": { "id": 12, "name": "Ruth Pec", "age": 36, "hobby": "swimming" }, "meta": { "id": "rec12_UK", "class_type": 3, "updated_date": "2016-09-01" } }
 +{ "rec": { "id": 3, "name": "Dan David", "age": 40, "hobby": "bowling" }, "meta": { "id": "rec3_UK", "class_type": 2, "updated_date": "2018-02-02" }, "count": [ 9 ] }
 +{ "rec": { "id": 5, "name": "Sandy Donald", "age": 35, "hobby": "soccer" }, "meta": { "id": "rec5_UK", "class_type": 2, "updated_date": "2018-01-04" }, "count": [ 9 ] }
 +{ "rec": { "id": 6, "name": "Joe Dana", "age": 24, "hobby": "tennis" }, "meta": { "id": "rec6_US", "class_type": 2, "updated_date": "2018-06-05" }, "count": [ 9 ] }
 +{ "rec": { "id": 7, "name": "Watson Jordon", "age": 28, "hobby": "basketball" }, "meta": { "id": "rec7_US", "class_type": 1, "updated_date": "2018-06-07" }, "count": [ 9 ] }
 +{ "rec": { "id": 8, "name": "Mat Steve", "age": 45, "hobby": "tennis" }, "meta": { "id": "rec8_UK", "class_type": 2, "updated_date": "2018-06-05" }, "count": [ 9 ] }
 +{ "rec": { "id": 9, "name": "Sandra Pec", "age": 36, "hobby": "hiking" }, "meta": { "id": "rec9_US", "class_type": 3, "updated_date": "2018-06-09" }, "count": [ 9 ] }
 +{ "rec": { "id": 10, "name": "Sandra Lan", "age": 36, "hobby": "football" }, "meta": { "id": "rec10_US", "class_type": 3, "updated_date": "2017-06-09" }, "count": [ 9 ] }
 +{ "rec": { "id": 11, "name": "Trever Jones", "age": 36, "hobby": "hiking" }, "meta": { "id": "rec11_UK", "class_type": 3, "updated_date": "2018-09-09" }, "count": [ 9 ] }
- { "rec": { "id": 12, "name": "Ruth Pec", "age": 36, "hobby": "swimming" }, "meta": { "id": "rec12_UK", "class_type": 3, "updated_date": "2016-09-01" }, "count": [ 9 ] }
++{ "rec": { "id": 12, "name": "Ruth Pec", "age": 36, "hobby": "swimming" }, "meta": { "id": "rec12_UK", "class_type": 3, "updated_date": "2016-09-01" }, "count": [ 9 ] }
diff --cc asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.6.adm
index 533eee0,4a0957e..47827a9
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.6.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.6.adm
@@@ -1,5 -1,5 +1,5 @@@
 -{ "rec": { "id": 3, "name": "Dan David", "age": 40, "hobby": "bowling" }, "meta": { "id": "rec3_UK", "class_type": 2, "updated_date": "2018-02-02" } }
 -{ "rec": { "id": 5, "name": "Sandy Donald", "age": 35, "hobby": "soccer" }, "meta": { "id": "rec5_UK", "class_type": 2, "updated_date": "2018-01-04" } }
 -{ "rec": { "id": 6, "name": "Joe Dana", "age": 24, "hobby": "tennis" }, "meta": { "id": "rec6_US", "class_type": 2, "updated_date": "2018-06-05" } }
 -{ "rec": { "id": 8, "name": "Mat Steve", "age": 45, "hobby": "tennis" }, "meta": { "id": "rec8_UK", "class_type": 2, "updated_date": "2018-06-05" } }
 -{ "rec": { "id": 13, "name": "Sally Bush", "age": 29, "hobby": "reading" }, "meta": { "id": "rec13_US", "class_type": 2, "updated_date": "2014-09-01" } }
 +{ "rec": { "id": 3, "name": "Dan David", "age": 40, "hobby": "bowling" }, "meta": { "id": "rec3_UK", "class_type": 2, "updated_date": "2018-02-02" }, "count": [ 5 ] }
 +{ "rec": { "id": 5, "name": "Sandy Donald", "age": 35, "hobby": "soccer" }, "meta": { "id": "rec5_UK", "class_type": 2, "updated_date": "2018-01-04" }, "count": [ 5 ] }
 +{ "rec": { "id": 6, "name": "Joe Dana", "age": 24, "hobby": "tennis" }, "meta": { "id": "rec6_US", "class_type": 2, "updated_date": "2018-06-05" }, "count": [ 5 ] }
 +{ "rec": { "id": 8, "name": "Mat Steve", "age": 45, "hobby": "tennis" }, "meta": { "id": "rec8_UK", "class_type": 2, "updated_date": "2018-06-05" }, "count": [ 5 ] }
- { "rec": { "id": 13, "name": "Sally Bush", "age": 29, "hobby": "reading" }, "meta": { "id": "rec13_US", "class_type": 2, "updated_date": "2014-09-01" }, "count": [ 5 ] }
++{ "rec": { "id": 13, "name": "Sally Bush", "age": 29, "hobby": "reading" }, "meta": { "id": "rec13_US", "class_type": 2, "updated_date": "2014-09-01" }, "count": [ 5 ] }
diff --cc asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.7.adm
index 3f25df9,5f119c2..2422d52
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.7.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.7.adm
@@@ -1,4 -1,4 +1,4 @@@
 -{ "rec": { "id": 9, "name": "Sandra Pec", "age": 36, "hobby": "hiking" }, "meta": { "id": "rec9_US", "class_type": 3, "updated_date": "2018-06-09" } }
 -{ "rec": { "id": 10, "name": "Sandra Lan", "age": 36, "hobby": "football" }, "meta": { "id": "rec10_US", "class_type": 3, "updated_date": "2017-06-09" } }
 -{ "rec": { "id": 11, "name": "Trever Jones", "age": 36, "hobby": "hiking" }, "meta": { "id": "rec11_UK", "class_type": 3, "updated_date": "2018-09-09" } }
 -{ "rec": { "id": 12, "name": "Ruth Pec", "age": 36, "hobby": "swimming" }, "meta": { "id": "rec12_UK", "class_type": 3, "updated_date": "2016-09-01" } }
 +{ "rec": { "id": 9, "name": "Sandra Pec", "age": 36, "hobby": "hiking" }, "meta": { "id": "rec9_US", "class_type": 3, "updated_date": "2018-06-09" }, "count": [ 4 ] }
 +{ "rec": { "id": 10, "name": "Sandra Lan", "age": 36, "hobby": "football" }, "meta": { "id": "rec10_US", "class_type": 3, "updated_date": "2017-06-09" }, "count": [ 4 ] }
 +{ "rec": { "id": 11, "name": "Trever Jones", "age": 36, "hobby": "hiking" }, "meta": { "id": "rec11_UK", "class_type": 3, "updated_date": "2018-09-09" }, "count": [ 4 ] }
- { "rec": { "id": 12, "name": "Ruth Pec", "age": 36, "hobby": "swimming" }, "meta": { "id": "rec12_UK", "class_type": 3, "updated_date": "2016-09-01" }, "count": [ 4 ] }
++{ "rec": { "id": 12, "name": "Ruth Pec", "age": 36, "hobby": "swimming" }, "meta": { "id": "rec12_UK", "class_type": 3, "updated_date": "2016-09-01" }, "count": [ 4 ] }


[asterixdb] 03/06: [NO ISSUE][CLUS] Attempt To Get Node IP From Existing Nodes

Posted by mh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mhubail pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git

commit cba9cbe380e04a183caadc13497c97d0db6ff31c
Author: Murtadha Hubail <mh...@apache.org>
AuthorDate: Thu Sep 5 05:06:05 2019 +0300

    [NO ISSUE][CLUS] Attempt To Get Node IP From Existing Nodes
    
    - user model changes: no
    - storage format changes: no
    - interface changes: no
    
    Details:
    - When we fail to resolve a node's host to an IP on node
      failure/removal, attempt to find its IP from the list
      of existing nodes. This is done to prevent failing the
      node removal operation when the node's host address
      cannot be resolved anymore.
    
    Change-Id: I8f12a3dbb84a4cb731f1379efd65ca50606a8b07
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/3544
    Sonar-Qube: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Reviewed-by: Till Westmann <ti...@apache.org>
---
 .../hyracks/control/cc/cluster/NodeManager.java    | 24 ++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/cluster/NodeManager.java b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/cluster/NodeManager.java
index 4f76ced..0e374a6 100644
--- a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/cluster/NodeManager.java
+++ b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/cluster/NodeManager.java
@@ -205,8 +205,19 @@ public class NodeManager implements INodeManager {
         nodeRegistry.forEach(nodeFunction::apply);
     }
 
-    private void removeNodeFromIpAddressMap(String nodeId, NodeControllerState ncState) throws HyracksException {
-        InetAddress ipAddress = getIpAddress(ncState);
+    private void removeNodeFromIpAddressMap(String nodeId, NodeControllerState ncState) {
+        InetAddress ipAddress;
+        try {
+            ipAddress = getIpAddress(ncState);
+        } catch (Exception e) {
+            LOGGER.warn("failed to get ip address of node {}; attempting to find it on existing nodes lists", nodeId,
+                    e);
+            ipAddress = findNodeIpById(nodeId);
+        }
+        if (ipAddress == null) {
+            LOGGER.warn("failed to get ip address of node {}", nodeId);
+            return;
+        }
         Set<String> nodes = ipAddressNodeNameMap.get(ipAddress);
         if (nodes != null) {
             nodes.remove(nodeId);
@@ -242,4 +253,13 @@ public class NodeManager implements INodeManager {
             }
         });
     }
+
+    private InetAddress findNodeIpById(String nodeId) {
+        for (Map.Entry<InetAddress, Set<String>> ipToNodesEntry : ipAddressNodeNameMap.entrySet()) {
+            if (ipToNodesEntry.getValue().contains(nodeId)) {
+                return ipToNodesEntry.getKey();
+            }
+        }
+        return null;
+    }
 }


[asterixdb] 05/06: [NO ISSUE][ING][EXT] Handle filters on meta() fields for feeds

Posted by mh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mhubail pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git

commit 8930f0d7614f43ad52624fd121de45ab27fb281e
Author: Ali Alsuliman <al...@gmail.com>
AuthorDate: Wed Sep 11 11:56:53 2019 -0700

    [NO ISSUE][ING][EXT] Handle filters on meta() fields for feeds
    
    - user model changes: no
    - storage format changes: no
    - interface changes: no
    
    Details:
    This fix is to handle filters on meta() fields where the feed name
    is not supplied as an arguement to the meta() when connecting the feed.
    Both of these statement should work:
    CONNECT FEED ds_feed TO DATASET ds WHERE meta(ds_feed).id LIKE "%WEB%"
    CONNECT FEED ds_feed TO DATASET ds WHERE meta().id LIKE "%WEB%"
    
    Change-Id: I1dbf40525601584efa29eb3adf4ba41062ebe53a
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/3557
    Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Reviewed-by: Dmitry Lychagin <dm...@couchbase.com>
---
 .../rules/MetaFunctionToMetaVariableRule.java      | 60 ++++++++++++++----
 asterixdb/asterix-app/data/csv/people2.csv         | 14 +++++
 .../change-feed-with-filter-on-meta.1.ddl.sqlpp    | 73 ++++++++++++++++++++++
 ...change-feed-with-filter-on-meta.10.update.sqlpp | 38 +++++++++++
 .../change-feed-with-filter-on-meta.11.query.sqlpp | 22 +++++++
 .../change-feed-with-filter-on-meta.12.query.sqlpp | 22 +++++++
 .../change-feed-with-filter-on-meta.13.query.sqlpp | 22 +++++++
 .../change-feed-with-filter-on-meta.14.query.sqlpp | 22 +++++++
 .../change-feed-with-filter-on-meta.15.query.sqlpp | 22 +++++++
 .../change-feed-with-filter-on-meta.16.query.sqlpp | 22 +++++++
 .../change-feed-with-filter-on-meta.17.query.sqlpp | 22 +++++++
 .../change-feed-with-filter-on-meta.18.ddl.sqlpp   | 20 ++++++
 .../change-feed-with-filter-on-meta.2.update.sqlpp | 38 +++++++++++
 .../change-feed-with-filter-on-meta.3.query.sqlpp  | 22 +++++++
 .../change-feed-with-filter-on-meta.4.query.sqlpp  | 22 +++++++
 .../change-feed-with-filter-on-meta.5.query.sqlpp  | 22 +++++++
 .../change-feed-with-filter-on-meta.6.query.sqlpp  | 22 +++++++
 .../change-feed-with-filter-on-meta.7.query.sqlpp  | 22 +++++++
 .../change-feed-with-filter-on-meta.8.query.sqlpp  | 22 +++++++
 .../change-feed-with-filter-on-meta.9.query.sqlpp  | 22 +++++++
 .../change-feed-with-filter-on-meta.11.adm         |  9 +++
 .../change-feed-with-filter-on-meta.12.adm         |  5 ++
 .../change-feed-with-filter-on-meta.13.adm         |  5 ++
 .../change-feed-with-filter-on-meta.14.adm         |  5 ++
 .../change-feed-with-filter-on-meta.15.adm         |  4 ++
 .../change-feed-with-filter-on-meta.16.adm         |  5 ++
 .../change-feed-with-filter-on-meta.17.adm         |  9 +++
 .../change-feed-with-filter-on-meta.3.adm          |  9 +++
 .../change-feed-with-filter-on-meta.4.adm          |  5 ++
 .../change-feed-with-filter-on-meta.5.adm          |  5 ++
 .../change-feed-with-filter-on-meta.6.adm          |  5 ++
 .../change-feed-with-filter-on-meta.7.adm          |  4 ++
 .../change-feed-with-filter-on-meta.8.adm          |  5 ++
 .../change-feed-with-filter-on-meta.9.adm          |  9 +++
 .../test/resources/runtimets/testsuite_sqlpp.xml   |  5 ++
 35 files changed, 627 insertions(+), 13 deletions(-)

diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/MetaFunctionToMetaVariableRule.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/MetaFunctionToMetaVariableRule.java
index c47acd1..dc756ea 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/MetaFunctionToMetaVariableRule.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/MetaFunctionToMetaVariableRule.java
@@ -77,13 +77,13 @@ public class MetaFunctionToMetaVariableRule implements IAlgebraicRewriteRule {
         ILogicalOperator op = opRef.getValue();
 
         // Reaches NTS or ETS.
-        if (op.getInputs().size() == 0) {
+        if (op.getInputs().isEmpty()) {
             return NoOpExpressionReferenceTransform.INSTANCE;
         }
         // Datascan returns an useful transform if the meta part presents in the dataset.
         if (op.getOperatorTag() == LogicalOperatorTag.DATASOURCESCAN) {
             DataSourceScanOperator scanOp = (DataSourceScanOperator) op;
-            ILogicalExpressionReferenceTransformWithCondition inputTransfomer = visit(op.getInputs().get(0));
+            ILogicalExpressionReferenceTransformWithCondition inputTransformer = visit(op.getInputs().get(0));
             DataSource dataSource = (DataSource) scanOp.getDataSource();
             List<ILogicalExpressionReferenceTransformWithCondition> transformers = null;
             List<LogicalVariable> allVars = scanOp.getVariables();
@@ -106,26 +106,26 @@ public class MetaFunctionToMetaVariableRule implements IAlgebraicRewriteRule {
                 }
             }
             if (!dataSource.hasMeta() && transformers == null) {
-                return inputTransfomer;
+                return inputTransformer;
             }
             if (metaVar != null) {
                 currentTransformer = new LogicalExpressionReferenceTransform(dataVar, metaVar);
             }
-            if (inputTransfomer.equals(NoOpExpressionReferenceTransform.INSTANCE) && transformers == null) {
+            if (inputTransformer.equals(NoOpExpressionReferenceTransform.INSTANCE) && transformers == null) {
                 return currentTransformer;
-            } else if (inputTransfomer.equals(NoOpExpressionReferenceTransform.INSTANCE)
+            } else if (inputTransformer.equals(NoOpExpressionReferenceTransform.INSTANCE)
                     && currentTransformer == null) {
                 return transformers.get(0);
             } else {
-                // Requires an argument variable to resolve ambiguity.
                 if (transformers == null) {
                     transformers = new ArrayList<>();
                 }
-                if (!inputTransfomer.equals(NoOpExpressionReferenceTransform.INSTANCE)) {
-                    inputTransfomer.setVariableRequired();
-                    transformers.add(inputTransfomer);
+                if (!inputTransformer.equals(NoOpExpressionReferenceTransform.INSTANCE)) {
+                    // require an argument variable to resolve ambiguity when there are 2 or more distinct data sources
+                    inputTransformer.setVariableRequired();
+                    currentTransformer.setVariableRequired();
+                    transformers.add(inputTransformer);
                 }
-                currentTransformer.setVariableRequired();
                 transformers.add(currentTransformer);
                 return new CompositeExpressionReferenceTransform(transformers);
             }
@@ -185,6 +185,17 @@ class NoOpExpressionReferenceTransform implements ILogicalExpressionReferenceTra
 
 }
 
+/**
+ * <pre>
+ * This class replaces meta() references with their corresponding meta record variables. It maintains the data record
+ * variable and meta record variable. The data variable is used to match the data variable inside meta() if supplied.
+ * For example:
+ * If the data source produces 2 records, the data record as $$ds and the meta record as $$7, then any reference to
+ * meta($$ds) will be rewritten as $$7.
+ *
+ * meta($$ds) means "get the meta record of the data source ds".
+ * </pre>
+ */
 class LogicalExpressionReferenceTransform implements ILogicalExpressionReferenceTransformWithCondition {
     private final LogicalVariable dataVar;
     private final LogicalVariable metaVar;
@@ -273,6 +284,15 @@ class CompositeExpressionReferenceTransform implements ILogicalExpressionReferen
     }
 }
 
+/**
+ * <pre>
+ * This class replaces meta-key() references with their corresponding field accessors. It maintains the meta
+ * variable that will replace the meta-key(). Meta-key() acts as a field access of the meta record. For example:
+ * If the meta record variable is $$7, meta-key($$ds, "address.zip") will be rewritten as $$7.address.zip.
+ *
+ * meta-key($$ds, "address.zip") means "access the field address.zip of the meta record of data source ds".
+ * </pre>
+ */
 class MetaKeyToFieldAccessTransform implements ILogicalExpressionReferenceTransformWithCondition {
     private final LogicalVariable metaVar;
 
@@ -291,9 +311,8 @@ class MetaKeyToFieldAccessTransform implements ILogicalExpressionReferenceTransf
             return false;
         }
         SourceLocation sourceLoc = expr.getSourceLocation();
-        // Get arguments
-        // first argument : Resource key
-        // second argument: field
+        // get arguments. First argument : Resource key, second argument: field
+        // TODO: how come arg 1 (the data source) is not checked?
         List<Mutable<ILogicalExpression>> args = funcExpr.getArguments();
         ConstantExpression fieldNameExpression = (ConstantExpression) args.get(1).getValue();
         AsterixConstantValue fieldNameValue = (AsterixConstantValue) fieldNameExpression.getValue();
@@ -325,6 +344,21 @@ class MetaKeyToFieldAccessTransform implements ILogicalExpressionReferenceTransf
     }
 }
 
+/**
+ * <pre>
+ * This class replaces meta-key() references with their corresponding logical variables. It maintains a list of
+ * meta-key() references together with their logical variables (the logical variables being the primary key variables
+ * of the data source). For example:
+ * primary key variable (i.e. keyVars): $$1, $$2
+ * meta-key() references (i.e. metaKeyAccessExpressions): meta-key($$ds, "id1"), meta-key($$ds, "id2")
+ *
+ * Any reference to meta-key($$ds, "id1") will be rewritten as $$1.
+ *
+ * meta-key($$ds, "id1") means "access the field id1 of the meta record of data source ds which is also a primary key".
+ *
+ * "id1" and "id2" are the primary keys of the data source "ds". They are fields of the meta record (not $$ds record).
+ * </pre>
+ */
 class MetaKeyExpressionReferenceTransform implements ILogicalExpressionReferenceTransformWithCondition {
     private final List<LogicalVariable> keyVars;
     private final List<ScalarFunctionCallExpression> metaKeyAccessExpressions;
diff --git a/asterixdb/asterix-app/data/csv/people2.csv b/asterixdb/asterix-app/data/csv/people2.csv
new file mode 100644
index 0000000..8488a15
--- /dev/null
+++ b/asterixdb/asterix-app/data/csv/people2.csv
@@ -0,0 +1,14 @@
+rec1_US,1,2007-02-02,"{""id"":1, ""name"":""John Mad"", ""age"":29, ""hobby"":""reading""}"
+rec2_US,1,2008-02-04,"{""id"":2, ""name"":""Scott Scott"", ""age"":30, ""hobby"":""hiking""}"
+rec3_UK,2,2018-02-02,"{""id"":3, ""name"":""Dan David"", ""age"":40, ""hobby"":""bowling""}"
+rec4_US,1,2006-01-04,"{""id"":4, ""name"":""Robert Moore"", ""age"":32, ""hobby"":""reading""}"
+rec5_UK,2,2018-01-04,"{""id"":5, ""name"":""Sandy Donald"", ""age"":35, ""hobby"":""soccer""}"
+rec6_US,2,2018-06-05,"{""id"":6, ""name"":""Joe Dana"", ""age"":24, ""hobby"":""tennis""}"
+rec7_US,1,2018-06-07,"{""id"":7, ""name"":""Watson Jordon"", ""age"":28, ""hobby"":""basketball""}"
+rec8_UK,2,2018-06-05,"{""id"":8, ""name"":""Mat Steve"", ""age"":45, ""hobby"":""tennis""}"
+rec9_US,3,2018-06-09,"{""id"":9, ""name"":""Sandra Pec"", ""age"":36, ""hobby"":""hiking""}"
+rec10_US,3,2017-06-09,"{""id"":10, ""name"":""Sandra Lan"", ""age"":36, ""hobby"":""football""}"
+rec11_UK,3,2018-09-09,"{""id"":11, ""name"":""Trever Jones"", ""age"":36, ""hobby"":""hiking""}"
+rec12_UK,3,2016-09-01,"{""id"":12, ""name"":""Ruth Pec"", ""age"":36, ""hobby"":""swimming""}"
+rec13_US,2,2014-09-01,"{""id"":13, ""name"":""Sally Bush"", ""age"":29, ""hobby"":""reading""}"
+rec14_US,1,2010-09-01,"{""id"":14, ""name"":""Sarah Tran"", ""age"":20, ""hobby"":""reading""}"
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.1.ddl.sqlpp
new file mode 100644
index 0000000..51b9ffc
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.1.ddl.sqlpp
@@ -0,0 +1,73 @@
+/*
+ * 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 and connect a feed with a filter on meta() fields. Specify the data source for the meta() for
+ *                some datasets and leave it out for others.
+ * Expected Res : Success
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+create type DataType as open {
+id:int,
+name:string,
+age:int,
+hobby:string
+};
+
+create type MetaType as closed {
+id:string,
+class_type:int,
+updated_date:string
+};
+
+create dataset US_DS1(DataType) with meta(MetaType) primary key meta().id;
+create dataset UK_DS1(DataType) with meta(MetaType) primary key meta().id;
+create dataset CLASS1_DS1(DataType) with meta(MetaType) primary key meta().id;
+create dataset CLASS2_DS1(DataType) with meta(MetaType) primary key meta().id;
+create dataset CLASS3_DS1(DataType) with meta(MetaType) primary key meta().id;
+create dataset REC_B2016_1(DataType) with meta(MetaType) primary key meta().id;
+create dataset REC_A2016_1(DataType) with meta(MetaType) primary key meta().id;
+
+create dataset US_DS2(DataType) with meta(MetaType) primary key meta().id;
+create dataset UK_DS2(DataType) with meta(MetaType) primary key meta().id;
+create dataset CLASS1_DS2(DataType) with meta(MetaType) primary key meta().id;
+create dataset CLASS2_DS2(DataType) with meta(MetaType) primary key meta().id;
+create dataset CLASS3_DS2(DataType) with meta(MetaType) primary key meta().id;
+create dataset REC_B2016_2(DataType) with meta(MetaType) primary key meta().id;
+create dataset REC_A2016_2(DataType) with meta(MetaType) primary key meta().id;
+
+create feed ds_stream with {
+ "adapter-name" : "localfs",
+ "reader" : "localfs",
+ "parser" : "record-with-metadata",
+ "type-name" : "DataType",
+ "meta-type-name" : "MetaType",
+ "path" : "asterix_nc1://data/csv/people2.csv",
+ "format" : "csv",
+ "delimiter" : ",",
+ "record-format" : "adm",
+ "record-index" : "3",
+ "key-indexes" : "0",
+ "key-indicators" : "1",
+ "header" : "false",
+ "change-feed" : "true"
+};
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.10.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.10.update.sqlpp
new file mode 100644
index 0000000..c921631
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.10.update.sqlpp
@@ -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.
+ */
+
+use test;
+
+set `wait-for-completion-feed` "true";
+connect feed ds_stream to dataset US_DS2 where meta(ds_stream).id like "%US%";
+connect feed ds_stream to dataset UK_DS2 where meta(ds_stream).id like "%UK%";
+connect feed ds_stream to dataset CLASS1_DS2 where meta(ds_stream).class_type = 1;
+connect feed ds_stream to dataset CLASS2_DS2 where meta(ds_stream).class_type = 2;
+connect feed ds_stream to dataset CLASS3_DS2 where meta(ds_stream).class_type = 3;
+connect feed ds_stream to dataset REC_B2016_2 where get_year(date(meta(ds_stream).updated_date)) < 2016;
+connect feed ds_stream to dataset REC_A2016_2 where get_year(date(meta(ds_stream).updated_date)) >= 2016;
+start feed ds_stream;
+
+disconnect feed ds_stream from dataset US_DS2;
+disconnect feed ds_stream from dataset UK_DS2;
+disconnect feed ds_stream from dataset CLASS1_DS2;
+disconnect feed ds_stream from dataset CLASS2_DS2;
+disconnect feed ds_stream from dataset CLASS3_DS2;
+disconnect feed ds_stream from dataset REC_B2016_2;
+disconnect feed ds_stream from dataset REC_A2016_2;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.11.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.11.query.sqlpp
new file mode 100644
index 0000000..40e6447
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.11.query.sqlpp
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use test;
+
+select value {"rec": v, "meta": meta()} from US_DS2 v order by v.id;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.12.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.12.query.sqlpp
new file mode 100644
index 0000000..620687b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.12.query.sqlpp
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use test;
+
+select value {"rec": v, "meta": meta()} from UK_DS2 v order by v.id;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.13.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.13.query.sqlpp
new file mode 100644
index 0000000..63302fd
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.13.query.sqlpp
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use test;
+
+select value {"rec": v, "meta": meta()} from CLASS1_DS2 v order by v.id;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.14.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.14.query.sqlpp
new file mode 100644
index 0000000..d9e8108
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.14.query.sqlpp
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use test;
+
+select value {"rec": v, "meta": meta()} from CLASS2_DS2 v order by v.id;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.15.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.15.query.sqlpp
new file mode 100644
index 0000000..3afc23a
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.15.query.sqlpp
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use test;
+
+select value {"rec": v, "meta": meta()} from CLASS3_DS2 v order by v.id;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.16.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.16.query.sqlpp
new file mode 100644
index 0000000..72b902a
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.16.query.sqlpp
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use test;
+
+select value {"rec": v, "meta": meta()} from REC_B2016_2 v order by v.id;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.17.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.17.query.sqlpp
new file mode 100644
index 0000000..a80e223
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.17.query.sqlpp
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use test;
+
+select value {"rec": v, "meta": meta()} from REC_A2016_2 v order by v.id;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.18.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.18.ddl.sqlpp
new file mode 100644
index 0000000..f12a2b7
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.18.ddl.sqlpp
@@ -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.
+ */
+
+drop dataverse test;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.2.update.sqlpp
new file mode 100644
index 0000000..11f81a0
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.2.update.sqlpp
@@ -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.
+ */
+
+use test;
+
+set `wait-for-completion-feed` "true";
+connect feed ds_stream to dataset US_DS1 where meta().id like "%US%";
+connect feed ds_stream to dataset UK_DS1 where meta().id like "%UK%";
+connect feed ds_stream to dataset CLASS1_DS1 where meta().class_type = 1;
+connect feed ds_stream to dataset CLASS2_DS1 where meta().class_type = 2;
+connect feed ds_stream to dataset CLASS3_DS1 where meta().class_type = 3;
+connect feed ds_stream to dataset REC_B2016_1 where get_year(date(meta().updated_date)) < 2016;
+connect feed ds_stream to dataset REC_A2016_1 where get_year(date(meta().updated_date)) >= 2016;
+start feed ds_stream;
+
+disconnect feed ds_stream from dataset US_DS1;
+disconnect feed ds_stream from dataset UK_DS1;
+disconnect feed ds_stream from dataset CLASS1_DS1;
+disconnect feed ds_stream from dataset CLASS2_DS1;
+disconnect feed ds_stream from dataset CLASS3_DS1;
+disconnect feed ds_stream from dataset REC_B2016_1;
+disconnect feed ds_stream from dataset REC_A2016_1;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.3.query.sqlpp
new file mode 100644
index 0000000..a4250ae
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.3.query.sqlpp
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use test;
+
+select value {"rec": v, "meta": meta(v)} from US_DS1 v order by v.id;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.4.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.4.query.sqlpp
new file mode 100644
index 0000000..e653128
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.4.query.sqlpp
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use test;
+
+select value {"rec": v, "meta": meta()} from UK_DS1 v order by v.id;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.5.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.5.query.sqlpp
new file mode 100644
index 0000000..a32e706
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.5.query.sqlpp
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use test;
+
+select value {"rec": v, "meta": meta()} from CLASS1_DS1 v order by v.id;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.6.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.6.query.sqlpp
new file mode 100644
index 0000000..b505eb6
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.6.query.sqlpp
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use test;
+
+select value {"rec": v, "meta": meta()} from CLASS2_DS1 v order by v.id;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.7.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.7.query.sqlpp
new file mode 100644
index 0000000..35cd2c2
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.7.query.sqlpp
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use test;
+
+select value {"rec": v, "meta": meta()} from CLASS3_DS1 v order by v.id;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.8.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.8.query.sqlpp
new file mode 100644
index 0000000..476267b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.8.query.sqlpp
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use test;
+
+select value {"rec": v, "meta": meta()} from REC_B2016_1 v order by v.id;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.9.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.9.query.sqlpp
new file mode 100644
index 0000000..6923b60
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.9.query.sqlpp
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use test;
+
+select value {"rec": v, "meta": meta()} from REC_A2016_1 v order by v.id;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.11.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.11.adm
new file mode 100644
index 0000000..cf5fe4a
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.11.adm
@@ -0,0 +1,9 @@
+{ "rec": { "id": 1, "name": "John Mad", "age": 29, "hobby": "reading" }, "meta": { "id": "rec1_US", "class_type": 1, "updated_date": "2007-02-02" } }
+{ "rec": { "id": 2, "name": "Scott Scott", "age": 30, "hobby": "hiking" }, "meta": { "id": "rec2_US", "class_type": 1, "updated_date": "2008-02-04" } }
+{ "rec": { "id": 4, "name": "Robert Moore", "age": 32, "hobby": "reading" }, "meta": { "id": "rec4_US", "class_type": 1, "updated_date": "2006-01-04" } }
+{ "rec": { "id": 6, "name": "Joe Dana", "age": 24, "hobby": "tennis" }, "meta": { "id": "rec6_US", "class_type": 2, "updated_date": "2018-06-05" } }
+{ "rec": { "id": 7, "name": "Watson Jordon", "age": 28, "hobby": "basketball" }, "meta": { "id": "rec7_US", "class_type": 1, "updated_date": "2018-06-07" } }
+{ "rec": { "id": 9, "name": "Sandra Pec", "age": 36, "hobby": "hiking" }, "meta": { "id": "rec9_US", "class_type": 3, "updated_date": "2018-06-09" } }
+{ "rec": { "id": 10, "name": "Sandra Lan", "age": 36, "hobby": "football" }, "meta": { "id": "rec10_US", "class_type": 3, "updated_date": "2017-06-09" } }
+{ "rec": { "id": 13, "name": "Sally Bush", "age": 29, "hobby": "reading" }, "meta": { "id": "rec13_US", "class_type": 2, "updated_date": "2014-09-01" } }
+{ "rec": { "id": 14, "name": "Sarah Tran", "age": 20, "hobby": "reading" }, "meta": { "id": "rec14_US", "class_type": 1, "updated_date": "2010-09-01" } }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.12.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.12.adm
new file mode 100644
index 0000000..9fb07fe
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.12.adm
@@ -0,0 +1,5 @@
+{ "rec": { "id": 3, "name": "Dan David", "age": 40, "hobby": "bowling" }, "meta": { "id": "rec3_UK", "class_type": 2, "updated_date": "2018-02-02" } }
+{ "rec": { "id": 5, "name": "Sandy Donald", "age": 35, "hobby": "soccer" }, "meta": { "id": "rec5_UK", "class_type": 2, "updated_date": "2018-01-04" } }
+{ "rec": { "id": 8, "name": "Mat Steve", "age": 45, "hobby": "tennis" }, "meta": { "id": "rec8_UK", "class_type": 2, "updated_date": "2018-06-05" } }
+{ "rec": { "id": 11, "name": "Trever Jones", "age": 36, "hobby": "hiking" }, "meta": { "id": "rec11_UK", "class_type": 3, "updated_date": "2018-09-09" } }
+{ "rec": { "id": 12, "name": "Ruth Pec", "age": 36, "hobby": "swimming" }, "meta": { "id": "rec12_UK", "class_type": 3, "updated_date": "2016-09-01" } }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.13.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.13.adm
new file mode 100644
index 0000000..2cd20f2
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.13.adm
@@ -0,0 +1,5 @@
+{ "rec": { "id": 1, "name": "John Mad", "age": 29, "hobby": "reading" }, "meta": { "id": "rec1_US", "class_type": 1, "updated_date": "2007-02-02" } }
+{ "rec": { "id": 2, "name": "Scott Scott", "age": 30, "hobby": "hiking" }, "meta": { "id": "rec2_US", "class_type": 1, "updated_date": "2008-02-04" } }
+{ "rec": { "id": 4, "name": "Robert Moore", "age": 32, "hobby": "reading" }, "meta": { "id": "rec4_US", "class_type": 1, "updated_date": "2006-01-04" } }
+{ "rec": { "id": 7, "name": "Watson Jordon", "age": 28, "hobby": "basketball" }, "meta": { "id": "rec7_US", "class_type": 1, "updated_date": "2018-06-07" } }
+{ "rec": { "id": 14, "name": "Sarah Tran", "age": 20, "hobby": "reading" }, "meta": { "id": "rec14_US", "class_type": 1, "updated_date": "2010-09-01" } }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.14.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.14.adm
new file mode 100644
index 0000000..4a0957e
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.14.adm
@@ -0,0 +1,5 @@
+{ "rec": { "id": 3, "name": "Dan David", "age": 40, "hobby": "bowling" }, "meta": { "id": "rec3_UK", "class_type": 2, "updated_date": "2018-02-02" } }
+{ "rec": { "id": 5, "name": "Sandy Donald", "age": 35, "hobby": "soccer" }, "meta": { "id": "rec5_UK", "class_type": 2, "updated_date": "2018-01-04" } }
+{ "rec": { "id": 6, "name": "Joe Dana", "age": 24, "hobby": "tennis" }, "meta": { "id": "rec6_US", "class_type": 2, "updated_date": "2018-06-05" } }
+{ "rec": { "id": 8, "name": "Mat Steve", "age": 45, "hobby": "tennis" }, "meta": { "id": "rec8_UK", "class_type": 2, "updated_date": "2018-06-05" } }
+{ "rec": { "id": 13, "name": "Sally Bush", "age": 29, "hobby": "reading" }, "meta": { "id": "rec13_US", "class_type": 2, "updated_date": "2014-09-01" } }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.15.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.15.adm
new file mode 100644
index 0000000..5f119c2
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.15.adm
@@ -0,0 +1,4 @@
+{ "rec": { "id": 9, "name": "Sandra Pec", "age": 36, "hobby": "hiking" }, "meta": { "id": "rec9_US", "class_type": 3, "updated_date": "2018-06-09" } }
+{ "rec": { "id": 10, "name": "Sandra Lan", "age": 36, "hobby": "football" }, "meta": { "id": "rec10_US", "class_type": 3, "updated_date": "2017-06-09" } }
+{ "rec": { "id": 11, "name": "Trever Jones", "age": 36, "hobby": "hiking" }, "meta": { "id": "rec11_UK", "class_type": 3, "updated_date": "2018-09-09" } }
+{ "rec": { "id": 12, "name": "Ruth Pec", "age": 36, "hobby": "swimming" }, "meta": { "id": "rec12_UK", "class_type": 3, "updated_date": "2016-09-01" } }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.16.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.16.adm
new file mode 100644
index 0000000..303b8b5
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.16.adm
@@ -0,0 +1,5 @@
+{ "rec": { "id": 1, "name": "John Mad", "age": 29, "hobby": "reading" }, "meta": { "id": "rec1_US", "class_type": 1, "updated_date": "2007-02-02" } }
+{ "rec": { "id": 2, "name": "Scott Scott", "age": 30, "hobby": "hiking" }, "meta": { "id": "rec2_US", "class_type": 1, "updated_date": "2008-02-04" } }
+{ "rec": { "id": 4, "name": "Robert Moore", "age": 32, "hobby": "reading" }, "meta": { "id": "rec4_US", "class_type": 1, "updated_date": "2006-01-04" } }
+{ "rec": { "id": 13, "name": "Sally Bush", "age": 29, "hobby": "reading" }, "meta": { "id": "rec13_US", "class_type": 2, "updated_date": "2014-09-01" } }
+{ "rec": { "id": 14, "name": "Sarah Tran", "age": 20, "hobby": "reading" }, "meta": { "id": "rec14_US", "class_type": 1, "updated_date": "2010-09-01" } }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.17.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.17.adm
new file mode 100644
index 0000000..0a93b0b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.17.adm
@@ -0,0 +1,9 @@
+{ "rec": { "id": 3, "name": "Dan David", "age": 40, "hobby": "bowling" }, "meta": { "id": "rec3_UK", "class_type": 2, "updated_date": "2018-02-02" } }
+{ "rec": { "id": 5, "name": "Sandy Donald", "age": 35, "hobby": "soccer" }, "meta": { "id": "rec5_UK", "class_type": 2, "updated_date": "2018-01-04" } }
+{ "rec": { "id": 6, "name": "Joe Dana", "age": 24, "hobby": "tennis" }, "meta": { "id": "rec6_US", "class_type": 2, "updated_date": "2018-06-05" } }
+{ "rec": { "id": 7, "name": "Watson Jordon", "age": 28, "hobby": "basketball" }, "meta": { "id": "rec7_US", "class_type": 1, "updated_date": "2018-06-07" } }
+{ "rec": { "id": 8, "name": "Mat Steve", "age": 45, "hobby": "tennis" }, "meta": { "id": "rec8_UK", "class_type": 2, "updated_date": "2018-06-05" } }
+{ "rec": { "id": 9, "name": "Sandra Pec", "age": 36, "hobby": "hiking" }, "meta": { "id": "rec9_US", "class_type": 3, "updated_date": "2018-06-09" } }
+{ "rec": { "id": 10, "name": "Sandra Lan", "age": 36, "hobby": "football" }, "meta": { "id": "rec10_US", "class_type": 3, "updated_date": "2017-06-09" } }
+{ "rec": { "id": 11, "name": "Trever Jones", "age": 36, "hobby": "hiking" }, "meta": { "id": "rec11_UK", "class_type": 3, "updated_date": "2018-09-09" } }
+{ "rec": { "id": 12, "name": "Ruth Pec", "age": 36, "hobby": "swimming" }, "meta": { "id": "rec12_UK", "class_type": 3, "updated_date": "2016-09-01" } }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.3.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.3.adm
new file mode 100644
index 0000000..cf5fe4a
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.3.adm
@@ -0,0 +1,9 @@
+{ "rec": { "id": 1, "name": "John Mad", "age": 29, "hobby": "reading" }, "meta": { "id": "rec1_US", "class_type": 1, "updated_date": "2007-02-02" } }
+{ "rec": { "id": 2, "name": "Scott Scott", "age": 30, "hobby": "hiking" }, "meta": { "id": "rec2_US", "class_type": 1, "updated_date": "2008-02-04" } }
+{ "rec": { "id": 4, "name": "Robert Moore", "age": 32, "hobby": "reading" }, "meta": { "id": "rec4_US", "class_type": 1, "updated_date": "2006-01-04" } }
+{ "rec": { "id": 6, "name": "Joe Dana", "age": 24, "hobby": "tennis" }, "meta": { "id": "rec6_US", "class_type": 2, "updated_date": "2018-06-05" } }
+{ "rec": { "id": 7, "name": "Watson Jordon", "age": 28, "hobby": "basketball" }, "meta": { "id": "rec7_US", "class_type": 1, "updated_date": "2018-06-07" } }
+{ "rec": { "id": 9, "name": "Sandra Pec", "age": 36, "hobby": "hiking" }, "meta": { "id": "rec9_US", "class_type": 3, "updated_date": "2018-06-09" } }
+{ "rec": { "id": 10, "name": "Sandra Lan", "age": 36, "hobby": "football" }, "meta": { "id": "rec10_US", "class_type": 3, "updated_date": "2017-06-09" } }
+{ "rec": { "id": 13, "name": "Sally Bush", "age": 29, "hobby": "reading" }, "meta": { "id": "rec13_US", "class_type": 2, "updated_date": "2014-09-01" } }
+{ "rec": { "id": 14, "name": "Sarah Tran", "age": 20, "hobby": "reading" }, "meta": { "id": "rec14_US", "class_type": 1, "updated_date": "2010-09-01" } }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.4.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.4.adm
new file mode 100644
index 0000000..9fb07fe
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.4.adm
@@ -0,0 +1,5 @@
+{ "rec": { "id": 3, "name": "Dan David", "age": 40, "hobby": "bowling" }, "meta": { "id": "rec3_UK", "class_type": 2, "updated_date": "2018-02-02" } }
+{ "rec": { "id": 5, "name": "Sandy Donald", "age": 35, "hobby": "soccer" }, "meta": { "id": "rec5_UK", "class_type": 2, "updated_date": "2018-01-04" } }
+{ "rec": { "id": 8, "name": "Mat Steve", "age": 45, "hobby": "tennis" }, "meta": { "id": "rec8_UK", "class_type": 2, "updated_date": "2018-06-05" } }
+{ "rec": { "id": 11, "name": "Trever Jones", "age": 36, "hobby": "hiking" }, "meta": { "id": "rec11_UK", "class_type": 3, "updated_date": "2018-09-09" } }
+{ "rec": { "id": 12, "name": "Ruth Pec", "age": 36, "hobby": "swimming" }, "meta": { "id": "rec12_UK", "class_type": 3, "updated_date": "2016-09-01" } }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.5.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.5.adm
new file mode 100644
index 0000000..2cd20f2
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.5.adm
@@ -0,0 +1,5 @@
+{ "rec": { "id": 1, "name": "John Mad", "age": 29, "hobby": "reading" }, "meta": { "id": "rec1_US", "class_type": 1, "updated_date": "2007-02-02" } }
+{ "rec": { "id": 2, "name": "Scott Scott", "age": 30, "hobby": "hiking" }, "meta": { "id": "rec2_US", "class_type": 1, "updated_date": "2008-02-04" } }
+{ "rec": { "id": 4, "name": "Robert Moore", "age": 32, "hobby": "reading" }, "meta": { "id": "rec4_US", "class_type": 1, "updated_date": "2006-01-04" } }
+{ "rec": { "id": 7, "name": "Watson Jordon", "age": 28, "hobby": "basketball" }, "meta": { "id": "rec7_US", "class_type": 1, "updated_date": "2018-06-07" } }
+{ "rec": { "id": 14, "name": "Sarah Tran", "age": 20, "hobby": "reading" }, "meta": { "id": "rec14_US", "class_type": 1, "updated_date": "2010-09-01" } }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.6.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.6.adm
new file mode 100644
index 0000000..4a0957e
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.6.adm
@@ -0,0 +1,5 @@
+{ "rec": { "id": 3, "name": "Dan David", "age": 40, "hobby": "bowling" }, "meta": { "id": "rec3_UK", "class_type": 2, "updated_date": "2018-02-02" } }
+{ "rec": { "id": 5, "name": "Sandy Donald", "age": 35, "hobby": "soccer" }, "meta": { "id": "rec5_UK", "class_type": 2, "updated_date": "2018-01-04" } }
+{ "rec": { "id": 6, "name": "Joe Dana", "age": 24, "hobby": "tennis" }, "meta": { "id": "rec6_US", "class_type": 2, "updated_date": "2018-06-05" } }
+{ "rec": { "id": 8, "name": "Mat Steve", "age": 45, "hobby": "tennis" }, "meta": { "id": "rec8_UK", "class_type": 2, "updated_date": "2018-06-05" } }
+{ "rec": { "id": 13, "name": "Sally Bush", "age": 29, "hobby": "reading" }, "meta": { "id": "rec13_US", "class_type": 2, "updated_date": "2014-09-01" } }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.7.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.7.adm
new file mode 100644
index 0000000..5f119c2
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.7.adm
@@ -0,0 +1,4 @@
+{ "rec": { "id": 9, "name": "Sandra Pec", "age": 36, "hobby": "hiking" }, "meta": { "id": "rec9_US", "class_type": 3, "updated_date": "2018-06-09" } }
+{ "rec": { "id": 10, "name": "Sandra Lan", "age": 36, "hobby": "football" }, "meta": { "id": "rec10_US", "class_type": 3, "updated_date": "2017-06-09" } }
+{ "rec": { "id": 11, "name": "Trever Jones", "age": 36, "hobby": "hiking" }, "meta": { "id": "rec11_UK", "class_type": 3, "updated_date": "2018-09-09" } }
+{ "rec": { "id": 12, "name": "Ruth Pec", "age": 36, "hobby": "swimming" }, "meta": { "id": "rec12_UK", "class_type": 3, "updated_date": "2016-09-01" } }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.8.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.8.adm
new file mode 100644
index 0000000..303b8b5
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.8.adm
@@ -0,0 +1,5 @@
+{ "rec": { "id": 1, "name": "John Mad", "age": 29, "hobby": "reading" }, "meta": { "id": "rec1_US", "class_type": 1, "updated_date": "2007-02-02" } }
+{ "rec": { "id": 2, "name": "Scott Scott", "age": 30, "hobby": "hiking" }, "meta": { "id": "rec2_US", "class_type": 1, "updated_date": "2008-02-04" } }
+{ "rec": { "id": 4, "name": "Robert Moore", "age": 32, "hobby": "reading" }, "meta": { "id": "rec4_US", "class_type": 1, "updated_date": "2006-01-04" } }
+{ "rec": { "id": 13, "name": "Sally Bush", "age": 29, "hobby": "reading" }, "meta": { "id": "rec13_US", "class_type": 2, "updated_date": "2014-09-01" } }
+{ "rec": { "id": 14, "name": "Sarah Tran", "age": 20, "hobby": "reading" }, "meta": { "id": "rec14_US", "class_type": 1, "updated_date": "2010-09-01" } }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.9.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.9.adm
new file mode 100644
index 0000000..0a93b0b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/feeds/change-feed-with-filter-on-meta/change-feed-with-filter-on-meta.9.adm
@@ -0,0 +1,9 @@
+{ "rec": { "id": 3, "name": "Dan David", "age": 40, "hobby": "bowling" }, "meta": { "id": "rec3_UK", "class_type": 2, "updated_date": "2018-02-02" } }
+{ "rec": { "id": 5, "name": "Sandy Donald", "age": 35, "hobby": "soccer" }, "meta": { "id": "rec5_UK", "class_type": 2, "updated_date": "2018-01-04" } }
+{ "rec": { "id": 6, "name": "Joe Dana", "age": 24, "hobby": "tennis" }, "meta": { "id": "rec6_US", "class_type": 2, "updated_date": "2018-06-05" } }
+{ "rec": { "id": 7, "name": "Watson Jordon", "age": 28, "hobby": "basketball" }, "meta": { "id": "rec7_US", "class_type": 1, "updated_date": "2018-06-07" } }
+{ "rec": { "id": 8, "name": "Mat Steve", "age": 45, "hobby": "tennis" }, "meta": { "id": "rec8_UK", "class_type": 2, "updated_date": "2018-06-05" } }
+{ "rec": { "id": 9, "name": "Sandra Pec", "age": 36, "hobby": "hiking" }, "meta": { "id": "rec9_US", "class_type": 3, "updated_date": "2018-06-09" } }
+{ "rec": { "id": 10, "name": "Sandra Lan", "age": 36, "hobby": "football" }, "meta": { "id": "rec10_US", "class_type": 3, "updated_date": "2017-06-09" } }
+{ "rec": { "id": 11, "name": "Trever Jones", "age": 36, "hobby": "hiking" }, "meta": { "id": "rec11_UK", "class_type": 3, "updated_date": "2018-09-09" } }
+{ "rec": { "id": 12, "name": "Ruth Pec", "age": 36, "hobby": "swimming" }, "meta": { "id": "rec12_UK", "class_type": 3, "updated_date": "2016-09-01" } }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
index 18c5f88..e49b36d 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -9056,6 +9056,11 @@
         <expected-error>Function fundv.test_func0@1 is being used. It cannot be dropped</expected-error>
       </compilation-unit>
     </test-case>
+    <test-case FilePath="feeds">
+      <compilation-unit name="change-feed-with-filter-on-meta">
+        <output-dir compare="Text">change-feed-with-filter-on-meta</output-dir>
+      </compilation-unit>
+    </test-case>
   </test-group>
   <test-group name="meta">
     <test-case FilePath="meta">


[asterixdb] 04/06: [NO ISSUE][COMP] Fix index selection for datasets with meta

Posted by mh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mhubail pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git

commit d292d99bc652e81ae1e7877e88529ce2b29cf6d0
Author: Ali Alsuliman <al...@gmail.com>
AuthorDate: Fri Sep 6 00:21:36 2019 -0700

    [NO ISSUE][COMP] Fix index selection for datasets with meta
    
    - user model changes: no
    - storage format changes: no
    - interface changes: no
    
    Details:
    Fix index selection for datasets with meta. Access method rule should
    check where the field is coming from (dataset record or meta record)
    and then determine if the field matches the keys in the index based
    on their names and sources.
    
    This patch also fixes resolving PK field accesses to the primary key
    variable (e.g. $ds.getField("id") is turned into $13 where id is a PK).
    The fix considers whether the PK is coming from the data record or the
    meta record.
    The patch also includes fixing rewriting of meta() references and
    replacing them with their corresponding meta variables. Now nested plans
    are visited also when looking for meta() references to take care of cases
    where the data scan producing the meta variable and the meta() references
    happen to be inside the nested plans.
    MetaFunctionToMetaVariable() is fired also after the rules which eliminate
    subplans to allow for rewriting of the meta() if it couldn't be replaced
    when the meta() reference was in the subplan but referring to meta variable
    outside the nested plan.
    ReinferAllTypesRule() is now fired before ByNameToByIndexFieldAccessRule()
    to allow the latter rule to get the up-to-date types in the whole plan.
    
    Change-Id: I0503f64cd51153896e2d7d7abc465c679f82e2fd
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/3545
    Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Reviewed-by: Dmitry Lychagin <dm...@couchbase.com>
    Contrib: Till Westmann <ti...@apache.org>
---
 .../asterix/optimizer/base/RuleCollections.java    |  3 +-
 .../rules/MetaFunctionToMetaVariableRule.java      | 21 ++++--
 .../optimizer/rules/PushFieldAccessRule.java       | 58 ++++++++++-----
 .../am/AbstractIntroduceAccessMethodRule.java      | 82 ++++++++++++++++------
 .../optimizer/rules/am/BTreeAccessMethod.java      | 17 +++--
 .../optimizer/rules/am/IOptimizableFuncExpr.java   |  4 +-
 .../rules/am/IntroduceLSMComponentFilterRule.java  | 23 ++++--
 .../optimizer/rules/am/OptimizableFuncExpr.java    | 11 ++-
 .../rules/am/OptimizableOperatorSubTree.java       |  1 +
 asterixdb/asterix-app/data/csv/people.csv          |  9 +++
 asterixdb/asterix-app/data/csv/people3.csv         |  9 +++
 .../meta/field_access_with_data_and_meta_1.sqlpp   | 41 +++++++++++
 .../meta/field_access_with_data_and_meta_2.sqlpp   | 41 +++++++++++
 .../meta/field_access_with_data_and_meta_3.sqlpp   | 41 +++++++++++
 .../meta/field_access_with_data_and_meta_4.sqlpp   | 41 +++++++++++
 .../meta/indexes_on_dataset_with_meta_01.sqlpp     | 44 ++++++++++++
 .../meta/indexes_on_dataset_with_meta_02.sqlpp     | 44 ++++++++++++
 .../meta/indexes_on_dataset_with_meta_03.sqlpp     | 44 ++++++++++++
 .../meta/indexes_on_dataset_with_meta_04.sqlpp     | 44 ++++++++++++
 .../meta/indexes_on_dataset_with_meta_05.sqlpp     | 48 +++++++++++++
 .../meta/indexes_on_dataset_with_meta_06.sqlpp     | 48 +++++++++++++
 .../meta/indexes_on_dataset_with_meta_07.sqlpp     | 48 +++++++++++++
 .../meta/indexes_on_dataset_with_meta_08.sqlpp     | 46 ++++++++++++
 .../meta/indexes_on_dataset_with_meta_09.sqlpp     | 45 ++++++++++++
 .../meta/indexes_on_dataset_with_meta_10.sqlpp     | 47 +++++++++++++
 .../meta/indexes_on_dataset_with_meta_11.sqlpp     | 47 +++++++++++++
 .../queries/meta/with_clause_meta.sqlpp            | 47 +++++++++++++
 .../meta/field_access_with_data_and_meta_1.plan    | 14 ++++
 .../meta/field_access_with_data_and_meta_2.plan    | 11 +++
 .../meta/field_access_with_data_and_meta_3.plan    | 11 +++
 .../meta/field_access_with_data_and_meta_4.plan    | 14 ++++
 .../meta/indexes_on_dataset_with_meta_01.plan      | 10 +++
 .../meta/indexes_on_dataset_with_meta_02.plan      | 10 +++
 .../meta/indexes_on_dataset_with_meta_03.plan      | 10 +++
 .../meta/indexes_on_dataset_with_meta_04.plan      | 11 +++
 .../meta/indexes_on_dataset_with_meta_05.plan      | 24 +++++++
 .../meta/indexes_on_dataset_with_meta_06.plan      | 17 +++++
 .../meta/indexes_on_dataset_with_meta_07.plan      | 18 +++++
 .../meta/indexes_on_dataset_with_meta_08.plan      | 17 +++++
 .../meta/indexes_on_dataset_with_meta_09.plan      | 10 +++
 .../meta/indexes_on_dataset_with_meta_10.plan      | 24 +++++++
 .../meta/indexes_on_dataset_with_meta_11.plan      | 17 +++++
 .../optimizerts/results/meta/with_clause_meta.plan | 44 ++++++++++++
 .../dataset-with-meta.01.ddl.sqlpp                 | 68 ++++++++++++++++++
 .../dataset-with-meta.02.update.sqlpp              | 27 +++++++
 .../dataset-with-meta.03.query.sqlpp               | 29 ++++++++
 .../dataset-with-meta.04.query.sqlpp               | 29 ++++++++
 .../dataset-with-meta.05.query.sqlpp               | 29 ++++++++
 .../dataset-with-meta.06.query.sqlpp               | 29 ++++++++
 .../dataset-with-meta.07.query.sqlpp               | 30 ++++++++
 .../dataset-with-meta.08.query.sqlpp               | 30 ++++++++
 .../dataset-with-meta.09.query.sqlpp               | 30 ++++++++
 .../dataset-with-meta.10.ddl.sqlpp                 | 22 ++++++
 .../dataset-with-meta.11.query.sqlpp               | 29 ++++++++
 .../dataset-with-meta.12.query.sqlpp               | 29 ++++++++
 .../dataset-with-meta.13.query.sqlpp               | 30 ++++++++
 .../dataset-with-meta.14.query.sqlpp               | 30 ++++++++
 .../dataset-with-meta.15.ddl.sqlpp                 | 20 ++++++
 .../meta_in_with_clause.1.ddl.sqlpp                | 71 +++++++++++++++++++
 .../meta_in_with_clause.2.update.sqlpp             | 27 +++++++
 .../meta_in_with_clause.3.query.sqlpp              | 29 ++++++++
 .../meta_in_with_clause.4.query.sqlpp              | 29 ++++++++
 .../meta_in_with_clause.5.query.sqlpp              | 29 ++++++++
 .../meta_in_with_clause.6.query.sqlpp              | 29 ++++++++
 .../meta_in_with_clause.7.ddl.sqlpp                | 20 ++++++
 .../resolving_pk_with_meta.1.ddl.sqlpp             | 68 ++++++++++++++++++
 .../resolving_pk_with_meta.2.update.sqlpp          | 27 +++++++
 .../resolving_pk_with_meta.3.query.sqlpp           | 27 +++++++
 .../resolving_pk_with_meta.4.query.sqlpp           | 27 +++++++
 .../resolving_pk_with_meta.5.query.sqlpp           | 27 +++++++
 .../resolving_pk_with_meta.6.query.sqlpp           | 27 +++++++
 .../resolving_pk_with_meta.7.ddl.sqlpp             | 27 +++++++
 .../dataset-with-meta/dataset-with-meta.03.adm     |  1 +
 .../dataset-with-meta/dataset-with-meta.04.adm     |  1 +
 .../dataset-with-meta/dataset-with-meta.05.adm     |  1 +
 .../dataset-with-meta/dataset-with-meta.06.adm     |  1 +
 .../dataset-with-meta/dataset-with-meta.07.adm     |  9 +++
 .../dataset-with-meta/dataset-with-meta.08.adm     |  2 +
 .../dataset-with-meta/dataset-with-meta.09.adm     |  9 +++
 .../dataset-with-meta/dataset-with-meta.11.adm     |  1 +
 .../dataset-with-meta/dataset-with-meta.12.adm     |  1 +
 .../dataset-with-meta/dataset-with-meta.13.adm     |  9 +++
 .../dataset-with-meta/dataset-with-meta.14.adm     |  2 +
 .../meta_in_with_clause/meta_in_with_clause.3.adm  |  8 +++
 .../meta_in_with_clause/meta_in_with_clause.4.adm  |  8 +++
 .../meta_in_with_clause/meta_in_with_clause.5.adm  |  8 +++
 .../meta_in_with_clause/meta_in_with_clause.6.adm  |  8 +++
 .../resolving_pk_with_meta.3.adm                   |  9 +++
 .../resolving_pk_with_meta.4.adm                   |  9 +++
 .../resolving_pk_with_meta.5.adm                   |  9 +++
 .../resolving_pk_with_meta.6.adm                   |  9 +++
 .../test/resources/runtimets/testsuite_sqlpp.xml   | 17 +++++
 .../apache/asterix/metadata/utils/DatasetUtil.java | 41 ++++++++++-
 93 files changed, 2247 insertions(+), 57 deletions(-)

diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/base/RuleCollections.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/base/RuleCollections.java
index f9b5c38..841043d 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/base/RuleCollections.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/base/RuleCollections.java
@@ -235,7 +235,7 @@ public final class RuleCollections {
         // The following rule should be fired after PushAggregateIntoNestedSubplanRule because
         // pulling invariants out of a subplan will make PushAggregateIntoGroupby harder.
         condPushDownAndJoinInference.add(new AsterixMoveFreeVariableOperatorOutOfSubplanRule());
-
+        condPushDownAndJoinInference.add(new MetaFunctionToMetaVariableRule());
         return condPushDownAndJoinInference;
     }
 
@@ -244,6 +244,7 @@ public final class RuleCollections {
         fieldLoads.add(new LoadRecordFieldsRule());
         fieldLoads.add(new PushFieldAccessRule());
         // fieldLoads.add(new ByNameToByHandleFieldAccessRule()); -- disabled
+        fieldLoads.add(new ReinferAllTypesRule());
         fieldLoads.add(new ByNameToByIndexFieldAccessRule());
         fieldLoads.add(new RemoveRedundantVariablesRule());
         fieldLoads.add(new AsterixInlineVariablesRule());
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/MetaFunctionToMetaVariableRule.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/MetaFunctionToMetaVariableRule.java
index cd99c28..c47acd1 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/MetaFunctionToMetaVariableRule.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/MetaFunctionToMetaVariableRule.java
@@ -34,6 +34,7 @@ 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.ILogicalPlan;
 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;
@@ -44,6 +45,8 @@ import org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCall
 import org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 import org.apache.hyracks.algebricks.core.algebra.functions.IFunctionInfo;
+import org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
+import org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractOperatorWithNestedPlans;
 import org.apache.hyracks.algebricks.core.algebra.operators.logical.DataSourceScanOperator;
 import org.apache.hyracks.algebricks.core.algebra.visitors.ILogicalExpressionReferenceTransform;
 import org.apache.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
@@ -148,6 +151,15 @@ public class MetaFunctionToMetaVariableRule implements IAlgebraicRewriteRule {
             }
             currentTransformer = new CompositeExpressionReferenceTransform(transformers);
         }
+
+        if (((AbstractLogicalOperator) op).hasNestedPlans()) {
+            AbstractOperatorWithNestedPlans opWithNestedPlans = (AbstractOperatorWithNestedPlans) op;
+            for (ILogicalPlan nestedPlan : opWithNestedPlans.getNestedPlans()) {
+                for (Mutable<ILogicalOperator> root : nestedPlan.getRoots()) {
+                    visit(root);
+                }
+            }
+        }
         rewritten |= op.acceptExpressionTransform(currentTransformer);
         return currentTransformer;
     }
@@ -197,13 +209,14 @@ class LogicalExpressionReferenceTransform implements ILogicalExpressionReference
         AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) expr;
         List<Mutable<ILogicalExpression>> argRefs = funcExpr.getArguments();
 
+        boolean changed = false;
         // Recursively transform argument expressions.
         for (Mutable<ILogicalExpression> argRef : argRefs) {
-            transform(argRef);
+            changed |= transform(argRef);
         }
 
         if (!funcExpr.getFunctionIdentifier().equals(BuiltinFunctions.META)) {
-            return false;
+            return changed;
         }
         // The user query provides more than one parameter for the meta function.
         if (argRefs.size() > 1) {
@@ -215,12 +228,12 @@ class LogicalExpressionReferenceTransform implements ILogicalExpressionReference
         if (argRefs.size() == 1) {
             ILogicalExpression argExpr = argRefs.get(0).getValue();
             if (argExpr.getExpressionTag() != LogicalExpressionTag.VARIABLE) {
-                return false;
+                return changed;
             }
             VariableReferenceExpression argVarExpr = (VariableReferenceExpression) argExpr;
             LogicalVariable argVar = argVarExpr.getVariableReference();
             if (!dataVar.equals(argVar)) {
-                return false;
+                return changed;
             }
             VariableReferenceExpression metaVarRef = new VariableReferenceExpression(metaVar);
             metaVarRef.setSourceLocation(expr.getSourceLocation());
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/PushFieldAccessRule.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/PushFieldAccessRule.java
index b779c83..758b041 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/PushFieldAccessRule.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/PushFieldAccessRule.java
@@ -288,8 +288,6 @@ public class PushFieldAccessRule implements IAlgebraicRewriteRule {
             // fields. If yes, we can equate the two variables.
             if (op2.getOperatorTag() == LogicalOperatorTag.DATASOURCESCAN) {
                 DataSourceScanOperator scan = (DataSourceScanOperator) op2;
-                int n = scan.getVariables().size();
-                LogicalVariable scanRecordVar = scan.getVariables().get(n - 1);
 
                 IDataSource<DataSourceId> dataSource = (IDataSource<DataSourceId>) scan.getDataSource();
                 byte dsType = ((DataSource) dataSource).getDatasourceType();
@@ -308,6 +306,10 @@ public class PushFieldAccessRule implements IAlgebraicRewriteRule {
                     return false;
                 }
 
+                List<LogicalVariable> allVars = scan.getVariables();
+                LogicalVariable dataRecVarInScan = ((DataSource) dataSource).getDataRecordVariable(allVars);
+                LogicalVariable metaRecVarInScan = ((DataSource) dataSource).getMetaVariable(allVars);
+
                 String tName = dataset.getItemTypeName();
                 IAType t = mp.findType(dataset.getItemTypeDataverseName(), tName);
                 if (t.getTypeTag() != ATypeTag.OBJECT) {
@@ -315,23 +317,37 @@ public class PushFieldAccessRule implements IAlgebraicRewriteRule {
                 }
                 ARecordType rt = (ARecordType) t;
                 Pair<ILogicalExpression, List<String>> fieldPathAndVar = getFieldExpression(access, rt);
-                ILogicalExpression e0 = fieldPathAndVar.first;
-                LogicalExpressionTag tag = e0.getExpressionTag();
-                if (tag == LogicalExpressionTag.VARIABLE) {
-                    VariableReferenceExpression varRef = (VariableReferenceExpression) e0;
-                    if (varRef.getVariableReference() == scanRecordVar) {
-                        int p = DatasetUtil.getPositionOfPartitioningKeyField(dataset, fieldPathAndVar.second);
-                        if (p < 0) { // not one of the partitioning fields
-                            setAsFinal(access, context, finalAnnot);
-                            return false;
+                ILogicalExpression targetRecVar = fieldPathAndVar.first;
+                List<String> targetFieldPath = fieldPathAndVar.second;
+                boolean rewrite = false;
+                boolean fieldFromMeta = false;
+                if (sameRecords(targetRecVar, dataRecVarInScan)) {
+                    rewrite = true;
+                } else {
+                    // check meta part
+                    IAType metaType = mp.findMetaType(dataset); // could be null
+                    if (metaType != null && metaType.getTypeTag() == ATypeTag.OBJECT) {
+                        fieldPathAndVar = getFieldExpression(access, (ARecordType) metaType);
+                        targetRecVar = fieldPathAndVar.first;
+                        targetFieldPath = fieldPathAndVar.second;
+                        if (sameRecords(targetRecVar, metaRecVarInScan)) {
+                            rewrite = true;
+                            fieldFromMeta = true;
                         }
-                        LogicalVariable keyVar = scan.getVariables().get(p);
-                        VariableReferenceExpression keyVarRef = new VariableReferenceExpression(keyVar);
-                        keyVarRef.setSourceLocation(varRef.getSourceLocation());
-                        access.getExpressions().get(0).setValue(keyVarRef);
-                        return true;
+                    }
+                }
 
+                if (rewrite) {
+                    int p = DatasetUtil.getPositionOfPartitioningKeyField(dataset, targetFieldPath, fieldFromMeta);
+                    if (p < 0) { // not one of the partitioning fields
+                        setAsFinal(access, context, finalAnnot);
+                        return false;
                     }
+                    LogicalVariable keyVar = scan.getVariables().get(p);
+                    VariableReferenceExpression keyVarRef = new VariableReferenceExpression(keyVar);
+                    keyVarRef.setSourceLocation(targetRecVar.getSourceLocation());
+                    access.getExpressions().get(0).setValue(keyVarRef);
+                    return true;
                 }
             }
             setAsFinal(access, context, finalAnnot);
@@ -339,6 +355,16 @@ public class PushFieldAccessRule implements IAlgebraicRewriteRule {
         }
     }
 
+    /**
+     * @param recordInAssign the variable reference expression in assign op
+     * @param recordInScan the record (payload) variable in scan op
+     * @return true if the expression in the assign op is a variable and that variable = record variable in scan op
+     */
+    private boolean sameRecords(ILogicalExpression recordInAssign, LogicalVariable recordInScan) {
+        return recordInAssign != null && recordInAssign.getExpressionTag() == LogicalExpressionTag.VARIABLE
+                && ((VariableReferenceExpression) recordInAssign).getVariableReference().equals(recordInScan);
+    }
+
     private Pair<ILogicalExpression, List<String>> getFieldExpression(AssignOperator access, ARecordType rt)
             throws AlgebricksException {
         LinkedList<String> fieldPath = new LinkedList<>();
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/AbstractIntroduceAccessMethodRule.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/AbstractIntroduceAccessMethodRule.java
index c8bec85..d232ce0 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/AbstractIntroduceAccessMethodRule.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/AbstractIntroduceAccessMethodRule.java
@@ -34,7 +34,9 @@ import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.exceptions.ErrorCode;
 import org.apache.asterix.dataflow.data.common.ExpressionTypeComputer;
 import org.apache.asterix.metadata.declared.MetadataProvider;
+import org.apache.asterix.metadata.entities.Dataset;
 import org.apache.asterix.metadata.entities.Index;
+import org.apache.asterix.metadata.utils.DatasetUtil;
 import org.apache.asterix.metadata.utils.MetadataUtil;
 import org.apache.asterix.om.base.AOrderedList;
 import org.apache.asterix.om.base.AString;
@@ -51,6 +53,7 @@ import org.apache.asterix.om.utils.ConstantExpressionUtil;
 import org.apache.asterix.optimizer.base.AnalysisUtil;
 import org.apache.asterix.optimizer.rules.am.OptimizableOperatorSubTree.DataSourceType;
 import org.apache.commons.lang3.mutable.Mutable;
+import org.apache.commons.lang3.mutable.MutableInt;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.common.utils.Pair;
 import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
@@ -533,17 +536,20 @@ public abstract class AbstractIntroduceAccessMethodRule implements IAlgebraicRew
      */
     protected boolean fillIndexExprs(List<Index> datasetIndexes, List<String> fieldName, IAType fieldType,
             IOptimizableFuncExpr optFuncExpr, int matchedFuncExprIndex, int varIdx,
-            OptimizableOperatorSubTree matchedSubTree, AccessMethodAnalysisContext analysisCtx)
+            OptimizableOperatorSubTree matchedSubTree, AccessMethodAnalysisContext analysisCtx, int fieldSource)
             throws AlgebricksException {
         List<Index> indexCandidates = new ArrayList<>();
         // Add an index to the candidates if one of the indexed fields is fieldName
         for (Index index : datasetIndexes) {
             // Need to also verify the index is pending no op
-            if (index.getKeyFieldNames().contains(fieldName) && index.getPendingOp() == MetadataUtil.PENDING_NO_OP) {
+            int keyIdx = index.getKeyFieldNames().indexOf(fieldName);
+            List<Integer> keySources = index.getKeyFieldSourceIndicators();
+            if (keyIdx >= 0 && keySourceMatches(keySources, keyIdx, fieldSource)
+                    && index.getPendingOp() == MetadataUtil.PENDING_NO_OP) {
                 indexCandidates.add(index);
                 boolean isFieldTypeUnknown = fieldType == BuiltinType.AMISSING || fieldType == BuiltinType.ANY;
                 if (isFieldTypeUnknown && (!index.isOverridingKeyFieldTypes() || index.isEnforced())) {
-                    IAType indexedType = index.getKeyFieldTypes().get(index.getKeyFieldNames().indexOf(fieldName));
+                    IAType indexedType = index.getKeyFieldTypes().get(keyIdx);
                     optFuncExpr.setFieldType(varIdx, indexedType);
                 }
                 analysisCtx.addIndexExpr(matchedSubTree.getDataset(), index, matchedFuncExprIndex, varIdx);
@@ -556,6 +562,11 @@ public abstract class AbstractIntroduceAccessMethodRule implements IAlgebraicRew
         return true;
     }
 
+    private static boolean keySourceMatches(List<Integer> keySources, int keyIdx, int fieldSource) {
+        // TODO(ali): keySources from Index should not be null. should investigate if it can happen (ie on external ds)
+        return keySources == null ? fieldSource == 0 : keySources.get(keyIdx) == fieldSource;
+    }
+
     protected void fillAllIndexExprs(OptimizableOperatorSubTree subTree, AccessMethodAnalysisContext analysisCtx,
             IOptimizationContext context) throws AlgebricksException {
         int optFuncExprIndex = 0;
@@ -624,6 +635,7 @@ public abstract class AbstractIntroduceAccessMethodRule implements IAlgebraicRew
         // Remember matching subtree.
         optFuncExpr.setOptimizableSubTree(funcVarIndex, subTree);
         List<String> fieldName = null;
+        MutableInt fieldSource = new MutableInt(0);
         if (subTree.getDataSourceType() == DataSourceType.COLLECTION_SCAN) {
             VariableReferenceExpression varRef = new VariableReferenceExpression(var);
             varRef.setSourceLocation(unnestOp.getSourceLocation());
@@ -631,7 +643,7 @@ public abstract class AbstractIntroduceAccessMethodRule implements IAlgebraicRew
         } else {
             fieldName = getFieldNameFromSubTree(optFuncExpr, subTree, assignOrUnnestIndex, 0, subTree.getRecordType(),
                     funcVarIndex, optFuncExpr.getFuncExpr().getArguments().get(funcVarIndex).getValue(),
-                    subTree.getMetaRecordType(), datasetMetaVar);
+                    subTree.getMetaRecordType(), datasetMetaVar, fieldSource);
             if (fieldName.isEmpty()) {
                 return;
             }
@@ -640,13 +652,13 @@ public abstract class AbstractIntroduceAccessMethodRule implements IAlgebraicRew
                 (IAType) context.getOutputTypeEnvironment(unnestOp).getType(optFuncExpr.getLogicalExpr(funcVarIndex));
         // Set the fieldName in the corresponding matched function
         // expression.
-        optFuncExpr.setFieldName(funcVarIndex, fieldName);
+        optFuncExpr.setFieldName(funcVarIndex, fieldName, fieldSource.intValue());
         optFuncExpr.setFieldType(funcVarIndex, fieldType);
 
         setTypeTag(context, subTree, optFuncExpr, funcVarIndex);
         if (subTree.hasDataSource()) {
             fillIndexExprs(datasetIndexes, fieldName, fieldType, optFuncExpr, optFuncExprIndex, funcVarIndex, subTree,
-                    analysisCtx);
+                    analysisCtx, fieldSource.intValue());
         }
     }
 
@@ -655,6 +667,7 @@ public abstract class AbstractIntroduceAccessMethodRule implements IAlgebraicRew
             IOptimizationContext context, List<Index> datasetIndexes, int optFuncExprIndex,
             AccessMethodAnalysisContext analysisCtx) throws AlgebricksException {
         List<LogicalVariable> varList = assignOp.getVariables();
+        MutableInt fieldSource = new MutableInt(0);
         for (int varIndex = 0; varIndex < varList.size(); varIndex++) {
             LogicalVariable var = varList.get(varIndex);
             int optVarIndex = optFuncExpr.findLogicalVar(var);
@@ -667,21 +680,22 @@ public abstract class AbstractIntroduceAccessMethodRule implements IAlgebraicRew
             // Remember matching subtree.
             optFuncExpr.setOptimizableSubTree(optVarIndex, subTree);
 
+            fieldSource.setValue(0);
             List<String> fieldName = getFieldNameFromSubTree(optFuncExpr, subTree, assignOrUnnestIndex, varIndex,
                     subTree.getRecordType(), optVarIndex,
                     optFuncExpr.getFuncExpr().getArguments().get(optVarIndex).getValue(), subTree.getMetaRecordType(),
-                    datasetMetaVar);
+                    datasetMetaVar, fieldSource);
 
             IAType fieldType = (IAType) context.getOutputTypeEnvironment(assignOp).getVarType(var);
             // Set the fieldName in the corresponding matched
             // function expression.
-            optFuncExpr.setFieldName(optVarIndex, fieldName);
+            optFuncExpr.setFieldName(optVarIndex, fieldName, fieldSource.intValue());
             optFuncExpr.setFieldType(optVarIndex, fieldType);
 
             setTypeTag(context, subTree, optFuncExpr, optVarIndex);
             if (subTree.hasDataSource()) {
                 fillIndexExprs(datasetIndexes, fieldName, fieldType, optFuncExpr, optFuncExprIndex, optVarIndex,
-                        subTree, analysisCtx);
+                        subTree, analysisCtx, fieldSource.intValue());
             }
         }
     }
@@ -690,6 +704,7 @@ public abstract class AbstractIntroduceAccessMethodRule implements IAlgebraicRew
             List<Index> datasetIndexes, List<LogicalVariable> dsVarList, OptimizableOperatorSubTree subTree,
             AccessMethodAnalysisContext analysisCtx, IOptimizationContext context, boolean fromAdditionalDataSource)
             throws AlgebricksException {
+        MutableInt mutableFieldSource = new MutableInt(0);
         for (int varIndex = 0; varIndex < dsVarList.size(); varIndex++) {
             LogicalVariable var = dsVarList.get(varIndex);
             int funcVarIndex = optFuncExpr.findLogicalVar(var);
@@ -701,28 +716,39 @@ public abstract class AbstractIntroduceAccessMethodRule implements IAlgebraicRew
             List<String> fieldName = null;
             IAType fieldType = null;
             List<List<String>> subTreePKs = null;
+            mutableFieldSource.setValue(0);
 
             if (!fromAdditionalDataSource) {
-                subTreePKs = subTree.getDataset().getPrimaryKeys();
+                Dataset dataset = subTree.getDataset();
+                subTreePKs = dataset.getPrimaryKeys();
                 // Check whether this variable is PK, not a record variable.
                 if (varIndex <= subTreePKs.size() - 1) {
                     fieldName = subTreePKs.get(varIndex);
                     fieldType = (IAType) context.getOutputTypeEnvironment(subTree.getDataSourceRef().getValue())
                             .getVarType(var);
+                    List<Integer> keySourceIndicators = DatasetUtil.getKeySourceIndicators(dataset);
+                    if (keySourceIndicators != null) {
+                        mutableFieldSource.setValue(keySourceIndicators.get(varIndex));
+                    }
                 }
             } else {
                 // Need to check additional dataset one by one
                 for (int i = 0; i < subTree.getIxJoinOuterAdditionalDatasets().size(); i++) {
-                    if (subTree.getIxJoinOuterAdditionalDatasets().get(i) != null) {
-                        subTreePKs = subTree.getIxJoinOuterAdditionalDatasets().get(i).getPrimaryKeys();
-
+                    Dataset dataset = subTree.getIxJoinOuterAdditionalDatasets().get(i);
+                    if (dataset != null) {
+                        subTreePKs = dataset.getPrimaryKeys();
                         // Check whether this variable is PK, not a record variable.
+                        // TODO(ali): investigate why var (LogicalVariable) is looked up in subTreePKs (List<List<str>>)
                         if (subTreePKs.contains(var) && varIndex <= subTreePKs.size() - 1) {
                             fieldName = subTreePKs.get(varIndex);
                             fieldType = (IAType) context
                                     .getOutputTypeEnvironment(
                                             subTree.getIxJoinOuterAdditionalDataSourceRefs().get(i).getValue())
                                     .getVarType(var);
+                            List<Integer> keySourceIndicators = DatasetUtil.getKeySourceIndicators(dataset);
+                            if (keySourceIndicators != null) {
+                                mutableFieldSource.setValue(keySourceIndicators.get(varIndex));
+                            }
                             break;
                         }
                     }
@@ -730,7 +756,8 @@ public abstract class AbstractIntroduceAccessMethodRule implements IAlgebraicRew
             }
             // Set the fieldName in the corresponding matched function
             // expression, and remember matching subtree.
-            optFuncExpr.setFieldName(funcVarIndex, fieldName);
+            int fieldSource = mutableFieldSource.intValue();
+            optFuncExpr.setFieldName(funcVarIndex, fieldName, fieldSource);
             optFuncExpr.setOptimizableSubTree(funcVarIndex, subTree);
             optFuncExpr.setSourceVar(funcVarIndex, var);
             VariableReferenceExpression varRef = new VariableReferenceExpression(var);
@@ -739,7 +766,7 @@ public abstract class AbstractIntroduceAccessMethodRule implements IAlgebraicRew
             setTypeTag(context, subTree, optFuncExpr, funcVarIndex);
             if (subTree.hasDataSourceScan()) {
                 fillIndexExprs(datasetIndexes, fieldName, fieldType, optFuncExpr, optFuncExprIndex, funcVarIndex,
-                        subTree, analysisCtx);
+                        subTree, analysisCtx, fieldSource);
             }
         }
     }
@@ -761,7 +788,7 @@ public abstract class AbstractIntroduceAccessMethodRule implements IAlgebraicRew
      */
     protected List<String> getFieldNameFromSubTree(IOptimizableFuncExpr optFuncExpr, OptimizableOperatorSubTree subTree,
             int opIndex, int assignVarIndex, ARecordType recordType, int funcVarIndex,
-            ILogicalExpression parentFuncExpr, ARecordType metaType, LogicalVariable metaVar)
+            ILogicalExpression parentFuncExpr, ARecordType metaType, LogicalVariable metaVar, MutableInt fieldSource)
             throws AlgebricksException {
         // Get expression corresponding to opVar at varIndex.
         AbstractLogicalExpression expr = null;
@@ -830,6 +857,11 @@ public abstract class AbstractIntroduceAccessMethodRule implements IAlgebraicRew
         if (isFieldAccess) {
             LogicalVariable sourceVar =
                     ((VariableReferenceExpression) funcExpr.getArguments().get(0).getValue()).getVariableReference();
+            if (sourceVar.equals(metaVar)) {
+                fieldSource.setValue(1);
+            } else {
+                fieldSource.setValue(0);
+            }
             if (optFuncExpr != null) {
                 optFuncExpr.setLogicalExpr(funcVarIndex, parentFuncExpr);
             }
@@ -870,7 +902,7 @@ public abstract class AbstractIntroduceAccessMethodRule implements IAlgebraicRew
                 //Recursive call on nested assign
                 List<String> parentFieldNames = getFieldNameFromSubTree(optFuncExpr, subTree,
                         assignAndExpressionIndexes[0], assignAndExpressionIndexes[1], recordType, funcVarIndex,
-                        parentFuncExpr, metaType, metaVar);
+                        parentFuncExpr, metaType, metaVar, fieldSource);
 
                 if (parentFieldNames.isEmpty()) {
                     //Nested assign was not a field access.
@@ -946,7 +978,7 @@ public abstract class AbstractIntroduceAccessMethodRule implements IAlgebraicRew
                     if (var.equals(curVar) && optFuncExpr != null) {
                         optFuncExpr.setSourceVar(funcVarIndex, var);
                         return getFieldNameFromSubTree(optFuncExpr, subTree, assignOrUnnestIndex, varIndex, recordType,
-                                funcVarIndex, childFuncExpr, metaType, metaVar);
+                                funcVarIndex, childFuncExpr, metaType, metaVar, fieldSource);
                     }
                 }
             } else {
@@ -954,7 +986,7 @@ public abstract class AbstractIntroduceAccessMethodRule implements IAlgebraicRew
                 LogicalVariable var = unnestOp.getVariable();
                 if (var.equals(curVar)) {
                     getFieldNameFromSubTree(optFuncExpr, subTree, assignOrUnnestIndex, 0, recordType, funcVarIndex,
-                            childFuncExpr, metaType, metaVar);
+                            childFuncExpr, metaType, metaVar, fieldSource);
                 }
             }
         }
@@ -973,6 +1005,7 @@ public abstract class AbstractIntroduceAccessMethodRule implements IAlgebraicRew
                 datasetMetaVar = datasetVars.get(datasetVars.size() - 1);
             }
         }
+        MutableInt fieldSource = new MutableInt(0);
         for (int assignOrUnnestIndex = 0; assignOrUnnestIndex < subTree.getAssignsAndUnnests()
                 .size(); assignOrUnnestIndex++) {
             AbstractLogicalOperator op = subTree.getAssignsAndUnnests().get(assignOrUnnestIndex);
@@ -983,8 +1016,10 @@ public abstract class AbstractIntroduceAccessMethodRule implements IAlgebraicRew
                     LogicalVariable var = varList.get(varIndex);
                     // funcVarIndex is not required. Thus, we set it to -1.
                     // optFuncExpr and parentFuncExpr are not required, too. Thus, we set them to null.
+                    fieldSource.setValue(0);
                     List<String> fieldName = getFieldNameFromSubTree(null, subTree, assignOrUnnestIndex, varIndex,
-                            subTree.getRecordType(), -1, null, subTree.getMetaRecordType(), datasetMetaVar);
+                            subTree.getRecordType(), -1, null, subTree.getMetaRecordType(), datasetMetaVar,
+                            fieldSource);
                     if (fieldName != null && !fieldName.isEmpty()) {
                         subTree.getVarsToFieldNameMap().put(var, fieldName);
                     }
@@ -996,8 +1031,9 @@ public abstract class AbstractIntroduceAccessMethodRule implements IAlgebraicRew
                 if (subTree.getDataSourceType() != DataSourceType.COLLECTION_SCAN) {
                     // funcVarIndex is not required. Thus, we set it to -1.
                     // optFuncExpr and parentFuncExpr are not required, too. Thus, we set them to null.
+                    fieldSource.setValue(0);
                     fieldName = getFieldNameFromSubTree(null, subTree, assignOrUnnestIndex, 0, subTree.getRecordType(),
-                            -1, null, subTree.getMetaRecordType(), datasetMetaVar);
+                            -1, null, subTree.getMetaRecordType(), datasetMetaVar, fieldSource);
                     if (fieldName != null && !fieldName.isEmpty()) {
                         subTree.getVarsToFieldNameMap().put(var, fieldName);
                     }
@@ -1022,8 +1058,10 @@ public abstract class AbstractIntroduceAccessMethodRule implements IAlgebraicRew
                     LogicalVariable var = varList.get(varIndex);
                     // funcVarIndex is not required. Thus, we set it to -1.
                     // optFuncExpr and parentFuncExpr are not required, too. Thus, we set them to null.
+                    fieldSource.setValue(0);
                     List<String> fieldName = getFieldNameFromSubTree(null, subTree, assignOrUnnestIndex, varIndex,
-                            subTree.getRecordType(), -1, null, subTree.getMetaRecordType(), datasetMetaVar);
+                            subTree.getRecordType(), -1, null, subTree.getMetaRecordType(), datasetMetaVar,
+                            fieldSource);
                     if (fieldName != null && !fieldName.isEmpty()) {
                         subTree.getVarsToFieldNameMap().put(var, fieldName);
                     }
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/BTreeAccessMethod.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/BTreeAccessMethod.java
index b45e1c6..8845722 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/BTreeAccessMethod.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/BTreeAccessMethod.java
@@ -350,10 +350,12 @@ public class BTreeAccessMethod implements IAccessMethod {
         for (Pair<Integer, Integer> exprIndex : exprAndVarList) {
             // Position of the field of matchedFuncExprs.get(exprIndex) in the chosen index's indexed exprs.
             IOptimizableFuncExpr optFuncExpr = analysisCtx.getMatchedFuncExpr(exprIndex.first);
-            int keyPos = indexOf(optFuncExpr.getFieldName(0), chosenIndex.getKeyFieldNames());
+            int keyPos = indexOf(optFuncExpr.getFieldName(0), optFuncExpr.getFieldSource(0),
+                    chosenIndex.getKeyFieldNames(), chosenIndex.getKeyFieldSourceIndicators());
             if (keyPos < 0 && optFuncExpr.getNumLogicalVars() > 1) {
                 // If we are optimizing a join, the matching field may be the second field name.
-                keyPos = indexOf(optFuncExpr.getFieldName(1), chosenIndex.getKeyFieldNames());
+                keyPos = indexOf(optFuncExpr.getFieldName(1), optFuncExpr.getFieldSource(1),
+                        chosenIndex.getKeyFieldNames(), chosenIndex.getKeyFieldSourceIndicators());
             }
             if (keyPos < 0) {
                 throw CompilationException.create(ErrorCode.NO_INDEX_FIELD_NAME_FOR_GIVEN_FUNC_EXPR,
@@ -817,10 +819,11 @@ public class BTreeAccessMethod implements IAccessMethod {
         }
     }
 
-    private <T> int indexOf(T value, List<T> coll) {
+    private static int indexOf(List<String> fieldName, int fieldSource, List<List<String>> keyNames,
+            List<Integer> keySources) {
         int i = 0;
-        for (T member : coll) {
-            if (member.equals(value)) {
+        for (List<String> keyName : keyNames) {
+            if (keyName.equals(fieldName) && keyMatches(keySources, i, fieldSource)) {
                 return i;
             }
             i++;
@@ -828,6 +831,10 @@ public class BTreeAccessMethod implements IAccessMethod {
         return -1;
     }
 
+    private static boolean keyMatches(List<Integer> keySources, int keyIndex, int fieldSource) {
+        return keySources == null ? fieldSource == 0 : keySources.get(keyIndex) == fieldSource;
+    }
+
     private LimitType getLimitType(IOptimizableFuncExpr optFuncExpr, OptimizableOperatorSubTree probeSubTree) {
         ComparisonKind ck =
                 AlgebricksBuiltinFunctions.getComparisonType(optFuncExpr.getFuncExpr().getFunctionIdentifier());
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/IOptimizableFuncExpr.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/IOptimizableFuncExpr.java
index 05dc4a6..6278865 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/IOptimizableFuncExpr.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/IOptimizableFuncExpr.java
@@ -43,10 +43,12 @@ public interface IOptimizableFuncExpr {
 
     public ILogicalExpression getLogicalExpr(int index);
 
-    public void setFieldName(int index, List<String> fieldName);
+    public void setFieldName(int index, List<String> fieldName, int fieldSource);
 
     public List<String> getFieldName(int index);
 
+    public int getFieldSource(int index);
+
     public void setFieldType(int index, IAType fieldName);
 
     public IAType getFieldType(int index);
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/IntroduceLSMComponentFilterRule.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/IntroduceLSMComponentFilterRule.java
index 7739833..bfae365 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/IntroduceLSMComponentFilterRule.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/IntroduceLSMComponentFilterRule.java
@@ -117,7 +117,9 @@ public class IntroduceLSMComponentFilterRule implements IAlgebraicRewriteRule {
             for (int i = 0; i < analysisCtx.getMatchedFuncExprs().size(); i++) {
                 IOptimizableFuncExpr optFuncExpr = analysisCtx.getMatchedFuncExpr(i);
                 boolean found = findMacthedExprFieldName(optFuncExpr, op, dataset, recType, datasetIndexes, context);
-                if (found && optFuncExpr.getFieldName(0).equals(filterFieldName)) {
+                // the field name source should be from the dataset record, i.e. source should be == 0
+                if (found && optFuncExpr.getFieldName(0).equals(filterFieldName)
+                        && optFuncExpr.getFieldSource(0) == 0) {
                     optFuncExprs.add(optFuncExpr);
                 }
             }
@@ -500,12 +502,13 @@ public class IntroduceLSMComponentFilterRule implements IAlgebraicRewriteRule {
                     if (funcVarIndex == -1) {
                         continue;
                     }
+                    // TODO(ali): this SQ NPE should be investigated
                     List<String> fieldName =
                             getFieldNameFromSubAssignTree(optFuncExpr, descendantOp, varIndex, recType).second;
                     if (fieldName == null) {
                         return false;
                     }
-                    optFuncExpr.setFieldName(funcVarIndex, fieldName);
+                    optFuncExpr.setFieldName(funcVarIndex, fieldName, 0);
                     return true;
                 }
             } else if (descendantOp.getOperatorTag() == LogicalOperatorTag.DATASOURCESCAN) {
@@ -522,7 +525,9 @@ public class IntroduceLSMComponentFilterRule implements IAlgebraicRewriteRule {
                     if (fieldName == null) {
                         return false;
                     }
-                    optFuncExpr.setFieldName(funcVarIndex, fieldName);
+                    List<Integer> keySourceIndicators = DatasetUtil.getKeySourceIndicators(dataset);
+                    int keySource = getKeySource(keySourceIndicators, varIndex);
+                    optFuncExpr.setFieldName(funcVarIndex, fieldName, keySource);
                     return true;
                 }
             } else if (descendantOp.getOperatorTag() == LogicalOperatorTag.UNNEST_MAP) {
@@ -560,15 +565,19 @@ public class IntroduceLSMComponentFilterRule implements IAlgebraicRewriteRule {
                     ARecordType metaRecType = (ARecordType) metaItemType;
                     int numSecondaryKeys = KeyFieldTypeUtil.getNumSecondaryKeys(index, recType, metaRecType);
                     List<String> fieldName;
+                    int keySource;
                     if (varIndex >= numSecondaryKeys) {
-                        fieldName = dataset.getPrimaryKeys().get(varIndex - numSecondaryKeys);
+                        int idx = varIndex - numSecondaryKeys;
+                        fieldName = dataset.getPrimaryKeys().get(idx);
+                        keySource = getKeySource(DatasetUtil.getKeySourceIndicators(dataset), idx);
                     } else {
                         fieldName = index.getKeyFieldNames().get(varIndex);
+                        keySource = getKeySource(index.getKeyFieldSourceIndicators(), varIndex);
                     }
                     if (fieldName == null) {
                         return false;
                     }
-                    optFuncExpr.setFieldName(funcVarIndex, fieldName);
+                    optFuncExpr.setFieldName(funcVarIndex, fieldName, keySource);
                     return true;
                 }
             }
@@ -581,6 +590,10 @@ public class IntroduceLSMComponentFilterRule implements IAlgebraicRewriteRule {
         return false;
     }
 
+    private static int getKeySource(List<Integer> keySourceIndicators, int keyIdx) {
+        return keySourceIndicators == null ? 0 : keySourceIndicators.get(keyIdx);
+    }
+
     private Pair<ARecordType, List<String>> getFieldNameFromSubAssignTree(IOptimizableFuncExpr optFuncExpr,
             AbstractLogicalOperator op, int varIndex, ARecordType recType) {
         AbstractLogicalExpression expr = null;
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/OptimizableFuncExpr.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/OptimizableFuncExpr.java
index 1389f5e..7b04340 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/OptimizableFuncExpr.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/OptimizableFuncExpr.java
@@ -37,6 +37,7 @@ public class OptimizableFuncExpr implements IOptimizableFuncExpr {
     protected final LogicalVariable[] sourceVars;
     protected final ILogicalExpression[] logicalExprs;
     protected final List<List<String>> fieldNames;
+    protected final int[] fieldSources;
     protected final IAType[] fieldTypes;
     protected final OptimizableOperatorSubTree[] subTrees;
     protected final ILogicalExpression[] constantExpressions;
@@ -51,6 +52,7 @@ public class OptimizableFuncExpr implements IOptimizableFuncExpr {
         this.logicalExprs = new ILogicalExpression[logicalVars.length];
         this.constantExpressionTypes = constantExpressionTypes;
         this.constantExpressions = constantExpressions;
+        this.fieldSources = new int[logicalVars.length];
         this.fieldNames = new ArrayList<List<String>>();
         for (int i = 0; i < logicalVars.length; i++) {
             fieldNames.add(new ArrayList<String>());
@@ -74,6 +76,7 @@ public class OptimizableFuncExpr implements IOptimizableFuncExpr {
         this.logicalExprs = new ILogicalExpression[1];
         this.constantExpressions = new ILogicalExpression[] { constantExpression };
         this.constantExpressionTypes = new IAType[] { constantExpressionType };
+        this.fieldSources = new int[logicalVars.length];
         this.fieldNames = new ArrayList<List<String>>();
         for (int i = 0; i < logicalVars.length; i++) {
             fieldNames.add(new ArrayList<String>());
@@ -118,8 +121,9 @@ public class OptimizableFuncExpr implements IOptimizableFuncExpr {
     }
 
     @Override
-    public void setFieldName(int index, List<String> fieldName) {
+    public void setFieldName(int index, List<String> fieldName, int fieldSource) {
         fieldNames.set(index, fieldName);
+        fieldSources[index] = fieldSource;
     }
 
     @Override
@@ -128,6 +132,11 @@ public class OptimizableFuncExpr implements IOptimizableFuncExpr {
     }
 
     @Override
+    public int getFieldSource(int index) {
+        return fieldSources[index];
+    }
+
+    @Override
     public void setFieldType(int index, IAType fieldType) {
         fieldTypes[index] = fieldType;
     }
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/OptimizableOperatorSubTree.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/OptimizableOperatorSubTree.java
index 9673da3..578b516 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/OptimizableOperatorSubTree.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/OptimizableOperatorSubTree.java
@@ -80,6 +80,7 @@ public class OptimizableOperatorSubTree {
     private ARecordType metaRecordType = null;
     // Contains the field names for all assign operations in this sub-tree.
     // This will be used for the index-only plan check.
+    // TODO(ali): this map should be fixed to include the source of the field (dataset record or meta record)
     private Map<LogicalVariable, List<String>> varsToFieldNameMap = new HashMap<>();
 
     // Additional datasources can exist if IntroduceJoinAccessMethodRule has been applied.
diff --git a/asterixdb/asterix-app/data/csv/people.csv b/asterixdb/asterix-app/data/csv/people.csv
new file mode 100644
index 0000000..9b009ac
--- /dev/null
+++ b/asterixdb/asterix-app/data/csv/people.csv
@@ -0,0 +1,9 @@
+76041664,"{""id"":1, ""name"":""John Mad"", ""age"":29, ""hobby"":""reading""}"
+52037425,"{""id"":2, ""name"":""Scott Scott"", ""age"":30, ""hobby"":""hiking""}"
+45962603,"{""id"":3, ""name"":""Dan David"", ""age"":40, ""hobby"":""bowling""}"
+51041435,"{""id"":4, ""name"":""Robert Moore"", ""age"":32, ""hobby"":""reading""}"
+39225791,"{""id"":5, ""name"":""Sandy Donald"", ""age"":35, ""hobby"":""soccer""}"
+13071782,"{""id"":6, ""name"":""Joe Dana"", ""age"":24, ""hobby"":""tennis""}"
+26237702,"{""id"":7, ""name"":""Watson Jordon"", ""age"":28, ""hobby"":""basketball""}"
+32571888,"{""id"":8, ""name"":""Mat Steve"", ""age"":45, ""hobby"":""tennis""}"
+86897761,"{""id"":9, ""name"":""Sandra Pec"", ""age"":36, ""hobby"":""hiking""}"
\ No newline at end of file
diff --git a/asterixdb/asterix-app/data/csv/people3.csv b/asterixdb/asterix-app/data/csv/people3.csv
new file mode 100644
index 0000000..817b4a6
--- /dev/null
+++ b/asterixdb/asterix-app/data/csv/people3.csv
@@ -0,0 +1,9 @@
+76041664,"{""id"":""1"", ""name"":""John Mad"", ""age"":29, ""hobby"":""reading""}"
+52037425,"{""id"":""2"", ""name"":""Scott Scott"", ""age"":30, ""hobby"":""hiking""}"
+45962603,"{""id"":""3"", ""name"":""Dan David"", ""age"":40, ""hobby"":""bowling""}"
+51041435,"{""id"":""4"", ""name"":""Robert Moore"", ""age"":32, ""hobby"":""reading""}"
+7,"{""id"":""5"", ""name"":""Sandy Donald"", ""age"":35, ""hobby"":""soccer""}"
+13071782,"{""id"":""6"", ""name"":""Joe Dana"", ""age"":24, ""hobby"":""tennis""}"
+5,"{""id"":""7"", ""name"":""Watson Jordon"", ""age"":28, ""hobby"":""basketball""}"
+32571888,"{""id"":""8"", ""name"":""Mat Steve"", ""age"":45, ""hobby"":""tennis""}"
+86897761,"{""id"":""9"", ""name"":""Sandra Pec"", ""age"":36, ""hobby"":""hiking""}"
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/field_access_with_data_and_meta_1.sqlpp b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/field_access_with_data_and_meta_1.sqlpp
new file mode 100644
index 0000000..2c7a94e
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/field_access_with_data_and_meta_1.sqlpp
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * Description: tests that meta().id isn't resolved as PK when the primary key happens to have the same name as the meta.
+ *              Data scan happens.
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+create type MetaType as open {
+  id:int32
+};
+
+create type DataType as open {
+  id:int32,
+  text: string
+};
+
+create dataset ds(DataType) with meta(MetaType) primary key id;
+create primary index on ds;
+
+select count(meta().id) from ds;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/field_access_with_data_and_meta_2.sqlpp b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/field_access_with_data_and_meta_2.sqlpp
new file mode 100644
index 0000000..74d39ea
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/field_access_with_data_and_meta_2.sqlpp
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * Description: tests that primary key access is resolved correctly in the presence of meta having the same field name.
+ *              Primary index is used
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+create type MetaType as open {
+  id:int32
+};
+
+create type DataType as open {
+  id:int32,
+  text: string
+};
+
+create dataset ds(DataType) with meta(MetaType) primary key id;
+create primary index on ds;
+
+select count(id) from ds;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/field_access_with_data_and_meta_3.sqlpp b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/field_access_with_data_and_meta_3.sqlpp
new file mode 100644
index 0000000..453f5b1
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/field_access_with_data_and_meta_3.sqlpp
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * Description: tests that meta().id is resolved correctly as PK in the presence of a data record field having the same name.
+ *              Primary index is used.
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+create type MetaType as open {
+  id:int32
+};
+
+create type DataType as open {
+  id:int32,
+  text: string
+};
+
+create dataset ds(DataType) with meta(MetaType) primary key meta().id;
+create primary index on ds;
+
+select count(meta().id) from ds;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/field_access_with_data_and_meta_4.sqlpp b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/field_access_with_data_and_meta_4.sqlpp
new file mode 100644
index 0000000..722cc4d
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/field_access_with_data_and_meta_4.sqlpp
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * Description: tests that id isn't resolved as PK when the PK is coming from the meta record having the same name.
+ *              Data scan happens.
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+create type MetaType as open {
+  id:int32
+};
+
+create type DataType as open {
+  id:int32,
+  text: string
+};
+
+create dataset ds(DataType) with meta(MetaType) primary key meta().id;
+create primary index on ds;
+
+select count(id) from ds;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_01.sqlpp b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_01.sqlpp
new file mode 100644
index 0000000..7955726
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_01.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.
+ */
+
+/*
+ * Description  : Testing that data scan is used (no primary index is used)
+ * Expected Res : Success
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+create type DataType as open {
+id:string,
+name:string,
+age:int,
+hobby:string
+};
+
+create type MetaType as closed {
+id:string
+};
+
+create dataset DS1(DataType) with meta(MetaType) primary key meta().id;
+
+// DS1 primary index is on meta().id
+select * from DS1
+where id = "2";
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_02.sqlpp b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_02.sqlpp
new file mode 100644
index 0000000..398c028
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_02.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.
+ */
+
+/*
+ * Description  : Testing that primary index is used
+ * Expected Res : Success
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+create type DataType as open {
+id:string,
+name:string,
+age:int,
+hobby:string
+};
+
+create type MetaType as closed {
+id:string
+};
+
+create dataset DS1(DataType) with meta(MetaType) primary key meta().id;
+
+// DS1 primary index is on meta().id
+select * from DS1
+where meta().id = "5";
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_03.sqlpp b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_03.sqlpp
new file mode 100644
index 0000000..a701d86
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_03.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.
+ */
+
+/*
+ * Description  : Testing that primary index is used
+ * Expected Res : Success
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+create type DataType as open {
+id:string,
+name:string,
+age:int,
+hobby:string
+};
+
+create type MetaType as closed {
+id:string
+};
+
+create dataset DS2(DataType) with meta(MetaType) primary key id;
+
+// DS2 primary index is on id
+select * from DS2
+where id = "2";
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_04.sqlpp b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_04.sqlpp
new file mode 100644
index 0000000..a63697a
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_04.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.
+ */
+
+/*
+ * Description  : Testing that data scan is used
+ * Expected Res : Success
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+create type DataType as open {
+id:string,
+name:string,
+age:int,
+hobby:string
+};
+
+create type MetaType as closed {
+id:string
+};
+
+create dataset DS2(DataType) with meta(MetaType) primary key id;
+
+// DS2 primary index is on id
+select * from DS2
+where meta().id = "5";
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_05.sqlpp b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_05.sqlpp
new file mode 100644
index 0000000..67d016e
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_05.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * Description  : Testing that data scan is used
+ * Expected Res : Success
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+create type DataType as open {
+id:string,
+name:string,
+age:int,
+hobby:string
+};
+
+create type MetaType as closed {
+id:string
+};
+
+create dataset DS1(DataType) with meta(MetaType) primary key meta().id;
+create dataset DS2(DataType) with meta(MetaType) primary key id;
+
+// DS2 primary index is on id. DS1 primary index is on meta().id
+use test;
+
+from DS2 as ds2 join DS1 as ds1 on ds2.id /*+ indexnl */ = ds1.id
+select ds2, ds1
+order by ds2.id;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_06.sqlpp b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_06.sqlpp
new file mode 100644
index 0000000..8a72f86
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_06.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * Description  : Testing that primary index of DS1 is used
+ * Expected Res : Success
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+create type DataType as open {
+id:string,
+name:string,
+age:int,
+hobby:string
+};
+
+create type MetaType as closed {
+id:string
+};
+
+create dataset DS1(DataType) with meta(MetaType) primary key meta().id;
+create dataset DS2(DataType) with meta(MetaType) primary key id;
+
+// DS2 primary index is on id. DS1 primary index is on meta().id
+use test;
+
+from DS2 as ds2 join DS1 as ds1 on ds2.id /*+ indexnl */ = meta(ds1).id
+select meta(ds1).id as ds1_meta_id, ds2, ds1
+order by ds2.id;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_07.sqlpp b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_07.sqlpp
new file mode 100644
index 0000000..9753c9c
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_07.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * Description  : Testing that primary index of DS2 is used
+ * Expected Res : Success
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+create type DataType as open {
+id:string,
+name:string,
+age:int,
+hobby:string
+};
+
+create type MetaType as closed {
+id:string
+};
+
+create dataset DS1(DataType) with meta(MetaType) primary key meta().id;
+create dataset DS2(DataType) with meta(MetaType) primary key id;
+
+// DS2 primary index is on id. DS1 primary index is on meta().id
+use test;
+
+from DS1 as ds1 join DS2 as ds2 on ds1.id /*+ indexnl */ = ds2.id
+select ds1, ds2
+order by ds2.id;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_08.sqlpp b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_08.sqlpp
new file mode 100644
index 0000000..5540b38
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_08.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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  : Testing that secondary index is used
+ * Expected Res : Success
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+create type DataType as open {
+id:string,
+name:string,
+age:int,
+hobby:string
+};
+
+create type MetaType as closed {
+id:string
+};
+
+create dataset DS1(DataType) with meta(MetaType) primary key meta().id;
+create index id_sec_idx on DS1(id);
+
+// DS1 primary index is on meta().id & now has a secondary index on id
+
+select * from DS1
+where id = "2";
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_09.sqlpp b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_09.sqlpp
new file mode 100644
index 0000000..27b69db
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_09.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * Description  : Testing that primary index is used
+ * Expected Res : Success
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+create type DataType as open {
+id:string,
+name:string,
+age:int,
+hobby:string
+};
+
+create type MetaType as closed {
+id:string
+};
+
+create dataset DS1(DataType) with meta(MetaType) primary key meta().id;
+create index id_sec_idx on DS1(id);
+
+// DS1 primary index is on meta().id & now has a secondary index on id
+select * from DS1
+where meta().id = "5";
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_10.sqlpp b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_10.sqlpp
new file mode 100644
index 0000000..68cee62
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_10.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * Description  : Testing that secondary index of DS1 is used
+ * Expected Res : Success
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+create type DataType as open {
+id:string,
+name:string,
+age:int,
+hobby:string
+};
+
+create type MetaType as closed {
+id:string
+};
+
+create dataset DS1(DataType) with meta(MetaType) primary key meta().id;
+create dataset DS2(DataType) with meta(MetaType) primary key id;
+create index id_sec_idx on DS1(id);
+
+// DS1 primary index is on meta().id & now has a secondary index on id. DS2 primary index is on id
+from DS2 as ds2 join DS1 as ds1 on ds2.id /*+ indexnl */ = ds1.id
+select ds2, ds1
+order by ds2.id;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_11.sqlpp b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_11.sqlpp
new file mode 100644
index 0000000..d5b922a
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/indexes_on_dataset_with_meta_11.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * Description  : Testing that primary index of DS1 is used
+ * Expected Res : Success
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+create type DataType as open {
+id:string,
+name:string,
+age:int,
+hobby:string
+};
+
+create type MetaType as closed {
+id:string
+};
+
+create dataset DS1(DataType) with meta(MetaType) primary key meta().id;
+create dataset DS2(DataType) with meta(MetaType) primary key id;
+create index id_sec_idx on DS1(id);
+
+// DS1 primary index is on meta().id & now has a secondary index on id. DS2 primary index is on id
+from DS2 as ds2 join DS1 as ds1 on ds2.id /*+ indexnl */ = meta(ds1).id
+select meta(ds1).id as ds1_meta_id, ds2, ds1
+order by ds2.id;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/with_clause_meta.sqlpp b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/with_clause_meta.sqlpp
new file mode 100644
index 0000000..dc94800
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/meta/with_clause_meta.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * Description: tests that meta().id is resolved as PK when used in WITH clause.
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+create type MetaType as open {
+  id:string
+};
+
+create type DataType as open {
+  id:int32,
+  text: string
+};
+
+create dataset ds(DataType) with meta(MetaType) primary key id;
+
+with raw_data as (
+  select meta(a).id as aid, age as age
+  from ds a
+  where hobby in ["tennis", "reading", "hiking", "soccer"] )
+
+select t2.raw_data.age, t2.raw_data.aid, array_count(t1) total
+from (select value g from raw_data group by series group as g) as t1 unnest t1 as t2
+order by aid
+limit 5;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/field_access_with_data_and_meta_1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/field_access_with_data_and_meta_1.plan
new file mode 100644
index 0000000..000f2f0
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/field_access_with_data_and_meta_1.plan
@@ -0,0 +1,14 @@
+-- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    -- STREAM_PROJECT  |UNPARTITIONED|
+      -- ASSIGN  |UNPARTITIONED|
+        -- AGGREGATE  |UNPARTITIONED|
+          -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            -- AGGREGATE  |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|
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/field_access_with_data_and_meta_2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/field_access_with_data_and_meta_2.plan
new file mode 100644
index 0000000..efb6c63
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/field_access_with_data_and_meta_2.plan
@@ -0,0 +1,11 @@
+-- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    -- STREAM_PROJECT  |UNPARTITIONED|
+      -- ASSIGN  |UNPARTITIONED|
+        -- AGGREGATE  |UNPARTITIONED|
+          -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            -- AGGREGATE  |PARTITIONED|
+              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                -- BTREE_SEARCH  |PARTITIONED|
+                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/field_access_with_data_and_meta_3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/field_access_with_data_and_meta_3.plan
new file mode 100644
index 0000000..efb6c63
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/field_access_with_data_and_meta_3.plan
@@ -0,0 +1,11 @@
+-- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    -- STREAM_PROJECT  |UNPARTITIONED|
+      -- ASSIGN  |UNPARTITIONED|
+        -- AGGREGATE  |UNPARTITIONED|
+          -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            -- AGGREGATE  |PARTITIONED|
+              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                -- BTREE_SEARCH  |PARTITIONED|
+                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/field_access_with_data_and_meta_4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/field_access_with_data_and_meta_4.plan
new file mode 100644
index 0000000..000f2f0
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/field_access_with_data_and_meta_4.plan
@@ -0,0 +1,14 @@
+-- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    -- STREAM_PROJECT  |UNPARTITIONED|
+      -- ASSIGN  |UNPARTITIONED|
+        -- AGGREGATE  |UNPARTITIONED|
+          -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            -- AGGREGATE  |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|
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_01.plan
new file mode 100644
index 0000000..5df1890
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_01.plan
@@ -0,0 +1,10 @@
+-- DISTRIBUTE_RESULT  |PARTITIONED|
+  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    -- STREAM_PROJECT  |PARTITIONED|
+      -- ASSIGN  |PARTITIONED|
+        -- STREAM_SELECT  |PARTITIONED|
+          -- STREAM_PROJECT  |PARTITIONED|
+            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              -- DATASOURCE_SCAN  |PARTITIONED|
+                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_02.plan
new file mode 100644
index 0000000..fec009a
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_02.plan
@@ -0,0 +1,10 @@
+-- DISTRIBUTE_RESULT  |PARTITIONED|
+  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    -- STREAM_PROJECT  |PARTITIONED|
+      -- ASSIGN  |PARTITIONED|
+        -- STREAM_PROJECT  |PARTITIONED|
+          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            -- BTREE_SEARCH  |PARTITIONED|
+              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                -- ASSIGN  |PARTITIONED|
+                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_03.plan
new file mode 100644
index 0000000..fec009a
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_03.plan
@@ -0,0 +1,10 @@
+-- DISTRIBUTE_RESULT  |PARTITIONED|
+  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    -- STREAM_PROJECT  |PARTITIONED|
+      -- ASSIGN  |PARTITIONED|
+        -- STREAM_PROJECT  |PARTITIONED|
+          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            -- BTREE_SEARCH  |PARTITIONED|
+              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                -- ASSIGN  |PARTITIONED|
+                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_04.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_04.plan
new file mode 100644
index 0000000..1a11a0c
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_04.plan
@@ -0,0 +1,11 @@
+-- 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|
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_05.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_05.plan
new file mode 100644
index 0000000..83d3362
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_05.plan
@@ -0,0 +1,24 @@
+-- DISTRIBUTE_RESULT  |PARTITIONED|
+  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    -- STREAM_PROJECT  |PARTITIONED|
+      -- ASSIGN  |PARTITIONED|
+        -- STREAM_PROJECT  |PARTITIONED|
+          -- SORT_MERGE_EXCHANGE [$$25(ASC) ]  |PARTITIONED|
+            -- STABLE_SORT [$$25(ASC)]  |PARTITIONED|
+              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                -- STREAM_PROJECT  |PARTITIONED|
+                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    -- HYBRID_HASH_JOIN [$$25][$$30]  |PARTITIONED|
+                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        -- STREAM_PROJECT  |PARTITIONED|
+                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                      -- HASH_PARTITION_EXCHANGE [$$30]  |PARTITIONED|
+                        -- ASSIGN  |PARTITIONED|
+                          -- STREAM_PROJECT  |PARTITIONED|
+                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_06.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_06.plan
new file mode 100644
index 0000000..2273bfd
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_06.plan
@@ -0,0 +1,17 @@
+-- DISTRIBUTE_RESULT  |PARTITIONED|
+  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    -- STREAM_PROJECT  |PARTITIONED|
+      -- ASSIGN  |PARTITIONED|
+        -- STREAM_PROJECT  |PARTITIONED|
+          -- SORT_MERGE_EXCHANGE [$$29(ASC) ]  |PARTITIONED|
+            -- STABLE_SORT [$$29(ASC)]  |PARTITIONED|
+              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                -- STREAM_PROJECT  |PARTITIONED|
+                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    -- BTREE_SEARCH  |PARTITIONED|
+                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        -- STREAM_PROJECT  |PARTITIONED|
+                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_07.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_07.plan
new file mode 100644
index 0000000..6e0b4cd
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_07.plan
@@ -0,0 +1,18 @@
+-- DISTRIBUTE_RESULT  |PARTITIONED|
+  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    -- STREAM_PROJECT  |PARTITIONED|
+      -- ASSIGN  |PARTITIONED|
+        -- STREAM_PROJECT  |PARTITIONED|
+          -- SORT_MERGE_EXCHANGE [$$27(ASC) ]  |PARTITIONED|
+            -- STREAM_PROJECT  |PARTITIONED|
+              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                -- BTREE_SEARCH  |PARTITIONED|
+                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    -- STABLE_SORT [$$29(ASC)]  |PARTITIONED|
+                      -- HASH_PARTITION_EXCHANGE [$$29]  |PARTITIONED|
+                        -- ASSIGN  |PARTITIONED|
+                          -- STREAM_PROJECT  |PARTITIONED|
+                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_08.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_08.plan
new file mode 100644
index 0000000..04dcc66
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_08.plan
@@ -0,0 +1,17 @@
+-- DISTRIBUTE_RESULT  |PARTITIONED|
+  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    -- STREAM_PROJECT  |PARTITIONED|
+      -- ASSIGN  |PARTITIONED|
+        -- STREAM_SELECT  |PARTITIONED|
+          -- STREAM_PROJECT  |PARTITIONED|
+            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              -- BTREE_SEARCH  |PARTITIONED|
+                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  -- STABLE_SORT [$$20(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|
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_09.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_09.plan
new file mode 100644
index 0000000..fec009a
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_09.plan
@@ -0,0 +1,10 @@
+-- DISTRIBUTE_RESULT  |PARTITIONED|
+  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    -- STREAM_PROJECT  |PARTITIONED|
+      -- ASSIGN  |PARTITIONED|
+        -- STREAM_PROJECT  |PARTITIONED|
+          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            -- BTREE_SEARCH  |PARTITIONED|
+              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                -- ASSIGN  |PARTITIONED|
+                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_10.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_10.plan
new file mode 100644
index 0000000..b518b83
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_10.plan
@@ -0,0 +1,24 @@
+-- DISTRIBUTE_RESULT  |PARTITIONED|
+  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    -- STREAM_PROJECT  |PARTITIONED|
+      -- ASSIGN  |PARTITIONED|
+        -- STREAM_PROJECT  |PARTITIONED|
+          -- SORT_MERGE_EXCHANGE [$$25(ASC) ]  |PARTITIONED|
+            -- STABLE_SORT [$$25(ASC)]  |PARTITIONED|
+              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                -- STREAM_SELECT  |PARTITIONED|
+                  -- STREAM_PROJECT  |PARTITIONED|
+                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          -- STABLE_SORT [$$33(ASC)]  |PARTITIONED|
+                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              -- STREAM_PROJECT  |PARTITIONED|
+                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                      -- STREAM_PROJECT  |PARTITIONED|
+                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_11.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_11.plan
new file mode 100644
index 0000000..2273bfd
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_11.plan
@@ -0,0 +1,17 @@
+-- DISTRIBUTE_RESULT  |PARTITIONED|
+  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    -- STREAM_PROJECT  |PARTITIONED|
+      -- ASSIGN  |PARTITIONED|
+        -- STREAM_PROJECT  |PARTITIONED|
+          -- SORT_MERGE_EXCHANGE [$$29(ASC) ]  |PARTITIONED|
+            -- STABLE_SORT [$$29(ASC)]  |PARTITIONED|
+              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                -- STREAM_PROJECT  |PARTITIONED|
+                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    -- BTREE_SEARCH  |PARTITIONED|
+                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        -- STREAM_PROJECT  |PARTITIONED|
+                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/with_clause_meta.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/with_clause_meta.plan
new file mode 100644
index 0000000..ae0fb17
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/with_clause_meta.plan
@@ -0,0 +1,44 @@
+-- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    -- STREAM_LIMIT  |UNPARTITIONED|
+      -- STREAM_PROJECT  |PARTITIONED|
+        -- ASSIGN  |PARTITIONED|
+          -- SORT_MERGE_EXCHANGE [$#1(ASC) ]  |PARTITIONED|
+            -- STREAM_LIMIT  |PARTITIONED|
+              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                -- STABLE_SORT [topK: 5] [$#1(ASC)]  |PARTITIONED|
+                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    -- STREAM_PROJECT  |PARTITIONED|
+                      -- ASSIGN  |PARTITIONED|
+                        -- STREAM_PROJECT  |PARTITIONED|
+                          -- ASSIGN  |PARTITIONED|
+                            -- STREAM_PROJECT  |PARTITIONED|
+                              -- UNNEST  |PARTITIONED|
+                                -- STREAM_PROJECT  |PARTITIONED|
+                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    -- PRE_CLUSTERED_GROUP_BY[$$95]  |PARTITIONED|
+                                            {
+                                              -- AGGREGATE  |LOCAL|
+                                                -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                            }
+                                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        -- STABLE_SORT [$$95(ASC)]  |PARTITIONED|
+                                          -- HASH_PARTITION_EXCHANGE [$$95]  |PARTITIONED|
+                                            -- STREAM_PROJECT  |PARTITIONED|
+                                              -- ASSIGN  |PARTITIONED|
+                                                -- STREAM_PROJECT  |PARTITIONED|
+                                                  -- ASSIGN  |PARTITIONED|
+                                                    -- STREAM_PROJECT  |PARTITIONED|
+                                                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        -- HYBRID_HASH_JOIN [$$76][$$99]  |PARTITIONED|
+                                                          -- ONE_TO_ONE_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|
+                                                            -- UNNEST  |UNPARTITIONED|
+                                                              -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.01.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.01.ddl.sqlpp
new file mode 100644
index 0000000..ae60888
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.01.ddl.sqlpp
@@ -0,0 +1,68 @@
+/*
+ * 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 DataType as open {
+id:string,
+name:string,
+age:int,
+hobby:string
+};
+
+create type MetaType as closed {
+id:string
+};
+
+create dataset DS1(DataType) with meta(MetaType) primary key meta().id;
+create dataset DS2(DataType) with meta(MetaType) primary key id;
+
+create feed DsStream1 with {
+ "adapter-name" : "localfs",
+ "reader" : "localfs",
+ "parser" : "record-with-metadata",
+ "type-name" : "DataType",
+ "meta-type-name" : "MetaType",
+ "path" : "asterix_nc1://data/csv/people3.csv",
+ "format" : "csv",
+ "delimiter" : ",",
+ "record-format" : "adm",
+ "record-index" : "1",
+ "key-indexes" : "0",
+ "key-indicators" : "1",
+ "header" : "false"
+};
+
+create feed DsStream2 with {
+ "adapter-name" : "localfs",
+ "reader" : "localfs",
+ "parser" : "record-with-metadata",
+ "type-name" : "DataType",
+ "meta-type-name" : "MetaType",
+ "path" : "asterix_nc1://data/csv/people3.csv",
+ "format" : "csv",
+ "delimiter" : ",",
+ "record-format" : "adm",
+ "record-index" : "1",
+ "key-indexes" : "0",
+ "key-indicators" : "0",
+ "header" : "false"
+};
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.02.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.02.update.sqlpp
new file mode 100644
index 0000000..3174cc5
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.02.update.sqlpp
@@ -0,0 +1,27 @@
+/*
+ * 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;
+
+set `wait-for-completion-feed` "true";
+connect feed DsStream1 to dataset DS1;
+start feed DsStream1;
+
+connect feed DsStream2 to dataset DS2;
+start feed DsStream2;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.03.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.03.query.sqlpp
new file mode 100644
index 0000000..39e3707
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.03.query.sqlpp
@@ -0,0 +1,29 @@
+/*
+ * 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  : Testing that data scan is used (no primary index is used)
+ * Expected Res : Success
+ */
+
+// DS1 primary index is on meta().id
+use test;
+
+select * from DS1
+where id = "2";
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.04.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.04.query.sqlpp
new file mode 100644
index 0000000..cb87da7
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.04.query.sqlpp
@@ -0,0 +1,29 @@
+/*
+ * 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  : Testing that primary index is used
+ * Expected Res : Success
+ */
+
+// DS1 primary index is on meta().id
+use test;
+
+select * from DS1
+where meta().id = "5";
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.05.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.05.query.sqlpp
new file mode 100644
index 0000000..55a2cee
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.05.query.sqlpp
@@ -0,0 +1,29 @@
+/*
+ * 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  : Testing that primary index is used
+ * Expected Res : Success
+ */
+
+// DS2 primary index is on id
+use test;
+
+select * from DS2
+where id = "2";
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.06.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.06.query.sqlpp
new file mode 100644
index 0000000..2b1b11d
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.06.query.sqlpp
@@ -0,0 +1,29 @@
+/*
+ * 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  : Testing that data scan is used
+ * Expected Res : Success
+ */
+
+// DS2 primary index is on id
+use test;
+
+select * from DS2
+where meta().id = "5";
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.07.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.07.query.sqlpp
new file mode 100644
index 0000000..22ba5b2
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.07.query.sqlpp
@@ -0,0 +1,30 @@
+/*
+ * 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  : Testing that data scan is used
+ * Expected Res : Success
+ */
+
+// DS2 primary index is on id. DS1 primary index is on meta().id
+use test;
+
+from DS2 as ds2 join DS1 as ds1 on ds2.id /*+ indexnl */ = ds1.id
+select ds2, ds1
+order by ds2.id;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.08.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.08.query.sqlpp
new file mode 100644
index 0000000..4b85cf9
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.08.query.sqlpp
@@ -0,0 +1,30 @@
+/*
+ * 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  : Testing that primary index of DS1 is used
+ * Expected Res : Success
+ */
+
+// DS2 primary index is on id. DS1 primary index is on meta().id
+use test;
+
+from DS2 as ds2 join DS1 as ds1 on ds2.id /*+ indexnl */ = meta(ds1).id
+select meta(ds1).id as ds1_meta_id, ds2, ds1
+order by ds2.id;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.09.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.09.query.sqlpp
new file mode 100644
index 0000000..0c4c744
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.09.query.sqlpp
@@ -0,0 +1,30 @@
+/*
+ * 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  : Testing that primary index of DS2 is used
+ * Expected Res : Success
+ */
+
+// DS2 primary index is on id. DS1 primary index is on meta().id
+use test;
+
+from DS1 as ds1 join DS2 as ds2 on ds1.id /*+ indexnl */ = ds2.id
+select ds1, ds2
+order by ds2.id;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.10.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.10.ddl.sqlpp
new file mode 100644
index 0000000..204dfd9
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.10.ddl.sqlpp
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use test;
+
+create index id_sec_idx on DS1(id);
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.11.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.11.query.sqlpp
new file mode 100644
index 0000000..bc12e9c
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.11.query.sqlpp
@@ -0,0 +1,29 @@
+/*
+ * 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  : Testing that secondary index is used
+ * Expected Res : Success
+ */
+
+// DS1 primary index is on meta().id & now has a secondary index on id
+use test;
+
+select * from DS1
+where id = "2";
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.12.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.12.query.sqlpp
new file mode 100644
index 0000000..e14e8ba
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.12.query.sqlpp
@@ -0,0 +1,29 @@
+/*
+ * 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  : Testing that primary index is used
+ * Expected Res : Success
+ */
+
+// DS1 primary index is on meta().id & now has a secondary index on id
+use test;
+
+select * from DS1
+where meta().id = "5";
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.13.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.13.query.sqlpp
new file mode 100644
index 0000000..07f96c2
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.13.query.sqlpp
@@ -0,0 +1,30 @@
+/*
+ * 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  : Testing that secondary index of DS1 is used
+ * Expected Res : Success
+ */
+
+// DS1 primary index is on meta().id & now has a secondary index on id. DS2 primary index is on id
+use test;
+
+from DS2 as ds2 join DS1 as ds1 on ds2.id /*+ indexnl */ = ds1.id
+select ds2, ds1
+order by ds2.id;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.14.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.14.query.sqlpp
new file mode 100644
index 0000000..f1e3c7c
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.14.query.sqlpp
@@ -0,0 +1,30 @@
+/*
+ * 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  : Testing that primary index of DS1 is used
+ * Expected Res : Success
+ */
+
+// DS1 primary index is on meta().id & now has a secondary index on id. DS2 primary index is on id
+use test;
+
+from DS2 as ds2 join DS1 as ds1 on ds2.id /*+ indexnl */ = meta(ds1).id
+select meta(ds1).id as ds1_meta_id, ds2, ds1
+order by ds2.id;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.15.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.15.ddl.sqlpp
new file mode 100644
index 0000000..548e632
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/dataset-with-meta/dataset-with-meta.15.ddl.sqlpp
@@ -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.
+ */
+
+drop dataverse test if exists;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/meta_in_with_clause/meta_in_with_clause.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/meta_in_with_clause/meta_in_with_clause.1.ddl.sqlpp
new file mode 100644
index 0000000..e722f40
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/meta_in_with_clause/meta_in_with_clause.1.ddl.sqlpp
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+ /*
+  * Description: tests that meta() used in WITH clause is resolved correctly and produces a correct result
+  */
+
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+create type DataType as open {
+id:int,
+name:string,
+age:int,
+hobby:string
+};
+
+create type MetaType as closed {
+id:int
+};
+
+create dataset DS(DataType) with meta(MetaType) primary key meta().id;
+create dataset DS2(DataType) with meta(MetaType) primary key id;
+
+create feed DsStream with {
+ "adapter-name" : "localfs",
+ "reader" : "localfs",
+ "parser" : "record-with-metadata",
+ "type-name" : "DataType",
+ "meta-type-name" : "MetaType",
+ "path" : "asterix_nc1://data/csv/people.csv",
+ "format" : "csv",
+ "delimiter" : ",",
+ "record-format" : "adm",
+ "record-index" : "1",
+ "key-indexes" : "0",
+ "key-indicators" : "1",
+ "header" : "false"
+};
+
+create feed DsStream2 with {
+ "adapter-name" : "localfs",
+ "reader" : "localfs",
+ "parser" : "record-with-metadata",
+ "type-name" : "DataType",
+ "meta-type-name" : "MetaType",
+ "path" : "asterix_nc1://data/csv/people.csv",
+ "format" : "csv",
+ "delimiter" : ",",
+ "record-format" : "adm",
+ "record-index" : "1",
+ "key-indexes" : "0",
+ "key-indicators" : "0",
+ "header" : "false"
+};
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/meta_in_with_clause/meta_in_with_clause.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/meta_in_with_clause/meta_in_with_clause.2.update.sqlpp
new file mode 100644
index 0000000..7da99cd
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/meta_in_with_clause/meta_in_with_clause.2.update.sqlpp
@@ -0,0 +1,27 @@
+/*
+ * 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;
+
+set `wait-for-completion-feed` "true";
+connect feed DsStream to dataset DS;
+start feed DsStream;
+
+connect feed DsStream2 to dataset DS2;
+start feed DsStream2;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/meta_in_with_clause/meta_in_with_clause.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/meta_in_with_clause/meta_in_with_clause.3.query.sqlpp
new file mode 100644
index 0000000..cfcd79e
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/meta_in_with_clause/meta_in_with_clause.3.query.sqlpp
@@ -0,0 +1,29 @@
+/*
+ * 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;
+
+with raw_data as (
+  select meta(a).id as aid, age as age, hobby as hobby
+  from DS a
+  where hobby in ["tennis", "reading","swimming", "hiking", "basketball", "soccer"] )
+
+select t2.raw_data.age, t2.raw_data.aid, array_count(t1) total, t2.raw_data.hobby
+from (select value g from raw_data group by series group as g) as t1 unnest t1 as t2
+order by aid;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/meta_in_with_clause/meta_in_with_clause.4.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/meta_in_with_clause/meta_in_with_clause.4.query.sqlpp
new file mode 100644
index 0000000..0847ae2
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/meta_in_with_clause/meta_in_with_clause.4.query.sqlpp
@@ -0,0 +1,29 @@
+/*
+ * 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;
+
+with raw_data as (
+  select id as aid, age as age, hobby as hobby
+  from DS a
+  where hobby in ["tennis", "reading","swimming", "hiking", "basketball", "soccer"] )
+
+select t2.raw_data.age, t2.raw_data.aid, array_count(t1) total, t2.raw_data.hobby
+from (select value g from raw_data group by series group as g) as t1 unnest t1 as t2
+order by aid;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/meta_in_with_clause/meta_in_with_clause.5.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/meta_in_with_clause/meta_in_with_clause.5.query.sqlpp
new file mode 100644
index 0000000..3fcc2fc
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/meta_in_with_clause/meta_in_with_clause.5.query.sqlpp
@@ -0,0 +1,29 @@
+/*
+ * 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;
+
+with raw_data as (
+  select meta(a).id as aid, age as age, hobby as hobby
+  from DS2 a
+  where hobby in ["tennis", "reading","swimming", "hiking", "basketball", "soccer"] )
+
+select t2.raw_data.age, t2.raw_data.aid, array_count(t1) total, t2.raw_data.hobby
+from (select value g from raw_data group by series group as g) as t1 unnest t1 as t2
+order by aid;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/meta_in_with_clause/meta_in_with_clause.6.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/meta_in_with_clause/meta_in_with_clause.6.query.sqlpp
new file mode 100644
index 0000000..88f7c27
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/meta_in_with_clause/meta_in_with_clause.6.query.sqlpp
@@ -0,0 +1,29 @@
+/*
+ * 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;
+
+with raw_data as (
+  select id as aid, age as age, hobby as hobby
+  from DS2 a
+  where hobby in ["tennis", "reading","swimming", "hiking", "basketball", "soccer"] )
+
+select t2.raw_data.age, t2.raw_data.aid, array_count(t1) total, t2.raw_data.hobby
+from (select value g from raw_data group by series group as g) as t1 unnest t1 as t2
+order by aid;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/meta_in_with_clause/meta_in_with_clause.7.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/meta_in_with_clause/meta_in_with_clause.7.ddl.sqlpp
new file mode 100644
index 0000000..f12a2b7
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/meta_in_with_clause/meta_in_with_clause.7.ddl.sqlpp
@@ -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.
+ */
+
+drop dataverse test;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.1.ddl.sqlpp
new file mode 100644
index 0000000..4297639
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.1.ddl.sqlpp
@@ -0,0 +1,68 @@
+/*
+ * 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 DataType as open {
+id:int,
+name:string,
+age:int,
+hobby:string
+};
+
+create type MetaType as closed {
+id:int
+};
+
+create dataset DS(DataType) with meta(MetaType) primary key meta().id;
+create dataset DS2(DataType) with meta(MetaType) primary key id;
+
+create feed DsStream with {
+ "adapter-name" : "localfs",
+ "reader" : "localfs",
+ "parser" : "record-with-metadata",
+ "type-name" : "DataType",
+ "meta-type-name" : "MetaType",
+ "path" : "asterix_nc1://data/csv/people.csv",
+ "format" : "csv",
+ "delimiter" : ",",
+ "record-format" : "adm",
+ "record-index" : "1",
+ "key-indexes" : "0",
+ "key-indicators" : "1",
+ "header" : "false"
+};
+
+create feed DsStream2 with {
+ "adapter-name" : "localfs",
+ "reader" : "localfs",
+ "parser" : "record-with-metadata",
+ "type-name" : "DataType",
+ "meta-type-name" : "MetaType",
+ "path" : "asterix_nc1://data/csv/people.csv",
+ "format" : "csv",
+ "delimiter" : ",",
+ "record-format" : "adm",
+ "record-index" : "1",
+ "key-indexes" : "0",
+ "key-indicators" : "0",
+ "header" : "false"
+};
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.2.update.sqlpp
new file mode 100644
index 0000000..7da99cd
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.2.update.sqlpp
@@ -0,0 +1,27 @@
+/*
+ * 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;
+
+set `wait-for-completion-feed` "true";
+connect feed DsStream to dataset DS;
+start feed DsStream;
+
+connect feed DsStream2 to dataset DS2;
+start feed DsStream2;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.3.query.sqlpp
new file mode 100644
index 0000000..39efedb
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.3.query.sqlpp
@@ -0,0 +1,27 @@
+/*
+ * 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: tests resolving primary key correctly
+ */
+
+use test;
+
+from DS
+select meta().id as i
+order by i;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.4.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.4.query.sqlpp
new file mode 100644
index 0000000..2b73666
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.4.query.sqlpp
@@ -0,0 +1,27 @@
+/*
+ * 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: tests that id isn't confused for primary key
+ */
+
+use test;
+
+from DS
+select id as i
+order by i;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.5.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.5.query.sqlpp
new file mode 100644
index 0000000..7346025
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.5.query.sqlpp
@@ -0,0 +1,27 @@
+/*
+ * 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: tests that meta().id isn't confused for primary key
+ */
+
+use test;
+
+from DS2
+select meta().id as i
+order by i;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.6.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.6.query.sqlpp
new file mode 100644
index 0000000..40f14ae
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.6.query.sqlpp
@@ -0,0 +1,27 @@
+/*
+ * 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: tests resolving primary key correctly
+ */
+
+use test;
+
+from DS2
+select id as i
+order by i;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.7.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.7.ddl.sqlpp
new file mode 100644
index 0000000..40f14ae
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/meta/resolving_pk_with_meta/resolving_pk_with_meta.7.ddl.sqlpp
@@ -0,0 +1,27 @@
+/*
+ * 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: tests resolving primary key correctly
+ */
+
+use test;
+
+from DS2
+select id as i
+order by i;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.03.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.03.adm
new file mode 100644
index 0000000..708eef0
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.03.adm
@@ -0,0 +1 @@
+{ "DS1": { "id": "2", "name": "Scott Scott", "age": 30, "hobby": "hiking" } }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.04.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.04.adm
new file mode 100644
index 0000000..2c1129d
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.04.adm
@@ -0,0 +1 @@
+{ "DS1": { "id": "7", "name": "Watson Jordon", "age": 28, "hobby": "basketball" } }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.05.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.05.adm
new file mode 100644
index 0000000..fd1e899
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.05.adm
@@ -0,0 +1 @@
+{ "DS2": { "id": "2", "name": "Scott Scott", "age": 30, "hobby": "hiking" } }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.06.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.06.adm
new file mode 100644
index 0000000..227dd34
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.06.adm
@@ -0,0 +1 @@
+{ "DS2": { "id": "7", "name": "Watson Jordon", "age": 28, "hobby": "basketball" } }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.07.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.07.adm
new file mode 100644
index 0000000..43ef810
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.07.adm
@@ -0,0 +1,9 @@
+{ "ds2": { "id": "1", "name": "John Mad", "age": 29, "hobby": "reading" }, "ds1": { "id": "1", "name": "John Mad", "age": 29, "hobby": "reading" } }
+{ "ds2": { "id": "2", "name": "Scott Scott", "age": 30, "hobby": "hiking" }, "ds1": { "id": "2", "name": "Scott Scott", "age": 30, "hobby": "hiking" } }
+{ "ds2": { "id": "3", "name": "Dan David", "age": 40, "hobby": "bowling" }, "ds1": { "id": "3", "name": "Dan David", "age": 40, "hobby": "bowling" } }
+{ "ds2": { "id": "4", "name": "Robert Moore", "age": 32, "hobby": "reading" }, "ds1": { "id": "4", "name": "Robert Moore", "age": 32, "hobby": "reading" } }
+{ "ds2": { "id": "5", "name": "Sandy Donald", "age": 35, "hobby": "soccer" }, "ds1": { "id": "5", "name": "Sandy Donald", "age": 35, "hobby": "soccer" } }
+{ "ds2": { "id": "6", "name": "Joe Dana", "age": 24, "hobby": "tennis" }, "ds1": { "id": "6", "name": "Joe Dana", "age": 24, "hobby": "tennis" } }
+{ "ds2": { "id": "7", "name": "Watson Jordon", "age": 28, "hobby": "basketball" }, "ds1": { "id": "7", "name": "Watson Jordon", "age": 28, "hobby": "basketball" } }
+{ "ds2": { "id": "8", "name": "Mat Steve", "age": 45, "hobby": "tennis" }, "ds1": { "id": "8", "name": "Mat Steve", "age": 45, "hobby": "tennis" } }
+{ "ds2": { "id": "9", "name": "Sandra Pec", "age": 36, "hobby": "hiking" }, "ds1": { "id": "9", "name": "Sandra Pec", "age": 36, "hobby": "hiking" } }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.08.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.08.adm
new file mode 100644
index 0000000..99fd8f1
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.08.adm
@@ -0,0 +1,2 @@
+{ "ds1_meta_id": "5", "ds2": { "id": "5", "name": "Sandy Donald", "age": 35, "hobby": "soccer" }, "ds1": { "id": "7", "name": "Watson Jordon", "age": 28, "hobby": "basketball" } }
+{ "ds1_meta_id": "7", "ds2": { "id": "7", "name": "Watson Jordon", "age": 28, "hobby": "basketball" }, "ds1": { "id": "5", "name": "Sandy Donald", "age": 35, "hobby": "soccer" } }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.09.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.09.adm
new file mode 100644
index 0000000..eeb11e5
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.09.adm
@@ -0,0 +1,9 @@
+{ "ds1": { "id": "1", "name": "John Mad", "age": 29, "hobby": "reading" }, "ds2": { "id": "1", "name": "John Mad", "age": 29, "hobby": "reading" } }
+{ "ds1": { "id": "2", "name": "Scott Scott", "age": 30, "hobby": "hiking" }, "ds2": { "id": "2", "name": "Scott Scott", "age": 30, "hobby": "hiking" } }
+{ "ds1": { "id": "3", "name": "Dan David", "age": 40, "hobby": "bowling" }, "ds2": { "id": "3", "name": "Dan David", "age": 40, "hobby": "bowling" } }
+{ "ds1": { "id": "4", "name": "Robert Moore", "age": 32, "hobby": "reading" }, "ds2": { "id": "4", "name": "Robert Moore", "age": 32, "hobby": "reading" } }
+{ "ds1": { "id": "5", "name": "Sandy Donald", "age": 35, "hobby": "soccer" }, "ds2": { "id": "5", "name": "Sandy Donald", "age": 35, "hobby": "soccer" } }
+{ "ds1": { "id": "6", "name": "Joe Dana", "age": 24, "hobby": "tennis" }, "ds2": { "id": "6", "name": "Joe Dana", "age": 24, "hobby": "tennis" } }
+{ "ds1": { "id": "7", "name": "Watson Jordon", "age": 28, "hobby": "basketball" }, "ds2": { "id": "7", "name": "Watson Jordon", "age": 28, "hobby": "basketball" } }
+{ "ds1": { "id": "8", "name": "Mat Steve", "age": 45, "hobby": "tennis" }, "ds2": { "id": "8", "name": "Mat Steve", "age": 45, "hobby": "tennis" } }
+{ "ds1": { "id": "9", "name": "Sandra Pec", "age": 36, "hobby": "hiking" }, "ds2": { "id": "9", "name": "Sandra Pec", "age": 36, "hobby": "hiking" } }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.11.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.11.adm
new file mode 100644
index 0000000..708eef0
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.11.adm
@@ -0,0 +1 @@
+{ "DS1": { "id": "2", "name": "Scott Scott", "age": 30, "hobby": "hiking" } }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.12.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.12.adm
new file mode 100644
index 0000000..2c1129d
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.12.adm
@@ -0,0 +1 @@
+{ "DS1": { "id": "7", "name": "Watson Jordon", "age": 28, "hobby": "basketball" } }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.13.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.13.adm
new file mode 100644
index 0000000..43ef810
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.13.adm
@@ -0,0 +1,9 @@
+{ "ds2": { "id": "1", "name": "John Mad", "age": 29, "hobby": "reading" }, "ds1": { "id": "1", "name": "John Mad", "age": 29, "hobby": "reading" } }
+{ "ds2": { "id": "2", "name": "Scott Scott", "age": 30, "hobby": "hiking" }, "ds1": { "id": "2", "name": "Scott Scott", "age": 30, "hobby": "hiking" } }
+{ "ds2": { "id": "3", "name": "Dan David", "age": 40, "hobby": "bowling" }, "ds1": { "id": "3", "name": "Dan David", "age": 40, "hobby": "bowling" } }
+{ "ds2": { "id": "4", "name": "Robert Moore", "age": 32, "hobby": "reading" }, "ds1": { "id": "4", "name": "Robert Moore", "age": 32, "hobby": "reading" } }
+{ "ds2": { "id": "5", "name": "Sandy Donald", "age": 35, "hobby": "soccer" }, "ds1": { "id": "5", "name": "Sandy Donald", "age": 35, "hobby": "soccer" } }
+{ "ds2": { "id": "6", "name": "Joe Dana", "age": 24, "hobby": "tennis" }, "ds1": { "id": "6", "name": "Joe Dana", "age": 24, "hobby": "tennis" } }
+{ "ds2": { "id": "7", "name": "Watson Jordon", "age": 28, "hobby": "basketball" }, "ds1": { "id": "7", "name": "Watson Jordon", "age": 28, "hobby": "basketball" } }
+{ "ds2": { "id": "8", "name": "Mat Steve", "age": 45, "hobby": "tennis" }, "ds1": { "id": "8", "name": "Mat Steve", "age": 45, "hobby": "tennis" } }
+{ "ds2": { "id": "9", "name": "Sandra Pec", "age": 36, "hobby": "hiking" }, "ds1": { "id": "9", "name": "Sandra Pec", "age": 36, "hobby": "hiking" } }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.14.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.14.adm
new file mode 100644
index 0000000..99fd8f1
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/dataset-with-meta/dataset-with-meta.14.adm
@@ -0,0 +1,2 @@
+{ "ds1_meta_id": "5", "ds2": { "id": "5", "name": "Sandy Donald", "age": 35, "hobby": "soccer" }, "ds1": { "id": "7", "name": "Watson Jordon", "age": 28, "hobby": "basketball" } }
+{ "ds1_meta_id": "7", "ds2": { "id": "7", "name": "Watson Jordon", "age": 28, "hobby": "basketball" }, "ds1": { "id": "5", "name": "Sandy Donald", "age": 35, "hobby": "soccer" } }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/meta/meta_in_with_clause/meta_in_with_clause.3.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/meta/meta_in_with_clause/meta_in_with_clause.3.adm
new file mode 100644
index 0000000..b9ed3c3
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/meta/meta_in_with_clause/meta_in_with_clause.3.adm
@@ -0,0 +1,8 @@
+{ "age": 24, "aid": 13071782, "total": 8, "hobby": "tennis" }
+{ "age": 28, "aid": 26237702, "total": 8, "hobby": "basketball" }
+{ "age": 45, "aid": 32571888, "total": 8, "hobby": "tennis" }
+{ "age": 35, "aid": 39225791, "total": 8, "hobby": "soccer" }
+{ "age": 32, "aid": 51041435, "total": 8, "hobby": "reading" }
+{ "age": 30, "aid": 52037425, "total": 8, "hobby": "hiking" }
+{ "age": 29, "aid": 76041664, "total": 8, "hobby": "reading" }
+{ "age": 36, "aid": 86897761, "total": 8, "hobby": "hiking" }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/meta/meta_in_with_clause/meta_in_with_clause.4.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/meta/meta_in_with_clause/meta_in_with_clause.4.adm
new file mode 100644
index 0000000..1cc10ea
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/meta/meta_in_with_clause/meta_in_with_clause.4.adm
@@ -0,0 +1,8 @@
+{ "age": 29, "aid": 1, "total": 8, "hobby": "reading" }
+{ "age": 30, "aid": 2, "total": 8, "hobby": "hiking" }
+{ "age": 32, "aid": 4, "total": 8, "hobby": "reading" }
+{ "age": 35, "aid": 5, "total": 8, "hobby": "soccer" }
+{ "age": 24, "aid": 6, "total": 8, "hobby": "tennis" }
+{ "age": 28, "aid": 7, "total": 8, "hobby": "basketball" }
+{ "age": 45, "aid": 8, "total": 8, "hobby": "tennis" }
+{ "age": 36, "aid": 9, "total": 8, "hobby": "hiking" }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/meta/meta_in_with_clause/meta_in_with_clause.5.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/meta/meta_in_with_clause/meta_in_with_clause.5.adm
new file mode 100644
index 0000000..b9ed3c3
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/meta/meta_in_with_clause/meta_in_with_clause.5.adm
@@ -0,0 +1,8 @@
+{ "age": 24, "aid": 13071782, "total": 8, "hobby": "tennis" }
+{ "age": 28, "aid": 26237702, "total": 8, "hobby": "basketball" }
+{ "age": 45, "aid": 32571888, "total": 8, "hobby": "tennis" }
+{ "age": 35, "aid": 39225791, "total": 8, "hobby": "soccer" }
+{ "age": 32, "aid": 51041435, "total": 8, "hobby": "reading" }
+{ "age": 30, "aid": 52037425, "total": 8, "hobby": "hiking" }
+{ "age": 29, "aid": 76041664, "total": 8, "hobby": "reading" }
+{ "age": 36, "aid": 86897761, "total": 8, "hobby": "hiking" }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/meta/meta_in_with_clause/meta_in_with_clause.6.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/meta/meta_in_with_clause/meta_in_with_clause.6.adm
new file mode 100644
index 0000000..1cc10ea
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/meta/meta_in_with_clause/meta_in_with_clause.6.adm
@@ -0,0 +1,8 @@
+{ "age": 29, "aid": 1, "total": 8, "hobby": "reading" }
+{ "age": 30, "aid": 2, "total": 8, "hobby": "hiking" }
+{ "age": 32, "aid": 4, "total": 8, "hobby": "reading" }
+{ "age": 35, "aid": 5, "total": 8, "hobby": "soccer" }
+{ "age": 24, "aid": 6, "total": 8, "hobby": "tennis" }
+{ "age": 28, "aid": 7, "total": 8, "hobby": "basketball" }
+{ "age": 45, "aid": 8, "total": 8, "hobby": "tennis" }
+{ "age": 36, "aid": 9, "total": 8, "hobby": "hiking" }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/meta/resolving_pk_with_meta/resolving_pk_with_meta.3.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/meta/resolving_pk_with_meta/resolving_pk_with_meta.3.adm
new file mode 100644
index 0000000..aca68e1
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/meta/resolving_pk_with_meta/resolving_pk_with_meta.3.adm
@@ -0,0 +1,9 @@
+{ "i": 13071782 }
+{ "i": 26237702 }
+{ "i": 32571888 }
+{ "i": 39225791 }
+{ "i": 45962603 }
+{ "i": 51041435 }
+{ "i": 52037425 }
+{ "i": 76041664 }
+{ "i": 86897761 }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/meta/resolving_pk_with_meta/resolving_pk_with_meta.4.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/meta/resolving_pk_with_meta/resolving_pk_with_meta.4.adm
new file mode 100644
index 0000000..16bce91
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/meta/resolving_pk_with_meta/resolving_pk_with_meta.4.adm
@@ -0,0 +1,9 @@
+{ "i": 1 }
+{ "i": 2 }
+{ "i": 3 }
+{ "i": 4 }
+{ "i": 5 }
+{ "i": 6 }
+{ "i": 7 }
+{ "i": 8 }
+{ "i": 9 }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/meta/resolving_pk_with_meta/resolving_pk_with_meta.5.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/meta/resolving_pk_with_meta/resolving_pk_with_meta.5.adm
new file mode 100644
index 0000000..aca68e1
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/meta/resolving_pk_with_meta/resolving_pk_with_meta.5.adm
@@ -0,0 +1,9 @@
+{ "i": 13071782 }
+{ "i": 26237702 }
+{ "i": 32571888 }
+{ "i": 39225791 }
+{ "i": 45962603 }
+{ "i": 51041435 }
+{ "i": 52037425 }
+{ "i": 76041664 }
+{ "i": 86897761 }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/meta/resolving_pk_with_meta/resolving_pk_with_meta.6.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/meta/resolving_pk_with_meta/resolving_pk_with_meta.6.adm
new file mode 100644
index 0000000..16bce91
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/meta/resolving_pk_with_meta/resolving_pk_with_meta.6.adm
@@ -0,0 +1,9 @@
+{ "i": 1 }
+{ "i": 2 }
+{ "i": 3 }
+{ "i": 4 }
+{ "i": 5 }
+{ "i": 6 }
+{ "i": 7 }
+{ "i": 8 }
+{ "i": 9 }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
index 4fcf9f8..18c5f88 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -3536,6 +3536,11 @@
         <output-dir compare="Text">disjunctive-predicate-1</output-dir>
       </compilation-unit>
     </test-case>
+    <test-case FilePath="index-selection">
+      <compilation-unit name="dataset-with-meta">
+        <output-dir compare="Text">dataset-with-meta</output-dir>
+      </compilation-unit>
+    </test-case>
   </test-group>
   <test-group name="inverted-index-join">
     <test-case FilePath="inverted-index-join">
@@ -9052,6 +9057,18 @@
       </compilation-unit>
     </test-case>
   </test-group>
+  <test-group name="meta">
+    <test-case FilePath="meta">
+      <compilation-unit name="meta_in_with_clause">
+        <output-dir compare="Text">meta_in_with_clause</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="meta">
+      <compilation-unit name="resolving_pk_with_meta">
+        <output-dir compare="Text">resolving_pk_with_meta</output-dir>
+      </compilation-unit>
+    </test-case>
+  </test-group>
   <test-group name="big-object">
     <test-case FilePath="big-object">
       <compilation-unit name="big_object_sort">
diff --git a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/DatasetUtil.java b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/DatasetUtil.java
index 28c612f..c0b36ea 100644
--- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/DatasetUtil.java
+++ b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/DatasetUtil.java
@@ -41,6 +41,7 @@ import org.apache.asterix.external.indexing.IndexingConstants;
 import org.apache.asterix.formats.base.IDataFormat;
 import org.apache.asterix.formats.nontagged.SerializerDeserializerProvider;
 import org.apache.asterix.formats.nontagged.TypeTraitProvider;
+import org.apache.asterix.metadata.IDatasetDetails;
 import org.apache.asterix.metadata.MetadataManager;
 import org.apache.asterix.metadata.MetadataTransactionContext;
 import org.apache.asterix.metadata.declared.MetadataProvider;
@@ -173,17 +174,53 @@ public class DatasetUtil {
         return btreeFields;
     }
 
-    public static int getPositionOfPartitioningKeyField(Dataset dataset, List<String> fieldExpr) {
+    /**
+     * Returns the primary key source indicators of the {@code dataset} or {@code null} if the dataset does not have
+     * primary key source indicators (e.g. external datasets)
+     */
+    public static List<Integer> getKeySourceIndicators(Dataset dataset) {
+        IDatasetDetails datasetDetails = dataset.getDatasetDetails();
+        if (datasetDetails.getDatasetType() == DatasetType.INTERNAL) {
+            return ((InternalDatasetDetails) datasetDetails).getKeySourceIndicator();
+        }
+        return null;
+    }
+
+    public static int getPositionOfPartitioningKeyField(Dataset dataset, List<String> fieldExpr,
+            boolean fieldFromMeta) {
+        List<Integer> keySourceIndicator = null;
+        IDatasetDetails datasetDetails = dataset.getDatasetDetails();
+        if (datasetDetails.getDatasetType() == DatasetType.INTERNAL) {
+            keySourceIndicator = ((InternalDatasetDetails) datasetDetails).getKeySourceIndicator();
+        }
         List<List<String>> partitioningKeys = dataset.getPrimaryKeys();
         for (int i = 0; i < partitioningKeys.size(); i++) {
             List<String> partitioningKey = partitioningKeys.get(i);
-            if (partitioningKey.equals(fieldExpr)) {
+            if (partitioningKey.equals(fieldExpr) && keySourceMatches(keySourceIndicator, i, fieldFromMeta)) {
                 return i;
             }
         }
         return -1;
     }
 
+    /**
+     * Once it's determined that a field name is a key (by just comparing the names), this method checks whether the
+     * field is actually a key by making sure the field is coming from the right record (data record or meta record),
+     * e.g. if the field name happens to be equal to the key name but the field is coming from the data record while
+     * the key is coming from the meta record.
+     * @param keySourceIndicator indicates where the key is coming from, 1 from meta record, 0 from data record
+     * @param keyIndex the key index we're checking the field against
+     * @param fieldFromMeta whether the field is coming from the meta record or the data record
+     * @return true if the key source matches the field source. Otherwise, false.
+     */
+    private static boolean keySourceMatches(List<Integer> keySourceIndicator, int keyIndex, boolean fieldFromMeta) {
+        if (keySourceIndicator != null) {
+            return (fieldFromMeta && keySourceIndicator.get(keyIndex) == 1)
+                    || (!fieldFromMeta && keySourceIndicator.get(keyIndex) == 0);
+        }
+        return true;
+    }
+
     public static Pair<ILSMMergePolicyFactory, Map<String, String>> getMergePolicyFactory(Dataset dataset,
             MetadataTransactionContext mdTxnCtx) throws AlgebricksException {
         String policyName = dataset.getCompactionPolicy();


[asterixdb] 01/06: [NO ISSUE][NET] Ensure Recycling Buffer and Notifying Sender is Atomic

Posted by mh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mhubail pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git

commit 9554871aaee87a3bd5e528123eca50aa212749af
Author: Murtadha Hubail <mh...@apache.org>
AuthorDate: Fri Aug 16 13:53:25 2019 -0700

    [NO ISSUE][NET] Ensure Recycling Buffer and Notifying Sender is Atomic
    
    - user model changes: no
    - storage format changes: no
    - interface changes: no
    
    Details:
    - To avoid synchronization issues that might occur
      due to JVM reordering, ensure that both recycling
      read buffers and notifying the sender  of their
      availability are done atomically before the next
      buffer is received from the sender.
    
    Change-Id: Ia3b1920f33bf7d4e7efbd2ea3405cbc4310a78c7
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/3520
    Contrib: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Reviewed-by: Murtadha Hubail <mh...@apache.org>
    Reviewed-by: Till Westmann <ti...@apache.org>
    (cherry picked from commit 32eed5f384c5851eae1c613fcb3b9532744ed595)
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/3525
    Reviewed-by: Michael Blow <mb...@apache.org>
---
 .../muxdemux/FullFrameChannelReadInterface.java    | 90 +++++++++++-----------
 1 file changed, 47 insertions(+), 43 deletions(-)

diff --git a/hyracks-fullstack/hyracks/hyracks-net/src/main/java/org/apache/hyracks/net/protocols/muxdemux/FullFrameChannelReadInterface.java b/hyracks-fullstack/hyracks/hyracks-net/src/main/java/org/apache/hyracks/net/protocols/muxdemux/FullFrameChannelReadInterface.java
index 3ba8627..53be212 100644
--- a/hyracks-fullstack/hyracks/hyracks-net/src/main/java/org/apache/hyracks/net/protocols/muxdemux/FullFrameChannelReadInterface.java
+++ b/hyracks-fullstack/hyracks/hyracks-net/src/main/java/org/apache/hyracks/net/protocols/muxdemux/FullFrameChannelReadInterface.java
@@ -21,8 +21,8 @@ package org.apache.hyracks.net.protocols.muxdemux;
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.nio.channels.SocketChannel;
-import java.util.concurrent.BlockingDeque;
-import java.util.concurrent.LinkedBlockingDeque;
+import java.util.ArrayDeque;
+import java.util.Deque;
 
 import org.apache.hyracks.api.comm.IBufferFactory;
 import org.apache.hyracks.api.comm.IChannelControlBlock;
@@ -33,65 +33,69 @@ import org.apache.logging.log4j.Logger;
 public class FullFrameChannelReadInterface extends AbstractChannelReadInterface {
 
     private static final Logger LOGGER = LogManager.getLogger();
-    private final BlockingDeque<ByteBuffer> riEmptyStack;
+    private final Deque<ByteBuffer> riEmptyStack;
     private final IChannelControlBlock ccb;
+    private final Object bufferRecycleLock = new Object();
 
     public FullFrameChannelReadInterface(IChannelControlBlock ccb) {
         this.ccb = ccb;
-        riEmptyStack = new LinkedBlockingDeque<>();
+        riEmptyStack = new ArrayDeque<>();
         credits = 0;
-
         emptyBufferAcceptor = buffer -> {
-            if (ccb.isRemotelyClosed()) {
-                return;
-            }
             final int delta = buffer.remaining();
-            riEmptyStack.push(buffer);
-            ccb.addPendingCredits(delta);
+            synchronized (bufferRecycleLock) {
+                if (ccb.isRemotelyClosed()) {
+                    return;
+                }
+                riEmptyStack.push(buffer);
+                ccb.addPendingCredits(delta);
+            }
         };
     }
 
     @Override
     public int read(SocketChannel sc, int size) throws IOException, NetException {
-        while (true) {
-            if (size <= 0) {
-                return size;
-            }
-            if (currentReadBuffer == null) {
-                currentReadBuffer = riEmptyStack.poll();
-                //if current buffer == null and limit not reached
-                // factory.createBuffer factory
-                if (currentReadBuffer == null) {
-                    currentReadBuffer = bufferFactory.createBuffer();
+        synchronized (bufferRecycleLock) {
+            while (true) {
+                if (size <= 0) {
+                    return size;
                 }
-            }
-            if (currentReadBuffer == null) {
-                if (LOGGER.isWarnEnabled()) {
-                    LOGGER.warn("{} read buffers exceeded. Current empty buffers: {}", ccb, riEmptyStack.size());
+                if (currentReadBuffer == null) {
+                    currentReadBuffer = riEmptyStack.poll();
+                    //if current buffer == null and limit not reached
+                    // factory.createBuffer factory
+                    if (currentReadBuffer == null) {
+                        currentReadBuffer = bufferFactory.createBuffer();
+                    }
                 }
-                throw new IllegalStateException(ccb + " read buffers exceeded");
-            }
-            int rSize = Math.min(size, currentReadBuffer.remaining());
-            if (rSize > 0) {
-                currentReadBuffer.limit(currentReadBuffer.position() + rSize);
-                int len;
-                try {
-                    len = sc.read(currentReadBuffer);
-                    if (len < 0) {
-                        throw new NetException("Socket Closed");
+                if (currentReadBuffer == null) {
+                    if (LOGGER.isWarnEnabled()) {
+                        LOGGER.warn("{} read buffers exceeded. Current empty buffers: {}", ccb, riEmptyStack.size());
                     }
-                } finally {
-                    currentReadBuffer.limit(currentReadBuffer.capacity());
+                    throw new IllegalStateException(ccb + " read buffers exceeded");
                 }
-                size -= len;
-                if (len < rSize) {
+                int rSize = Math.min(size, currentReadBuffer.remaining());
+                if (rSize > 0) {
+                    currentReadBuffer.limit(currentReadBuffer.position() + rSize);
+                    int len;
+                    try {
+                        len = sc.read(currentReadBuffer);
+                        if (len < 0) {
+                            throw new NetException("Socket Closed");
+                        }
+                    } finally {
+                        currentReadBuffer.limit(currentReadBuffer.capacity());
+                    }
+                    size -= len;
+                    if (len < rSize) {
+                        return size;
+                    }
+                } else {
                     return size;
                 }
-            } else {
-                return size;
-            }
-            if (currentReadBuffer.remaining() <= 0) {
-                flush();
+                if (currentReadBuffer.remaining() <= 0) {
+                    flush();
+                }
             }
         }
     }


[asterixdb] 02/06: [NO ISSUE][*DB][REPL] Identifier comparability of unknown hosts

Posted by mh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mhubail pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git

commit fd0f4ce8fe94d2837552d8cf09cdaf27b5a11f2f
Author: Michael Blow <mi...@couchbase.com>
AuthorDate: Fri Aug 30 11:18:04 2019 -0400

    [NO ISSUE][*DB][REPL] Identifier comparability of unknown hosts
    
    Ensure that replication identifiers comparisons are not influenced by
    address resolution
    
    Change-Id: I6d7aa87777d17a3416d16cfad23b2773b1614a02
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/3536
    Sonar-Qube: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Reviewed-by: Michael Blow <mb...@apache.org>
    Reviewed-by: Murtadha Hubail <mh...@apache.org>
---
 .../main/java/org/apache/asterix/common/storage/ReplicaIdentifier.java  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/storage/ReplicaIdentifier.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/storage/ReplicaIdentifier.java
index 01ffba6..f68ad09 100644
--- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/storage/ReplicaIdentifier.java
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/storage/ReplicaIdentifier.java
@@ -29,7 +29,7 @@ public class ReplicaIdentifier {
     private ReplicaIdentifier(int partition, InetSocketAddress location) {
         this.partition = partition;
         this.location = location;
-        id = partition + "@" + location.toString();
+        id = partition + "@" + location.getHostString() + ":" + location.getPort();
     }
 
     public static ReplicaIdentifier of(int partition, InetSocketAddress location) {