You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "AMashenkov (via GitHub)" <gi...@apache.org> on 2024/12/25 13:24:08 UTC

[PR] IGNITE-24036 Sql schema. Introduce QualifiedName class [ignite-3]

AMashenkov opened a new pull request, #4971:
URL: https://github.com/apache/ignite-3/pull/4971

   Thank you for submitting the pull request.
   
   To streamline the review process of the patch and ensure better code quality
   we ask both an author and a reviewer to verify the following:
   
   ### The Review Checklist
   - [ ] **Formal criteria:** TC status, codestyle, mandatory documentation. Also make sure to complete the following:  
   \- There is a single JIRA ticket related to the pull request.  
   \- The web-link to the pull request is attached to the JIRA ticket.  
   \- The JIRA ticket has the Patch Available state.  
   \- The description of the JIRA ticket explains WHAT was made, WHY and HOW.  
   \- The pull request title is treated as the final commit message. The following pattern must be used: IGNITE-XXXX Change summary where XXXX - number of JIRA issue.
   - [ ] **Design:** new code conforms with the design principles of the components it is added to.
   - [ ] **Patch quality:** patch cannot be split into smaller pieces, its size must be reasonable.
   - [ ] **Code quality:** code is clean and readable, necessary developer documentation is added if needed.
   - [ ] **Tests code quality:** test set covers positive/negative scenarios, happy/edge cases. Tests are effective in terms of execution time and resources.
   
   ### Notes
   - [Apache Ignite Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Java+Code+Style+Guide)


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-24036 Sql schema. Introduce QualifiedName class [ignite-3]

Posted by "xtern (via GitHub)" <gi...@apache.org>.
xtern commented on code in PR #4971:
URL: https://github.com/apache/ignite-3/pull/4971#discussion_r1899590602


