[NO ISSUE][COMP] Improve database object name validation
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
- Move dataverse name and object name validation from
QueryTranslator to MetadataProvider
- Added testcases for CREATE statements with invalid
dataverse names
Change-Id: I76740bc1ad2bcb9c48a84246319a0b1342530b49
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/9150
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Dmitry Lychagin <dmitry.lychagin@couchbase.com>
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
index 45f0a82..2ba5c0e 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
@@ -494,23 +494,31 @@
protected Dataverse handleUseDataverseStatement(MetadataProvider metadataProvider, Statement stmt)
throws Exception {
DataverseDecl dvd = (DataverseDecl) stmt;
- SourceLocation sourceLoc = dvd.getSourceLocation();
DataverseName dvName = dvd.getDataverseName();
- MetadataTransactionContext mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
- metadataProvider.setMetadataTxnContext(mdTxnCtx);
+ metadataProvider.validateDataverseName(dvName, dvd.getSourceLocation());
lockManager.acquireDataverseReadLock(metadataProvider.getLocks(), dvName);
try {
+ return doUseDataverseStatement(metadataProvider, dvd);
+ } finally {
+ metadataProvider.getLocks().unlock();
+ }
+ }
+
+ protected Dataverse doUseDataverseStatement(MetadataProvider metadataProvider, DataverseDecl stmtUseDataverse)
+ throws Exception {
+ MetadataTransactionContext mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
+ metadataProvider.setMetadataTxnContext(mdTxnCtx);
+ try {
+ DataverseName dvName = stmtUseDataverse.getDataverseName();
Dataverse dv = MetadataManager.INSTANCE.getDataverse(metadataProvider.getMetadataTxnContext(), dvName);
if (dv == null) {
- throw new MetadataException(ErrorCode.UNKNOWN_DATAVERSE, sourceLoc, dvName);
+ throw new MetadataException(ErrorCode.UNKNOWN_DATAVERSE, stmtUseDataverse.getSourceLocation(), dvName);
}
MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
return dv;
} catch (Exception e) {
abort(e, e, mdTxnCtx);
- throw new MetadataException(ErrorCode.METADATA_ERROR, e, sourceLoc, e.toString());
- } finally {
- metadataProvider.getLocks().unlock();
+ throw e;
}
}
@@ -518,9 +526,7 @@
IRequestParameters requestParameters) throws Exception {
CreateDataverseStatement stmtCreateDataverse = (CreateDataverseStatement) stmt;
DataverseName dvName = stmtCreateDataverse.getDataverseName();
- for (String dvNamePart : dvName.getParts()) {
- validateDatabaseObjectName(dvNamePart, stmtCreateDataverse.getSourceLocation());
- }
+ metadataProvider.validateDataverseName(dvName, stmtCreateDataverse.getSourceLocation());
lockUtil.createDataverseBegin(lockManager, metadataProvider.getLocks(), dvName);
try {
doCreateDataverseStatement(metadataProvider, stmtCreateDataverse, requestParameters);
@@ -596,9 +602,9 @@
public void handleCreateDatasetStatement(MetadataProvider metadataProvider, Statement stmt,
IHyracksClientConnection hcc, IRequestParameters requestParameters) throws Exception {
DatasetDecl dd = (DatasetDecl) stmt;
- DataverseName dataverseName = getActiveDataverseName(dd.getDataverse());
String datasetName = dd.getName().getValue();
- validateDatabaseObjectName(datasetName, stmt.getSourceLocation());
+ metadataProvider.validateDatabaseObjectName(dd.getDataverse(), datasetName, stmt.getSourceLocation());
+ DataverseName dataverseName = getActiveDataverseName(dd.getDataverse());
TypeExpression itemTypeExpr = dd.getItemType();
DataverseName itemTypeDataverseName;
String itemTypeName;
@@ -968,10 +974,11 @@
public void handleCreateIndexStatement(MetadataProvider metadataProvider, Statement stmt,
IHyracksClientConnection hcc, IRequestParameters requestParameters) throws Exception {
CreateIndexStatement stmtCreateIndex = (CreateIndexStatement) stmt;
- DataverseName dataverseName = getActiveDataverseName(stmtCreateIndex.getDataverseName());
String datasetName = stmtCreateIndex.getDatasetName().getValue();
String indexName = stmtCreateIndex.getIndexName().getValue();
- validateDatabaseObjectName(indexName, stmt.getSourceLocation());
+ metadataProvider.validateDatabaseObjectName(stmtCreateIndex.getDataverseName(), indexName,
+ stmt.getSourceLocation());
+ DataverseName dataverseName = getActiveDataverseName(stmtCreateIndex.getDataverseName());
lockUtil.createIndexBegin(lockManager, metadataProvider.getLocks(), dataverseName, datasetName);
try {
doCreateIndex(metadataProvider, stmtCreateIndex, dataverseName, datasetName, hcc, requestParameters);
@@ -1395,9 +1402,9 @@
protected void handleCreateTypeStatement(MetadataProvider metadataProvider, Statement stmt) throws Exception {
TypeDecl stmtCreateType = (TypeDecl) stmt;
SourceLocation sourceLoc = stmtCreateType.getSourceLocation();
- DataverseName dataverseName = getActiveDataverseName(stmtCreateType.getDataverseName());
String typeName = stmtCreateType.getIdent().getValue();
- validateDatabaseObjectName(typeName, sourceLoc);
+ metadataProvider.validateDatabaseObjectName(stmtCreateType.getDataverseName(), typeName, sourceLoc);
+ DataverseName dataverseName = getActiveDataverseName(stmtCreateType.getDataverseName());
MetadataTransactionContext mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
metadataProvider.setMetadataTxnContext(mdTxnCtx);
lockUtil.createTypeBegin(lockManager, metadataProvider.getLocks(), dataverseName, typeName);
@@ -1995,7 +2002,8 @@
IStatementRewriter stmtRewriter) throws Exception {
CreateFunctionStatement cfs = (CreateFunctionStatement) stmt;
FunctionSignature signature = cfs.getFunctionSignature();
- validateDatabaseObjectName(signature.getName(), stmt.getSourceLocation());
+ metadataProvider.validateDatabaseObjectName(signature.getDataverseName(), signature.getName(),
+ stmt.getSourceLocation());
DataverseName dataverseName = getActiveDataverseName(signature.getDataverseName());
signature.setDataverseName(dataverseName);
DataverseName libraryDataverseName = null;
@@ -2896,9 +2904,9 @@
protected void handleCreateFeedStatement(MetadataProvider metadataProvider, Statement stmt) throws Exception {
CreateFeedStatement cfs = (CreateFeedStatement) stmt;
SourceLocation sourceLoc = cfs.getSourceLocation();
- DataverseName dataverseName = getActiveDataverseName(cfs.getDataverseName());
String feedName = cfs.getFeedName().getValue();
- validateDatabaseObjectName(feedName, sourceLoc);
+ metadataProvider.validateDatabaseObjectName(cfs.getDataverseName(), feedName, sourceLoc);
+ DataverseName dataverseName = getActiveDataverseName(cfs.getDataverseName());
MetadataTransactionContext mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
metadataProvider.setMetadataTxnContext(mdTxnCtx);
lockUtil.createFeedBegin(lockManager, metadataProvider.getLocks(), dataverseName, feedName);
@@ -2935,9 +2943,9 @@
MetadataTransactionContext mdTxnCtx = null;
CreateFeedPolicyStatement cfps = (CreateFeedPolicyStatement) stmt;
SourceLocation sourceLoc = cfps.getSourceLocation();
- DataverseName dataverseName = getActiveDataverseName(null);
String policyName = cfps.getPolicyName();
- validateDatabaseObjectName(policyName, sourceLoc);
+ metadataProvider.validateDatabaseObjectName(null, policyName, sourceLoc);
+ DataverseName dataverseName = getActiveDataverseName(null);
lockUtil.createFeedPolicyBegin(lockManager, metadataProvider.getLocks(), dataverseName, policyName);
try {
mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
@@ -3526,7 +3534,7 @@
NodegroupDecl stmtCreateNodegroup = (NodegroupDecl) stmt;
SourceLocation sourceLoc = stmtCreateNodegroup.getSourceLocation();
String ngName = stmtCreateNodegroup.getNodegroupName().getValue();
- validateDatabaseObjectName(ngName, sourceLoc);
+ metadataProvider.validateDatabaseObjectName(null, ngName, sourceLoc);
MetadataTransactionContext mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
metadataProvider.setMetadataTxnContext(mdTxnCtx);
@@ -3948,13 +3956,4 @@
throws CompilationException {
ExternalDataUtils.validateAdapterSpecificProperties(configuration, srcLoc, warningCollector);
}
-
- public static void validateDatabaseObjectName(String name, SourceLocation sourceLoc) throws CompilationException {
- if (name == null || name.isEmpty()) {
- throw new CompilationException(ErrorCode.INVALID_DATABASE_OBJECT_NAME, sourceLoc, "<empty>");
- }
- if (Character.isWhitespace(name.codePointAt(0))) {
- throw new CompilationException(ErrorCode.INVALID_DATABASE_OBJECT_NAME, sourceLoc, name);
- }
- }
}
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-dataset-name/invalid-dataset-name.3.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-dataset-name/invalid-dataset-name.3.ddl.sqlpp
index dc10acd..fcd7cb1 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-dataset-name/invalid-dataset-name.3.ddl.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-dataset-name/invalid-dataset-name.3.ddl.sqlpp
@@ -17,4 +17,8 @@
* under the License.
*/
-drop dataverse test if exists;
+/*
+ * Invalid dataverse name in CREATE DATASET -> Error
+ */
+
+create dataset ` invalid`.a(id int not unknown) primary key id;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-dataset-name/invalid-dataset-name.4.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-dataset-name/invalid-dataset-name.4.ddl.sqlpp
new file mode 100644
index 0000000..dc10acd
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-dataset-name/invalid-dataset-name.4.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;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-dataverse-name/invalid-dataverse-name.3.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-dataverse-name/invalid-dataverse-name.3.ddl.sqlpp
new file mode 100644
index 0000000..af006e3
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-dataverse-name/invalid-dataverse-name.3.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.
+ */
+
+/*
+ * Invalid dataverse in USE -> Error
+ */
+
+use ` invalid`;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-feed-name/invalid-feed-name.2.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-feed-name/invalid-feed-name.2.ddl.sqlpp
index 6d59d03..22ba05e 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-feed-name/invalid-feed-name.2.ddl.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-feed-name/invalid-feed-name.2.ddl.sqlpp
@@ -31,8 +31,6 @@
id: int64
};
-create dataset Tweets0(Tweet) primary key id;
-
create feed ` a` with {
"adapter-name" : "socket_adapter",
"sockets" : "127.0.0.1:10001",
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-feed-name/invalid-feed-name.3.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-feed-name/invalid-feed-name.3.ddl.sqlpp
index dc10acd..169e8c8 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-feed-name/invalid-feed-name.3.ddl.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-feed-name/invalid-feed-name.3.ddl.sqlpp
@@ -17,4 +17,24 @@
* under the License.
*/
+/*
+ * Invalid dataverse name in CREATE FEED -> Error
+ */
+
drop dataverse test if exists;
+create dataverse test;
+
+use test;
+
+create type Tweet as closed
+{
+ id: int64
+};
+
+create feed ` invalid`.a with {
+ "adapter-name" : "socket_adapter",
+ "sockets" : "127.0.0.1:10001",
+ "address-type" : "IP",
+ "type-name" : "Tweet",
+ "format" : "adm"
+};
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-feed-name/invalid-feed-name.4.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-feed-name/invalid-feed-name.4.ddl.sqlpp
new file mode 100644
index 0000000..dc10acd
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-feed-name/invalid-feed-name.4.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;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-index-name/invalid-index-name.3.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-index-name/invalid-index-name.3.ddl.sqlpp
index dc10acd..4799420 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-index-name/invalid-index-name.3.ddl.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-index-name/invalid-index-name.3.ddl.sqlpp
@@ -17,4 +17,8 @@
* under the License.
*/
-drop dataverse test if exists;
+/*
+ * Invalid dataverse name in CREATE INDEX -> Error
+ */
+
+create index a on ` invalid`.t1(x);
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-index-name/invalid-index-name.4.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-index-name/invalid-index-name.4.ddl.sqlpp
new file mode 100644
index 0000000..dc10acd
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-index-name/invalid-index-name.4.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;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-type-name/invalid-type-name.3.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-type-name/invalid-type-name.3.ddl.sqlpp
index dc10acd..ed322ef 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-type-name/invalid-type-name.3.ddl.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-type-name/invalid-type-name.3.ddl.sqlpp
@@ -17,4 +17,10 @@
* under the License.
*/
-drop dataverse test if exists;
+/*
+ * Invalid dataverse name in CREATE TYPE -> Error
+ */
+
+create type ` invalid`.a as closed {
+ id: int
+};
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-type-name/invalid-type-name.4.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-type-name/invalid-type-name.4.ddl.sqlpp
new file mode 100644
index 0000000..dc10acd
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-type-name/invalid-type-name.4.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;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-udf-name/invalid-udf-name.3.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-udf-name/invalid-udf-name.3.ddl.sqlpp
index dc10acd..1d85543 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-udf-name/invalid-udf-name.3.ddl.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-udf-name/invalid-udf-name.3.ddl.sqlpp
@@ -17,4 +17,10 @@
* under the License.
*/
-drop dataverse test if exists;
+/*
+ * Invalid dataverse name in CREATE FUNCTION -> Error
+ */
+
+create function ` invalid`.a() {
+ 1
+};
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-udf-name/invalid-udf-name.4.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-udf-name/invalid-udf-name.4.ddl.sqlpp
new file mode 100644
index 0000000..dc10acd
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/invalid-udf-name/invalid-udf-name.4.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;
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 3f6b76e..3086db4 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -4020,6 +4020,7 @@
<output-dir compare="Text">none</output-dir>
<expected-error>ASX1115: Invalid name for a database object: "<empty>"</expected-error>
<expected-error>ASX1115: Invalid name for a database object: " a"</expected-error>
+ <expected-error>ASX1115: Invalid name for a database object: " invalid"</expected-error>
<expected-error>ASX1079: Compilation error: Invalid operation - Cannot create dataverse: asterix</expected-error>
<expected-error>ASX1079: Compilation error: Invalid operation - Cannot create dataverse: algebricks</expected-error>
</compilation-unit>
@@ -4029,6 +4030,7 @@
<output-dir compare="Text">none</output-dir>
<expected-error>ASX1115: Invalid name for a database object: "<empty>"</expected-error>
<expected-error>ASX1115: Invalid name for a database object: " a"</expected-error>
+ <expected-error>ASX1115: Invalid name for a database object: " invalid"</expected-error>
</compilation-unit>
</test-case>
<test-case FilePath="ddl">
@@ -4036,6 +4038,7 @@
<output-dir compare="Text">none</output-dir>
<expected-error>ASX1115: Invalid name for a database object: "<empty>"</expected-error>
<expected-error>ASX1115: Invalid name for a database object: " a"</expected-error>
+ <expected-error>ASX1115: Invalid name for a database object: " invalid"</expected-error>
</compilation-unit>
</test-case>
<test-case FilePath="ddl">
@@ -4050,6 +4053,7 @@
<output-dir compare="Text">none</output-dir>
<expected-error>ASX1115: Invalid name for a database object: "<empty>"</expected-error>
<expected-error>ASX1115: Invalid name for a database object: " a"</expected-error>
+ <expected-error>ASX1115: Invalid name for a database object: " invalid"</expected-error>
</compilation-unit>
</test-case>
<test-case FilePath="ddl">
@@ -4064,6 +4068,7 @@
<output-dir compare="Text">none</output-dir>
<expected-error>ASX1115: Invalid name for a database object: "<empty>"</expected-error>
<expected-error>ASX1115: Invalid name for a database object: " a"</expected-error>
+ <expected-error>ASX1115: Invalid name for a database object: " invalid"</expected-error>
</compilation-unit>
</test-case>
<test-case FilePath="ddl">
@@ -4071,6 +4076,7 @@
<output-dir compare="Text">none</output-dir>
<expected-error>ASX1115: Invalid name for a database object: "<empty>"</expected-error>
<expected-error>ASX1115: Invalid name for a database object: " a"</expected-error>
+ <expected-error>ASX1115: Invalid name for a database object: " invalid"</expected-error>
</compilation-unit>
</test-case>
<test-case FilePath="ddl">
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 2bb4fd5..7d00c4b 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
@@ -39,6 +39,7 @@
import org.apache.asterix.common.dataflow.ICcApplicationContext;
import org.apache.asterix.common.dataflow.LSMTreeInsertDeleteOperatorDescriptor;
import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.ErrorCode;
import org.apache.asterix.common.external.IDataSourceAdapter;
import org.apache.asterix.common.functions.FunctionSignature;
import org.apache.asterix.common.metadata.DataverseName;
@@ -138,6 +139,7 @@
import org.apache.hyracks.api.dataflow.value.ITypeTraits;
import org.apache.hyracks.api.dataflow.value.RecordDescriptor;
import org.apache.hyracks.api.exceptions.IWarningCollector;
+import org.apache.hyracks.api.exceptions.SourceLocation;
import org.apache.hyracks.api.io.FileSplit;
import org.apache.hyracks.api.job.IOperatorDescriptorRegistry;
import org.apache.hyracks.api.job.JobSpecification;
@@ -1754,4 +1756,28 @@
public Set<Dataset> getAccessedDatasets() {
return Collections.unmodifiableSet(txnAccessedDatasets);
}
+
+ public void validateDataverseName(DataverseName dataverseName, SourceLocation sourceLoc)
+ throws AlgebricksException {
+ for (String dvNamePart : dataverseName.getParts()) {
+ validateDatabaseObjectNameImpl(dvNamePart, sourceLoc);
+ }
+ }
+
+ public void validateDatabaseObjectName(DataverseName dataverseName, String objectName, SourceLocation sourceLoc)
+ throws AlgebricksException {
+ if (dataverseName != null) {
+ validateDataverseName(dataverseName, sourceLoc);
+ }
+ validateDatabaseObjectNameImpl(objectName, sourceLoc);
+ }
+
+ private void validateDatabaseObjectNameImpl(String name, SourceLocation sourceLoc) throws AlgebricksException {
+ if (name == null || name.isEmpty()) {
+ throw new AsterixException(ErrorCode.INVALID_DATABASE_OBJECT_NAME, sourceLoc, "<empty>");
+ }
+ if (Character.isWhitespace(name.codePointAt(0))) {
+ throw new AsterixException(ErrorCode.INVALID_DATABASE_OBJECT_NAME, sourceLoc, name);
+ }
+ }
}