This is an automated email from the ASF dual-hosted git repository.
wyk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git
The following commit(s) were added to refs/heads/master by this push:
new 7efe49cd49 [ASTERIXDB-3345][COMP] Enforce identifiers to start with
letter in cloud deployment
7efe49cd49 is described below
commit 7efe49cd493a9cbf5b87ff3ca9fbb21b1fc4f0f6
Author: Ali Alsuliman <[email protected]>
AuthorDate: Thu Jan 25 09:30:35 2024 -0800
[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 <[email protected]>
Reviewed-by: Wail Alkowaileet <[email protected]>
Tested-by: Jenkins <[email protected]>
---
.../disallowed-chars/test.005.ddl.sqlpp | 20 ++++++++++++++++++++
.../disallowed-chars/test.006.ddl.sqlpp | 20 ++++++++++++++++++++
.../disallowed-chars/test.007.ddl.sqlpp | 20 ++++++++++++++++++++
.../resources/runtimets/testsuite_cloud_storage.xml | 3 +++
.../asterix/metadata/declared/MetadataProvider.java | 10 ++++++++--
5 files changed, 71 insertions(+), 2 deletions(-)
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 0000000000..0ca6e5b86a
--- /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 0000000000..f3223415ef
--- /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 0000000000..f1b646c5e2
--- /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 6359d8a0ed..6a7539473b 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 68a49faa8e..107cfb2cc5 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 @@ public class MetadataProvider implements
IMetadataProvider<DataSourceId, String>
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);
}