[NO ISSUE][COMP] Automatically adjust primary key field type
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
- Automatically set type quantifier to NOT UKNOWN for
primary key fields in CREATE DATASET / VIEW with
inline type definition
Change-Id: Id01e3a1a30a44964d5a2a71305b3e3d14ecacfb9
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/14026
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Dmitry Lychagin <dmitry.lychagin@couchbase.com>
Reviewed-by: Ali Alsuliman <ali.al.solaiman@gmail.com>
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/create-dataset-inline-type-1/create-dataset-inline-type-1.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/create-dataset-inline-type-1/create-dataset-inline-type-1.1.ddl.sqlpp
index 55f3604..4776ab4 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/create-dataset-inline-type-1/create-dataset-inline-type-1.1.ddl.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/create-dataset-inline-type-1/create-dataset-inline-type-1.1.ddl.sqlpp
@@ -25,7 +25,7 @@
CREATE FUNCTION listMetadata() {
SELECT "Dataset" AS en, d.DatasetName, d.DatatypeDataverseName, d.DatatypeName,
- d.MetatypeDataverseName, d.MetatypeName
+ d.MetatypeDataverseName, d.MetatypeName, d.InternalDetails.PrimaryKey, d.InternalDetails.KeySourceIndicator
FROM Metadata.`Dataset` d
WHERE d.DataverseName = "test"
UNION ALL
@@ -52,11 +52,11 @@
) CLOSED TYPE PRIMARY KEY c_custkey;
CREATE DATASET A_Customers_Open(
- c_custkey integer not unknown,
- c_name string not unknown,
+ c_custkey integer /* auto NOT UNKNOWN if used in PRIMARY KEY */,
+ c_name string /* auto NOT UNKNOWN if used in PRIMARY KEY */,
c_phone string,
c_comment string
-) OPEN TYPE PRIMARY KEY c_custkey;
+) OPEN TYPE PRIMARY KEY c_custkey, c_name;
/* External datasets */
@@ -117,16 +117,16 @@
PRIMARY KEY c_custkey ;
CREATE DATASET C_Customers_Meta_Closed(
- c_custkey integer not unknown,
+ c_custkey integer /* auto NOT UNKNOWN if used in PRIMARY KEY */,
c_name string not unknown,
c_phone string,
c_comment string
) CLOSED TYPE
WITH META(
- c_x integer not unknown,
+ c_x integer /* auto NOT UNKNOWN if used in PRIMARY KEY */,
c_y integer
) CLOSED TYPE
-PRIMARY KEY c_custkey;
+PRIMARY KEY c_custkey, META().c_x;
CREATE DATASET C_Customers_Meta_Open(
c_custkey integer not unknown,
@@ -135,7 +135,7 @@
c_comment string
) OPEN TYPE
WITH META(
- c_x integer not unknown,
- c_y integer
+ c_x integer /* auto NOT UNKNOWN if used in PRIMARY KEY */,
+ c_y integer /* auto NOT UNKNOWN if used in PRIMARY KEY */
) OPEN TYPE
-PRIMARY KEY c_custkey;
+PRIMARY KEY META().c_x, META().c_y;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/view/create-view-3-typed/create-view-3-typed.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/view/create-view-3-typed/create-view-3-typed.1.ddl.sqlpp
index 3576628..5c4ea0e 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/view/create-view-3-typed/create-view-3-typed.1.ddl.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/view/create-view-3-typed/create-view-3-typed.1.ddl.sqlpp
@@ -82,9 +82,10 @@
as t2;
/* primary key (not enforced), check that invalid tuples are eliminated */
+/* also check that NOT UNKNOWN type quantifier is automatically assumed for primary keys */
create view v6_pk_no_nulls(
- c_i64 int64 not unknown,
+ c_i64 int64,
c_id int32
) default null
primary key (c_i64) not enforced
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/view/create-view-3-typed/create-view-3-typed.12.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/view/create-view-3-typed/create-view-3-typed.12.query.sqlpp
index 8c5d268..96ab466 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/view/create-view-3-typed/create-view-3-typed.12.query.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/view/create-view-3-typed/create-view-3-typed.12.query.sqlpp
@@ -17,7 +17,8 @@
* under the License.
*/
-select DataverseName, DatasetName, ViewDetails
+select d.DataverseName, d.DatasetName, d.ViewDetails, dt.Derived.Record.Fields as DatatypeFields
from Metadata.`Dataset` d
-where DatasetType='VIEW'
-order by DataverseName, DatasetName;
+join Metadata.`Datatype` dt on d.DatatypeDataverseName = dt.DataverseName and d.DatatypeName = dt.DatatypeName
+where d.DatasetType='VIEW'
+order by d.DataverseName, d.DatasetName;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/view/create-view-6-typed-negative/create-view-6-typed-negative.11.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/view/create-view-6-typed-negative/create-view-6-typed-negative.11.ddl.sqlpp
index fcb6727..dd69e56 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/view/create-view-6-typed-negative/create-view-6-typed-negative.11.ddl.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/view/create-view-6-typed-negative/create-view-6-typed-negative.11.ddl.sqlpp
@@ -17,12 +17,10 @@
* under the License.
*/
---- Negative: primary key field must be declared as "not unknown"
+--- Negative: view inline type has duplicate fields
drop dataverse test if exists;
create dataverse test;
-create view test.v1(r bigint)
- default null
- primary key (r) not enforced
- as select r from range(1,2) r;
+create view test.v1(r bigint, r bigint) default null as
+ select r, [r] a from range(1,2) r;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/view/create-view-6-typed-negative/create-view-6-typed-negative.12.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/view/create-view-6-typed-negative/create-view-6-typed-negative.12.ddl.sqlpp
index 343967a..53e94fc 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/view/create-view-6-typed-negative/create-view-6-typed-negative.12.ddl.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/view/create-view-6-typed-negative/create-view-6-typed-negative.12.ddl.sqlpp
@@ -17,12 +17,25 @@
* under the License.
*/
---- Negative: primary key field must be declared as "not unknown"
+/*
+ * Negative: cannot replace typed view if the replacement declaration has a different primary key
+ * because there might be another typed view that refers to its primary key
+ * via foreign key declaration.
+ * (this limitation will be relaxed in the future)
+ */
-drop dataverse test if exists;
-create dataverse test;
+drop dataverse test1 if exists;
+create dataverse test1;
-create view test.v1(r bigint not unknown, r2 bigint)
+create dataset test1.employee(e_id int not unknown, e_name string, e_mgr_id int, e_hrr_id int)
+ primary key e_id;
+
+create view test1.employee_v1(e_id int not unknown, e_mgr_id int)
default null
- primary key (r, r2) not enforced
- as select r, -r as r2 from range(1,2) r;
+ primary key (e_id) not enforced
+ as employee;
+
+create or replace view test1.employee_v1(e_id int not unknown, e_mgr_id int not unknown)
+ default null
+ primary key (e_id, e_mgr_id) not enforced
+ as employee;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/view/create-view-6-typed-negative/create-view-6-typed-negative.26.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/view/create-view-6-typed-negative/create-view-6-typed-negative.26.ddl.sqlpp
deleted file mode 100644
index 53e94fc..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/view/create-view-6-typed-negative/create-view-6-typed-negative.26.ddl.sqlpp
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/*
- * Negative: cannot replace typed view if the replacement declaration has a different primary key
- * because there might be another typed view that refers to its primary key
- * via foreign key declaration.
- * (this limitation will be relaxed in the future)
- */
-
-drop dataverse test1 if exists;
-create dataverse test1;
-
-create dataset test1.employee(e_id int not unknown, e_name string, e_mgr_id int, e_hrr_id int)
- primary key e_id;
-
-create view test1.employee_v1(e_id int not unknown, e_mgr_id int)
- default null
- primary key (e_id) not enforced
- as employee;
-
-create or replace view test1.employee_v1(e_id int not unknown, e_mgr_id int not unknown)
- default null
- primary key (e_id, e_mgr_id) not enforced
- as employee;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/view/create-view-6-typed-negative/create-view-6-typed-negative.27.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/view/create-view-6-typed-negative/create-view-6-typed-negative.27.ddl.sqlpp
deleted file mode 100644
index dd69e56..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/view/create-view-6-typed-negative/create-view-6-typed-negative.27.ddl.sqlpp
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
---- Negative: view inline type has duplicate fields
-
-drop dataverse test if exists;
-create dataverse test;
-
-create view test.v1(r bigint, r bigint) default null as
- select r, [r] a from range(1,2) r;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/ddl/create-dataset-inline-type-1/create-dataset-inline-type-1.2.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/ddl/create-dataset-inline-type-1/create-dataset-inline-type-1.2.adm
index 992045b..8af06a6 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/ddl/create-dataset-inline-type-1/create-dataset-inline-type-1.2.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/ddl/create-dataset-inline-type-1/create-dataset-inline-type-1.2.adm
@@ -1,12 +1,12 @@
-{ "en": "Dataset", "DatatypeName": "$d$t$i$A_Customers_Closed", "DatasetName": "A_Customers_Closed", "DatatypeDataverseName": "test" }
-{ "en": "Dataset", "DatatypeName": "$d$t$i$A_Customers_Default_Closed", "DatasetName": "A_Customers_Default_Closed", "DatatypeDataverseName": "test" }
-{ "en": "Dataset", "DatatypeName": "$d$t$i$A_Customers_Open", "DatasetName": "A_Customers_Open", "DatatypeDataverseName": "test" }
+{ "en": "Dataset", "DatatypeName": "$d$t$i$A_Customers_Closed", "DatasetName": "A_Customers_Closed", "DatatypeDataverseName": "test", "PrimaryKey": [ [ "c_custkey" ] ] }
+{ "en": "Dataset", "DatatypeName": "$d$t$i$A_Customers_Default_Closed", "DatasetName": "A_Customers_Default_Closed", "DatatypeDataverseName": "test", "PrimaryKey": [ [ "c_custkey" ] ] }
+{ "en": "Dataset", "DatatypeName": "$d$t$i$A_Customers_Open", "DatasetName": "A_Customers_Open", "DatatypeDataverseName": "test", "PrimaryKey": [ [ "c_custkey" ], [ "c_name" ] ] }
{ "en": "Dataset", "DatatypeName": "$d$t$i$B_Orders_Closed", "DatasetName": "B_Orders_Closed", "DatatypeDataverseName": "test" }
{ "en": "Dataset", "DatatypeName": "$d$t$i$B_Orders_Default_Closed", "DatasetName": "B_Orders_Default_Closed", "DatatypeDataverseName": "test" }
{ "en": "Dataset", "DatatypeName": "$d$t$i$B_Orders_Open", "DatasetName": "B_Orders_Open", "DatatypeDataverseName": "test" }
-{ "en": "Dataset", "DatatypeName": "$d$t$i$C_Customers_Meta_Closed", "DatasetName": "C_Customers_Meta_Closed", "DatatypeDataverseName": "test", "MetatypeDataverseName": "test", "MetatypeName": "$d$t$m$C_Customers_Meta_Closed" }
-{ "en": "Dataset", "DatatypeName": "$d$t$i$C_Customers_Meta_Default_Closed", "DatasetName": "C_Customers_Meta_Default_Closed", "DatatypeDataverseName": "test", "MetatypeDataverseName": "test", "MetatypeName": "$d$t$m$C_Customers_Meta_Default_Closed" }
-{ "en": "Dataset", "DatatypeName": "$d$t$i$C_Customers_Meta_Open", "DatasetName": "C_Customers_Meta_Open", "DatatypeDataverseName": "test", "MetatypeDataverseName": "test", "MetatypeName": "$d$t$m$C_Customers_Meta_Open" }
+{ "en": "Dataset", "DatatypeName": "$d$t$i$C_Customers_Meta_Closed", "DatasetName": "C_Customers_Meta_Closed", "DatatypeDataverseName": "test", "PrimaryKey": [ [ "c_custkey" ], [ "c_x" ] ], "MetatypeDataverseName": "test", "MetatypeName": "$d$t$m$C_Customers_Meta_Closed", "KeySourceIndicator": [ 0, 1 ] }
+{ "en": "Dataset", "DatatypeName": "$d$t$i$C_Customers_Meta_Default_Closed", "DatasetName": "C_Customers_Meta_Default_Closed", "DatatypeDataverseName": "test", "PrimaryKey": [ [ "c_custkey" ] ], "MetatypeDataverseName": "test", "MetatypeName": "$d$t$m$C_Customers_Meta_Default_Closed" }
+{ "en": "Dataset", "DatatypeName": "$d$t$i$C_Customers_Meta_Open", "DatasetName": "C_Customers_Meta_Open", "DatatypeDataverseName": "test", "PrimaryKey": [ [ "c_x" ], [ "c_y" ] ], "MetatypeDataverseName": "test", "MetatypeName": "$d$t$m$C_Customers_Meta_Open", "KeySourceIndicator": [ 1, 1 ] }
{ "en": "Datatype", "DatatypeName": "$d$t$i$A_Customers_Closed", "Derived": { "Tag": "RECORD", "IsAnonymous": true, "Record": { "IsOpen": false, "Fields": [ { "FieldName": "c_custkey", "FieldType": "int32", "IsNullable": false, "IsMissable": false }, { "FieldName": "c_name", "FieldType": "string", "IsNullable": false, "IsMissable": false }, { "FieldName": "c_phone", "FieldType": "string", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_comment", "FieldType": "string", "IsNullable": true, "IsMissable": true } ] } } }
{ "en": "Datatype", "DatatypeName": "$d$t$i$A_Customers_Default_Closed", "Derived": { "Tag": "RECORD", "IsAnonymous": true, "Record": { "IsOpen": false, "Fields": [ { "FieldName": "c_custkey", "FieldType": "int32", "IsNullable": false, "IsMissable": false }, { "FieldName": "c_name", "FieldType": "string", "IsNullable": false, "IsMissable": false }, { "FieldName": "c_phone", "FieldType": "string", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_comment", "FieldType": "string", "IsNullable": true, "IsMissable": true } ] } } }
{ "en": "Datatype", "DatatypeName": "$d$t$i$A_Customers_Open", "Derived": { "Tag": "RECORD", "IsAnonymous": true, "Record": { "IsOpen": true, "Fields": [ { "FieldName": "c_custkey", "FieldType": "int32", "IsNullable": false, "IsMissable": false }, { "FieldName": "c_name", "FieldType": "string", "IsNullable": false, "IsMissable": false }, { "FieldName": "c_phone", "FieldType": "string", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_comment", "FieldType": "string", "IsNullable": true, "IsMissable": true } ] } } }
@@ -18,4 +18,4 @@
{ "en": "Datatype", "DatatypeName": "$d$t$i$C_Customers_Meta_Open", "Derived": { "Tag": "RECORD", "IsAnonymous": true, "Record": { "IsOpen": true, "Fields": [ { "FieldName": "c_custkey", "FieldType": "int32", "IsNullable": false, "IsMissable": false }, { "FieldName": "c_name", "FieldType": "string", "IsNullable": false, "IsMissable": false }, { "FieldName": "c_phone", "FieldType": "string", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_comment", "FieldType": "string", "IsNullable": true, "IsMissable": true } ] } } }
{ "en": "Datatype", "DatatypeName": "$d$t$m$C_Customers_Meta_Closed", "Derived": { "Tag": "RECORD", "IsAnonymous": true, "Record": { "IsOpen": false, "Fields": [ { "FieldName": "c_x", "FieldType": "int32", "IsNullable": false, "IsMissable": false }, { "FieldName": "c_y", "FieldType": "int32", "IsNullable": true, "IsMissable": true } ] } } }
{ "en": "Datatype", "DatatypeName": "$d$t$m$C_Customers_Meta_Default_Closed", "Derived": { "Tag": "RECORD", "IsAnonymous": true, "Record": { "IsOpen": false, "Fields": [ { "FieldName": "c_x", "FieldType": "int32", "IsNullable": false, "IsMissable": false }, { "FieldName": "c_y", "FieldType": "int32", "IsNullable": true, "IsMissable": true } ] } } }
-{ "en": "Datatype", "DatatypeName": "$d$t$m$C_Customers_Meta_Open", "Derived": { "Tag": "RECORD", "IsAnonymous": true, "Record": { "IsOpen": true, "Fields": [ { "FieldName": "c_x", "FieldType": "int32", "IsNullable": false, "IsMissable": false }, { "FieldName": "c_y", "FieldType": "int32", "IsNullable": true, "IsMissable": true } ] } } }
+{ "en": "Datatype", "DatatypeName": "$d$t$m$C_Customers_Meta_Open", "Derived": { "Tag": "RECORD", "IsAnonymous": true, "Record": { "IsOpen": true, "Fields": [ { "FieldName": "c_x", "FieldType": "int32", "IsNullable": false, "IsMissable": false }, { "FieldName": "c_y", "FieldType": "int32", "IsNullable": false, "IsMissable": false } ] } } }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/view/create-view-3-typed/create-view-3-typed.12.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/view/create-view-3-typed/create-view-3-typed.12.adm
index e561054..dffdb6e 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/view/create-view-3-typed/create-view-3-typed.12.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/view/create-view-3-typed/create-view-3-typed.12.adm
@@ -1,9 +1,9 @@
-{ "DataverseName": "test1", "DatasetName": "v1", "ViewDetails": { "Definition": "t1", "Dependencies": [ [ [ "test1", "t1" ] ], [ ], [ ] ], "Default": null } }
-{ "DataverseName": "test1", "DatasetName": "v2_ref_type", "ViewDetails": { "Definition": "select c_id,\n c_i8, c_i16, c_i32, c_i64, c_f, c_d,\n c_b, c_s,\n c_datetime, c_date, c_time,\n c_dur, c_ymdur, c_dtdur\n from t1", "Dependencies": [ [ [ "test1", "t1" ] ], [ ], [ ] ], "Default": null } }
-{ "DataverseName": "test1", "DatasetName": "v3_datetime_format", "ViewDetails": { "Definition": "t2", "Dependencies": [ [ [ "test1", "t2" ] ], [ ], [ ] ], "Default": null, "DataFormat": [ "MM/DD/YYYY hh:mm:ss.nnna", "MM/DD/YYYY", "hh:mm:ss.nnna" ] } }
-{ "DataverseName": "test1", "DatasetName": "v4_date_format_only", "ViewDetails": { "Definition": "t2", "Dependencies": [ [ [ "test1", "t2" ] ], [ ], [ ] ], "Default": null, "DataFormat": [ null, "MM/DD/YYYY", null ] } }
-{ "DataverseName": "test1", "DatasetName": "v5_pk", "ViewDetails": { "Definition": "t2", "Dependencies": [ [ [ "test1", "t2" ] ], [ ], [ ] ], "Default": null, "PrimaryKey": [ [ "c_id" ] ], "PrimaryKeyEnforced": false, "DataFormat": [ "MM/DD/YYYY hh:mm:ss.nnna", null, null ] } }
-{ "DataverseName": "test1", "DatasetName": "v6_pk_no_nulls", "ViewDetails": { "Definition": "t1", "Dependencies": [ [ [ "test1", "t1" ] ], [ ], [ ] ], "Default": null, "PrimaryKey": [ [ "c_i64" ] ], "PrimaryKeyEnforced": false } }
-{ "DataverseName": "test1", "DatasetName": "v7_no_nulls", "ViewDetails": { "Definition": "t1", "Dependencies": [ [ [ "test1", "t1" ] ], [ ], [ ] ], "Default": null } }
-{ "DataverseName": "test1", "DatasetName": "v8_no_nulls_multi", "ViewDetails": { "Definition": "select\n c_id,\n case when to_bigint(c_i32) >= 0 then to_bigint(c_i32) when to_bigint(c_i32) < 0 then null else 0 end as c_x,\n case when to_bigint(c_i64) >= 0 then null when to_bigint(c_i64) < 0 then to_bigint(c_i64) else 0 end as c_y\n from t1", "Dependencies": [ [ [ "test1", "t1" ] ], [ ], [ ] ], "Default": null } }
-{ "DataverseName": "test1", "DatasetName": "v9_pk_composite", "ViewDetails": { "Definition": "select c_id as c_id1, -c_id as c_id2\n from t1", "Dependencies": [ [ [ "test1", "t1" ] ], [ ], [ ] ], "Default": null, "PrimaryKey": [ [ "c_id1" ], [ "c_id2" ] ], "PrimaryKeyEnforced": false } }
+{ "DataverseName": "test1", "DatasetName": "v1", "DatatypeFields": [ { "FieldName": "c_id", "FieldType": "int32", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_i8", "FieldType": "int8", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_i16", "FieldType": "int16", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_i32", "FieldType": "int32", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_i64", "FieldType": "int64", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_f", "FieldType": "float", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_d", "FieldType": "double", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_b", "FieldType": "boolean", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_s", "FieldType": "string", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_datetime", "FieldType": "datetime", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_date", "FieldType": "date", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_time", "FieldType": "time", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_dur", "FieldType": "duration", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_ymdur", "FieldType": "year-month-duration", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_dtdur", "FieldType": "day-time-duration", "IsNullable": true, "IsMissable": true } ], "ViewDetails": { "Definition": "t1", "Dependencies": [ [ [ "test1", "t1" ] ], [ ], [ ] ], "Default": null } }
+{ "DataverseName": "test1", "DatasetName": "v2_ref_type", "DatatypeFields": [ { "FieldName": "c_id", "FieldType": "int32", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_i8", "FieldType": "int8", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_i16", "FieldType": "int16", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_i32", "FieldType": "int32", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_i64", "FieldType": "int64", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_f", "FieldType": "float", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_d", "FieldType": "double", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_b", "FieldType": "boolean", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_s", "FieldType": "string", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_datetime", "FieldType": "datetime", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_date", "FieldType": "date", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_time", "FieldType": "time", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_dur", "FieldType": "duration", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_ymdur", "FieldType": "year-month-duration", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_dtdur", "FieldType": "day-time-duration", "IsNullable": true, "IsMissable": true } ], "ViewDetails": { "Definition": "select c_id,\n c_i8, c_i16, c_i32, c_i64, c_f, c_d,\n c_b, c_s,\n c_datetime, c_date, c_time,\n c_dur, c_ymdur, c_dtdur\n from t1", "Dependencies": [ [ [ "test1", "t1" ] ], [ ], [ ] ], "Default": null } }
+{ "DataverseName": "test1", "DatasetName": "v3_datetime_format", "DatatypeFields": [ { "FieldName": "c_id", "FieldType": "int32", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_datetime", "FieldType": "datetime", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_date", "FieldType": "date", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_time", "FieldType": "time", "IsNullable": true, "IsMissable": true } ], "ViewDetails": { "Definition": "t2", "Dependencies": [ [ [ "test1", "t2" ] ], [ ], [ ] ], "Default": null, "DataFormat": [ "MM/DD/YYYY hh:mm:ss.nnna", "MM/DD/YYYY", "hh:mm:ss.nnna" ] } }
+{ "DataverseName": "test1", "DatasetName": "v4_date_format_only", "DatatypeFields": [ { "FieldName": "c_id", "FieldType": "int32", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_datetime", "FieldType": "datetime", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_date", "FieldType": "date", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_time", "FieldType": "time", "IsNullable": true, "IsMissable": true } ], "ViewDetails": { "Definition": "t2", "Dependencies": [ [ [ "test1", "t2" ] ], [ ], [ ] ], "Default": null, "DataFormat": [ null, "MM/DD/YYYY", null ] } }
+{ "DataverseName": "test1", "DatasetName": "v5_pk", "DatatypeFields": [ { "FieldName": "c_id", "FieldType": "int32", "IsNullable": false, "IsMissable": false }, { "FieldName": "c_datetime", "FieldType": "datetime", "IsNullable": true, "IsMissable": true } ], "ViewDetails": { "Definition": "t2", "Dependencies": [ [ [ "test1", "t2" ] ], [ ], [ ] ], "Default": null, "PrimaryKey": [ [ "c_id" ] ], "PrimaryKeyEnforced": false, "DataFormat": [ "MM/DD/YYYY hh:mm:ss.nnna", null, null ] } }
+{ "DataverseName": "test1", "DatasetName": "v6_pk_no_nulls", "DatatypeFields": [ { "FieldName": "c_i64", "FieldType": "int64", "IsNullable": false, "IsMissable": false }, { "FieldName": "c_id", "FieldType": "int32", "IsNullable": true, "IsMissable": true } ], "ViewDetails": { "Definition": "t1", "Dependencies": [ [ [ "test1", "t1" ] ], [ ], [ ] ], "Default": null, "PrimaryKey": [ [ "c_i64" ] ], "PrimaryKeyEnforced": false } }
+{ "DataverseName": "test1", "DatasetName": "v7_no_nulls", "DatatypeFields": [ { "FieldName": "c_i64", "FieldType": "int64", "IsNullable": false, "IsMissable": false }, { "FieldName": "c_id", "FieldType": "int32", "IsNullable": true, "IsMissable": true } ], "ViewDetails": { "Definition": "t1", "Dependencies": [ [ [ "test1", "t1" ] ], [ ], [ ] ], "Default": null } }
+{ "DataverseName": "test1", "DatasetName": "v8_no_nulls_multi", "DatatypeFields": [ { "FieldName": "c_id", "FieldType": "int32", "IsNullable": true, "IsMissable": true }, { "FieldName": "c_x", "FieldType": "int64", "IsNullable": false, "IsMissable": false }, { "FieldName": "c_y", "FieldType": "int64", "IsNullable": false, "IsMissable": false } ], "ViewDetails": { "Definition": "select\n c_id,\n case when to_bigint(c_i32) >= 0 then to_bigint(c_i32) when to_bigint(c_i32) < 0 then null else 0 end as c_x,\n case when to_bigint(c_i64) >= 0 then null when to_bigint(c_i64) < 0 then to_bigint(c_i64) else 0 end as c_y\n from t1", "Dependencies": [ [ [ "test1", "t1" ] ], [ ], [ ] ], "Default": null } }
+{ "DataverseName": "test1", "DatasetName": "v9_pk_composite", "DatatypeFields": [ { "FieldName": "c_id1", "FieldType": "int32", "IsNullable": false, "IsMissable": false }, { "FieldName": "c_id2", "FieldType": "int32", "IsNullable": false, "IsMissable": false } ], "ViewDetails": { "Definition": "select c_id as c_id1, -c_id as c_id2\n from t1", "Dependencies": [ [ [ "test1", "t1" ] ], [ ], [ ] ], "Default": null, "PrimaryKey": [ [ "c_id1" ], [ "c_id2" ] ], "PrimaryKeyEnforced": false } }
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 77f412c..896497f 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -13360,8 +13360,8 @@
<expected-error><![CDATA[ASX1014: Field "unknown_field" is not found (in line 25, at column 1)]]></expected-error>
<expected-error><![CDATA[ASX1014: Field "unknown_field_2" is not found (in line 25, at column 1)]]></expected-error>
<expected-error><![CDATA[ASX1001: Syntax error: In line 28 >> as select r from range(1,2) r;<< Encountered "as" at column 3]]></expected-error>
- <expected-error><![CDATA[ASX1021: The primary key field "r" cannot be nullable (in line 25, at column 1)]]></expected-error>
- <expected-error><![CDATA[ASX1021: The primary key field "r2" cannot be nullable (in line 25, at column 1)]]></expected-error>
+ <expected-error><![CDATA[ASX0013: Duplicate field name "r" (in line 25, at column 20)]]></expected-error>
+ <expected-error><![CDATA[ASX1167: Cannot change primary key of view test1.employee_v1 (in line 38, at column 1)]]></expected-error>
<expected-error><![CDATA[ASX1162: Invalid primary key definition (in line 25, at column 1)]]></expected-error>
<expected-error><![CDATA[ASX1162: Invalid primary key definition (in line 26, at column 1)]]></expected-error>
<expected-error><![CDATA[ASX1001: Syntax error: In line 36 >> as employee;<< Encountered "as" at column 3]]></expected-error>
@@ -13375,8 +13375,6 @@
<expected-error><![CDATA[ASX1164: Invalid foreign key definition (in line 43, at column 1)]]></expected-error>
<expected-error><![CDATA[ASX1164: Invalid foreign key definition (in line 39, at column 1)]]></expected-error>
<expected-error><![CDATA[ASX1166: Invalid foreign key definition: foreign key does not match primary key of view test1.employee_v1 (in line 39, at column 1)]]></expected-error>
- <expected-error><![CDATA[ASX1167: Cannot change primary key of view test1.employee_v1 (in line 38, at column 1)]]></expected-error>
- <expected-error><![CDATA[ASX0013: Duplicate field name "r" (in line 25, at column 20)]]></expected-error>
<source-location>false</source-location>
</compilation-unit>
</test-case>
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/DatasetDeclParametersUtil.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/DatasetDeclParametersUtil.java
index 8e91169..0aef69f 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/DatasetDeclParametersUtil.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/DatasetDeclParametersUtil.java
@@ -18,9 +18,14 @@
*/
package org.apache.asterix.lang.common.util;
+import java.util.List;
+
import org.apache.asterix.common.config.DatasetConfig;
import org.apache.asterix.common.exceptions.CompilationException;
import org.apache.asterix.lang.common.expression.RecordConstructor;
+import org.apache.asterix.lang.common.expression.RecordTypeDefinition;
+import org.apache.asterix.lang.common.expression.TypeExpression;
+import org.apache.asterix.metadata.entities.Index;
import org.apache.asterix.object.base.AdmObjectNode;
import org.apache.asterix.om.types.ARecordType;
import org.apache.asterix.om.types.AUnionType;
@@ -127,4 +132,38 @@
final IAType[] schemeType = { BuiltinType.ASTRING };
return new ARecordType(NODE_GROUP_NAME, schemeName, schemeType, false);
}
+
+ /**
+ * Adjusts dataset inline type definition if it has primary key specification:
+ * forces NOT UNKNOWN on fields that are part of primary key.
+ */
+ public static void adjustInlineTypeDecl(TypeExpression typeDecl, List<List<String>> primaryKeyFields,
+ List<Integer> primaryKeySources, boolean isMeta) {
+ switch (typeDecl.getTypeKind()) {
+ case RECORD:
+ RecordTypeDefinition recordTypeDef = (RecordTypeDefinition) typeDecl;
+ for (int i = 0, n = primaryKeyFields.size(); i < n; i++) {
+ List<String> primaryKeyPath = primaryKeyFields.get(i);
+ if (primaryKeyPath.size() == 1) {
+ String primaryKeyFieldName = primaryKeyPath.get(0);
+ boolean isMetaSource =
+ primaryKeySources != null && primaryKeySources.get(i) == Index.META_RECORD_INDICATOR;
+ boolean isSameSource = isMetaSource == isMeta;
+ if (isSameSource) {
+ int fieldIdx = recordTypeDef.getFieldNames().indexOf(primaryKeyFieldName);
+ if (fieldIdx >= 0) {
+ recordTypeDef.getMissableFields().set(fieldIdx, false);
+ recordTypeDef.getNullableFields().set(fieldIdx, false);
+ }
+ }
+ }
+ }
+ break;
+ case TYPEREFERENCE:
+ // this is not an inline type decl
+ break;
+ default:
+ throw new IllegalStateException(typeDecl.getTypeKind().toString());
+ }
+ }
}
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
index 9f9ab3d..728b240 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
+++ b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
@@ -172,6 +172,7 @@
import org.apache.asterix.lang.common.struct.OperatorType;
import org.apache.asterix.lang.common.struct.QuantifiedPair;
import org.apache.asterix.lang.common.struct.VarIdentifier;
+import org.apache.asterix.lang.common.util.DatasetDeclParametersUtil;
import org.apache.asterix.lang.common.util.ExpressionUtils;
import org.apache.asterix.lang.common.util.RangeMapBuilder;
import org.apache.asterix.lang.sqlpp.clause.AbstractBinaryCorrelateClause;
@@ -1038,6 +1039,11 @@
try {
InternalDetailsDecl idd = new InternalDetailsDecl(primaryKeyFields.second, primaryKeyFields.first, autogenerated,
filterField == null? null : filterField.first, filterField == null? null : filterField.second);
+ DatasetDeclParametersUtil.adjustInlineTypeDecl(typeExpr, primaryKeyFields.second, primaryKeyFields.first, false);
+ if (metaTypeExpr != null) {
+ DatasetDeclParametersUtil.adjustInlineTypeDecl(metaTypeExpr, primaryKeyFields.second, primaryKeyFields.first,
+ true);
+ }
stmt = new DatasetDecl(nameComponents.first, nameComponents.second, typeExpr, metaTypeExpr, hints,
DatasetType.INTERNAL, idd, withRecord, ifNotExists);
return addSourceLocation(stmt, startStmtToken);
@@ -1563,6 +1569,9 @@
endPos.endColumn + 1);
removeCurrentScope();
defaultDataverse = currentDataverse;
+ if (typeExpr != null && primaryKeyFields != null) {
+ DatasetDeclParametersUtil.adjustInlineTypeDecl(typeExpr, primaryKeyFields.second, primaryKeyFields.first, false);
+ }
CreateViewStatement.KeyDecl primaryKeyDecl = primaryKeyFields != null ?
new CreateViewStatement.KeyDecl(primaryKeyFields.second, primaryKeyFields.first) : null;
CreateViewStatement stmt = new CreateViewStatement(nameComponents.first, nameComponents.second.getValue(),