##########
modules/api/src/main/java/org/apache/ignite/table/QualifiedName.java:
##########
@@ -0,0 +1,344 @@
+/*
+ * 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 static org.apache.ignite.lang.util.IgniteNameUtils.identifierExtend;
+import static org.apache.ignite.lang.util.IgniteNameUtils.identifierStart;
+import static org.apache.ignite.lang.util.IgniteNameUtils.quote;
+
+import java.util.NoSuchElementException;
+import java.util.Objects;
+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, when not set, then
+ * {@link QualifiedName#DEFAULT_SCHEMA_NAME} will be used.
+ *
+ * <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 {
+    /** Default schema name. */
+    public static final String DEFAULT_SCHEMA_NAME = "PUBLIC";
+
+    /** Normalized schema name. */
+    private final String schemaIdentifier;
+
+    /** Normalized object name. */
+    private final String objectIdentifier;
+
+    /**
+     * Parses given simple or canonical name, and returns the object qualified name.
+     */
+    public static QualifiedName parse(String simpleOrCanonicalName) {
+        verifyObjectIdentifier(simpleOrCanonicalName);
+
+        Tokenizer tokenizer = new Tokenizer(simpleOrCanonicalName);
+
+        String schemaName = DEFAULT_SCHEMA_NAME;
+        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);
+        }
+
+        verifySchemaIdentifier(schemaName);
+        verifyObjectIdentifier(objectName);
+
+        return new QualifiedName(schemaName, objectName);
+    }
+
+    /**
+     * Resolves 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.
+     *
+     * @param schemaName Schema name or {@code null} for default schema.
+     * @param objectName Object name.
+     */
+    public static QualifiedName of(@Nullable String schemaName, String objectName) {
+        String schemaIdentifier = schemaName == null ? DEFAULT_SCHEMA_NAME : parseIdentifier(schemaName);
+        String objectIdentifier = parseIdentifier(objectName);
+
+        verifySchemaIdentifier(schemaIdentifier);
+        verifyObjectIdentifier(objectIdentifier);
+
+        return new QualifiedName(schemaIdentifier, objectIdentifier);
+    }
+
+    /**
+     * Constructs a qualified name.
+     *
+     * @param schemaName Normalized schema name.
+     * @param objectName Normalized object name.
+     */
+    private QualifiedName(String schemaName, String objectName) {
+        this.schemaIdentifier = schemaName;
+        this.objectIdentifier = objectName;
+    }
+
+    /** Returns normalized schema name. */
+    public String schemaName() {
+        return schemaIdentifier;
+    }
+
+    /** Returns normalized object name. */
+    public String objectName() {
+        return objectIdentifier;
+    }
+
+    /** Returns qualified name in canonical form. */
+    public String toCanonicalForm() {
+        // TODO https://issues.apache.org/jira/browse/IGNITE-24021 Extract method and move to IgniteNameUtils
+        return quoteIfNeeded(schemaIdentifier) + '.' + quoteIfNeeded(objectIdentifier);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public boolean equals(Object object) {
+        if (this == object) {
+            return true;
+        }
+        if (object == null || getClass() != object.getClass()) {
+            return false;
+        }
+        QualifiedName that = (QualifiedName) object;
+        return Objects.equals(schemaIdentifier, that.schemaIdentifier) && Objects.equals(objectIdentifier, that.objectIdentifier);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public int hashCode() {
+        return Objects.hash(schemaIdentifier, objectIdentifier);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public String toString() {
+        return "QualifiedName["
+                + "schemaName='" + schemaIdentifier + '\''
+                + ", objectName='" + objectIdentifier + '\''
+                + ']';
+    }
+
+    private static void verifyObjectIdentifier(@Nullable String identifier) {
+        Objects.requireNonNull(identifier);
+
+        if (identifier.isEmpty()) {
+            throw new IllegalArgumentException("Object identifier can't be empty.");
+        }
+    }
+
+    private static void verifySchemaIdentifier(@Nullable String identifier) {
+        if (identifier != null && identifier.isEmpty()) {
+            throw new IllegalArgumentException("Schema identifier can't be empty.");
+        }
+    }
+
+    /**
+     * Parse simple name: unquote name or cast to upper case not-quoted name.
+     *
+     * @param name String to parse object name.
+     * @return Unquoted name or name is cast to upper case. "tbl0" -&gt; "TBL0", "\"Tbl0\"" -&gt; "Tbl0".
+     */
+    // TODO https://issues.apache.org/jira/browse/IGNITE-24021: Use QualifiedName instead.
+    //  This method should be called from QualifiedName class only. Rename to parseIdentifier.
+    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("Fully qualified name is not expected [name=" + name + "]");
+        }
+
+        return parsedName;
+    }
+
+    /**
+     * Wraps the given name with double quotes if it not uppercased non-quoted name, e.g. "myColumn" -&gt; "\"myColumn\"", "MYCOLUMN" -&gt;
+     * "MYCOLUMN"
+     *
+     * @param identifier Object identifier.
+     * @return Quoted object name.
+     */
+    public static String quoteIfNeeded(String identifier) {
+        if (identifier.isEmpty()) {
+            return identifier;
+        }
+
+        if (!identifierStart(identifier.codePointAt(0)) && !Character.isUpperCase(identifier.codePointAt(0))) {
+            return quote(identifier);
+        }
+
+        for (int pos = 1; pos < identifier.length(); pos++) {
+            int codePoint = identifier.codePointAt(pos);
+
+            if (!identifierExtend(codePoint) && !Character.isUpperCase(codePoint)) {
+                return quote(identifier);
+            }
+        }
+
+        return identifier;
+    }
+
+    /**
+     * Identifier chain tokenizer.
+     *
+     * <p>Splits provided identifier chain (complex identifier like PUBLIC.MY_TABLE) into its component parts.
+     */
+    public static class Tokenizer {

Review Comment:
   I prefer to keep it private until [IGNITE-24021](https://issues.apache.org/jira/browse/IGNITE-24021) will be implemented



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-24036 Sql schema. Introduce QualifiedName class [ignite-3]

Posted by "AMashenkov (via GitHub)" <gi...@apache.org>.
AMashenkov commented on code in PR #4971:
URL: https://github.com/apache/ignite-3/pull/4971#discussion_r1897756040


##########
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()) {
+            throw new IllegalArgumentException("Object name can't be null or empty.");
+        }
+    }
+
+    private static void verifySchemaName(@Nullable String schemaName) {
+        if (schemaName != null && schemaName.isEmpty()) {
+            throw new IllegalArgumentException("Schema name can't be empty.");
+        }
+    }
+
+    private final @Nullable String schemaName;
+    private final String objectName;
+
+    /**
+     * Constructs a qualified name.
+     *
+     * @param schemaName Normalized schema name.
+     * @param objectName Normalized object name.
+     */
+    private QualifiedName(@Nullable String schemaName, String objectName) {
+        this.schemaName = schemaName;
+        this.objectName = objectName;
+    }
+
+    /** Returns normalized schema name. */
+    public @Nullable String schemaName() {
+        return schemaName;
+    }
+
+    /** Returns normalized object name. */
+    public String name() {
+        return objectName;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public boolean equals(Object object) {
+        if (this == object) {
+            return true;
+        }
+        if (object == null || getClass() != object.getClass()) {
+            return false;
+        }
+        QualifiedName that = (QualifiedName) object;
+        return Objects.equals(schemaName, that.schemaName) && Objects.equals(objectName, that.objectName);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public int hashCode() {
+        return Objects.hash(schemaName, objectName);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public String toString() {
+        String simpleName = IgniteNameUtils.quoteIfNeeded(objectName);
+
+        return schemaName == null ? simpleName : IgniteNameUtils.quoteIfNeeded(schemaName) + '.' + simpleName;
+    }
+
+    /**
+     * Identifier chain tokenizer.
+     *
+     * <p>Splits provided identifier chain (complex identifier like PUBLIC.MY_TABLE) into its component parts.
+     *
+     * <p>This tokenizer is not SQL compliant, but it is ok since it used to retrieve an object only. The sole purpose of this tokenizer
+     * is to split the chain into parts by a dot considering the quotation.
+     */
+    private static class Tokenizer {

Review Comment:
   It has wrong implementation.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-24036 Sql schema. Introduce QualifiedName class [ignite-3]

Posted by "xtern (via GitHub)" <gi...@apache.org>.
xtern commented on code in PR #4971:
URL: https://github.com/apache/ignite-3/pull/4971#discussion_r1899586928


##########
modules/api/src/main/java/org/apache/ignite/table/QualifiedName.java:
##########
@@ -0,0 +1,344 @@
+/*
+ * 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 static org.apache.ignite.lang.util.IgniteNameUtils.identifierExtend;
+import static org.apache.ignite.lang.util.IgniteNameUtils.identifierStart;
+import static org.apache.ignite.lang.util.IgniteNameUtils.quote;
+
+import java.util.NoSuchElementException;
+import java.util.Objects;
+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, when not set, then
+ * {@link QualifiedName#DEFAULT_SCHEMA_NAME} will be used.
+ *
+ * <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 {
+    /** Default schema name. */
+    public static final String DEFAULT_SCHEMA_NAME = "PUBLIC";
+
+    /** Normalized schema name. */
+    private final String schemaIdentifier;
+
+    /** Normalized object name. */
+    private final String objectIdentifier;
+
+    /**
+     * Parses given simple or canonical name, and returns the object qualified name.
+     */
+    public static QualifiedName parse(String simpleOrCanonicalName) {
+        verifyObjectIdentifier(simpleOrCanonicalName);
+
+        Tokenizer tokenizer = new Tokenizer(simpleOrCanonicalName);
+
+        String schemaName = DEFAULT_SCHEMA_NAME;
+        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);
+        }
+
+        verifySchemaIdentifier(schemaName);
+        verifyObjectIdentifier(objectName);
+
+        return new QualifiedName(schemaName, objectName);
+    }
+
+    /**
+     * Resolves 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.
+     *
+     * @param schemaName Schema name or {@code null} for default schema.
+     * @param objectName Object name.
+     */
+    public static QualifiedName of(@Nullable String schemaName, String objectName) {
+        String schemaIdentifier = schemaName == null ? DEFAULT_SCHEMA_NAME : parseIdentifier(schemaName);
+        String objectIdentifier = parseIdentifier(objectName);
+
+        verifySchemaIdentifier(schemaIdentifier);
+        verifyObjectIdentifier(objectIdentifier);
+
+        return new QualifiedName(schemaIdentifier, objectIdentifier);
+    }
+
+    /**
+     * Constructs a qualified name.
+     *
+     * @param schemaName Normalized schema name.
+     * @param objectName Normalized object name.
+     */
+    private QualifiedName(String schemaName, String objectName) {
+        this.schemaIdentifier = schemaName;
+        this.objectIdentifier = objectName;
+    }
+
+    /** Returns normalized schema name. */
+    public String schemaName() {
+        return schemaIdentifier;
+    }
+
+    /** Returns normalized object name. */
+    public String objectName() {
+        return objectIdentifier;
+    }
+
+    /** Returns qualified name in canonical form. */
+    public String toCanonicalForm() {
+        // TODO https://issues.apache.org/jira/browse/IGNITE-24021 Extract method and move to IgniteNameUtils
+        return quoteIfNeeded(schemaIdentifier) + '.' + quoteIfNeeded(objectIdentifier);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public boolean equals(Object object) {
+        if (this == object) {
+            return true;
+        }
+        if (object == null || getClass() != object.getClass()) {
+            return false;
+        }
+        QualifiedName that = (QualifiedName) object;
+        return Objects.equals(schemaIdentifier, that.schemaIdentifier) && Objects.equals(objectIdentifier, that.objectIdentifier);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public int hashCode() {
+        return Objects.hash(schemaIdentifier, objectIdentifier);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public String toString() {
+        return "QualifiedName["
+                + "schemaName='" + schemaIdentifier + '\''
+                + ", objectName='" + objectIdentifier + '\''
+                + ']';
+    }
+
+    private static void verifyObjectIdentifier(@Nullable String identifier) {
+        Objects.requireNonNull(identifier);
+
+        if (identifier.isEmpty()) {
+            throw new IllegalArgumentException("Object identifier can't be empty.");
+        }
+    }
+
+    private static void verifySchemaIdentifier(@Nullable String identifier) {
+        if (identifier != null && identifier.isEmpty()) {
+            throw new IllegalArgumentException("Schema identifier can't be empty.");
+        }
+    }
+
+    /**
+     * Parse simple name: unquote name or cast to upper case not-quoted name.
+     *
+     * @param name String to parse object name.
+     * @return Unquoted name or name is cast to upper case. "tbl0" -&gt; "TBL0", "\"Tbl0\"" -&gt; "Tbl0".
+     */
+    // TODO https://issues.apache.org/jira/browse/IGNITE-24021: Use QualifiedName instead.
+    //  This method should be called from QualifiedName class only. Rename to parseIdentifier.
+    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("Fully qualified name is not expected [name=" + name + "]");
+        }
+
+        return parsedName;
+    }
+
+    /**
+     * Wraps the given name with double quotes if it not uppercased non-quoted name, e.g. "myColumn" -&gt; "\"myColumn\"", "MYCOLUMN" -&gt;
+     * "MYCOLUMN"
+     *
+     * @param identifier Object identifier.
+     * @return Quoted object name.
+     */
+    public static String quoteIfNeeded(String identifier) {

Review Comment:
   I prefer to keep it private until [IGNITE-24021](https://issues.apache.org/jira/browse/IGNITE-24021) will be implemented



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-24036 Sql schema. Introduce QualifiedName class [ignite-3]

Posted by "AMashenkov (via GitHub)" <gi...@apache.org>.
AMashenkov merged PR #4971:
URL: https://github.com/apache/ignite-3/pull/4971


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-24036 Sql schema. Introduce QualifiedName class [ignite-3]

Posted by "xtern (via GitHub)" <gi...@apache.org>.
xtern commented on code in PR #4971:
URL: https://github.com/apache/ignite-3/pull/4971#discussion_r1897707727


##########
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()) {
+            throw new IllegalArgumentException("Object name can't be null or empty.");
+        }
+    }
+
+    private static void verifySchemaName(@Nullable String schemaName) {
+        if (schemaName != null && schemaName.isEmpty()) {
+            throw new IllegalArgumentException("Schema name can't be empty.");
+        }
+    }
+
+    private final @Nullable String schemaName;
+    private final String objectName;
+
+    /**
+     * Constructs a qualified name.
+     *
+     * @param schemaName Normalized schema name.
+     * @param objectName Normalized object name.
+     */
+    private QualifiedName(@Nullable String schemaName, String objectName) {
+        this.schemaName = schemaName;
+        this.objectName = objectName;
+    }
+
+    /** Returns normalized schema name. */
+    public @Nullable String schemaName() {
+        return schemaName;
+    }
+
+    /** Returns normalized object name. */
+    public String name() {
+        return objectName;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public boolean equals(Object object) {
+        if (this == object) {
+            return true;
+        }
+        if (object == null || getClass() != object.getClass()) {
+            return false;
+        }
+        QualifiedName that = (QualifiedName) object;
+        return Objects.equals(schemaName, that.schemaName) && Objects.equals(objectName, that.objectName);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public int hashCode() {
+        return Objects.hash(schemaName, objectName);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public String toString() {
+        String simpleName = IgniteNameUtils.quoteIfNeeded(objectName);
+
+        return schemaName == null ? simpleName : IgniteNameUtils.quoteIfNeeded(schemaName) + '.' + simpleName;
+    }
+
+    /**
+     * Identifier chain tokenizer.
+     *
+     * <p>Splits provided identifier chain (complex identifier like PUBLIC.MY_TABLE) into its component parts.
+     *
+     * <p>This tokenizer is not SQL compliant, but it is ok since it used to retrieve an object only. The sole purpose of this tokenizer
+     * is to split the chain into parts by a dot considering the quotation.
+     */
+    private static class Tokenizer {

Review Comment:
   Why we can't use `IgniteNmeUtils.Tokenizer` ?



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-24036 Sql schema. Introduce QualifiedName class [ignite-3]

Posted by "AMashenkov (via GitHub)" <gi...@apache.org>.
AMashenkov commented on code in PR #4971:
URL: https://github.com/apache/ignite-3/pull/4971#discussion_r1898433982


##########
modules/api/src/main/java/org/apache/ignite/table/QualifiedName.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.apache.ignite.lang.util.IgniteNameUtils.Tokenizer;
+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, when not set, then
+ * default schema name "PUBLIC" is used.
+ *
+ * <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 {
+    static final String DEFAULT_SCHEMA_NAME = "PUBLIC";
+
+    /**
+     * Parses given simple or canonical name, and returns the object qualified name.
+     */
+    public static QualifiedName parse(String simpleOrCanonicalName) {
+        verifyObjectIdentifier(simpleOrCanonicalName);
+
+        Tokenizer tokenizer = new Tokenizer(simpleOrCanonicalName);
+
+        String schemaName = DEFAULT_SCHEMA_NAME;
+        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);
+        }
+
+        verifySchemaIdentifier(schemaName);
+        verifyObjectIdentifier(objectName);
+
+        return new QualifiedName(schemaName, objectName);
+    }
+
+    /**
+     * Resolves 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.
+     *
+     * @param schemaName Schema name or {@code null} for default schema.
+     * @param objectName Object name.
+     */
+    public static QualifiedName of(@Nullable String schemaName, String objectName) {
+        String schemaIdentifier = schemaName == null ? DEFAULT_SCHEMA_NAME : IgniteNameUtils.parseSimpleName(schemaName);
+        String objectIdentifier = IgniteNameUtils.parseSimpleName(objectName);
+
+        verifySchemaIdentifier(schemaIdentifier);
+        verifyObjectIdentifier(objectIdentifier);
+
+        return new QualifiedName(schemaIdentifier, objectIdentifier);
+    }
+
+    private static void verifyObjectIdentifier(@Nullable String identifier) {
+        Objects.requireNonNull(identifier);
+
+        if (identifier.isEmpty()) {
+            throw new IllegalArgumentException("Object identifier can't be empty.");
+        }
+    }
+
+    private static void verifySchemaIdentifier(@Nullable String identifier) {
+        if (identifier != null && identifier.isEmpty()) {
+            throw new IllegalArgumentException("Schema identifier can't be empty.");
+        }
+    }
+
+    /** Normalized schema name. */
+    private final String schemaIdentifier;

Review Comment:
   done.



##########
modules/api/src/main/java/org/apache/ignite/lang/util/IgniteNameUtils.java:
##########
@@ -150,26 +170,43 @@ public Tokenizer(String source) {
 
         /** Returns {@code true} if at least one token is available. */
         public boolean hasNext() {
-            return currentPosition < source.length();
+            return foundDot || !isEol();
         }
 
         /** Returns next token. */
-        public @Nullable String nextToken() {
+        public String nextToken() {
             if (!hasNext()) {
-                return null;
+                throw new NoSuchElementException("No more tokens available.");
+            } else if (isEol()) {
+                if (foundDot) {
+                    foundDot = false;
+                    return "";
+                }
+                throw new NoSuchElementException("No more tokens available.");

Review Comment:
   done



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-24036 Sql schema. Introduce QualifiedName class [ignite-3]

Posted by "zstan (via GitHub)" <gi...@apache.org>.
zstan commented on code in PR #4971:
URL: https://github.com/apache/ignite-3/pull/4971#discussion_r1898270158


##########
modules/api/src/main/java/org/apache/ignite/table/QualifiedName.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.apache.ignite.lang.util.IgniteNameUtils.Tokenizer;
+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, when not set, then
+ * default schema name "PUBLIC" is used.
+ *
+ * <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 {
+    static final String DEFAULT_SCHEMA_NAME = "PUBLIC";

Review Comment:
   plz also fix it here SqlCommon#DEFAULT_SCHEMA_NAME



##########
modules/api/src/main/java/org/apache/ignite/lang/util/IgniteNameUtils.java:
##########
@@ -150,26 +170,43 @@ public Tokenizer(String source) {
 
         /** Returns {@code true} if at least one token is available. */
         public boolean hasNext() {
-            return currentPosition < source.length();
+            return foundDot || !isEol();
         }
 
         /** Returns next token. */
-        public @Nullable String nextToken() {
+        public String nextToken() {
             if (!hasNext()) {
-                return null;
+                throw new NoSuchElementException("No more tokens available.");
+            } else if (isEol()) {
+                if (foundDot) {
+                    foundDot = false;
+                    return "";
+                }
+                throw new NoSuchElementException("No more tokens available.");

Review Comment:
   this exception can be returned through public api, but what does it mean from user point of view, may be it need be wrapped ?



##########
modules/api/src/main/java/org/apache/ignite/table/QualifiedName.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.apache.ignite.lang.util.IgniteNameUtils.Tokenizer;
+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, when not set, then
+ * default schema name "PUBLIC" is used.
+ *
+ * <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 {
+    static final String DEFAULT_SCHEMA_NAME = "PUBLIC";
+
+    /**
+     * Parses given simple or canonical name, and returns the object qualified name.
+     */
+    public static QualifiedName parse(String simpleOrCanonicalName) {
+        verifyObjectIdentifier(simpleOrCanonicalName);
+
+        Tokenizer tokenizer = new Tokenizer(simpleOrCanonicalName);
+
+        String schemaName = DEFAULT_SCHEMA_NAME;
+        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);
+        }
+
+        verifySchemaIdentifier(schemaName);
+        verifyObjectIdentifier(objectName);
+
+        return new QualifiedName(schemaName, objectName);
+    }
+
+    /**
+     * Resolves 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.
+     *
+     * @param schemaName Schema name or {@code null} for default schema.
+     * @param objectName Object name.
+     */
+    public static QualifiedName of(@Nullable String schemaName, String objectName) {
+        String schemaIdentifier = schemaName == null ? DEFAULT_SCHEMA_NAME : IgniteNameUtils.parseSimpleName(schemaName);
+        String objectIdentifier = IgniteNameUtils.parseSimpleName(objectName);
+
+        verifySchemaIdentifier(schemaIdentifier);
+        verifyObjectIdentifier(objectIdentifier);
+
+        return new QualifiedName(schemaIdentifier, objectIdentifier);
+    }
+
+    private static void verifyObjectIdentifier(@Nullable String identifier) {
+        Objects.requireNonNull(identifier);
+
+        if (identifier.isEmpty()) {
+            throw new IllegalArgumentException("Object identifier can't be empty.");
+        }
+    }
+
+    private static void verifySchemaIdentifier(@Nullable String identifier) {
+        if (identifier != null && identifier.isEmpty()) {
+            throw new IllegalArgumentException("Schema identifier can't be empty.");
+        }
+    }
+
+    /** Normalized schema name. */
+    private final String schemaIdentifier;

Review Comment:
   plz move it into beginning, just become more readable



##########
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:
   ```suggestion
           if (org.apache.ignite.internal.util.StringUtils#nullOrEmpty(name)) {
   ```



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-24036 Sql schema. Introduce QualifiedName class [ignite-3]

Posted by "xtern (via GitHub)" <gi...@apache.org>.
xtern commented on code in PR #4971:
URL: https://github.com/apache/ignite-3/pull/4971#discussion_r1899574447


##########
modules/api/src/main/java/org/apache/ignite/lang/util/IgniteNameUtils.java:
##########
@@ -36,6 +38,8 @@ private IgniteNameUtils() {
      * @param name String to parse object name.
      * @return Unquoted name or name is cast to upper case. "tbl0" -&gt; "TBL0", "\"Tbl0\"" -&gt; "Tbl0".
      */
+    // TODO https://issues.apache.org/jira/browse/IGNITE-24021: Use QualifiedName instead.
+    //  This method should be called from QualifiedName class only. Rename to parseIdentifier.

Review Comment:
   `Use QualifiedName instead.` and `Rename to parseIdentifier.` looks confusing :thinking: 



##########
modules/api/src/main/java/org/apache/ignite/table/QualifiedName.java:
##########
@@ -0,0 +1,344 @@
+/*
+ * 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 static org.apache.ignite.lang.util.IgniteNameUtils.identifierExtend;
+import static org.apache.ignite.lang.util.IgniteNameUtils.identifierStart;
+import static org.apache.ignite.lang.util.IgniteNameUtils.quote;
+
+import java.util.NoSuchElementException;
+import java.util.Objects;
+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, when not set, then
+ * {@link QualifiedName#DEFAULT_SCHEMA_NAME} will be used.
+ *
+ * <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 {
+    /** Default schema name. */
+    public static final String DEFAULT_SCHEMA_NAME = "PUBLIC";
+
+    /** Normalized schema name. */
+    private final String schemaIdentifier;
+
+    /** Normalized object name. */
+    private final String objectIdentifier;
+
+    /**
+     * Parses given simple or canonical name, and returns the object qualified name.
+     */
+    public static QualifiedName parse(String simpleOrCanonicalName) {
+        verifyObjectIdentifier(simpleOrCanonicalName);
+
+        Tokenizer tokenizer = new Tokenizer(simpleOrCanonicalName);
+
+        String schemaName = DEFAULT_SCHEMA_NAME;
+        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);
+        }
+
+        verifySchemaIdentifier(schemaName);
+        verifyObjectIdentifier(objectName);
+
+        return new QualifiedName(schemaName, objectName);
+    }
+
+    /**
+     * Resolves 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.
+     *
+     * @param schemaName Schema name or {@code null} for default schema.
+     * @param objectName Object name.
+     */
+    public static QualifiedName of(@Nullable String schemaName, String objectName) {
+        String schemaIdentifier = schemaName == null ? DEFAULT_SCHEMA_NAME : parseIdentifier(schemaName);
+        String objectIdentifier = parseIdentifier(objectName);
+
+        verifySchemaIdentifier(schemaIdentifier);
+        verifyObjectIdentifier(objectIdentifier);
+
+        return new QualifiedName(schemaIdentifier, objectIdentifier);
+    }
+
+    /**
+     * Constructs a qualified name.
+     *
+     * @param schemaName Normalized schema name.
+     * @param objectName Normalized object name.
+     */
+    private QualifiedName(String schemaName, String objectName) {
+        this.schemaIdentifier = schemaName;
+        this.objectIdentifier = objectName;
+    }
+
+    /** Returns normalized schema name. */
+    public String schemaName() {
+        return schemaIdentifier;
+    }
+
+    /** Returns normalized object name. */
+    public String objectName() {
+        return objectIdentifier;
+    }
+
+    /** Returns qualified name in canonical form. */
+    public String toCanonicalForm() {
+        // TODO https://issues.apache.org/jira/browse/IGNITE-24021 Extract method and move to IgniteNameUtils
+        return quoteIfNeeded(schemaIdentifier) + '.' + quoteIfNeeded(objectIdentifier);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public boolean equals(Object object) {
+        if (this == object) {
+            return true;
+        }
+        if (object == null || getClass() != object.getClass()) {
+            return false;
+        }
+        QualifiedName that = (QualifiedName) object;
+        return Objects.equals(schemaIdentifier, that.schemaIdentifier) && Objects.equals(objectIdentifier, that.objectIdentifier);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public int hashCode() {
+        return Objects.hash(schemaIdentifier, objectIdentifier);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public String toString() {
+        return "QualifiedName["
+                + "schemaName='" + schemaIdentifier + '\''
+                + ", objectName='" + objectIdentifier + '\''
+                + ']';
+    }
+
+    private static void verifyObjectIdentifier(@Nullable String identifier) {
+        Objects.requireNonNull(identifier);
+
+        if (identifier.isEmpty()) {
+            throw new IllegalArgumentException("Object identifier can't be empty.");
+        }
+    }
+
+    private static void verifySchemaIdentifier(@Nullable String identifier) {
+        if (identifier != null && identifier.isEmpty()) {
+            throw new IllegalArgumentException("Schema identifier can't be empty.");
+        }
+    }
+
+    /**
+     * Parse simple name: unquote name or cast to upper case not-quoted name.
+     *
+     * @param name String to parse object name.
+     * @return Unquoted name or name is cast to upper case. "tbl0" -&gt; "TBL0", "\"Tbl0\"" -&gt; "Tbl0".
+     */
+    // TODO https://issues.apache.org/jira/browse/IGNITE-24021: Use QualifiedName instead.
+    //  This method should be called from QualifiedName class only. Rename to parseIdentifier.
+    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("Fully qualified name is not expected [name=" + name + "]");
+        }
+
+        return parsedName;
+    }
+
+    /**
+     * Wraps the given name with double quotes if it not uppercased non-quoted name, e.g. "myColumn" -&gt; "\"myColumn\"", "MYCOLUMN" -&gt;
+     * "MYCOLUMN"
+     *
+     * @param identifier Object identifier.
+     * @return Quoted object name.
+     */
+    public static String quoteIfNeeded(String identifier) {

Review Comment:
   why it's _public_?



##########
modules/api/src/main/java/org/apache/ignite/table/QualifiedName.java:
##########
@@ -0,0 +1,344 @@
+/*
+ * 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 static org.apache.ignite.lang.util.IgniteNameUtils.identifierExtend;
+import static org.apache.ignite.lang.util.IgniteNameUtils.identifierStart;
+import static org.apache.ignite.lang.util.IgniteNameUtils.quote;
+
+import java.util.NoSuchElementException;
+import java.util.Objects;
+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, when not set, then
+ * {@link QualifiedName#DEFAULT_SCHEMA_NAME} will be used.
+ *
+ * <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 {
+    /** Default schema name. */
+    public static final String DEFAULT_SCHEMA_NAME = "PUBLIC";
+
+    /** Normalized schema name. */
+    private final String schemaIdentifier;
+
+    /** Normalized object name. */
+    private final String objectIdentifier;
+
+    /**
+     * Parses given simple or canonical name, and returns the object qualified name.
+     */
+    public static QualifiedName parse(String simpleOrCanonicalName) {
+        verifyObjectIdentifier(simpleOrCanonicalName);
+
+        Tokenizer tokenizer = new Tokenizer(simpleOrCanonicalName);
+
+        String schemaName = DEFAULT_SCHEMA_NAME;
+        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);
+        }
+
+        verifySchemaIdentifier(schemaName);
+        verifyObjectIdentifier(objectName);
+
+        return new QualifiedName(schemaName, objectName);
+    }
+
+    /**
+     * Resolves 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.
+     *
+     * @param schemaName Schema name or {@code null} for default schema.
+     * @param objectName Object name.
+     */
+    public static QualifiedName of(@Nullable String schemaName, String objectName) {
+        String schemaIdentifier = schemaName == null ? DEFAULT_SCHEMA_NAME : parseIdentifier(schemaName);
+        String objectIdentifier = parseIdentifier(objectName);
+
+        verifySchemaIdentifier(schemaIdentifier);
+        verifyObjectIdentifier(objectIdentifier);
+
+        return new QualifiedName(schemaIdentifier, objectIdentifier);
+    }
+
+    /**
+     * Constructs a qualified name.
+     *
+     * @param schemaName Normalized schema name.
+     * @param objectName Normalized object name.
+     */
+    private QualifiedName(String schemaName, String objectName) {
+        this.schemaIdentifier = schemaName;
+        this.objectIdentifier = objectName;
+    }
+
+    /** Returns normalized schema name. */
+    public String schemaName() {
+        return schemaIdentifier;
+    }
+
+    /** Returns normalized object name. */
+    public String objectName() {
+        return objectIdentifier;
+    }
+
+    /** Returns qualified name in canonical form. */
+    public String toCanonicalForm() {
+        // TODO https://issues.apache.org/jira/browse/IGNITE-24021 Extract method and move to IgniteNameUtils
+        return quoteIfNeeded(schemaIdentifier) + '.' + quoteIfNeeded(objectIdentifier);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public boolean equals(Object object) {
+        if (this == object) {
+            return true;
+        }
+        if (object == null || getClass() != object.getClass()) {
+            return false;
+        }
+        QualifiedName that = (QualifiedName) object;
+        return Objects.equals(schemaIdentifier, that.schemaIdentifier) && Objects.equals(objectIdentifier, that.objectIdentifier);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public int hashCode() {
+        return Objects.hash(schemaIdentifier, objectIdentifier);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public String toString() {
+        return "QualifiedName["
+                + "schemaName='" + schemaIdentifier + '\''
+                + ", objectName='" + objectIdentifier + '\''
+                + ']';
+    }
+
+    private static void verifyObjectIdentifier(@Nullable String identifier) {
+        Objects.requireNonNull(identifier);
+
+        if (identifier.isEmpty()) {
+            throw new IllegalArgumentException("Object identifier can't be empty.");
+        }
+    }
+
+    private static void verifySchemaIdentifier(@Nullable String identifier) {
+        if (identifier != null && identifier.isEmpty()) {
+            throw new IllegalArgumentException("Schema identifier can't be empty.");
+        }
+    }
+
+    /**
+     * Parse simple name: unquote name or cast to upper case not-quoted name.
+     *
+     * @param name String to parse object name.
+     * @return Unquoted name or name is cast to upper case. "tbl0" -&gt; "TBL0", "\"Tbl0\"" -&gt; "Tbl0".
+     */
+    // TODO https://issues.apache.org/jira/browse/IGNITE-24021: Use QualifiedName instead.
+    //  This method should be called from QualifiedName class only. Rename to parseIdentifier.
+    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("Fully qualified name is not expected [name=" + name + "]");
+        }
+
+        return parsedName;
+    }
+
+    /**
+     * Wraps the given name with double quotes if it not uppercased non-quoted name, e.g. "myColumn" -&gt; "\"myColumn\"", "MYCOLUMN" -&gt;
+     * "MYCOLUMN"
+     *
+     * @param identifier Object identifier.
+     * @return Quoted object name.
+     */
+    public static String quoteIfNeeded(String identifier) {
+        if (identifier.isEmpty()) {
+            return identifier;
+        }
+
+        if (!identifierStart(identifier.codePointAt(0)) && !Character.isUpperCase(identifier.codePointAt(0))) {
+            return quote(identifier);
+        }
+
+        for (int pos = 1; pos < identifier.length(); pos++) {
+            int codePoint = identifier.codePointAt(pos);
+
+            if (!identifierExtend(codePoint) && !Character.isUpperCase(codePoint)) {
+                return quote(identifier);
+            }
+        }
+
+        return identifier;
+    }
+
+    /**
+     * Identifier chain tokenizer.
+     *
+     * <p>Splits provided identifier chain (complex identifier like PUBLIC.MY_TABLE) into its component parts.
+     */
+    public static class Tokenizer {

Review Comment:
   I prefer to keep it private until [IGNITE-24036](https://issues.apache.org/jira/browse/IGNITE-24036) will be implemented



##########
modules/api/src/main/java/org/apache/ignite/table/QualifiedName.java:
##########
@@ -0,0 +1,344 @@
+/*
+ * 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 static org.apache.ignite.lang.util.IgniteNameUtils.identifierExtend;
+import static org.apache.ignite.lang.util.IgniteNameUtils.identifierStart;
+import static org.apache.ignite.lang.util.IgniteNameUtils.quote;
+
+import java.util.NoSuchElementException;
+import java.util.Objects;
+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, when not set, then
+ * {@link QualifiedName#DEFAULT_SCHEMA_NAME} will be used.
+ *
+ * <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 {
+    /** Default schema name. */
+    public static final String DEFAULT_SCHEMA_NAME = "PUBLIC";
+
+    /** Normalized schema name. */
+    private final String schemaIdentifier;
+
+    /** Normalized object name. */
+    private final String objectIdentifier;
+
+    /**
+     * Parses given simple or canonical name, and returns the object qualified name.
+     */
+    public static QualifiedName parse(String simpleOrCanonicalName) {
+        verifyObjectIdentifier(simpleOrCanonicalName);
+
+        Tokenizer tokenizer = new Tokenizer(simpleOrCanonicalName);
+
+        String schemaName = DEFAULT_SCHEMA_NAME;
+        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);
+        }
+
+        verifySchemaIdentifier(schemaName);
+        verifyObjectIdentifier(objectName);
+
+        return new QualifiedName(schemaName, objectName);
+    }
+
+    /**
+     * Resolves 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.
+     *
+     * @param schemaName Schema name or {@code null} for default schema.
+     * @param objectName Object name.
+     */
+    public static QualifiedName of(@Nullable String schemaName, String objectName) {
+        String schemaIdentifier = schemaName == null ? DEFAULT_SCHEMA_NAME : parseIdentifier(schemaName);
+        String objectIdentifier = parseIdentifier(objectName);
+
+        verifySchemaIdentifier(schemaIdentifier);
+        verifyObjectIdentifier(objectIdentifier);
+
+        return new QualifiedName(schemaIdentifier, objectIdentifier);
+    }
+
+    /**
+     * Constructs a qualified name.
+     *
+     * @param schemaName Normalized schema name.
+     * @param objectName Normalized object name.
+     */
+    private QualifiedName(String schemaName, String objectName) {
+        this.schemaIdentifier = schemaName;
+        this.objectIdentifier = objectName;
+    }
+
+    /** Returns normalized schema name. */
+    public String schemaName() {
+        return schemaIdentifier;
+    }
+
+    /** Returns normalized object name. */
+    public String objectName() {
+        return objectIdentifier;
+    }
+
+    /** Returns qualified name in canonical form. */
+    public String toCanonicalForm() {
+        // TODO https://issues.apache.org/jira/browse/IGNITE-24021 Extract method and move to IgniteNameUtils
+        return quoteIfNeeded(schemaIdentifier) + '.' + quoteIfNeeded(objectIdentifier);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public boolean equals(Object object) {
+        if (this == object) {
+            return true;
+        }
+        if (object == null || getClass() != object.getClass()) {
+            return false;
+        }
+        QualifiedName that = (QualifiedName) object;
+        return Objects.equals(schemaIdentifier, that.schemaIdentifier) && Objects.equals(objectIdentifier, that.objectIdentifier);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public int hashCode() {
+        return Objects.hash(schemaIdentifier, objectIdentifier);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public String toString() {
+        return "QualifiedName["
+                + "schemaName='" + schemaIdentifier + '\''
+                + ", objectName='" + objectIdentifier + '\''
+                + ']';
+    }
+
+    private static void verifyObjectIdentifier(@Nullable String identifier) {
+        Objects.requireNonNull(identifier);
+
+        if (identifier.isEmpty()) {
+            throw new IllegalArgumentException("Object identifier can't be empty.");
+        }
+    }
+
+    private static void verifySchemaIdentifier(@Nullable String identifier) {
+        if (identifier != null && identifier.isEmpty()) {
+            throw new IllegalArgumentException("Schema identifier can't be empty.");
+        }
+    }
+
+    /**
+     * Parse simple name: unquote name or cast to upper case not-quoted name.
+     *
+     * @param name String to parse object name.
+     * @return Unquoted name or name is cast to upper case. "tbl0" -&gt; "TBL0", "\"Tbl0\"" -&gt; "Tbl0".
+     */
+    // TODO https://issues.apache.org/jira/browse/IGNITE-24021: Use QualifiedName instead.
+    //  This method should be called from QualifiedName class only. Rename to parseIdentifier.
+    static String parseIdentifier(String name) {

Review Comment:
   I suppose that this comment is a result of copy-paste from IgniteNameUtils#parseSimpleName and it should be removed?
   
   p.s. why this method should not be _private_?



##########
modules/api/src/main/java/org/apache/ignite/table/QualifiedName.java:
##########
@@ -0,0 +1,344 @@
+/*
+ * 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 static org.apache.ignite.lang.util.IgniteNameUtils.identifierExtend;
+import static org.apache.ignite.lang.util.IgniteNameUtils.identifierStart;
+import static org.apache.ignite.lang.util.IgniteNameUtils.quote;
+
+import java.util.NoSuchElementException;
+import java.util.Objects;
+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, when not set, then
+ * {@link QualifiedName#DEFAULT_SCHEMA_NAME} will be used.
+ *
+ * <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 {
+    /** Default schema name. */
+    public static final String DEFAULT_SCHEMA_NAME = "PUBLIC";
+
+    /** Normalized schema name. */
+    private final String schemaIdentifier;
+
+    /** Normalized object name. */
+    private final String objectIdentifier;
+
+    /**
+     * Parses given simple or canonical name, and returns the object qualified name.
+     */
+    public static QualifiedName parse(String simpleOrCanonicalName) {
+        verifyObjectIdentifier(simpleOrCanonicalName);
+
+        Tokenizer tokenizer = new Tokenizer(simpleOrCanonicalName);
+
+        String schemaName = DEFAULT_SCHEMA_NAME;
+        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);
+        }
+
+        verifySchemaIdentifier(schemaName);
+        verifyObjectIdentifier(objectName);
+
+        return new QualifiedName(schemaName, objectName);
+    }
+
+    /**
+     * Resolves 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.

Review Comment:
   I think it should be either
   normalize**S** and return**S** 
   or
   `normalize` and `return`
   
   :thinking: 



##########
modules/api/src/main/java/org/apache/ignite/table/QualifiedName.java:
##########
@@ -0,0 +1,344 @@
+/*
+ * 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 static org.apache.ignite.lang.util.IgniteNameUtils.identifierExtend;
+import static org.apache.ignite.lang.util.IgniteNameUtils.identifierStart;
+import static org.apache.ignite.lang.util.IgniteNameUtils.quote;
+
+import java.util.NoSuchElementException;
+import java.util.Objects;
+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, when not set, then
+ * {@link QualifiedName#DEFAULT_SCHEMA_NAME} will be used.
+ *
+ * <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 {
+    /** Default schema name. */
+    public static final String DEFAULT_SCHEMA_NAME = "PUBLIC";
+
+    /** Normalized schema name. */
+    private final String schemaIdentifier;
+
+    /** Normalized object name. */
+    private final String objectIdentifier;
+
+    /**
+     * Parses given simple or canonical name, and returns the object qualified name.
+     */
+    public static QualifiedName parse(String simpleOrCanonicalName) {
+        verifyObjectIdentifier(simpleOrCanonicalName);
+
+        Tokenizer tokenizer = new Tokenizer(simpleOrCanonicalName);
+
+        String schemaName = DEFAULT_SCHEMA_NAME;
+        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);
+        }
+
+        verifySchemaIdentifier(schemaName);
+        verifyObjectIdentifier(objectName);
+
+        return new QualifiedName(schemaName, objectName);
+    }
+
+    /**
+     * Resolves 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.
+     *
+     * @param schemaName Schema name or {@code null} for default schema.
+     * @param objectName Object name.
+     */
+    public static QualifiedName of(@Nullable String schemaName, String objectName) {
+        String schemaIdentifier = schemaName == null ? DEFAULT_SCHEMA_NAME : parseIdentifier(schemaName);
+        String objectIdentifier = parseIdentifier(objectName);
+
+        verifySchemaIdentifier(schemaIdentifier);
+        verifyObjectIdentifier(objectIdentifier);
+
+        return new QualifiedName(schemaIdentifier, objectIdentifier);
+    }
+
+    /**
+     * Constructs a qualified name.
+     *
+     * @param schemaName Normalized schema name.
+     * @param objectName Normalized object name.
+     */
+    private QualifiedName(String schemaName, String objectName) {
+        this.schemaIdentifier = schemaName;
+        this.objectIdentifier = objectName;
+    }
+
+    /** Returns normalized schema name. */
+    public String schemaName() {
+        return schemaIdentifier;
+    }
+
+    /** Returns normalized object name. */
+    public String objectName() {
+        return objectIdentifier;
+    }
+
+    /** Returns qualified name in canonical form. */
+    public String toCanonicalForm() {
+        // TODO https://issues.apache.org/jira/browse/IGNITE-24021 Extract method and move to IgniteNameUtils
+        return quoteIfNeeded(schemaIdentifier) + '.' + quoteIfNeeded(objectIdentifier);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public boolean equals(Object object) {
+        if (this == object) {
+            return true;
+        }
+        if (object == null || getClass() != object.getClass()) {
+            return false;
+        }
+        QualifiedName that = (QualifiedName) object;
+        return Objects.equals(schemaIdentifier, that.schemaIdentifier) && Objects.equals(objectIdentifier, that.objectIdentifier);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public int hashCode() {
+        return Objects.hash(schemaIdentifier, objectIdentifier);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public String toString() {
+        return "QualifiedName["
+                + "schemaName='" + schemaIdentifier + '\''
+                + ", objectName='" + objectIdentifier + '\''
+                + ']';
+    }
+
+    private static void verifyObjectIdentifier(@Nullable String identifier) {
+        Objects.requireNonNull(identifier);
+
+        if (identifier.isEmpty()) {
+            throw new IllegalArgumentException("Object identifier can't be empty.");
+        }
+    }
+
+    private static void verifySchemaIdentifier(@Nullable String identifier) {
+        if (identifier != null && identifier.isEmpty()) {
+            throw new IllegalArgumentException("Schema identifier can't be empty.");
+        }
+    }
+
+    /**
+     * Parse simple name: unquote name or cast to upper case not-quoted name.
+     *
+     * @param name String to parse object name.
+     * @return Unquoted name or name is cast to upper case. "tbl0" -&gt; "TBL0", "\"Tbl0\"" -&gt; "Tbl0".
+     */
+    // TODO https://issues.apache.org/jira/browse/IGNITE-24021: Use QualifiedName instead.
+    //  This method should be called from QualifiedName class only. Rename to parseIdentifier.
+    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("Fully qualified name is not expected [name=" + name + "]");
+        }
+
+        return parsedName;
+    }
+
+    /**
+     * Wraps the given name with double quotes if it not uppercased non-quoted name, e.g. "myColumn" -&gt; "\"myColumn\"", "MYCOLUMN" -&gt;
+     * "MYCOLUMN"
+     *
+     * @param identifier Object identifier.
+     * @return Quoted object name.
+     */
+    public static String quoteIfNeeded(String identifier) {

Review Comment:
   I prefer to keep it private until [IGNITE-24036](https://issues.apache.org/jira/browse/IGNITE-24036) will be implemented



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-24036 Sql schema. Introduce QualifiedName class [ignite-3]

Posted by "AMashenkov (via GitHub)" <gi...@apache.org>.
AMashenkov commented on code in PR #4971:
URL: https://github.com/apache/ignite-3/pull/4971#discussion_r1899523732


##########
modules/api/src/main/java/org/apache/ignite/table/QualifiedName.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.apache.ignite.lang.util.IgniteNameUtils.Tokenizer;
+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, when not set, then
+ * default schema name "PUBLIC" is used.
+ *
+ * <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 {
+    static final String DEFAULT_SCHEMA_NAME = "PUBLIC";

Review Comment:
   done



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-24036 Sql schema. Introduce QualifiedName class [ignite-3]

Posted by "AMashenkov (via GitHub)" <gi...@apache.org>.
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org