[NO ISSUE][MTD] Fix for standalone collection with columnar storage

- user model changes: no
- storage format changes: no
- interface changes: no

Details:
With standalone collections, the record type was missing
the primary key when passed to TupleProjectorFactory.

Change-Id: I3aede214cdfd3c0e6d00378bd07acaf7192b1195
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/17721
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Peeyush Gupta <peeyush.gupta@couchbase.com>
Reviewed-by: Wail Alkowaileet <wael.y.k@gmail.com>
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/atomic-statements/columnar-dataset/columnar-dataset.01.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/atomic-statements/columnar-dataset/columnar-dataset.01.ddl.sqlpp
new file mode 100644
index 0000000..f9868ac
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/atomic-statements/columnar-dataset/columnar-dataset.01.ddl.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.
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+create dataset reviews primary key (id: int) WITH {
+    "storage-format": {"format": "column"}
+};
+
+CREATE PRIMARY INDEX review_idx_primary ON reviews;
+
+CREATE INDEX review_idx_review ON reviews(review: string?) TYPE BTREE;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/atomic-statements/columnar-dataset/columnar-dataset.02.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/atomic-statements/columnar-dataset/columnar-dataset.02.update.sqlpp
new file mode 100644
index 0000000..b0c59df
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/atomic-statements/columnar-dataset/columnar-dataset.02.update.sqlpp
@@ -0,0 +1,32 @@
+/*
+ * 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;
+
+upsert into reviews ([
+    {"id": 1, "year": null, "quarter": null, "review": "good"},
+    {"id": 2, "year": null, "quarter": null, "review": "good"},
+    {"id": 3, "year": 2018, "quarter": null, "review": "good"},
+    {"id": 4, "year": 2018, "quarter": null, "review": "bad"},
+    {"id": 5, "year": 2018, "quarter": 1, "review": "bad"},
+    {"id": 7, "year": 2018, "quarter": 2, "review": "good"},
+    {"id": 8, "year": 2018, "quarter": 2, "review": "bad"},
+    {"id": 9, "year": 2019, "quarter": null, "review": "good"},
+    {"id": 10, "year": 2019, "quarter": null, "review": "bad"}
+]);
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/atomic-statements/columnar-dataset/columnar-dataset.03.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/atomic-statements/columnar-dataset/columnar-dataset.03.query.sqlpp
new file mode 100644
index 0000000..11d5a3f
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/atomic-statements/columnar-dataset/columnar-dataset.03.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 *
+from reviews order by id;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/atomic-statements/columnar-dataset/columnar-dataset.04.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/atomic-statements/columnar-dataset/columnar-dataset.04.query.sqlpp
new file mode 100644
index 0000000..8709326
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/atomic-statements/columnar-dataset/columnar-dataset.04.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 count(*)
+from reviews;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/atomic-statements/columnar-dataset/columnar-dataset.05.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/atomic-statements/columnar-dataset/columnar-dataset.05.query.sqlpp
new file mode 100644
index 0000000..4438fe6
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/atomic-statements/columnar-dataset/columnar-dataset.05.query.sqlpp
@@ -0,0 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+use test;
+
+select id,year from reviews where id < 5 order by id;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/atomic-statements/columnar-dataset/columnar-dataset.06.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/atomic-statements/columnar-dataset/columnar-dataset.06.ddl.sqlpp
new file mode 100644
index 0000000..3cc900b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/atomic-statements/columnar-dataset/columnar-dataset.06.ddl.sqlpp
@@ -0,0 +1,24 @@
+/*
+ * 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;
+
+drop dataset reviews;
+
+drop dataverse test;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/atomic-statements/columnar-dataset/columnar-dataset.03.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/atomic-statements/columnar-dataset/columnar-dataset.03.adm
new file mode 100644
index 0000000..e542bd0
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/atomic-statements/columnar-dataset/columnar-dataset.03.adm
@@ -0,0 +1,9 @@
+{ "reviews": { "id": 1, "year": null, "quarter": null, "review": "good" } }
+{ "reviews": { "id": 2, "year": null, "quarter": null, "review": "good" } }
+{ "reviews": { "id": 3, "year": 2018, "quarter": null, "review": "good" } }
+{ "reviews": { "id": 4, "year": 2018, "quarter": null, "review": "bad" } }
+{ "reviews": { "id": 5, "year": 2018, "quarter": 1, "review": "bad" } }
+{ "reviews": { "id": 7, "year": 2018, "quarter": 2, "review": "good" } }
+{ "reviews": { "id": 8, "year": 2018, "quarter": 2, "review": "bad" } }
+{ "reviews": { "id": 9, "year": 2019, "quarter": null, "review": "good" } }
+{ "reviews": { "id": 10, "year": 2019, "quarter": null, "review": "bad" } }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/atomic-statements/columnar-dataset/columnar-dataset.04.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/atomic-statements/columnar-dataset/columnar-dataset.04.adm
new file mode 100644
index 0000000..f11c82a
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/atomic-statements/columnar-dataset/columnar-dataset.04.adm
@@ -0,0 +1 @@
+9
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/atomic-statements/columnar-dataset/columnar-dataset.05.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/atomic-statements/columnar-dataset/columnar-dataset.05.adm
new file mode 100644
index 0000000..e908ea5
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/atomic-statements/columnar-dataset/columnar-dataset.05.adm
@@ -0,0 +1,4 @@
+{ "id": 1, "year": null }
+{ "id": 2, "year": null }
+{ "id": 3, "year": 2018 }
+{ "id": 4, "year": 2018 }
\ 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 16d5719..6d83fb5 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -16371,5 +16371,10 @@
         <output-dir compare="Clean-JSON">atomic-statements-4</output-dir>
       </compilation-unit>
     </test-case>
+    <test-case FilePath="atomic-statements">
+      <compilation-unit name="columnar-dataset">
+        <output-dir compare="Clean-JSON">columnar-dataset</output-dir>
+      </compilation-unit>
+    </test-case>
   </test-group>
 </test-suite>
diff --git a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/DatasetDataSource.java b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/DatasetDataSource.java
index f4e15de..9a7494f 100644
--- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/DatasetDataSource.java
+++ b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/DatasetDataSource.java
@@ -161,6 +161,8 @@
                                     dataset.getMetaItemTypeDataverseName(), dataset.getMetaItemTypeName())
                             .getDatatype();
                 }
+                datasetType = (ARecordType) metadataProvider.findTypeForDatasetWithoutType(datasetType, metaItemType,
+                        dataset);
                 int numberOfPrimaryKeys = dataset.getPrimaryKeys().size();
                 ITupleProjectorFactory tupleProjectorFactory =
                         IndexUtil.createTupleProjectorFactory(context, typeEnv, dataset.getDatasetFormatInfo(),