AMashenkov commented on code in PR #4971:
URL: https://github.com/apache/ignite-3/pull/4971#discussion_r1898433858


##########
modules/api/src/main/java/org/apache/ignite/table/QualifiedName.java:
##########
@@ -0,0 +1,306 @@
+/*
+ * 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.
+ */
+
+package org.apache.ignite.table;
+
+import java.util.Objects;
+import org.apache.ignite.lang.util.IgniteNameUtils;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Class represents a catalog object name (table, index and etc.) and provides 
factory methods.
+ *
+ * <p>Qualified name is a pair of schema name and object name. Schema name is 
optional and can be null, which means that it will be
+ * resolved in lazy manner against default schema. Default schema depends on 
the context, where the name will be used. If no context is
+ * available (e.g. client or embedded KeyValue API), then  "PUBLIC" will be 
used as default schema name.
+ *
+ * <p>Both schema name and object name can be case sensitive or insensitive 
respecting SQL-parser style quotation.
+ * Unquoted name will be cast to upper case. E.g. "tbl0" - is equivalent to 
"TBL0", "\"Tbl0\"" - "Tbl0", etc.
+ */
+public class QualifiedName {
+    /**
+     * Parses given simple or canonical name, and returns the object qualified 
name.
+     */
+    public static QualifiedName parse(String simpleOrCanonicalName) {
+        verifyObjectName(simpleOrCanonicalName);
+
+        Tokenizer tokenizer = new Tokenizer(simpleOrCanonicalName);
+
+        String schemaName = null;
+        String objectName = tokenizer.nextToken();
+
+        if (tokenizer.hasNext()) {
+            // Canonical name
+            schemaName = objectName;
+            objectName = tokenizer.nextToken();
+        }
+
+        if (tokenizer.hasNext()) {
+            throw new IllegalArgumentException("Canonical name format 
mismatch: " + simpleOrCanonicalName);
+        }
+
+        verifySchemaName(schemaName);
+        verifyObjectName(objectName);
+
+        return new QualifiedName(schemaName, objectName);
+    }
+
+    /**
+     * Resolves (maybe lazily) given simple name against default schema.
+     */
+    public static QualifiedName fromSimple(String simpleName) {
+        return of(null, simpleName);
+    }
+
+    /**
+     * Normalize schemaName and objectName, and returns the object qualified 
name.
+     */
+    public static QualifiedName of(@Nullable String schemaName, String 
objectName) {
+        String normalizedSchemaName = schemaName == null ? null : 
parseIdentifier(schemaName);
+        String normalizedObjectName = parseIdentifier(objectName);
+
+        verifySchemaName(normalizedSchemaName);
+        verifyObjectName(normalizedObjectName);
+
+        return new QualifiedName(normalizedSchemaName, normalizedObjectName);
+    }
+
+    private static String parseIdentifier(String name) {
+        if (name == null || name.isEmpty()) {
+            return name;
+        }
+
+        var tokenizer = new Tokenizer(name);
+
+        String parsedName = tokenizer.nextToken();
+
+        if (tokenizer.hasNext()) {
+            throw new IllegalArgumentException("Non-qualified identifier 
expected: " + name);
+        }
+
+        return parsedName;
+    }
+
+    private static void verifyObjectName(@Nullable String name) {
+        if (name == null || name.isEmpty()) {

Review Comment:
   Internal package from ignite-core module is not available in ignite-api 
module.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to