[ASTERIXDB-3345][COMP] Enforce identifiers to start with letter in cloud deployment
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
Change-Id: I6d3aaa003776152aa47e37cd219f741ba286e25e
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/18141
Reviewed-by: Ali Alsuliman <ali.al.solaiman@gmail.com>
Reviewed-by: Wail Alkowaileet <wael.y.k@gmail.com>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cloud_storage/disallowed-chars/test.005.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cloud_storage/disallowed-chars/test.005.ddl.sqlpp
new file mode 100644
index 0000000..0ca6e5b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cloud_storage/disallowed-chars/test.005.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.
+ */
+// should fail. first character needs to be a letter
+CREATE COLLECTION db1.dv1.`123collection` PRIMARY KEY (id:int);
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cloud_storage/disallowed-chars/test.006.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cloud_storage/disallowed-chars/test.006.ddl.sqlpp
new file mode 100644
index 0000000..f322341
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cloud_storage/disallowed-chars/test.006.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.
+ */
+// should fail. first character needs to be a letter
+CREATE DATAVERSE db1.`12dataverse`;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cloud_storage/disallowed-chars/test.007.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cloud_storage/disallowed-chars/test.007.ddl.sqlpp
new file mode 100644
index 0000000..f1b646c
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/cloud_storage/disallowed-chars/test.007.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.
+ */
+// should fail. first character needs to be a letter
+CREATE DATABASE `1db`;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_cloud_storage.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_cloud_storage.xml
index 6359d8a..6a75394 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_cloud_storage.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_cloud_storage.xml
@@ -38,6 +38,9 @@
<expected-error>ASX1115: Invalid name for a database object: 'dv.with.dot'</expected-error>
<expected-error>ASX1115: Invalid name for a database object: 'col.with.dot'</expected-error>
<expected-error>ASX1115: Invalid name for a database object: 'db.with.dot'</expected-error>
+ <expected-error>ASX1115: Invalid name for a database object: '123collection'</expected-error>
+ <expected-error>ASX1115: Invalid name for a database object: '12dataverse'</expected-error>
+ <expected-error>ASX1115: Invalid name for a database object: '1db'</expected-error>
</compilation-unit>
</test-case>
</test-group>
diff --git a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/MetadataProvider.java b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/MetadataProvider.java
index 68a49fa..107cfb2 100644
--- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/MetadataProvider.java
+++ b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/MetadataProvider.java
@@ -1956,10 +1956,16 @@
private static void validateChars(String name, SourceLocation srcLoc) throws AsterixException {
for (int off = 0, len = name.length(); off < len;) {
int codePointChar = name.codePointAt(off);
- if (!Character.isLetterOrDigit(codePointChar)) {
- if (codePointChar != '_' && codePointChar != '-') {
+ if (off == 0) {
+ if (!Character.isLetter(codePointChar)) {
throw new AsterixException(ErrorCode.INVALID_DATABASE_OBJECT_NAME, srcLoc, name);
}
+ } else {
+ if (!Character.isLetterOrDigit(codePointChar)) {
+ if (codePointChar != '_' && codePointChar != '-') {
+ throw new AsterixException(ErrorCode.INVALID_DATABASE_OBJECT_NAME, srcLoc, name);
+ }
+ }
}
off += Character.charCount(codePointChar);
}